]>
git.proxmox.com Git - ceph.git/blob - 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)
5 #include <boost/hana/detail/ebo.hpp>
7 #include <boost/hana/assert.hpp>
10 #include <type_traits>
12 namespace hana
= boost::hana
;
13 using hana::detail::ebo
;
16 template <int> struct empty
{ };
17 template <int> struct idx
;
18 template <typename
...Bases
> struct inherit
: Bases
... { };
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>>>), "");
26 // Test default-construction
28 constexpr ebo
<idx
<0>, int> e
;
29 static_assert(hana::detail::ebo_get
<idx
<0>>(e
) == 0, "");
32 // Test construction of a non-empty object
34 ebo
<idx
<0>, std::string
> e
{"foobar"};
35 BOOST_HANA_RUNTIME_CHECK(hana::detail::ebo_get
<idx
<0>>(e
) == "foobar");
39 ebo
<idx
<0>, std::string
> e
{};
40 BOOST_HANA_RUNTIME_CHECK(hana::detail::ebo_get
<idx
<0>>(e
) == "");
43 // Test construction of a non default-constructible type
47 explicit nodefault(char const*) { }
49 ebo
<idx
<0>, nodefault
> e
{"foobar"};
52 // Get lvalue, const lvalue and rvalue with a non-empty type
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");
58 BOOST_HANA_RUNTIME_CHECK(hana::detail::ebo_get
<idx
<0>>(e
) == "foobaz");
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");
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");
73 // Get lvalue, const lvalue and rvalue with an empty type
75 ebo
<idx
<0>, empty
<0>> e
{};
76 empty
<0>& s
= hana::detail::ebo_get
<idx
<0>>(e
);
81 ebo
<idx
<0>, empty
<0>> const e
{};
82 empty
<0> const& s
= hana::detail::ebo_get
<idx
<0>>(e
);
87 ebo
<idx
<0>, empty
<0>> e
{};
88 empty
<0>&& s
= hana::detail::ebo_get
<idx
<0>>(std::move(e
));