diff --git a/test/Jamfile b/test/Jamfile index b9ad29b..559f2b9 100644 --- a/test/Jamfile +++ b/test/Jamfile @@ -13,29 +13,43 @@ REQ = ; #[ requires cxx11_variadic_templates cxx11_template_aliases cxx11_declty run variant_size.cpp : : : $(REQ) ; run variant_alternative.cpp : : : $(REQ) ; + run variant_holds_alternative.cpp : : : $(REQ) ; compile variant_holds_alternative_cx.cpp : : : $(REQ) ; + run variant_get_by_index.cpp : : : $(REQ) ; compile variant_get_by_index_cx.cpp : : : $(REQ) ; + run variant_get_by_type.cpp : : : $(REQ) ; compile variant_get_by_type_cx.cpp : : : $(REQ) ; + run variant_default_construct.cpp : : : $(REQ) ; compile variant_default_construct_cx.cpp : : : $(REQ) ; + run variant_copy_construct.cpp : : : $(REQ) ; run variant_move_construct.cpp : : : $(REQ) ; + run variant_value_construct.cpp : : : $(REQ) ; compile variant_value_construct_cx.cpp : : : $(REQ) ; + run variant_in_place_index_construct.cpp : : : $(REQ) ; compile variant_in_place_index_construct_cx.cpp : : : $(REQ) ; + run variant_in_place_type_construct.cpp : : : $(REQ) ; compile variant_in_place_type_construct_cx.cpp : : : $(REQ) ; + run variant_copy_assign.cpp : : : $(REQ) ; run variant_move_assign.cpp : : : $(REQ) ; + run variant_value_assign.cpp : : : $(REQ) ; +compile variant_value_assign_cx.cpp : : : $(REQ) ; + run variant_emplace_index.cpp : : : $(REQ) ; compile variant_emplace_index_cx.cpp : : : $(REQ) ; + run variant_emplace_type.cpp : : : $(REQ) ; compile variant_emplace_type_cx.cpp : : : $(REQ) ; + run variant_swap.cpp : : : $(REQ) ; run variant_eq_ne.cpp : : : $(REQ) ; run variant_destroy.cpp : : : $(REQ) ; diff --git a/test/variant_value_assign_cx.cpp b/test/variant_value_assign_cx.cpp new file mode 100644 index 0000000..0a29a0a --- /dev/null +++ b/test/variant_value_assign_cx.cpp @@ -0,0 +1,106 @@ + +// 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 + +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 A test( A const& a ) +{ + V v; + + v = a; + + return get(v); +} + +int main() +{ + { + constexpr auto w = test, int>( 1 ); + STATIC_ASSERT( w == 1 ); + } + + { + constexpr auto w = test, X>( 1 ); + STATIC_ASSERT( w == 1 ); + } + +#if defined( BOOST_LIBSTDCXX_VERSION ) && BOOST_LIBSTDCXX_VERSION < 50000 +#else + + { + constexpr auto w = test, Y>( 1 ); + STATIC_ASSERT( w == 1 ); + } + +#endif + + { + constexpr auto w = test, int>( 1 ); + STATIC_ASSERT( w == 1 ); + } + + { + constexpr auto w = test, float>( 3.0f ); + STATIC_ASSERT( w == 3.0f ); + } + + { + constexpr auto w = test, float>( 3.0f ); + STATIC_ASSERT( w == 3.0f ); + } + + { + constexpr auto w = test, X>( 1 ); + STATIC_ASSERT( w == 1 ); + } + + { + constexpr auto w = test, X>( X(1) ); + STATIC_ASSERT( w == 1 ); + } + +#if defined( BOOST_LIBSTDCXX_VERSION ) && BOOST_LIBSTDCXX_VERSION < 50000 +#else + + { + constexpr auto w = test, Y>( 1 ); + STATIC_ASSERT( w == 1 ); + } + + { + constexpr auto w = test, Y>( Y(1) ); + STATIC_ASSERT( w == 1 ); + } + +#endif +}