diff --git a/test/Jamfile b/test/Jamfile index b0dc727..4830d34 100644 --- a/test/Jamfile +++ b/test/Jamfile @@ -42,6 +42,7 @@ run variant_copy_assign.cpp : : : $(REQ) ; compile variant_copy_assign_cx.cpp : : : $(REQ) ; run variant_move_assign.cpp : : : $(REQ) ; +compile variant_move_assign_cx.cpp : : : $(REQ) ; run variant_value_assign.cpp : : : $(REQ) ; compile variant_value_assign_cx.cpp : : : $(REQ) ; diff --git a/test/variant_move_assign_cx.cpp b/test/variant_move_assign_cx.cpp new file mode 100644 index 0000000..e6a6443 --- /dev/null +++ b/test/variant_move_assign_cx.cpp @@ -0,0 +1,116 @@ + +// 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 +#include + +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 constexpr T test( A&& a ) +{ + V v; + + v = std::forward(a); + + return get(v); +} + +int main() +{ + { + constexpr auto w = test, int>( variant( 1 ) ); + STATIC_ASSERT( w == 1 ); + } + + { + constexpr auto w = test, X>( variant( 1 ) ); + STATIC_ASSERT( w == 1 ); + } + +#if defined( BOOST_LIBSTDCXX_VERSION ) && BOOST_LIBSTDCXX_VERSION < 50000 +#else + + { + constexpr auto w = test, Y>( variant( 1 ) ); + STATIC_ASSERT( w == 1 ); + } + +#endif + + { + constexpr auto w = test, int>( variant( 1 ) ); + STATIC_ASSERT( w == 1 ); + } + + { + constexpr auto w = test, float>( variant( 3.0f ) ); + STATIC_ASSERT( w == 3.0f ); + } + + { + constexpr auto w = test, float>( variant( 3.0f ) ); + STATIC_ASSERT( w == 3.0f ); + } + + { + constexpr auto w = test, X>( variant( 1 ) ); + STATIC_ASSERT( w == 1 ); + } + + { + constexpr auto w = test, X>( variant( X(1) ) ); + STATIC_ASSERT( w == 1 ); + } + +#if defined( BOOST_LIBSTDCXX_VERSION ) && BOOST_LIBSTDCXX_VERSION < 50000 +#else + + { + constexpr auto w = test, Y>( variant( 1 ) ); + STATIC_ASSERT( w == 1 ); + } + + { + constexpr auto w = test, Y>( variant( Y(1) ) ); + STATIC_ASSERT( w == 1 ); + } + +#endif +} + +#endif // constexpr lambda support