22#if __cplusplus >= 202002L
34#include <boost/type_traits/is_same.hpp>
51static char const *
demangle(
char const *
const name)
53 static char buf[1024];
55 size_t size =
sizeof(buf)/
sizeof(*buf);
58 char const *
const res = abi::__cxa_demangle(name, buf, &size, &status);
59 return status != 0 ? NULL : res;
72 std::cout <<
"Neither x: " << x <<
", nor y: " << y
73 <<
" are interesting.\n";
76 boost::is_same<add_const_ref<int>::type,
int const&>::value <<
'\n';
78 boost::is_same<add_const_ref<int&>::type,
int&>::value <<
'\n';
80 boost::is_same<add_const_ref<int&>::type,
int const&>::value <<
'\n';
114 long& (*)(
long&)>::value
116# if __cplusplus >= 202002L
119 replace_type<
char& (*)(
char&,
int,
char*),
char&,
long&>::type,
120 long& (*)(
long&,
int,
char*)>::value
124 replace_type<
float& (*)(
char&,
float*,
float,
float[5]),
126 long& (*)(
char&,
long*,
long,
long[5])>::value
134 long& (*)(
long&)>::value
148 TestB *b_ptr = polymorphic_downcast<TestB*>(a_ptr);
150 std::cout <<
"Address of b_ptr = " <<
static_cast<void*
>(b_ptr) <<
'\n';
153 TestB& b_ref = polymorphic_downcast<TestB&>(a_ref);
154 std::cout <<
"Address of b_ref = " <<
static_cast<void*
>(&b_ref) <<
'\n';
174 std::cout << type_descriptor<int>() <<
'\n';
177 std::cout << type_descriptor<char*>() <<
'\n';
180 std::cout << type_descriptor<short[5]>() <<
'\n';
183 std::cout << type_descriptor<long const*&>() <<
'\n';
186 std::cout << type_descriptor<char*()>() <<
'\n';
189 std::cout << type_descriptor<char*(*)()>() <<
'\n';
199 std::cout << type_descriptor_eng<char*(*[])()>() <<
'\n';
208 std::cout <<
demangle(
typeid(
int*).name()) <<
'\n';
Solution to Exercise 2-1 (C++20).
Solution to Exercise 2-2 (C++20).
Solution to Exercise 2-4 (C++20).
Solution to Exercise 2-5 (C++20).
Solution to Exercise 2-0.
Solution to Exercise 2-1.
Solution to Exercise 2-2.
Solution to Exercise 2-3.
Solution to Exercise 2-4.
Solution to Exercise 2-5.
static void test_exercise_2_0()
Tests for Exercise 2-0.
static void test_exercise_2_1()
Tests for Exercise 2-1.
static void test_exercise_2_2()
Tests for Exercise 2-2.
static void test_exercise_2_3()
Tests for Exercise 2-3.
static void test_exercise_2_4()
Tests for Exercise 2-4.
static void test_exercise_2_5()
Tests for Exercise 2-5.
static char const * demangle(char const *const name)
Encapsulate solution for Exercise 2-0.
Encapsulate solution for Exercise 2-1.
Encapsulate solution for Exercise 2-2.
Encapsulate solution for Exercise 2-4.
Encapsulate solution for Exercise 2-5.
Given an arbitrary compound type, replace nested types.