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

Define a metafunction to replace types. More...

Files

file  c++20/exercise-2-1.hpp
 Solution to Exercise 2-1 (C++20).
 
file  exercise-2-1.hpp
 Solution to Exercise 2-1.
 

Namespaces

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

Functions

static void anonymous_namespace{chapter-2.cpp}::test_exercise_2_1 ()
 Tests for Exercise 2-1.
 

Detailed Description

Define a metafunction to replace types.

2-1. Write a ternary metafunction replace_type<c,x,y> that takes an arbitrary
     compound type c as its first parameter, and replaces all occurrences of
     a type x within c with y:

typedef replace_type<void*,void, int>::type t1; // int*
typedef replace_type<
    int const*[10]
    , int const
    , long
    >::type t2; // long*[10]
typedef replace_type<
    char& (*)(char&)
    , char&
    , long&
    >::type t3; // long& (*)(long&)

Function Documentation

◆ test_exercise_2_1()

static void anonymous_namespace{chapter-2.cpp}::test_exercise_2_1 ( )
static

Tests for Exercise 2-1.

Definition at line 92 of file chapter-2.cpp.