C++ Template Metaprogramming
Solutions to the exercises throughout the book
Loading...
Searching...
No Matches
exercise_2_4::type_descriptor< T > Struct Template Reference

Print (a limited set of) data-types. More...

#include <exercise-2-4.hpp>

Detailed Description

template<typename T>
struct exercise_2_4::type_descriptor< T >

Print (a limited set of) data-types.

When an instance of this type is streamed, the data-type of the template parameter should be printed.

Template Parameters
TThe data-type to describe to an output stream.
Precondition
type_descriptor's template parameter is limited to compound types built from the following integral types: char, short int, int, and long int.
Note
The real work is done by free functions. This allows us to claim almost no runtime overhead, as types are traversed recursively at compile time and printed directly without needing to build a run-time data strucutre. Interestingly, I've asked this question on a few interviews, and people almost always try to construct a std::string member within type_descriptor for printing.

Definition at line 50 of file exercise-2-4.hpp.


The documentation for this struct was generated from the following file: