From 483eb2f56657e8e7f419ab1a4fab8dce9ade8609 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sat, 27 Apr 2024 20:24:20 +0200 Subject: Adding upstream version 14.2.21. Signed-off-by: Daniel Baumann --- .../libs/variant2/test/variant_move_construct.cpp | 146 +++++++++++++++++++++ 1 file changed, 146 insertions(+) create mode 100644 src/boost/libs/variant2/test/variant_move_construct.cpp (limited to 'src/boost/libs/variant2/test/variant_move_construct.cpp') diff --git a/src/boost/libs/variant2/test/variant_move_construct.cpp b/src/boost/libs/variant2/test/variant_move_construct.cpp new file mode 100644 index 00000000..dd83c8c1 --- /dev/null +++ b/src/boost/libs/variant2/test/variant_move_construct.cpp @@ -0,0 +1,146 @@ + +// 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(); +} -- cgit v1.2.3