C++ Template Metaprogramming
Solutions to the exercises throughout the book
Loading...
Searching...
No Matches
exercise-2-5.hpp
Go to the documentation of this file.
1
// ===-- chapter-2/exercise-2-5.hpp ----------------------- -*- C++ -*- --=== //
9
#ifndef EXERCISE_2_5
10
#define EXERCISE_2_5
11
12
#include <iostream>
13
14
35
namespace
exercise_2_5
{
36
41
template
<
typename
T>
struct
type_descriptor_eng
{ };
42
44
// Non-leaf data-types:
46
47
template
<
typename
T>
48
std::ostream&
operator<<
(std::ostream& os,
type_descriptor_eng<T const>
const
&)
49
{
50
return
os <<
"const "
<<
type_descriptor_eng<T>
();
51
}
52
template
<
typename
T>
53
std::ostream&
operator<<
(std::ostream& os,
type_descriptor_eng<T&>
const
&)
54
{
55
return
os <<
"reference to "
<<
type_descriptor_eng<T>
();
56
}
57
template
<
typename
T>
58
std::ostream&
operator<<
(std::ostream& os,
type_descriptor_eng<T*>
const
&)
59
{
60
return
os <<
"pointer to "
<<
type_descriptor_eng<T>
();
61
}
62
template
<
typename
T>
63
std::ostream&
operator<<
(std::ostream& os,
type_descriptor_eng
<T[]>
const
&)
64
{
65
return
os <<
"array of "
<<
type_descriptor_eng<T>
();
66
}
67
template
<
typename
T,
size_t
N>
68
std::ostream&
operator<<
(std::ostream& os,
type_descriptor_eng
<T[N]>
const
&)
69
{
70
return
os << N <<
" element array of "
<<
type_descriptor_eng<T>
();
71
}
72
template
<
typename
T>
73
std::ostream&
operator<<
(std::ostream& os,
type_descriptor_eng
<T()>
const
&)
74
{
75
return
os <<
"function returning "
<<
type_descriptor_eng<T>
();
76
}
77
template
<
typename
T>
78
std::ostream&
operator<<
(std::ostream& os,
type_descriptor_eng
<T(*)()>
const
&)
79
{
80
return
os <<
"pointer to function returning "
<<
type_descriptor_eng<T>
();
81
}
82
84
// Leaf data-types:
86
87
std::ostream&
operator<<
(std::ostream& os,
type_descriptor_eng<char>
const
&)
88
{
return
os <<
"char"
; }
89
std::ostream&
operator<<
(std::ostream& os,
type_descriptor_eng<short>
const
&)
90
{
return
os <<
"short int"
; }
91
std::ostream&
operator<<
(std::ostream& os,
type_descriptor_eng<int>
const
&)
92
{
return
os <<
"int"
; }
93
std::ostream&
operator<<
(std::ostream& os,
type_descriptor_eng<long>
const
&)
94
{
return
os <<
"long int"
; }
95
96
}
// namespace exercise_2_5
97
98
#endif
// EXERCISE_2_5
exercise_2_5::cpp20::operator<<
std::ostream & operator<<(std::ostream &os, type_descriptor_eng< T > const &)
Definition:
c++20/exercise-2-5.hpp:36
exercise_2_5
Encapsulate solution for Exercise 2-5.
Definition:
c++20/exercise-2-5.hpp:23
exercise_2_5::type_descriptor_eng
Display data-types in English wording.
Definition:
exercise-2-5.hpp:41
chapter-2
exercise-2-5.hpp
Generated on Fri Mar 8 2024 12:11:47 for C++ Template Metaprogramming by
1.9.6