]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/hana/test/map/at_key.ref.cpp
update sources to v12.2.3
[ceph.git] / ceph / src / boost / libs / hana / test / map / at_key.ref.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/at_key.hpp>
7 #include <boost/hana/integral_constant.hpp>
8 #include <boost/hana/map.hpp>
9 #include <boost/hana/pair.hpp>
10
11 #include <utility>
12 namespace hana = boost::hana;
13
14
15 template <typename T>
16 T const& cref(T& t) { return t; }
17
18 int main() {
19 // using at_key
20 {
21 auto xs = hana::make_map(
22 hana::make_pair(hana::int_c<0>, 0),
23 hana::make_pair(hana::int_c<1>, '1'),
24 hana::make_pair(hana::int_c<2>, 2.2)
25 );
26
27 // Make sure we return lvalue-references
28 BOOST_HANA_RUNTIME_CHECK(hana::at_key(xs, hana::int_c<0>) == 0);
29 BOOST_HANA_RUNTIME_CHECK(hana::at_key(xs, hana::int_c<1>) == '1');
30 BOOST_HANA_RUNTIME_CHECK(hana::at_key(xs, hana::int_c<2>) == 2.2);
31
32 int& a = hana::at_key(xs, hana::int_c<0>);
33 char& b = hana::at_key(xs, hana::int_c<1>);
34 double& c = hana::at_key(xs, hana::int_c<2>);
35 a = 9;
36 b = '9';
37 c = 9.9;
38
39 // Make sure we return lvalue-references to const on a const map
40 int const& ca = hana::at_key(cref(xs), hana::int_c<0>);
41 char const& cb = hana::at_key(cref(xs), hana::int_c<1>);
42 double const& cc = hana::at_key(cref(xs), hana::int_c<2>);
43
44 BOOST_HANA_RUNTIME_CHECK(ca == 9);
45 BOOST_HANA_RUNTIME_CHECK(cb == '9');
46 BOOST_HANA_RUNTIME_CHECK(cc == 9.9);
47 }
48
49 // using operator[]
50 {
51 auto xs = hana::make_map(
52 hana::make_pair(hana::int_c<0>, 0),
53 hana::make_pair(hana::int_c<1>, '1'),
54 hana::make_pair(hana::int_c<2>, 2.2)
55 );
56
57 BOOST_HANA_RUNTIME_CHECK(xs[hana::int_c<0>] == 0);
58 BOOST_HANA_RUNTIME_CHECK(xs[hana::int_c<1>] == '1');
59 BOOST_HANA_RUNTIME_CHECK(xs[hana::int_c<2>] == 2.2);
60
61 xs[hana::int_c<0>] = 9;
62 xs[hana::int_c<1>] = '9';
63 xs[hana::int_c<2>] = 9.9;
64
65 BOOST_HANA_RUNTIME_CHECK(xs[hana::int_c<0>] == 9);
66 BOOST_HANA_RUNTIME_CHECK(xs[hana::int_c<1>] == '9');
67 BOOST_HANA_RUNTIME_CHECK(xs[hana::int_c<2>] == 9.9);
68 }
69
70 // Make sure we return a rvalue-reference from a temporary map
71 // (https://github.com/boostorg/hana/issues/90)
72 {
73 auto xs = hana::make_map(
74 hana::make_pair(hana::int_c<0>, 0),
75 hana::make_pair(hana::int_c<1>, '1'),
76 hana::make_pair(hana::int_c<2>, 2.2)
77 );
78
79 char&& c = hana::at_key(std::move(xs), hana::int_c<1>);
80 BOOST_HANA_RUNTIME_CHECK(hana::at_key(xs, hana::int_c<1>) == '1');
81 c = '9';
82 BOOST_HANA_RUNTIME_CHECK(hana::at_key(xs, hana::int_c<1>) == '9');
83 }
84 }