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

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

Namespaces

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

Functions

template<typename Target , typename Source >
Target polymorphic_downcast (Source *const x)
 Check the validity of a downcast.
 
template<typename Target , typename Source >
Target polymorphic_downcast (Source &x)
 Check the validity of a downcast.
 
template<typename Target , typename Source >
Target polymorphic_downcast (Source *const x)
 Check the validity of a downcast.
 
template<typename Target , typename Source >
Target polymorphic_downcast (Source &x)
 Check the validity of a downcast.
 

Detailed Description

Encapsulate solution for Exercise 2-2.

Function Documentation

◆ polymorphic_downcast() [1/4]

template<typename Target , typename Source >
Target exercise_2_2::polymorphic_downcast ( Source &  x)
inline

Check the validity of a downcast.

This method asserts (in debug builds only) that the downcast was legal. This overload accepts a reference type.

Template Parameters
TargetThe resulting type of the cast.
SourceThe input datatype (wihtout reference). Do not specify this explicitly: it should be deduced by the compiler.
Parameters
[in]xAn input reference type.
Returns
A dynamically casted instance from the source type.

Definition at line 75 of file exercise-2-2.hpp.

◆ polymorphic_downcast() [2/4]

template<typename Target , typename Source >
Target exercise_2_2::polymorphic_downcast ( Source *const  x)
inline

Check the validity of a downcast.

This method asserts (in debug builds only) that the downcast was legal. This overload accepts a pointer type.

Template Parameters
TargetThe resulting type of the cast.
SourceThe input datatype (wihtout pointer). Do not specify this explicitly: it should be deduced by the compiler.
Parameters
[in]xAn input pointer type.
Returns
A dynamically casted instance from the source type.

Definition at line 55 of file exercise-2-2.hpp.