1 // Copyright Louis Dionne 2013-2017
2 // Distributed under the Boost Software License, Version 1.0.
3 // (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)
4
5 #include <boost/hana/assert.hpp>
6 #include <boost/hana/comparing.hpp>
7 #include <boost/hana/equal.hpp>
8 #include <boost/hana/group.hpp>
9 #include <boost/hana/integral_constant.hpp>
10 #include <boost/hana/length.hpp>
11 #include <boost/hana/range.hpp>
12 #include <boost/hana/tuple.hpp>
13 #include <boost/hana/type.hpp>
14 namespace hana = boost::hana;
15
16
17 // group without a predicate
18 BOOST_HANA_CONSTANT_CHECK(
19 hana::group(hana::make_tuple(hana::int_c<1>, hana::long_c<1>, hana::type_c<int>, hana::char_c<'x'>, hana::char_c<'x'>))
20 == hana::make_tuple(
21 hana::make_tuple(hana::int_c<1>, hana::long_c<1>),
22 hana::make_tuple(hana::type_c<int>),
23 hana::make_tuple(hana::char_c<'x'>, hana::char_c<'x'>)
24 )
25 );
26
27
28 // group with a predicate
29 constexpr auto tuples = hana::make_tuple(
30 hana::range_c<int, 0, 1>,
31 hana::range_c<int, 0, 2>,
32 hana::range_c<int, 1, 3>,
33 hana::range_c<int, 2, 6>
34 );
35
36 BOOST_HANA_CONSTANT_CHECK(
37 hana::group(tuples, hana::comparing(hana::length))
38 == hana::make_tuple(
39 hana::make_tuple(
40 hana::range_c<int, 0, 1>
41 ),
42 hana::make_tuple(
43 hana::range_c<int, 0, 2>,
44 hana::range_c<int, 1, 3>
45 ),
46 hana::make_tuple(
47 hana::range_c<int, 2, 6>
48 )
49 )
50 );
51
52
53 // group.by is syntactic sugar
54 static_assert(
55 hana::group.by(hana::comparing(hana::typeid_),
56 hana::make_tuple(1, 2, 3, 'x', 'y', 4.4, 5.5))
57 == hana::make_tuple(
58 hana::make_tuple(1, 2, 3),
59 hana::make_tuple('x', 'y'),
60 hana::make_tuple(4.4, 5.5)
61 )
62 , "");
63
main()64 int main() { }
65