Imported Upstream version 1.64.0
[platform/upstream/boost.git] / libs / hana / example / lexicographical_compare.cpp
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/integral_constant.hpp>
7 #include <boost/hana/less.hpp>
8 #include <boost/hana/lexicographical_compare.hpp>
9 #include <boost/hana/tuple.hpp>
10 #include <boost/hana/type.hpp>
11 namespace hana = boost::hana;
12
13
14 int main() {
15     // works with elements whose `less` does not return a Constant
16     {
17         constexpr auto xs = hana::make_tuple(1, 2, 3, 4);
18         constexpr auto ys = hana::make_tuple(1, 6, 3, 4);
19         static_assert(hana::lexicographical_compare(xs, ys), "");
20     }
21
22     // and with those that do
23     {
24         auto xs = hana::make_tuple(hana::int_c<1>, hana::int_c<2>, hana::int_c<3>);
25         auto ys = hana::make_tuple(hana::int_c<1>, hana::int_c<5>, hana::int_c<3>);
26         BOOST_HANA_CONSTANT_CHECK(hana::lexicographical_compare(xs, ys));
27     }
28
29     // it also accepts a custom predicate
30     {
31         auto xs = hana::make_tuple(hana::type_c<int>, hana::type_c<char>, hana::type_c<void*>);
32         auto ys = hana::make_tuple(hana::type_c<int>, hana::type_c<long>, hana::type_c<void*>);
33         BOOST_HANA_CONSTANT_CHECK(
34             hana::lexicographical_compare(xs, ys, [](auto t, auto u) {
35                 return hana::sizeof_(t) < hana::sizeof_(u);
36             })
37         );
38     }
39 }