S
Stefan Ram
They have several type traits in C++. But what I often have
been missing for decades is a means to print the type of an
expression. Why do they not have a trait for a name of at
least the most common types?
#include <iostream>
#include <ostream>
template< typename T >struct type_name
{ static const bool is_specialization = false; };
template<> struct type_name< int >
{ static const bool is_specialization = true;
static constexpr char const * text = "int"; };
template<> struct type_name< long >
{ static const bool is_specialization = true;
static constexpr char const * text = "long"; };
int main()
{ { int i; ::std::cout << type_name< decltype( i )>::text << '\n'; }
{ long i; ::std::cout << type_name< decltype( i )>::text << '\n'; }}
prints
int
long
been missing for decades is a means to print the type of an
expression. Why do they not have a trait for a name of at
least the most common types?
#include <iostream>
#include <ostream>
template< typename T >struct type_name
{ static const bool is_specialization = false; };
template<> struct type_name< int >
{ static const bool is_specialization = true;
static constexpr char const * text = "int"; };
template<> struct type_name< long >
{ static const bool is_specialization = true;
static constexpr char const * text = "long"; };
int main()
{ { int i; ::std::cout << type_name< decltype( i )>::text << '\n'; }
{ long i; ::std::cout << type_name< decltype( i )>::text << '\n'; }}
prints
int
long