// Copyright 2017 Peter Dimov. // // Distributed under the Boost Software License, Version 1.0. // // See accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt #include #include #include #include #include #include using namespace boost::variant2; #define STATIC_ASSERT(...) static_assert(__VA_ARGS__, #__VA_ARGS__) struct X1 { X1() {} X1(X1 const&) {} X1(X1&&) {} }; inline bool operator==( X1, X1 ) { return true; } STATIC_ASSERT( !std::is_nothrow_default_constructible::value ); STATIC_ASSERT( !std::is_nothrow_copy_constructible::value ); STATIC_ASSERT( !std::is_nothrow_move_constructible::value ); struct X2 { X2() {} X2(X2 const&) {} X2(X2&&) {} }; inline bool operator==( X2, X2 ) { return true; } STATIC_ASSERT( !std::is_nothrow_default_constructible::value ); STATIC_ASSERT( !std::is_nothrow_copy_constructible::value ); STATIC_ASSERT( !std::is_nothrow_move_constructible::value ); struct Y { Y( Y&& ) = delete; }; template static void test( V&& v ) { V v2( v ); V v3( std::move(v) ); BOOST_TEST_EQ( v2.index(), v3.index() ); BOOST_TEST( v2 == v3 ); } int main() { test( variant() ); test( variant(1) ); test( variant() ); test( variant(1) ); test( variant() ); test( variant(1) ); test( variant(3.14f) ); test( variant() ); test( variant(1) ); test( variant(3.14f) ); test( variant() ); test( variant("test") ); test( variant() ); test( variant("test") ); test( variant() ); test( variant(1) ); test( variant(3.14f) ); test( variant("test") ); test( variant() ); test( variant() ); test( variant(3.14f) ); test( variant() ); test( variant("test") ); test( variant() ); test( variant() ); test( variant() ); test( variant() ); test( variant() ); test( variant() ); { variant v; v.emplace(); test( std::move(v) ); } { variant v; v.emplace(); test( std::move(v) ); } { BOOST_TEST_TRAIT_TRUE((std::is_nothrow_move_constructible>)); BOOST_TEST_TRAIT_TRUE((std::is_nothrow_move_constructible>)); BOOST_TEST_TRAIT_TRUE((std::is_nothrow_move_constructible>)); BOOST_TEST_TRAIT_TRUE((std::is_nothrow_move_constructible>)); BOOST_TEST_TRAIT_TRUE((std::is_nothrow_move_constructible>)); BOOST_TEST_TRAIT_FALSE((std::is_nothrow_move_constructible>)); BOOST_TEST_TRAIT_FALSE((std::is_nothrow_move_constructible>)); BOOST_TEST_TRAIT_FALSE((std::is_nothrow_move_constructible>)); BOOST_TEST_TRAIT_FALSE((std::is_nothrow_move_constructible>)); BOOST_TEST_TRAIT_FALSE((std::is_nothrow_move_constructible>)); BOOST_TEST_TRAIT_FALSE((std::is_nothrow_move_constructible>)); BOOST_TEST_TRAIT_FALSE((std::is_nothrow_move_constructible>)); BOOST_TEST_TRAIT_TRUE((std::is_move_constructible>)); #if !BOOST_WORKAROUND( BOOST_MSVC, <= 1910 ) BOOST_TEST_TRAIT_FALSE((std::is_move_constructible>)); #endif } return boost::report_errors(); }