mirror of
https://github.com/boostorg/variant2.git
synced 2025-07-30 20:27:17 +02:00
Add test/variant_copy_assign_cx
This commit is contained in:
@ -39,6 +39,8 @@ run variant_in_place_type_construct.cpp : : : $(REQ) ;
|
||||
compile variant_in_place_type_construct_cx.cpp : : : $(REQ) ;
|
||||
|
||||
run variant_copy_assign.cpp : : : $(REQ) ;
|
||||
compile variant_copy_assign_cx.cpp : : : $(REQ) ;
|
||||
|
||||
run variant_move_assign.cpp : : : $(REQ) ;
|
||||
|
||||
run variant_value_assign.cpp : : : $(REQ) ;
|
||||
|
125
test/variant_copy_assign_cx.cpp
Normal file
125
test/variant_copy_assign_cx.cpp
Normal file
@ -0,0 +1,125 @@
|
||||
|
||||
// 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
|
||||
|
||||
#if !defined( __cpp_constexpr ) || __cpp_constexpr < 201603
|
||||
|
||||
// no constexpr lambda support
|
||||
int main() {}
|
||||
|
||||
#else
|
||||
|
||||
#include <boost/variant2/variant.hpp>
|
||||
|
||||
using namespace boost::variant2;
|
||||
|
||||
struct X
|
||||
{
|
||||
int v;
|
||||
X() = default;
|
||||
constexpr X( int v ): v( v ) {}
|
||||
constexpr operator int() const { return v; }
|
||||
};
|
||||
|
||||
struct Y
|
||||
{
|
||||
int v;
|
||||
constexpr Y(): v() {}
|
||||
constexpr Y( int v ): v( v ) {}
|
||||
constexpr operator int() const { return v; }
|
||||
};
|
||||
|
||||
enum E
|
||||
{
|
||||
v
|
||||
};
|
||||
|
||||
#define STATIC_ASSERT(...) static_assert(__VA_ARGS__, #__VA_ARGS__)
|
||||
|
||||
template<class V, class T, class A> constexpr T test( A const& a )
|
||||
{
|
||||
V v;
|
||||
|
||||
v = a;
|
||||
|
||||
return get<T>(v);
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
constexpr variant<int> v( 1 );
|
||||
constexpr auto w = test<variant<int>, int>( v );
|
||||
STATIC_ASSERT( w == 1 );
|
||||
}
|
||||
|
||||
{
|
||||
constexpr variant<X> v( 1 );
|
||||
constexpr auto w = test<variant<X>, X>( v );
|
||||
STATIC_ASSERT( w == 1 );
|
||||
}
|
||||
|
||||
#if defined( BOOST_LIBSTDCXX_VERSION ) && BOOST_LIBSTDCXX_VERSION < 50000
|
||||
#else
|
||||
|
||||
{
|
||||
constexpr variant<Y> v( 1 );
|
||||
constexpr auto w = test<variant<Y>, Y>( v );
|
||||
STATIC_ASSERT( w == 1 );
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
{
|
||||
constexpr variant<int, float> v( 1 );
|
||||
constexpr auto w = test<variant<int, float>, int>( v );
|
||||
STATIC_ASSERT( w == 1 );
|
||||
}
|
||||
|
||||
{
|
||||
constexpr variant<int, float> v( 3.0f );
|
||||
constexpr auto w = test<variant<int, float>, float>( v );
|
||||
STATIC_ASSERT( w == 3.0f );
|
||||
}
|
||||
|
||||
{
|
||||
constexpr variant<int, int, float> v( 3.0f );
|
||||
constexpr auto w = test<variant<int, int, float>, float>( v );
|
||||
STATIC_ASSERT( w == 3.0f );
|
||||
}
|
||||
|
||||
{
|
||||
constexpr variant<E, E, X> v( 1 );
|
||||
constexpr auto w = test<variant<E, E, X>, X>( v );
|
||||
STATIC_ASSERT( w == 1 );
|
||||
}
|
||||
|
||||
{
|
||||
constexpr variant<int, int, float, float, X> v( X(1) );
|
||||
constexpr auto w = test<variant<int, int, float, float, X>, X>( v );
|
||||
STATIC_ASSERT( w == 1 );
|
||||
}
|
||||
|
||||
#if defined( BOOST_LIBSTDCXX_VERSION ) && BOOST_LIBSTDCXX_VERSION < 50000
|
||||
#else
|
||||
|
||||
{
|
||||
constexpr variant<E, E, Y> v( 1 );
|
||||
constexpr auto w = test<variant<E, E, Y>, Y>( v );
|
||||
STATIC_ASSERT( w == 1 );
|
||||
}
|
||||
|
||||
{
|
||||
constexpr variant<int, int, float, float, Y> v( Y(1) );
|
||||
constexpr auto w = test<variant<int, int, float, float, Y>, Y>( v );
|
||||
STATIC_ASSERT( w == 1 );
|
||||
}
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif // constexpr lambda support
|
Reference in New Issue
Block a user