C++ Template Metaprogramming
Solutions to the exercises throughout the book
Loading...
Searching...
No Matches
exercise-3-0.hpp
Go to the documentation of this file.
1
// ===-- chapter-3/exercise-3-0.hpp ----------------------- -*- C++ -*- --=== //
9
#ifndef EXERCISE_3_0
10
#define EXERCISE_3_0
11
12
#include <boost/static_assert.hpp>
13
14
29
namespace
exercise_3_0
{
30
36
template
<
unsigned
long
N>
37
struct
checked_binary
38
{
39
BOOST_STATIC_ASSERT
(((N % 10) < 2));
40
41
static
unsigned
const
value
=
42
(
checked_binary
<N/10>
::value
* 2) + (N % 10);
43
};
44
46
template
<>
47
struct
checked_binary
<0>
48
{
49
static
unsigned
const
value
= 0;
50
};
51
52
}
// namespace exercise_3_0
53
54
#endif
// EXERCISE_3_0
exercise_3_0
Encapsulate solution for Exercise 3-0.
Definition:
c++20/exercise-3-0.hpp:15
exercise_3_0::checked_binary
Compile-time binary to decimal number translation.
Definition:
exercise-3-0.hpp:38
exercise_3_0::checked_binary::BOOST_STATIC_ASSERT
BOOST_STATIC_ASSERT(((N % 10)< 2))
exercise_3_0::checked_binary::value
static unsigned const value
Definition:
exercise-3-0.hpp:41
chapter-3
exercise-3-0.hpp
Generated on Fri Mar 8 2024 12:11:47 for C++ Template Metaprogramming by
1.9.6