MPL11
 All Classes Namespaces Files Typedefs Macros Groups Pages
bitwise.hpp
Go to the documentation of this file.
1 
12 #ifndef BOOST_MPL11_BITWISE_HPP
13 #define BOOST_MPL11_BITWISE_HPP
14 
16 
17 #include <boost/mpl11/bool.hpp>
18 #include <boost/mpl11/core.hpp>
21 #include <boost/mpl11/integer.hpp> // required by fwd/bitwise.hpp
22 
23 
24 namespace boost { namespace mpl11 {
25  template <typename Left, typename Right, typename>
26  struct Bitwise : false_ { };
27 
28  template <typename x1, typename x2, typename ...xn>
29  struct bitand_
30  : detail::left_folds::variadic<bitand_, x1, x2, xn...>
31  { };
32 
33  template <typename x, typename y>
34  struct bitand_<x, y> :
35  Bitwise<
36  typename datatype<typename x::type>::type,
37  typename datatype<typename y::type>::type
38  >::template bitand_impl<typename x::type, typename y::type>
39  { };
40 
41 
42  template <typename x1, typename x2, typename ...xn>
43  struct bitor_
44  : detail::left_folds::variadic<bitor_, x1, x2, xn...>
45  { };
46 
47  template <typename x, typename y>
48  struct bitor_<x, y> :
49  Bitwise<
50  typename datatype<typename x::type>::type,
51  typename datatype<typename y::type>::type
52  >::template bitor_impl<typename x::type, typename y::type>
53  { };
54 
55 
56  template <typename x1, typename x2, typename ...xn>
57  struct bitxor
58  : detail::left_folds::variadic<bitxor, x1, x2, xn...>
59  { };
60 
61  template <typename x, typename y>
62  struct bitxor<x, y> :
63  Bitwise<
64  typename datatype<typename x::type>::type,
65  typename datatype<typename y::type>::type
66  >::template bitxor_impl<typename x::type, typename y::type>
67  { };
68 
69  namespace bitwise_detail {
70  template <typename x, typename n>
71  struct lshift_checks {
72  static_assert(n::type::value >= 0,
73  "Invalid usage of `shift_left` with a negative shift.");
74  };
75 
76  template <typename x, typename n>
77  struct rshift_checks {
78  static_assert(n::type::value >= 0,
79  "Invalid usage of `shift_right` with a negative shift.");
80  };
81  }
82 
83  template <typename x, typename n>
84  struct shift_left :
85  BOOST_MPL11_IF_ASSERTIONS(bitwise_detail::lshift_checks<x, n>,)
86  Bitwise<typename datatype<typename x::type>::type>::
87  template shift_left_impl<typename x::type, n>
88  { };
89 
90  template <typename x, typename n>
91  struct shift_right :
92  BOOST_MPL11_IF_ASSERTIONS(bitwise_detail::rshift_checks<x, n>,)
93  Bitwise<typename datatype<typename x::type>::type>::
94  template shift_right_impl<typename x::type, n>
95  { };
96 
97  template <typename x>
98  struct compl_ :
99  Bitwise<typename datatype<typename x::type>::type>::
100  template compl_impl<typename x::type>
101  { };
102 }} // end namespace boost::mpl11
103 
104 #endif // !BOOST_MPL11_BITWISE_HPP
Bitwise left shift (<<).
Definition: bitwise.hpp:84
Defines the Integer datatype.
Bitwise right shift (>>).
Definition: bitwise.hpp:91
Bitwise and (&&).
Definition: bitwise.hpp:29
Bitwise or (||).
Definition: bitwise.hpp:43
Bitwise xor (^).
Definition: bitwise.hpp:57
Manages configurable options of the library and defines utility macros.
Forward declares the Bitwise typeclass.
Defines the Core module.
Defines boost::mpl11::detail::left_folds::variadic.
#define BOOST_MPL11_IF_ASSERTIONS(...)
Macro expanding to its argument(s) if BOOST_MPL11_NO_ASSERTIONS is not defined, and to nothing otherw...
Definition: config.hpp:72
Bitwise complement (~).
Definition: bitwise.hpp:98
Recursive alias-based variadic left fold.
Definition: variadic_aliased.hpp:111
Forwards to boost/mpl11/integer.hpp.