Templa 0.0.1-alpha
C++ Metaprogramming Utilities
Loading...
Searching...
No Matches
type_info.hpp
Go to the documentation of this file.
1#pragma once
2#include <iostream>
3#include <cstdint>
8
12
17namespace templa::type_info
18{
19
27 template <typename T>
28 struct name_of
29 {
31 static constexpr auto value = "";
32 };
33
35 template <>
36 struct name_of<int>
37 {
38 static constexpr auto value = "int";
39 };
40
42 template <>
43 struct name_of<char>
44 {
45 static constexpr auto value = "char";
46 };
47
49 template <>
50 struct name_of<float>
51 {
52 static constexpr auto value = "float";
53 };
54
56 template <>
57 struct name_of<long>
58 {
59 static constexpr auto value = "long";
60 };
61
63 template <>
64 struct name_of<void>
65 {
66 static constexpr auto value = "void";
67 };
68
70 template <>
71 struct name_of<std::uint8_t>
72 {
73 static constexpr auto value = "uint8_t";
74 };
75
77 template <>
78 struct name_of<std::uint16_t>
79 {
80 static constexpr auto value = "uint16_t";
81 };
82
84 template <>
85 struct name_of<std::uint64_t>
86 {
87 static constexpr auto value = "uint64_t";
88 };
89
91 template <>
92 struct name_of<std::uint32_t>
93 {
94 static constexpr auto value = "uint32_t";
95 };
96
104 template <typename T>
106 {
116 constexpr static std::string stringify()
117 {
118 if constexpr (std::is_const_v<T>)
119 {
121 }
122 if constexpr (std::is_pointer_v<T>)
123 {
125 }
126 if constexpr (std::is_reference_v<T>)
127 {
129 }
130
131 return name_of<T>::value;
132 };
133 };
134
139 namespace ctti
140 {
148 template <typename C>
149 struct hash_t
150 {
151 private:
153 constexpr static int _var{0};
154
155 public:
157 constexpr static auto id{&_var};
158 };
159 }
160
161}
Compile-time type identification utilities.
Generates a unique type identifier for a type C at compile time.
Definition type_info.hpp:150
Primary template to get the string name of a type.
Definition type_info.hpp:29
static constexpr auto value
String literal representing the name of the type T.
Definition type_info.hpp:31
Provides a human-readable string description of the type T, including qualifiers and pointers.
Definition type_info.hpp:106
static constexpr std::string stringify()
Returns a string describing the type T.
Definition type_info.hpp:116