MPL11
 All Classes Namespaces Files Typedefs Macros Groups Pages
integer.hpp
Go to the documentation of this file.
1 
12 #ifndef BOOST_MPL11_INTEGER_HPP
13 #define BOOST_MPL11_INTEGER_HPP
14 
16 
17 #include <boost/mpl11/bitwise.hpp>
21 #include <boost/mpl11/group.hpp>
23 #include <boost/mpl11/logical.hpp>
24 #include <boost/mpl11/monoid.hpp>
26 #include <boost/mpl11/ring.hpp>
27 
28 
29 namespace boost { namespace mpl11 {
30  template <typename T, T ...v>
31  struct or_<integer_c<T, v>...>
32  : detail::logical_or::strict<bool_<(bool)v>...>
33  { };
34 
35  template <typename T, T ...v>
36  struct and_<integer_c<T, v>...> // DeMorgan
37  : bool_<!detail::logical_or::strict<bool_<!v>...>::value>
38  { };
39 
40 
41  template <>
42  struct Monoid<Integer> : instantiate<Monoid>::with<Integer> {
43  template <typename x, typename y>
44  using plus_impl = integer_c<
45  decltype(x::value + y::value),
46  x::value + y::value
47  >;
48 
49  template <typename ...>
50  using zero_impl = int_<0>;
51  };
52 
53  template <>
54  struct Group<Integer> : instantiate<Group>::with<Integer> {
55  template <typename x, typename y>
56  using minus_impl = integer_c<
57  decltype(x::value - y::value),
58  x::value - y::value
59  >;
60 
61  template <typename x>
62  using negate_impl = integer_c<
63  decltype(-x::value),
64  -x::value
65  >;
66  };
67 
68  template <>
69  struct Ring<Integer> : instantiate<Ring>::with<Integer> {
70  template <typename x, typename y>
71  using mult_impl = integer_c<
72  decltype(x::value * y::value),
73  x::value * y::value
74  >;
75 
76  template <typename ...>
77  using one_impl = int_<1>;
78  };
79 
80  template <>
81  struct IntegralDomain<Integer>
82  : instantiate<IntegralDomain>::with<Integer>
83  {
84  template <typename x, typename y>
85  using div_impl = integer_c<
86  decltype(x::value / y::value),
87  x::value / y::value
88  >;
89 
90  template <typename x, typename y>
91  using mod_impl = integer_c<
92  decltype(x::value % y::value),
93  x::value % y::value
94  >;
95  };
96 
97  template <>
98  struct Enumerable<Integer> : instantiate<Enumerable>::with<Integer> {
99  template <typename x>
100  using succ_impl = integer_c<
101  decltype(x::value + 1),
102  x::value + 1
103  >;
104 
105  template <typename x>
106  using pred_impl = integer_c<
107  decltype(x::value - 1),
108  x::value - 1
109  >;
110  };
111 
112  template <>
113  struct Comparable<Integer> : instantiate<Comparable>::with<Integer> {
114  template <typename x, typename y>
115  using equal_impl = bool_<x::value == y::value>;
116 
117  template <typename x, typename y>
118  using not_equal_impl = bool_<x::value != y::value>;
119  };
120 
121  template <>
122  struct Orderable<Integer> : instantiate<Orderable>::with<Integer> {
123  template <typename x, typename y>
124  using less_impl = bool_<(x::value < y::value)>;
125 
126  template <typename x, typename y>
127  using less_equal_impl = bool_<(x::value <= y::value)>;
128 
129  template <typename x, typename y>
130  using greater_impl = bool_<(x::value > y::value)>;
131 
132  template <typename x, typename y>
133  using greater_equal_impl = bool_<(x::value >= y::value)>;
134 
135  template <typename x, typename y>
136  using max_impl = if_c<(x::value < y::value), y, x>;
137 
138  template <typename x, typename y>
139  using min_impl = if_c<(x::value < y::value), x, y>;
140  };
141 
142  template <>
143  struct Bitwise<Integer> : instantiate<Bitwise>::with<Integer> {
144  template <typename x, typename y>
145  using bitand_impl = integer_c<
146  decltype(x::value & y::value),
147  x::value & y::value
148  >;
149 
150  template <typename x, typename y>
151  using bitor_impl = integer_c<
152  decltype(x::value | y::value),
153  x::value | y::value
154  >;
155 
156  template <typename x, typename y>
157  using bitxor_impl = integer_c<
158  decltype(x::value ^ y::value),
159  x::value ^ y::value
160  >;
161 
162  template <typename x, typename n>
163  using shift_left_impl = integer_c<
164  decltype(x::value << n::value),
165  (x::value << n::value)
166  >;
167 
168  template <typename x, typename n>
169  using shift_right_impl = integer_c<
170  decltype(x::value >> n::value),
171  (x::value >> n::value)
172  >;
173 
174  template <typename x>
175  using compl_impl = integer_c<
176  decltype(~x::value),
177  ~x::value
178  >;
179  };
180 }} // end namespace boost::mpl11
181 
182 #endif // !BOOST_MPL11_INTEGER_HPP
Forward declares the Integer datatype.
Defines the Ring typeclass.
Defines the Comparable typeclass.
Defines the methods of the Enumerable typeclass.
Defines the Integral Domain typeclass.
Defines the Logical module.
Defines boost::mpl11::detail::logical_or::strict.
Defines the Bitwise typeclass.
Defines the Group typeclass.
Defines the Orderable typeclass.
Defines the Monoid typeclass.