C++ Template Metaprogramming
Solutions to the exercises throughout the book
Loading...
Searching...
No Matches
exercise-4-1.hpp
Go to the documentation of this file.
1// ===-- chapter-4/exercise-4-1.hpp ----------------------- -*- C++ -*- --=== //
9#ifndef EXERCISE_4_1
10#define EXERCISE_4_1
11
13
14#include <boost/static_assert.hpp>
15#include <boost/mpl/bool.hpp>
16
17
32namespace exercise_4_1 {
33using namespace chapter4;
34
45template <typename E1, typename E2>
46struct logical_or : logical_or<boost::mpl::bool_<E1::value>, E2> { };
47
49template <typename E2>
50struct logical_or<boost::mpl::true_, E2>
51{
52 static bool const value = true;
53};
55template <typename E2>
56struct logical_or<boost::mpl::false_, E2>
57{
58 static bool const value = E2::value;
59};
60
71template <typename E1, typename E2>
72struct logical_and : logical_and<boost::mpl::bool_<E1::value>, E2> { };
73
75template <typename E2>
76struct logical_and<boost::mpl::false_, E2>
77{
78 static bool const value = false;
79};
81template <typename E2>
82struct logical_and<boost::mpl::true_, E2>
83{
84 static bool const value = E2::value;
85};
86
87} // namespace exercise_4_1
88
89#endif // EXERCISE_4_1
Define some booleans that don't compile on either true or false.
Exists to inject functionality into the Boost namespace.
Provide utilities availble to all Chapter 4 solutions.
Encapsulate solution for Exercise 4-1.
Short-circuit logical OR evaluation of two boolean values.
Short-circuit logical OR evaluation of two boolean values.