C++ Template Metaprogramming
Solutions to the exercises throughout the book
Loading...
Searching...
No Matches
exercise_2_4 Namespace Reference

Encapsulate solution for Exercise 2-4. More...

Namespaces

namespace  cpp20
 Encapsulate solution for Exercise 2-4 (C++20).
 

Classes

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

Functions

template<typename T >
consteval T * error_unhandled_type ()
 Produce a compile-time failure for an "unhandled" type.
 
template<typename T >
std::ostream & operator<< (std::ostream &os, type_descriptor< T > const &)
 
template<typename T >
consteval T * error_unhandled_type ()
 Produce a compile-time failure for an "unhandled" type.
 
template<typename T >
std::ostream & operator<< (std::ostream &os, type_descriptor< T const > const &)
 
template<typename T >
std::ostream & operator<< (std::ostream &os, type_descriptor< T & > const &)
 
template<typename T >
std::ostream & operator<< (std::ostream &os, type_descriptor< T * > const &)
 
template<typename T , size_t N>
std::ostream & operator<< (std::ostream &os, type_descriptor< T[N]> const &)
 
template<typename T >
std::ostream & operator<< (std::ostream &os, type_descriptor< T()> const &)
 
template<typename T >
std::ostream & operator<< (std::ostream &os, type_descriptor< T(*)()> const &)
 
std::ostream & operator<< (std::ostream &os, type_descriptor< char > const &)
 
std::ostream & operator<< (std::ostream &os, type_descriptor< short > const &)
 
std::ostream & operator<< (std::ostream &os, type_descriptor< int > const &)
 
std::ostream & operator<< (std::ostream &os, type_descriptor< long > const &)
 

Detailed Description

Encapsulate solution for Exercise 2-4.

Function Documentation

◆ error_unhandled_type() [1/2]

template<typename T >
consteval T * exercise_2_4::error_unhandled_type ( )

Produce a compile-time failure for an "unhandled" type.

The purpose of this is to induce a compilation error that indicates the type (T) that was not handled in the constexpr-if cases for operator<<.

Template Parameters
TThe type that was "unhandled."
Returns
This function always returns nullptr.
Todo:
Already defined in Exercise 2-4.

Definition at line 19 of file c++20/exercise-2-5.hpp.

◆ operator<<() [1/11]

std::ostream & exercise_2_4::operator<< ( std::ostream &  os,
type_descriptor< char > const &   
)

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

◆ operator<<() [2/11]

std::ostream & exercise_2_4::operator<< ( std::ostream &  os,
type_descriptor< int > const &   
)

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

◆ operator<<() [3/11]

std::ostream & exercise_2_4::operator<< ( std::ostream &  os,
type_descriptor< long > const &   
)

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

◆ operator<<() [4/11]

std::ostream & exercise_2_4::operator<< ( std::ostream &  os,
type_descriptor< short > const &   
)

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

◆ operator<<() [5/11]

template<typename T >
std::ostream & exercise_2_4::operator<< ( std::ostream &  os,
type_descriptor< T & > const &   
)

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

◆ operator<<() [6/11]

template<typename T >
std::ostream & exercise_2_4::operator<< ( std::ostream &  os,
type_descriptor< T * > const &   
)

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

◆ operator<<() [7/11]

template<typename T >
std::ostream & exercise_2_4::operator<< ( std::ostream &  os,
type_descriptor< T const > const &   
)

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

◆ operator<<() [8/11]

template<typename T >
std::ostream & exercise_2_4::operator<< ( std::ostream &  os,
type_descriptor< T()> const &   
)

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

◆ operator<<() [9/11]

template<typename T >
std::ostream & exercise_2_4::operator<< ( std::ostream &  os,
type_descriptor< T(*)()> const &   
)

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

◆ operator<<() [10/11]

template<typename T , size_t N>
std::ostream & exercise_2_4::operator<< ( std::ostream &  os,
type_descriptor< T[N]> const &   
)

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