12 #ifndef BOOST_MPL11_DETAIL_TEST_FOLDABLE_HPP
13 #define BOOST_MPL11_DETAIL_TEST_FOLDABLE_HPP
27 #define static_assert_(...) static_assert(__VA_ARGS__, # __VA_ARGS__)
29 namespace boost {
namespace mpl11 {
namespace detail {
30 namespace foldable_detail {
31 template <
typename ...x>
32 struct f {
using type = f<
typename x::type...>; };
33 struct x0 {
using type = x0; };
34 struct x1 {
using type = x1; };
35 struct x2 {
using type = x2; };
36 struct x3 {
using type = x3; };
37 struct x4 {
using type = x4; };
38 struct x5 {
using type = x5; };
40 struct t {
using type = t; };
41 struct x {
using type = x; };
42 struct y {
using type = y; };
43 struct z {
using type = z; };
48 template <
template <
typename ...>
class structure>
50 template <
typename ...xs>
51 using _foldr1 = foldr1<lift<f>, structure<xs...>>;
54 : expect<_foldr1<x1>>::template to_eq<x1>
55 , expect<_foldr1<x1, x2>>::template to_eq<f<x1, x2>>
56 , expect<_foldr1<x1, x2, x3>>::template to_eq<f<x1, f<x2, x3>>>
57 , expect<_foldr1<x1, x2, x3, x4>>::template
58 to_eq<f<x1, f<x2, f<x3, x4>>>>
59 , expect<_foldr1<x1, x2, x3, x4, x5>>::template
60 to_eq<f<x1, f<x2, f<x3, f<x4, x5>>>>>
66 template <
template <
typename ...>
class structure>
68 template <
typename ...xs>
69 using _foldl1 = foldl1<lift<f>, structure<xs...>>;
72 : expect<_foldl1<x1>>::template to_eq<x1>
73 , expect<_foldl1<x1, x2>>::template to_eq<f<x1, x2>>
74 , expect<_foldl1<x1, x2, x3>>::template to_eq<f<f<x1, x2>, x3>>
75 , expect<_foldl1<x1, x2, x3, x4>>::template
76 to_eq<f<f<f<x1, x2>, x3>, x4>>
77 , expect<_foldl1<x1, x2, x3, x4, x5>>::template
78 to_eq<f<f<f<f<x1, x2>, x3>, x4>, x5>>
84 template <
template <
typename ...>
class structure>
86 template <
typename predicate,
typename ...xs>
87 using _any = any<predicate, structure<xs...>>;
97 using is_t = rsect_<equal, t>;
111 template <
template <
typename ...>
class structure>
113 template <
typename predicate,
typename ...xs>
114 using _none = none<predicate, structure<xs...>>;
124 using is_t = rsect_<equal, t>;
138 template <
template <
typename ...>
class structure>
140 template <
typename predicate,
typename ...xs>
141 using _all = all<predicate, structure<xs...>>;
151 using is_t = rsect_<equal, t>;
165 template <
template <
typename ...>
class structure>
167 template <
typename ...xs>
168 using _all_of = all_of<structure<xs...>>;
186 template <
template <
typename ...>
class structure>
188 template <
typename ...xs>
189 using _any_of = any_of<structure<xs...>>;
206 template <
template <
typename ...>
class structure>
207 struct test_none_of {
208 template <
typename ...xs>
209 using _none_of = none_of<structure<xs...>>;
226 template <
template <
typename ...>
class structure>
229 using _sum = sum<structure<int_<xs>...>>;
241 static_assert_(_sum<1, 2, 3, 4, 5, 0>::value == 1 + 2 + 3 + 4 + 5 + 0);
244 template <
template <
typename ...>
class structure>
245 struct test_product {
247 using _prod = product<structure<int_<xs>...>>;
262 template <
template <
typename ...>
class structure>
263 struct test_maximum {
265 using _max =
typename maximum<structure<int_<xs>...>>::type;
276 template <
template <
typename ...>
class structure>
277 struct test_maximum_by {
279 using _max =
typename maximum_by<lift<less>, structure<int_<xs>...>>::type;
290 template <
template <
typename ...>
class structure>
291 struct test_minimum {
293 using _min =
typename minimum<structure<int_<xs>...>>::type;
303 template <
template <
typename ...>
class structure>
304 struct test_minimum_by {
306 using _min =
typename minimum_by<lift<less>, structure<int_<xs>...>>::type;
316 template <
template <
typename ...>
class structure>
318 template <
typename ...xs>
319 using _unpack = detail::std_is_same<
320 typename unpack<lift<f>, structure<xs...>>::type,
321 typename f<xs...>::type
332 template <
template <
typename ...>
class structure>
333 struct test_datatype {
334 template <
typename ...xs>
335 using _datatype =
typename expect<
336 typename datatype<
typename structure<xs...>::type>::type
337 >::template to_satisfy<lift<mpl11::Foldable>>;
340 sizeof(_datatype<>) +
341 sizeof(_datatype<u>) +
342 sizeof(_datatype<u, u>) +
343 sizeof(_datatype<u, u, u>)
348 template <
typename ...>
class fold,
349 template <
typename ...>
class structure
354 template <
typename f,
typename z,
typename ...xs>
355 struct go : fold<f, z, structure<xs...>> { };
359 template <
template <
typename ...>
class structure>
361 : test_foldl<foldable_detail::fold_on<foldl, structure>::template go>
362 , test_foldr<foldable_detail::fold_on<foldr, structure>::template go>
363 , foldable_detail::test_foldl1<structure>
364 , foldable_detail::test_foldr1<structure>
366 , foldable_detail::test_all<structure>
367 , foldable_detail::test_all_of<structure>
368 , foldable_detail::test_any<structure>
369 , foldable_detail::test_any_of<structure>
370 , foldable_detail::test_none<structure>
371 , foldable_detail::test_none_of<structure>
373 , foldable_detail::test_sum<structure>
374 , foldable_detail::test_product<structure>
376 , foldable_detail::test_maximum<structure>
377 , foldable_detail::test_maximum_by<structure>
378 , foldable_detail::test_minimum<structure>
379 , foldable_detail::test_minimum_by<structure>
381 , foldable_detail::test_unpack<structure>
382 , foldable_detail::test_datatype<structure>
386 #endif // !BOOST_MPL11_DETAIL_TEST_FOLDABLE_HPP
Defines the Integer datatype.
Defines unit tests for left fold algorithms.
Defines unit tests for right fold algorithms.
Defines boost::mpl11::detail::std_is_same.
Returns the given boolean expression and statically asserts that its value is true.
Definition: static_assert.hpp:22
Defines utilities to write unit tests.
Forwards to boost/mpl11/integer.hpp.
Defines the methods of the Foldable typeclass.
Defines the Functional module.