1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
// Copyright Louis Dionne 2013-2017
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)
#include <boost/hana/assert.hpp>
#include <boost/hana/equal.hpp>
#include <boost/hana/front.hpp>
#include <boost/hana/greater.hpp>
#include <boost/hana/integral_constant.hpp>
#include <boost/hana/negate.hpp>
#include <boost/hana/ordering.hpp>
#include <boost/hana/sort.hpp>
#include <boost/hana/tuple.hpp>
#include <string>
namespace hana = boost::hana;
using namespace hana::literals;
using namespace std::literals;
// sort without a predicate
BOOST_HANA_CONSTANT_CHECK(
hana::sort(hana::make_tuple(1_c, -2_c, 3_c, 0_c)) ==
hana::make_tuple(-2_c, 0_c, 1_c, 3_c)
);
// sort with a predicate
BOOST_HANA_CONSTANT_CHECK(
hana::sort(hana::make_tuple(1_c, -2_c, 3_c, 0_c), hana::greater) ==
hana::make_tuple(3_c, 1_c, 0_c, -2_c)
);
int main() {
// sort.by is syntactic sugar
auto tuples = hana::make_tuple(
hana::make_tuple(2_c, 'x', nullptr),
hana::make_tuple(1_c, "foobar"s, hana::int_c<4>)
);
BOOST_HANA_RUNTIME_CHECK(
hana::sort.by(hana::ordering(hana::front), tuples)
== hana::make_tuple(
hana::make_tuple(1_c, "foobar"s, hana::int_c<4>),
hana::make_tuple(2_c, 'x', nullptr)
)
);
}
|