]>
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 #ifdef BOOST_HANA_WORKAROUND_MSVC_EMPTYBASE
19 template <typename
...Bases
> struct __declspec(empty_bases
) inherit
: Bases
... { };
21 template <typename
...Bases
> struct inherit
: Bases
... { };
24 static_assert(sizeof(inherit
<>) == sizeof(inherit
<ebo
<idx
<0>, empty
<0>>>), "");
25 static_assert(sizeof(inherit
<>) == sizeof(inherit
<ebo
<idx
<0>, empty
<0>>, ebo
<idx
<1>, empty
<1>>>), "");
26 static_assert(sizeof(inherit
<>) == sizeof(inherit
<ebo
<idx
<0>, empty
<0>>, ebo
<idx
<1>, empty
<1>>, ebo
<idx
<2>, empty
<2>>>), "");
30 // Test default-construction
32 constexpr ebo
<idx
<0>, int> e
;
33 static_assert(hana::detail::ebo_get
<idx
<0>>(e
) == 0, "");
36 // Test construction of a non-empty object
38 ebo
<idx
<0>, std::string
> e
{"foobar"};
39 BOOST_HANA_RUNTIME_CHECK(hana::detail::ebo_get
<idx
<0>>(e
) == "foobar");
43 ebo
<idx
<0>, std::string
> e
{};
44 BOOST_HANA_RUNTIME_CHECK(hana::detail::ebo_get
<idx
<0>>(e
) == "");
47 // Test construction of a non default-constructible type
51 explicit nodefault(char const*) { }
53 ebo
<idx
<0>, nodefault
> e
{"foobar"};
56 // Get lvalue, const lvalue and rvalue with a non-empty type
58 ebo
<idx
<0>, std::string
> e
{"foobar"};
59 std::string
& s
= hana::detail::ebo_get
<idx
<0>>(e
);
60 BOOST_HANA_RUNTIME_CHECK(s
== "foobar");
62 BOOST_HANA_RUNTIME_CHECK(hana::detail::ebo_get
<idx
<0>>(e
) == "foobaz");
66 ebo
<idx
<0>, std::string
> const e
{"foobar"};
67 std::string
const& s
= hana::detail::ebo_get
<idx
<0>>(e
);
68 BOOST_HANA_RUNTIME_CHECK(s
== "foobar");
72 ebo
<idx
<0>, std::string
> e
{"foobar"};
73 std::string
&& s
= hana::detail::ebo_get
<idx
<0>>(std::move(e
));
74 BOOST_HANA_RUNTIME_CHECK(s
== "foobar");
77 // Get lvalue, const lvalue and rvalue with an empty type
79 ebo
<idx
<0>, empty
<0>> e
{};
80 empty
<0>& s
= hana::detail::ebo_get
<idx
<0>>(e
);
85 ebo
<idx
<0>, empty
<0>> const e
{};
86 empty
<0> const& s
= hana::detail::ebo_get
<idx
<0>>(e
);
91 ebo
<idx
<0>, empty
<0>> e
{};
92 empty
<0>&& s
= hana::detail::ebo_get
<idx
<0>>(std::move(e
));