Change operator* and operator-> to throw instead of having a precondition

This commit is contained in:
Peter Dimov
2026-02-21 03:26:49 +02:00
parent 0ff6989330
commit 9ead4aeea9
16 changed files with 228 additions and 141 deletions
+11 -2
View File
@@ -26,6 +26,15 @@ struct X
int X::instances = 0;
struct E
{
};
BOOST_NORETURN void throw_exception_from_error( X const &, boost::source_location const& )
{
throw E();
}
int main()
{
{
@@ -45,7 +54,7 @@ int main()
BOOST_TEST( r.has_value() );
BOOST_TEST( !r.has_error() );
BOOST_TEST_EQ( *r, 1 );
BOOST_TEST_EQ( r.unsafe_value(), 1 );
}
BOOST_TEST_EQ( X::instances, 0 );
@@ -135,7 +144,7 @@ int main()
BOOST_TEST( r.has_value() );
BOOST_TEST( !r.has_error() );
BOOST_TEST_EQ( *r, 1 );
BOOST_TEST_EQ( r.unsafe_value(), 1 );
}
return boost::report_errors();