repr 0.1
Reconstructable string representations and more
Loading...
Searching...
No Matches
type.h
Go to the documentation of this file.
1#pragma once
2#include <cstddef>
3#include <sstream>
4#include <string>
5#include <string_view>
6#include <type_traits>
7#include <typeinfo>
8#include <utility>
9
13#include "ctti.h"
14#include "rtti.h"
15
16namespace librepr {
17template <typename T>
19
20namespace detail {
21
22template <typename T>
25 constexpr static bool is_templated = false;
26};
27
28template <template <typename...> typename U, typename... Ts>
29struct TemplateInfo<U<Ts...>> {
30 using type = U<Ts...>;
31 using arguments = TypeList<Ts...>;
32 constexpr static bool is_templated = true;
33
34private:
35 template <std::size_t... Idx>
36 consteval static auto get_min_required(std::index_sequence<Idx...> seq) -> std::size_t {
37 if constexpr (requires {
38 typename U<typename arguments::template get<Idx>...>; // pack::rebox<arguments::head<Idx>, U>
40 }) {
41 if constexpr (sizeof...(Idx) == 0) {
42 return 0;
43 } else {
44 return get_min_required(std::make_index_sequence<seq.size() - 1>());
45 }
46 }
47 return seq.size() + 1;
48 }
49 constexpr static auto required_amount = get_min_required(std::make_index_sequence<sizeof...(Ts)>());
50
51public:
52 using required = typename arguments::template head<required_amount>;
53 using defaulted = typename arguments::template tail<required_amount>;
54
55 static std::string name() {
57
58 auto marker = full.find('<');
59 if (marker == full.npos) {
60 return full;
61 }
62
63 return REPR_FORMAT("{}<{}>", std::string_view(full.data(), marker), format_template_arguments());
64 }
65
67 constexpr static auto argument_count = USING(REPR_DEFAULT_TEMPLATE_ARGUMENTS) ? sizeof...(Ts) : required_amount;
68
69 return []<std::size_t... Idx>(std::index_sequence<Idx...>) {
70 const char* sep = "";
72
74 return out.str();
76 }
77};
78
79} // namespace detail
80
81template <typename T>
82char const* get_mangled_name() {
83#if USING(LIBREPR_COMPILER_MSVC)
84 return typeid(T).raw_name();
85#else
86 return typeid(T).name();
87#endif
88}
89
90template <typename T>
94} // namespace librepr
#define REPR_FORMAT(...)
#define REPR_DEFAULT_TEMPLATE_ARGUMENTS
Definition default.h:42
#define USING(operation)
Definition feature.h:2
T is_same_v
Definition ctvi/ctvi.h:9
std::string code_for()
Definition repr:39
char const * get_mangled_name()
Definition type.h:82
std::string get_name()
Definition type.h:91
Definition list.h:64
typename arguments::template head< required_amount > required
Definition type.h:52
static std::string format_template_arguments()
Definition type.h:66
typename arguments::template tail< required_amount > defaulted
Definition type.h:53
U< Ts... > type
Definition type.h:30
static std::string name()
Definition type.h:55
Definition type.h:23
static std::string name()
Definition type.h:24
static constexpr bool is_templated
Definition type.h:25