]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/hana/test/detail/ebo.cpp
update sources to v12.2.3
[ceph.git] / ceph / src / boost / libs / hana / test / detail / ebo.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)
4
5 #include <boost/hana/detail/ebo.hpp>
6
7 #include <boost/hana/assert.hpp>
8
9 #include <string>
10 #include <type_traits>
11 #include <utility>
12 namespace hana = boost::hana;
13 using hana::detail::ebo;
14
15
16 template <int> struct empty { };
17 template <int> struct idx;
18 template <typename ...Bases> struct inherit : Bases... { };
19
20 static_assert(sizeof(inherit<>) == sizeof(inherit<ebo<idx<0>, empty<0>>>), "");
21 static_assert(sizeof(inherit<>) == sizeof(inherit<ebo<idx<0>, empty<0>>, ebo<idx<1>, empty<1>>>), "");
22 static_assert(sizeof(inherit<>) == sizeof(inherit<ebo<idx<0>, empty<0>>, ebo<idx<1>, empty<1>>, ebo<idx<2>, empty<2>>>), "");
23
24
25 int main() {
26 // Test default-construction
27 {
28 constexpr ebo<idx<0>, int> e;
29 static_assert(hana::detail::ebo_get<idx<0>>(e) == 0, "");
30 }
31
32 // Test construction of a non-empty object
33 {
34 ebo<idx<0>, std::string> e{"foobar"};
35 BOOST_HANA_RUNTIME_CHECK(hana::detail::ebo_get<idx<0>>(e) == "foobar");
36 }
37
38 {
39 ebo<idx<0>, std::string> e{};
40 BOOST_HANA_RUNTIME_CHECK(hana::detail::ebo_get<idx<0>>(e) == "");
41 }
42
43 // Test construction of a non default-constructible type
44 {
45 struct nodefault {
46 nodefault() = delete;
47 explicit nodefault(char const*) { }
48 };
49 ebo<idx<0>, nodefault> e{"foobar"};
50 }
51
52 // Get lvalue, const lvalue and rvalue with a non-empty type
53 {
54 ebo<idx<0>, std::string> e{"foobar"};
55 std::string& s = hana::detail::ebo_get<idx<0>>(e);
56 BOOST_HANA_RUNTIME_CHECK(s == "foobar");
57 s = "foobaz";
58 BOOST_HANA_RUNTIME_CHECK(hana::detail::ebo_get<idx<0>>(e) == "foobaz");
59 }
60
61 {
62 ebo<idx<0>, std::string> const e{"foobar"};
63 std::string const& s = hana::detail::ebo_get<idx<0>>(e);
64 BOOST_HANA_RUNTIME_CHECK(s == "foobar");
65 }
66
67 {
68 ebo<idx<0>, std::string> e{"foobar"};
69 std::string&& s = hana::detail::ebo_get<idx<0>>(std::move(e));
70 BOOST_HANA_RUNTIME_CHECK(s == "foobar");
71 }
72
73 // Get lvalue, const lvalue and rvalue with an empty type
74 {
75 ebo<idx<0>, empty<0>> e{};
76 empty<0>& s = hana::detail::ebo_get<idx<0>>(e);
77 (void)s;
78 }
79
80 {
81 ebo<idx<0>, empty<0>> const e{};
82 empty<0> const& s = hana::detail::ebo_get<idx<0>>(e);
83 (void)s;
84 }
85
86 {
87 ebo<idx<0>, empty<0>> e{};
88 empty<0>&& s = hana::detail::ebo_get<idx<0>>(std::move(e));
89 (void)s;
90 }
91 }