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

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

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 &)
 

Detailed Description

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

Function Documentation

◆ error_unhandled_type()

template<typename T >
consteval T * exercise_2_4::cpp20::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.

Definition at line 51 of file c++20/exercise-2-4.hpp.

◆ operator<<()

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

Definition at line 54 of file c++20/exercise-2-4.hpp.