]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/hana/example/tutorial/containers.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 #include <boost/hana.hpp>
12 namespace hana
= boost::hana
;
13 using namespace hana::literals
;
14 using namespace std::literals
;
22 auto xs
= hana::make
<hana::tuple_tag
>(1, 2.2, 'a', "bcde"s
);
28 constexpr auto r
= hana::make
<hana::range_tag
>(hana::int_c
<3>, hana::int_c
<10>);
29 static_assert(r
== hana::make_range(hana::int_c
<3>, hana::int_c
<10>), "");
34 //! [tuple_constructor]
35 hana::tuple
<int, double, char, std::string
> xs
{1, 2.2, 'a', "bcde"s
};
36 //! [tuple_constructor]
42 auto xs
= hana::make_tuple(1, '2', "345");
43 auto ints
= hana::make_range(hana::int_c
<0>, hana::int_c
<100>);
44 // what can we say about the types of `xs` and `ints`?
51 //! [types_maximally_specified]
52 hana::tuple
<int, char, char const*> xs
= hana::make_tuple(1, '2', "345");
53 auto ints
= hana::make_range(hana::int_c
<0>, hana::int_c
<100>);
54 // can't specify the type of ints, however
55 //! [types_maximally_specified]
62 std::string hello
= "Hello";
63 std::vector
<char> world
= {'W', 'o', 'r', 'l', 'd'};
65 // hello is copied, world is moved-in
66 auto xs
= hana::make_tuple(hello
, std::move(world
));
68 // s is a reference to the copy of hello inside xs.
69 // It becomes a dangling reference as soon as xs is destroyed.
70 std::string
& s
= xs
[0_c
];
76 //! [reference_wrapper]
77 std::vector
<int> ints
= { /* huge vector of ints */ };
78 std::vector
<std::string
> strings
= { /* huge vector of strings */ };
80 auto map
= hana::make_map(
81 hana::make_pair(hana::type_c
<int>, std::ref(ints
)),
82 hana::make_pair(hana::type_c
<std::string
>, std::ref(strings
))
85 auto& v
= map
[hana::type_c
<int>].get();
86 BOOST_HANA_RUNTIME_CHECK(&v
== &ints
);
87 //! [reference_wrapper]
94 namespace overloading
{
97 void f(std::vector
<T
> xs
) {
101 template <typename R
, typename
= std::enable_if_t
<hana::is_a
<hana::range_tag
, R
>()>>