]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/hana/example/lexicographical_compare.cpp
677b76421fcc5012e994d4f075be2b842e339f95
1 // Copyright Louis Dionne 2013-2016
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)
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
;
15 // works with elements whose `less` does not return a Constant
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
), "");
22 // and with those that do
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
));
29 // it also accepts a custom predicate
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
);