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
29namespace exercise_3_0 {
30
36template <unsigned long N>
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
46template<>
48{
49 static unsigned const value = 0;
50};
51
52} // namespace exercise_3_0
53
54#endif // EXERCISE_3_0
Encapsulate solution for Exercise 3-0.
Compile-time binary to decimal number translation.
BOOST_STATIC_ASSERT(((N % 10)< 2))
static unsigned const value