]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/libs/hana/example/sort.cpp
update sources to v12.2.3
[ceph.git] / ceph / src / boost / libs / hana / example / sort.cpp
CommitLineData
b32b8144 1// Copyright Louis Dionne 2013-2017
7c673cae
FG
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/equal.hpp>
7#include <boost/hana/front.hpp>
8#include <boost/hana/greater.hpp>
9#include <boost/hana/integral_constant.hpp>
10#include <boost/hana/negate.hpp>
11#include <boost/hana/ordering.hpp>
12#include <boost/hana/sort.hpp>
13#include <boost/hana/tuple.hpp>
14
15#include <string>
16namespace hana = boost::hana;
17using namespace hana::literals;
18using namespace std::literals;
19
20
21// sort without a predicate
22BOOST_HANA_CONSTANT_CHECK(
23 hana::sort(hana::make_tuple(1_c, -2_c, 3_c, 0_c)) ==
24 hana::make_tuple(-2_c, 0_c, 1_c, 3_c)
25);
26
27// sort with a predicate
28BOOST_HANA_CONSTANT_CHECK(
29 hana::sort(hana::make_tuple(1_c, -2_c, 3_c, 0_c), hana::greater) ==
30 hana::make_tuple(3_c, 1_c, 0_c, -2_c)
31);
32
33int main() {
34 // sort.by is syntactic sugar
35 auto tuples = hana::make_tuple(
36 hana::make_tuple(2_c, 'x', nullptr),
37 hana::make_tuple(1_c, "foobar"s, hana::int_c<4>)
38 );
39
40 BOOST_HANA_RUNTIME_CHECK(
41 hana::sort.by(hana::ordering(hana::front), tuples)
42 == hana::make_tuple(
43 hana::make_tuple(1_c, "foobar"s, hana::int_c<4>),
44 hana::make_tuple(2_c, 'x', nullptr)
45 )
46 );
47}