diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 index 596c478..515ad40 100644 --- a/test/Jamfile.v2 +++ b/test/Jamfile.v2 @@ -135,3 +135,5 @@ run hash_tuple_like_test2.cpp run is_range_test4.cpp ; run hash_container_test2.cpp ; + +run hash_variant_test2.cpp ; diff --git a/test/hash_variant_test2.cpp b/test/hash_variant_test2.cpp new file mode 100644 index 0000000..9f46334 --- /dev/null +++ b/test/hash_variant_test2.cpp @@ -0,0 +1,50 @@ +// Copyright 2026 Peter Dimov +// Distributed under the Boost Software License, Version 1.0. +// https://www.boost.org/LICENSE_1_0.txt + +#include +#include +#include + +#if defined(BOOST_NO_CXX17_HDR_VARIANT) + +BOOST_PRAGMA_MESSAGE( "Skipping test because BOOST_NO_CXX17_HDR_VARIANT is defined" ) +int main() {} + +#else + +#include +#include + +struct X +{ + operator int() const { throw 5; } +}; + +std::variant make_valueless_variant() +{ + std::variant v; + + try + { + v.emplace( X() ); + } + catch( int ) + { + } + + BOOST_TEST( v.valueless_by_exception() ); + + return v; +} + +int main() +{ + std::variant v1, v2 = make_valueless_variant(); + + BOOST_TEST_NE( (boost::hash>()( v1 )), (boost::hash>()( v2 )) ); + + return boost::report_errors(); +} + +#endif