repr 0.1
Reconstructable string representations and more
Loading...
Searching...
No Matches
type_info.h
Go to the documentation of this file.
1#pragma once
2#include <iosfwd>
3#include <string>
4#include <string_view>
5
8#include <librepr/name/type.h>
9namespace librepr {
10
11template <typename T>
12struct TypeName {
14
15 /* implicit */ operator std::string() const noexcept { // NOLINT
16 return to_string();
17 }
18
19 friend std::ostream& operator<<(std::ostream& ctx, TypeName<T> const& obj) { return ctx << obj.to_string(); }
21 return ctx << obj.to_string();
22 }
23};
24} // namespace librepr
25
26namespace librepr::detail {
27template <class CharT>
28using StrFormatter = REPR_FORMAT_NS::formatter<std::string, CharT>;
29} // namespace librepr::detail
30
31// REPR_FORMAT_NS::format support for librepr::TypeName<T>{} and nameof<T>
32template <class T, class CharT>
33struct REPR_FORMAT_RNS::formatter<librepr::TypeName<T>, CharT> : librepr::detail::StrFormatter<CharT> { // NOLINT
34 auto format(librepr::TypeName<T> const& obj, auto& ctx) const {
36 }
37};
Definition assert.h:89
REPR_FORMAT_NS::formatter< std::string, CharT > StrFormatter
Definition type_info.h:28
Definition ctvi/ctvi.h:9
std::string code_for()
Definition repr:39
auto format(librepr::TypeName< T > const &obj, auto &ctx) const
Definition type_info.h:34
Definition type_info.h:12
friend detail::StringBuffer & operator<<(detail::StringBuffer &ctx, TypeName< T > const &obj)
Definition type_info.h:20
friend std::ostream & operator<<(std::ostream &ctx, TypeName< T > const &obj)
Definition type_info.h:19
static std::string to_string() noexcept
Definition type_info.h:13
Wrapper around std::string.
Definition buffer.h:14