- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 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
- 50
- 51
- 52
#include <typeinfo>
#include <string>
#include <iostream>
using namespace std::literals::string_literals;
using std::cout;
#if defined(__GNUG__) || defined(__clang__)
#include <cxxabi.h>
template <typename T>
std::string get_real_type() {
int status;
char *real_name = abi::__cxa_demangle(typeid(T).name(), nullptr, nullptr, &status);
return (status == 0 ? std::string(real_name) : ("(not demangled)"s + typeid(T).name()));
}
#else
template <typename T>
std::string get_real_type() {
return typeid(T).name();
}
#endif
template <typename T>
struct overload_generator {
std::string get_type_impl() {
return get_real_type<T>();
}
};
template <typename... Ts>
struct printer : overload_generator<Ts>...
{
using overload_generator<Ts>::get_type_impl...;
template<typename T>
void println_type() {
cout << overload_generator<T>::get_type_impl() << '\n';
}
template <typename... Us>
void println_types() {
println_types_impl((std::string(overload_generator<Us>::get_type_impl()) + "\n")...);
}
private:
template <typename... Us>
void println_types_impl(Us... args) {
(cout << ... << args);
}
};
int main() {
auto pr = printer<int,long,decltype(nullptr)>();
pr.println_type<long>();
pr.println_types<long, decltype(nullptr),int>();
}