diff --git a/test/Jamfile b/test/Jamfile index 8242786..fdb6024 100644 --- a/test/Jamfile +++ b/test/Jamfile @@ -112,3 +112,5 @@ run variant_trivial.cpp ; run variant_special.cpp ; run variant_visit_derived.cpp ; + +run variant_many_types.cpp ; diff --git a/test/variant_many_types.cpp b/test/variant_many_types.cpp new file mode 100644 index 0000000..683e58b --- /dev/null +++ b/test/variant_many_types.cpp @@ -0,0 +1,107 @@ + +// Copyright 2020 Peter Dimov. +// Distributed under the Boost Software License, Version 1.0. +// https://www.boost.org/LICENSE_1_0.txt + +#if defined(_MSC_VER) +# pragma warning( disable: 4503 ) // decorated name length exceeded +#endif + +#include +#include +#include + +using namespace boost::mp11; + +template struct X +{ + static int const value = I::value; + int v_; +}; + +template int const X::value; + +template struct Y +{ + static int const value = I::value; + int v_; + + Y() = default; + Y( Y const& ) = default; + + Y& operator=( Y const& ) noexcept = default; + + Y& operator=( Y&& r ) noexcept + { + v_ = r.v_; + return *this; + } +}; + +template int const Y::value; + +template struct Z +{ + static int const value = I::value; + int v_; + + ~Z() {} +}; + +template int const Z::value; + +template struct F1 +{ + template void operator()( T ) const + { + int const i = T::value; + + T t{ i * 2 }; + + using boost::variant2::get; + + { + V v( t ); + + BOOST_TEST_EQ( v.index(), t.value ); + BOOST_TEST_EQ( get( v ).v_, t.v_ ); + BOOST_TEST_EQ( get( v ).v_, t.v_ ); + } + + { + V const v( t ); + + BOOST_TEST_EQ( v.index(), t.value ); + BOOST_TEST_EQ( get( v ).v_, t.v_ ); + BOOST_TEST_EQ( get( v ).v_, t.v_ ); + } + + { + V v; + + v = t; + + BOOST_TEST_EQ( v.index(), t.value ); + BOOST_TEST_EQ( get( v ).v_, t.v_ ); + BOOST_TEST_EQ( get( v ).v_, t.v_ ); + } + } +}; + +template void test() +{ + mp_for_each( F1() ); +} + +int main() +{ + int const N = 32; + + using V = mp_rename, boost::variant2::variant>; + + test< mp_transform >(); + test< mp_transform >(); + test< mp_transform >(); + + return boost::report_errors(); +}