1
+ /* *
2
+ * @file logger.hpp
3
+ * @author d.deka (https://ddeka0.github.io/)
4
+ * @brief
5
+ * @version 0.1
6
+ * @date 2021-02-14
7
+ *
8
+ */
9
+ #pragma once
10
+ #include < type_traits>
11
+ #include < typeinfo>
12
+ #ifndef _MSC_VER
13
+ # include < cxxabi.h>
14
+ #endif
15
+ #include < memory>
16
+ #include < string>
17
+ #include < cstdlib>
18
+ #include < iostream>
19
+ #include < utility>
20
+
21
+ #if defined(_MSC_VER)
22
+ #define PrintF std::cout << __FUNCSIG__ <<" " << __LINE__ << std::endl;
23
+ #else
24
+ #define PrintF std::cout << __PRETTY_FUNCTION__<<" " << __LINE__ << std::endl;
25
+ #endif
26
+
27
+
28
+ // https://stackoverflow.com/questions/29326460/how-to-make-a-variadic-macro-for-stdcout
29
+ inline void Log (){
30
+ // std::cout is not thread safe
31
+ std::cout << std::endl;
32
+ }
33
+
34
+ template <typename First, typename ...Rest>
35
+ void Log (First && first, Rest && ...rest) {
36
+ // std::cout is not thread safe
37
+ std::cout << std::forward<First>(first)<<" " ;
38
+ Log (std::forward<Rest>(rest)...);
39
+ }
40
+
41
+
42
+
43
+ // C++ language standard detection
44
+ #if (defined(__cplusplus) && __cplusplus >= 202002L) || (defined(_MSVC_LANG) && _MSVC_LANG >= 202002L) \
45
+ || (defined(__cplusplus) && __cplusplus >= 201703L ) || (defined(_HAS_CXX17) && _HAS_CXX17 == 1 )
46
+
47
+ #include < string_view>
48
+ #include < type_traits>
49
+
50
+ template <class T >
51
+ constexpr std::string_view type_name () {
52
+ using namespace std ;
53
+ #ifdef __clang__
54
+ string_view p = __PRETTY_FUNCTION__;
55
+ return string_view (p.data () + 34 , p.size () - 34 - 1 );
56
+ #elif defined(__GNUC__)
57
+ string_view p = __PRETTY_FUNCTION__;
58
+ # if __cplusplus < 201402
59
+ return string_view (p.data () + 36 , p.size () - 36 - 1 );
60
+ # else
61
+ return string_view (p.data () + 49 , p.find (' ;' , 49 ) - 49 );
62
+ # endif
63
+ #elif defined(_MSC_VER)
64
+ string_view p = __FUNCSIG__;
65
+ return string_view (p.data () + 84 , p.size () - 84 - 7 );
66
+ #endif
67
+ }
68
+
69
+ template <typename T>
70
+ struct refType {
71
+ static constexpr std::string_view type = (std::is_lvalue_reference<T>::value) > 0 ? " lvalue" :" ravlue" ;
72
+ };
73
+
74
+ #define getRefType (expr ) refType<decltype(expr)>::type
75
+
76
+ #define GetKeyTypeFromInternalLogic std::string
77
+ #define GetValueTypeFromInternalLogic int
78
+
79
+ #else
80
+
81
+
82
+ template <class T >
83
+ std::string
84
+ type_name ()
85
+ {
86
+ typedef typename std::remove_reference<T>::type TR;
87
+ std::unique_ptr<char , void (*)(void *)> own
88
+ (
89
+ #ifndef _MSC_VER
90
+ abi::__cxa_demangle (typeid (TR).name (), nullptr ,
91
+ nullptr , nullptr ),
92
+ #else
93
+ nullptr ,
94
+ #endif
95
+ std::free
96
+ );
97
+ std::string r = own != nullptr ? own.get () : typeid (TR).name ();
98
+ if (std::is_const<TR>::value)
99
+ r += " const" ;
100
+ if (std::is_volatile<TR>::value)
101
+ r += " volatile" ;
102
+ if (std::is_lvalue_reference<T>::value)
103
+ r += " &" ;
104
+ else if (std::is_rvalue_reference<T>::value)
105
+ r += " &&" ;
106
+ return r;
107
+ }
108
+
109
+ template <typename T>
110
+ struct refType {
111
+ static constexpr const char * type = (std::is_lvalue_reference<T>::value) > 0 ? " lvalue" :" ravlue" ;
112
+ };
113
+
114
+ #define getRefType (expr ) refType<decltype(expr)>::type
115
+
116
+ #define GetKeyTypeFromInternalLogic std::string
117
+ #define GetValueTypeFromInternalLogic int
118
+
119
+ #endif
120
+
121
+ #define BreakLine std::cout << std::endl << std::endl;
0 commit comments