August 2017
Intermediate to advanced
438 pages
14h 19m
English
In the first case, we need a human-readable type name without qualifiers. The Boost.TypeIndex library will help us out:
#include <iostream>#include <boost/type_index.hpp>template <class T>void do_something_again(const T& x) { if (x == 0) { std::cout << "x == 0. T is " << boost::typeindex::type_id<T>() << std::endl; } // ...}
In the second case, we need to keep the qualifiers, so we need to call a slightly different function from the same library:
#include <boost/type_index.hpp>void sample2() { auto&& x = 42; std::cout << "x is " << boost::typeindex::type_id_with_cvr<decltype(x)>() << std::endl;}
Read now
Unlock full access