]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/hana/example/tutorial/mpl_cheatsheet.cpp
update sources to v12.2.3
[ceph.git] / ceph / src / boost / libs / hana / example / tutorial / mpl_cheatsheet.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/config.hpp>
7 #include <boost/hana/equal.hpp>
8 #include <boost/hana/ext/boost/mpl/vector.hpp>
9 #include <boost/hana/ext/std/integral_constant.hpp>
10 #include <boost/hana/integral_constant.hpp>
11 #include <boost/hana/plus.hpp>
12 #include <boost/hana/tuple.hpp>
13
14 #include <boost/mpl/fold.hpp>
15 #include <boost/mpl/if.hpp>
16 #include <boost/mpl/int.hpp>
17 #include <boost/mpl/next.hpp>
18 #include <boost/mpl/placeholders.hpp>
19 #include <boost/mpl/vector.hpp>
20
21 #include <type_traits>
22 namespace hana = boost::hana;
23 namespace mpl = boost::mpl;
24
25
26 namespace with_mpl {
27 //! [mpl]
28 using types = mpl::vector<long, float, short, float, long, long double>;
29 using number_of_floats = mpl::fold<
30 types,
31 mpl::int_<0>,
32 mpl::if_<std::is_floating_point<mpl::_2>,
33 mpl::next<mpl::_1>,
34 mpl::_1
35 >
36 >::type;
37 static_assert(number_of_floats::value == 3, "");
38 //! [mpl]
39 }
40
41 namespace with_hana {
42 //! [hana]
43 constexpr auto types = hana::tuple_t<long, float, short, float, long, long double>;
44 BOOST_HANA_CONSTEXPR_LAMBDA auto number_of_floats = hana::fold_left(
45 types,
46 hana::int_c<0>,
47 [](auto count, auto t) {
48 return hana::if_(hana::trait<std::is_floating_point>(t),
49 count + hana::int_c<1>,
50 count
51 );
52 }
53 );
54 BOOST_HANA_CONSTANT_CHECK(number_of_floats == hana::int_c<3>);
55 //! [hana]
56 }
57
58 int main() { }