]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/hana/example/tutorial/introduction.cpp
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 // Make sure `assert` always triggers an assertion
10 #include <boost/fusion/include/comparison.hpp>
11 #include <boost/fusion/include/make_vector.hpp>
12 #include <boost/fusion/include/transform.hpp>
13 #include <boost/fusion/include/vector.hpp>
15 #include <boost/mpl/equal.hpp>
16 #include <boost/mpl/placeholders.hpp>
17 #include <boost/mpl/transform.hpp>
18 #include <boost/mpl/vector.hpp>
26 namespace fusion
= boost::fusion
;
27 namespace mpl
= boost::mpl
;
28 using namespace std::literals
;
36 auto f
= [](int i
) -> std::string
{
37 return std::to_string(i
* i
);
40 std::vector
<int> ints
{1, 2, 3, 4};
41 std::vector
<std::string
> strings
;
42 std::transform(ints
.begin(), ints
.end(), std::back_inserter(strings
), f
);
44 assert((strings
== std::vector
<std::string
>{"1", "4", "9", "16"}));
50 auto to_string
= [](auto t
) {
56 fusion::vector
<int, std::string
, float> seq
{1, "abc", 3.4f
};
57 fusion::vector
<std::string
, std::string
, std::string
>
58 strings
= fusion::transform(seq
, to_string
);
60 assert(strings
== fusion::make_vector("1"s
, "abc"s
, "3.4"s
));
69 struct add_const_pointer
{
70 using type
= T
const*;
73 using types
= mpl::vector
<int, char, float, void>;
74 using pointers
= mpl::transform
<types
, add_const_pointer
<mpl::_1
>>::type
;
76 static_assert(mpl::equal
<
78 mpl::vector
<int const*, char const*, float const*, void const*>