-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtype_name.hpp
49 lines (43 loc) · 1.44 KB
/
type_name.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#pragma once
#include <cstdint>
#include <type_traits>
namespace BasicLog_detail
{
// static_assert(sizeof(long double) == 128 / 8 && "assumed long double size");
static_assert(sizeof(double) == 64 / 8 && "assumed double size");
static_assert(sizeof(float) == 32 / 8 && "assumed float size");
static_assert(sizeof(bool) == 8 / 8 && "assumed bool size");
static_assert(sizeof(char) == 8 / 8 && "assumed char size");
// fallback to a compiler error if there is no specialization for T
template <typename T>
struct type_name
{
static_assert(std::is_same_v<void, T> && "type not supported");
};
// list of c++ name, my name
#define X_LIST_BASICLOG_TYPES \
X(double, float64) \
X(float, float32) \
X(bool, bool) \
X(char, char) \
X(int8_t, int8) \
X(int16_t, int16) \
X(int32_t, int32) \
X(int64_t, int64) \
X(uint8_t, uint8) \
X(uint16_t, uint16) \
X(uint32_t, uint32) \
X(uint64_t, uint64)
// for each type,name in the list define a specialization that looks like:
#define X(type, name) \
template <> \
struct type_name<type> \
{ \
static constexpr char value[] = #name; \
};
X_LIST_BASICLOG_TYPES
#undef X
#undef X_LIST_TYPES
}
template <typename T>
constexpr auto type_name_v = BasicLog_detail::type_name<T>::value;