uTL
micro Template library
operations.h
Go to the documentation of this file.
1 
20 #ifndef __utl_meta_operations_h__
21 #define __utl_meta_operations_h__
22 
23 #include <utl/core/impl.h>
24 #include <utl/meta/selection.h>
25 
26 
32 namespace utl {
34 namespace meta{
35 
39 
42  template <bool B>
43  using not_c = bool_<!B>;
44 
46  template<typename _Tp>
48 
51  namespace detail {
52  template<typename...> struct _or_;
53 
54  template<>
55  struct _or_<> : false_ { };
56 
57  template<typename _T1>
58  struct _or_<_T1> : _T1 { };
59 
60  template<typename _T1, typename _T2>
62  : if_<_T1, _T1, _T2> { };
63 
64  template<typename _T1, typename _T2, typename _T3, typename... _Tn>
65  struct _or_<_T1, _T2, _T3, _Tn...>
66  : if_<_T1, _T1, _or_<_T2, _T3, _Tn...>> { };
67  }
68 
69  template <typename... _Ts>
70  using or_ = eval<detail::_or_<_Ts...>>;
72 
75  namespace detail {
76  template<typename...> struct _and_;
77 
78  template<>
79  struct _and_<>
80  : true_ { };
81 
82  template<typename _T1>
83  struct _and_ <_T1>
84  : _T1 { };
85 
86  template<typename _T1, typename _T2>
88  : if_<_T1, _T2, _T1> { };
89 
90  template<typename _T1, typename _T2, typename _T3, typename... _Tn>
91  struct _and_<_T1, _T2, _T3, _Tn...>
92  : if_<_T1, _and_<_T2, _T3, _Tn...>, _T1> { };
93  }
94 
95  template <typename... _Ts>
96  using and_ = eval<detail::_and_<_Ts...>>;
98 
101  template<typename _T1, typename _T2>
102  struct same_ : false_ { };
103 
104  template<typename _Tp>
105  struct same_ <_Tp, _Tp> : true_ { };
107 
110  template<typename _T1, typename _T2>
113 
115 }}
116 
118 
119 
125 
127 namespace utl {
128 namespace meta {
129 
134 
137  template <typename _Tp>
138  using negate = integral_<decltype(-_Tp()), -_Tp()>;
140  template <typename _Tp1, typename _Tp2>
141  using add = integral_<
142  decltype(_Tp1() + _Tp2()),
143  _Tp1() + _Tp2()
144  >;
146  template <typename _Tp1, typename _Tp2>
147  using mult = integral_<
148  decltype(_Tp2() * _Tp2()),
149  _Tp1() * _Tp2()
150  >;
152  template <typename _Tp1, typename _Tp2>
153  using divide = integral_<
154  decltype(_Tp2() / _Tp2()),
155  _Tp1() / _Tp2()
156  >;
158  template <typename _Tp1, typename _Tp2>
159  using modulo = integral_<
160  decltype(_Tp1() % _Tp2()),
161  _Tp1() % _Tp2()
162  >;
164  template <typename _Tp1, typename _Tp2>
166 
168  template <typename _Tp>
170 
172  template <typename _Tp>
173  using dec = add<_Tp, int_<-1>>;
174 
176 
181 
184  template <typename _Tp1, typename _Tp2> using comp_eq = bool_<_Tp1() == _Tp2()>;
186  template <typename _Tp1, typename _Tp2> using comp_lt = bool_<(_Tp1() < _Tp2())>;
187 
189  template <typename _Tp1, typename _Tp2> using comp_ne = not_<comp_eq<_Tp1, _Tp2>>;
191  template <typename _Tp1, typename _Tp2> using comp_gt = comp_lt <_Tp2, _Tp1>;
193  template <typename _Tp1, typename _Tp2> using comp_le = not_<comp_lt<_Tp2, _Tp1>>;
195  template <typename _Tp1, typename _Tp2> using comp_ge = not_<comp_lt<_Tp1, _Tp2>>;
197 
202 
207  template <typename _Tp1, typename _Tp2>
210  template <typename _Tp1, typename _Tp2>
212 
214  template <typename _Tp1, typename _Tp2>
217  template <typename _Tp, typename shift>
220  template <typename _Tp, typename shift>
223 }}
225 
226 
227 #endif /* __utl_meta_operations_h__ */
bool_< _Tp1()==_Tp2()> comp_eq
Definition: operations.h:184
integral_< typename _Tp::value_type,(typename _Tp::value_type)(_Tp() > > shift())> shift_right
Definition: operations.h:221
not_< comp_eq< _Tp1, _Tp2 > > comp_ne
Not equal.
Definition: operations.h:189
if_c< If::type::value, Args... > if_
Select one type or another depending on a compile-time Boolean type.
Definition: selection.h:66
integral_< decltype(_Tp1() &_Tp2()), _Tp1() &_Tp2()> bitand_
Definition: operations.h:208
integral_< decltype(-_Tp()), -_Tp()> negate
Negation.
Definition: operations.h:138
add< _Tp1, negate< _Tp2 > > sub
Substruction.
Definition: operations.h:165
integral_< decltype(_Tp2() *_Tp2()), _Tp1() *_Tp2() > mult
Multiplication.
Definition: operations.h:150
bool_< true > true_
The type used as a compile-time boolean with true value.
Definition: integral.h:68
bool_<(_Tp1()< _Tp2())> comp_lt
Definition: operations.h:186
integral_< decltype(_Tp1()|_Tp2()), _Tp1()|_Tp2()> bitor_
Definition: operations.h:211
integral_< typename _T::value_type,(typename _T::value_type)(~_T())> bitnot_
Definition: operations.h:205
std::integral_constant< Tp, v > integral_
Definition: integral.h:58
Template meta-programming type selections.
integral_< decltype(_Tp1() % _Tp2()), _Tp1() % _Tp2() > modulo
Modulo.
Definition: operations.h:162
comp_lt< _Tp2, _Tp1 > comp_gt
Greater than.
Definition: operations.h:191
integral_< typename _Tp::value_type,(typename _Tp::value_type)(_Tp()<< shift())> shift_left
Definition: operations.h:218
integral_< int, v > int_
int_ type: integral constant wrapper for int
Definition: integral.h:98
bool_< false > false_
The type used as a compile-time boolean with false value.
Definition: integral.h:69
integral_< decltype(_Tp1()+_Tp2()), _Tp1()+_Tp2() > add
Addition.
Definition: operations.h:144
typename Tp::type eval
Type alias for Tp::type. Used to evaluate/extract return type of metafunctions.
Definition: integral.h:49
bool_<!B > not_c
Negate the bool constant parameter.
Definition: operations.h:43
STL&#39;s core language concepts.
Definition: _1wire.h:30
integral_< decltype(_Tp1() ^ _Tp2()), _Tp1() ^ _Tp2()> bitxor_
Definition: operations.h:215
add< _Tp, int_<-1 > > dec
decrease
Definition: operations.h:173
not_< comp_lt< _Tp1, _Tp2 > > comp_ge
Greater or equal.
Definition: operations.h:195
integral_< bool, v > bool_
bool_ type: integral constant wrapper for bool
Definition: integral.h:66
integral_< decltype(_Tp2()/_Tp2()), _Tp1()/_Tp2() > divide
Division.
Definition: operations.h:156
not_< eval< same_< _T1, _T2 > >> not_same_
Definition: operations.h:111
eval< detail::_or_< _Ts... > > or_
Definition: operations.h:70
not_c< _Tp::type::value > not_
not
Definition: operations.h:47
eval< detail::_and_< _Ts... > > and_
Definition: operations.h:96
not_< comp_lt< _Tp2, _Tp1 > > comp_le
Less or equal.
Definition: operations.h:193
Implementation detail main forward header.
add< _Tp, int_< 1 > > inc
Increase.
Definition: operations.h:169