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
19using namespace boost::variant2;
20
21struct D
22{
23 ~D() noexcept {}
24};
25
26struct CC1
27{
28 CC1( CC1 const& ) {}
29};
30
31struct CC2
32{
33 CC2( CC2 const& ) = delete;
34};
35
36struct MC1
37{
38 MC1( MC1 && ) {}
39};
40
41struct MC2
42{
43 MC2( MC2 && ) = delete;
44};
45
46struct CA1
47{
48 CA1& operator=( CA1 const& ) { return *this; }
49};
50
51struct CA2
52{
53 CA2& operator=( CA2 const& ) = delete;
54};
55
56struct MA1
57{
58 MA1& operator=( MA1 && ) { return *this; }
59};
60
61struct MA2
62{
63 MA2& operator=( MA2 && ) = delete;
64};
65
66struct test
67{
68 template<class... T> void operator()( mp_list<T...> ) const noexcept
69 {
70 using U = mp_inherit<T...>;
71
72#if !BOOST_WORKAROUND( __GNUC__, < 5 )
73
74 BOOST_TEST_EQ( std::is_copy_constructible<variant<U>>::value, std::is_copy_constructible<U>::value );
75 BOOST_TEST_EQ( std::is_nothrow_copy_constructible<variant<U>>::value, std::is_nothrow_copy_constructible<U>::value );
76
77#endif
78
79#if !BOOST_WORKAROUND(BOOST_MSVC, < 1910)
80
81 BOOST_TEST_EQ( std::is_move_constructible<variant<U>>::value, std::is_move_constructible<U>::value );
82
83#else
84
85 BOOST_TEST_GE( std::is_move_constructible<variant<U>>::value, std::is_move_constructible<U>::value );
86
87#endif
88
89 BOOST_TEST_EQ( std::is_nothrow_move_constructible<variant<U>>::value, std::is_nothrow_move_constructible<U>::value );
90
91 BOOST_TEST_EQ( std::is_copy_assignable<variant<U>>::value, std::is_copy_constructible<U>::value && std::is_copy_assignable<U>::value );
92 BOOST_TEST_EQ( std::is_nothrow_copy_assignable<variant<U>>::value, std::is_nothrow_copy_constructible<U>::value && std::is_copy_assignable<U>::value );
93
94 BOOST_TEST_EQ( std::is_move_assignable<variant<U>>::value, std::is_move_constructible<U>::value && std::is_move_assignable<U>::value );
95 BOOST_TEST_EQ( std::is_nothrow_move_assignable<variant<U>>::value, std::is_nothrow_move_constructible<U>::value && std::is_move_assignable<U>::value );
96 }
97};
98
99int main()
100{
101 mp_for_each< mp_power_set< mp_list<D, CC1, CC2, MC1, MC2, CA1, CA2, MA1, MA2> > >( f: test() );
102 return boost::report_errors();
103}
104

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