1// Copyright 2020 Peter Dimov.
2// Distributed under the Boost Software License, Version 1.0.
3// https://www.boost.org/LICENSE_1_0.txt
4
5#if defined(_MSC_VER) && _MSC_VER < 1910
6# pragma warning(disable: 4503) // decorated name length exceeded
7#endif
8
9#include <boost/variant2/variant.hpp>
10#include <boost/core/lightweight_test_trait.hpp>
11#include <boost/config.hpp>
12#include <boost/config/workaround.hpp>
13
14#include <boost/mp11.hpp>
15using namespace boost::mp11;
16
17//
18
19struct D
20{
21 ~D() noexcept {}
22};
23
24struct CC1
25{
26 CC1( CC1 const& ) noexcept {}
27};
28
29struct CC2
30{
31 CC2( CC2 const& ) = delete;
32};
33
34struct MC1
35{
36 MC1( MC1 && ) noexcept {}
37};
38
39struct MC2
40{
41 MC2( MC2 && ) = delete;
42};
43
44struct CA1
45{
46 CA1& operator=( CA1 const& ) noexcept { return *this; }
47};
48
49struct CA2
50{
51 CA2& operator=( CA2 const& ) = delete;
52};
53
54struct MA1
55{
56 MA1& operator=( MA1 && ) noexcept { return *this; }
57};
58
59struct MA2
60{
61 MA2& operator=( MA2 && ) = delete;
62};
63
64using namespace boost::variant2;
65namespace v2d = boost::variant2::detail;
66
67struct test
68{
69 template<class... T> void operator()( mp_list<T...> ) const noexcept
70 {
71 using U = mp_inherit<T...>;
72
73#if !BOOST_WORKAROUND( __GNUC__, < 5 )
74
75 BOOST_TEST_EQ( v2d::is_trivially_copy_constructible<variant<U>>::value, v2d::is_trivially_copy_constructible<U>::value );
76 BOOST_TEST_EQ( v2d::is_trivially_copy_assignable<variant<U>>::value, std::is_trivially_destructible<U>::value && v2d::is_trivially_copy_constructible<U>::value && v2d::is_trivially_copy_assignable<U>::value );
77
78#endif
79
80 BOOST_TEST_EQ( std::is_trivially_destructible<variant<U>>::value, std::is_trivially_destructible<U>::value );
81
82#if !BOOST_WORKAROUND(BOOST_LIBSTDCXX_VERSION, < 50000)
83
84 BOOST_TEST_EQ( v2d::is_trivially_move_constructible<variant<U>>::value, v2d::is_trivially_move_constructible<U>::value );
85 BOOST_TEST_EQ( v2d::is_trivially_move_assignable<variant<U>>::value, std::is_trivially_destructible<U>::value && v2d::is_trivially_move_constructible<U>::value && v2d::is_trivially_move_assignable<U>::value );
86
87#endif
88 }
89};
90
91int main()
92{
93 mp_for_each< mp_power_set< mp_list<D, CC1, CC2, MC1, MC2, CA1, CA2, MA1, MA2> > >( f: test() );
94 return boost::report_errors();
95}
96

source code of boost/libs/variant2/test/variant_trivial.cpp