mirror of
https://github.com/paboyle/Grid.git
synced 2025-04-09 21:50:45 +01:00
Add function to return full type as std::string
Also works for nested templates. I find it useful for debugging. Possible usage: std::cout << "getTypename<AType>() = " << getTypename<Atype>() << std::endl; std::cout << "getTypename<decltype(AnInstance)>() = " << getTypename<decltype(AnInstance)>() << std::endl;
This commit is contained in:
parent
faf4278019
commit
1cb745c8dc
@ -23,6 +23,7 @@ Author: Christopher Kelly <ckelly@phys.columbia.edu>
|
|||||||
#define GRID_MATH_TRAITS_H
|
#define GRID_MATH_TRAITS_H
|
||||||
|
|
||||||
#include <type_traits>
|
#include <type_traits>
|
||||||
|
#include <cxxabi.h>
|
||||||
|
|
||||||
namespace Grid {
|
namespace Grid {
|
||||||
|
|
||||||
@ -288,6 +289,25 @@ namespace Grid {
|
|||||||
|
|
||||||
enum { value = sizeof(real_scalar_type)/sizeof(float) };
|
enum { value = sizeof(real_scalar_type)/sizeof(float) };
|
||||||
};
|
};
|
||||||
|
|
||||||
|
template<typename T> std::string getTypename() {
|
||||||
|
|
||||||
|
typedef typename std::remove_reference<T>::type TWoRef;
|
||||||
|
|
||||||
|
std::unique_ptr<char, void (*)(void *)> own(abi::__cxa_demangle(typeid(TWoRef).name(), nullptr, nullptr, nullptr), std::free);
|
||||||
|
|
||||||
|
std::string r = own != nullptr ? own.get() : typeid(TWoRef).name();
|
||||||
|
|
||||||
|
if(std::is_const<TWoRef>::value)
|
||||||
|
r += " const";
|
||||||
|
if(std::is_volatile<TWoRef>::value)
|
||||||
|
r += " volatile";
|
||||||
|
if(std::is_lvalue_reference<T>::value)
|
||||||
|
r += "&";
|
||||||
|
else if(std::is_rvalue_reference<T>::value)
|
||||||
|
r += "&&";
|
||||||
|
return r;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
x
Reference in New Issue
Block a user