C++ Template Metaprogramming
Solutions to the exercises throughout the book
Loading...
Searching...
No Matches
exercise-4-2.hpp
Go to the documentation of this file.
1// ===-- chapter-4/exercise-4-2.hpp ----------------------- -*- C++ -*- --=== //
9#ifndef EXERCISE_4_2
10#define EXERCISE_4_2
11
13
14#include <boost/static_assert.hpp>
15#include <boost/mpl/bool.hpp>
16
17
34namespace exercise_4_2 {
35using namespace chapter4;
36
47template <
48 typename E1,
49 typename E2,
50 typename E3 = boost::mpl::false_,
51 typename E4 = boost::mpl::false_,
52 typename E5 = boost::mpl::false_>
54 : logical_or5<boost::mpl::bool_<E1::value>, E2, E3, E4, E5> { };
55
57template <typename E2, typename E3, typename E4, typename E5>
58struct logical_or5<boost::mpl::true_, E2, E3, E4, E5>
59{
60 static bool const value = true;
61};
63template <typename E2, typename E3, typename E4, typename E5>
64struct logical_or5<boost::mpl::false_, E2, E3, E4, E5>
66 boost::mpl::bool_<E2::value>, E2, E3, E4, boost::mpl::false_> { };
67
69template <typename E5>
71 boost::mpl::false_,
72 boost::mpl::false_,
73 boost::mpl::false_,
74 boost::mpl::false_,
75 E5>
76{
77 static bool const value = E5::value;
78};
79
80} // namespace exercise_4_2
81
82#endif // EXERCISE_4_2
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-2.
Short-circuit logical OR evaluation for up to five boolean values.