DMRITool  v0.1.1-139-g860d86b4
Diffusion MRI Tool
utlTypeinfo.h
Go to the documentation of this file.
1 
11 #ifndef __utlTypeinfo_h
12 #define __utlTypeinfo_h
13 
14 
15 #include <type_traits>
16 #include <typeinfo>
17 
18 #include <complex>
19 #include <iostream>
20 #include <memory>
21 
22 #ifdef __GNUC__
23 #include <cstdlib>
24 #include <cxxabi.h>
25 #endif
26 
27 
28 namespace utl
29 {
30 
31 
32 template<bool B, class T, class F>
33 using conditional_t = typename ::std::conditional<B,T,F>::type;
34 
35 template<class T>
36 using remove_const_t = typename ::std::remove_const<T>::type;
37 
38 template<class T>
39 using remove_reference_t = typename ::std::remove_reference<T>::type;
40 
41 template<class T>
42 using remove_reference_t = typename ::std::remove_reference<T>::type;
43 
44 template<class... T>
45 using common_type_t = typename ::std::common_type<T...>::type;
46 
47 
55 template<typename T >
57  {
58  typedef conditional_t
59  <
60  std::is_same<T, std::complex<double>>::value, double,
62  >
64  };
65 
66 template<class T>
68 
69 template<typename T, typename t>
70 struct Superset
71  {
72  typedef conditional_t<sizeof(T) >= sizeof(t), T, t> type;
73  };
74 
75 template<class T, typename t>
77 
83 template<typename T, typename t>
85  {
86  static_assert(::std::is_scalar<T>::value
87  || ::std::is_same<T,std::complex<double>>::value
88  || ::std::is_same<T,std::complex<float>>::value, "T must be a scalar or std::complex<double> or std::complex<float>");
89  static_assert(::std::is_scalar<t>::value
90  || ::std::is_same<t,std::complex<double>>::value
91  || ::std::is_same<t,std::complex<float>>::value, "t must be a scalar or std::complex<double> or std::complex<float>");
92  typedef conditional_t<std::is_scalar<T>::value && std::is_scalar<t>::value, double, std::complex<double> > type;
93  };
94 
95 
96 
97 #ifdef __GNUC__
98 
105 inline std::string Demangle(const char *name)
106 {
107  int status = -1;
108  std::unique_ptr<char, void(*)(void*)> uptr { abi::__cxa_demangle(name, NULL, NULL, &status), std::free };
109  return status == 0 ? uptr.get() : name;
110 }
111 
112 #else
113 // TODO: support demangle for non-GCC compilers
114 inline std::string Demangle(const char *name)
115 {
116  return name;
117 }
118 #endif
119 
120 template<class T>
121 inline std::string TypeName()
122 {
123  return Demangle(typeid(T).name());
124 }
125 
126 template<class T>
127 inline std::string TypeName(const T&)
128 {
129  return TypeName<T>();
130 }
131 
132 
133 }
134 
135 
136 #endif
conditional_t< std::is_same< T, std::complex< double > >::value, double, conditional_t< std::is_same< T, std::complex< float > >::value, float, T > > type
Definition: utlTypeinfo.h:63
typename remove_complex< T >::type remove_complex_t
Definition: utlTypeinfo.h:67
std::string TypeName()
Definition: utlTypeinfo.h:121
float type which can be coverted to
Definition: utlTypeinfo.h:84
typename::std::common_type< T... >::type common_type_t
Definition: utlTypeinfo.h:45
typename::std::remove_reference< T >::type remove_reference_t
Definition: utlTypeinfo.h:39
typename Superset< T, t >::type superset_t
Definition: utlTypeinfo.h:76
Definition: utl.h:90
std::string Demangle(const char *name)
Definition: utlTypeinfo.h:114
Remove complex:
Definition: utlTypeinfo.h:56
typename::std::conditional< B, T, F >::type conditional_t
Definition: utlTypeinfo.h:33
typename::std::remove_const< T >::type remove_const_t
Definition: utlTypeinfo.h:36
conditional_t< std::is_scalar< T >::value &&std::is_scalar< t >::value, double, std::complex< double > > type
Definition: utlTypeinfo.h:88