Add throw_exception_from_error overload for std::error_code

This commit is contained in:
Peter Dimov
2022-02-03 18:35:42 +02:00
parent 9c6a09f41d
commit a5d68e52e6
2 changed files with 40 additions and 1 deletions

View File

@ -16,6 +16,7 @@
#include <type_traits>
#include <utility>
#include <iosfwd>
#include <system_error>
//
@ -31,6 +32,11 @@ BOOST_NORETURN BOOST_NOINLINE inline void throw_exception_from_error( error_code
boost::throw_exception( system_error( e ) );
}
BOOST_NORETURN BOOST_NOINLINE inline void throw_exception_from_error( std::error_code const & e )
{
boost::throw_exception( std::system_error( e ) );
}
// in_place_*
using in_place_value_t = variant2::in_place_index_t<0>;

View File

@ -1,10 +1,11 @@
// Copyright 2017, 2021 Peter Dimov.
// Copyright 2017, 2021, 2022 Peter Dimov.
// Distributed under the Boost Software License, Version 1.0.
// https://www.boost.org/LICENSE_1_0.txt
#include <boost/system/result.hpp>
#include <boost/core/lightweight_test.hpp>
#include <boost/core/lightweight_test_trait.hpp>
#include <system_error>
using namespace boost::system;
@ -165,6 +166,22 @@ int main()
BOOST_TEST_EQ( result<int>( ec ).operator->(), static_cast<int*>(0) );
}
{
auto ec = make_error_code( std::errc::invalid_argument );
result<int, std::error_code> const r( ec );
BOOST_TEST( !r.has_value() );
BOOST_TEST( r.has_error() );
BOOST_TEST_NOT( r );
BOOST_TEST( !r );
BOOST_TEST_THROWS( r.value(), std::system_error );
BOOST_TEST_EQ( r.operator->(), static_cast<int*>(0) );
}
{
result<X> r( 1 );
@ -341,5 +358,21 @@ int main()
BOOST_TEST_EQ( result<void>( ec ).operator->(), static_cast<void*>(0) );
}
{
auto ec = make_error_code( std::errc::invalid_argument );
result<void, std::error_code> const r( ec );
BOOST_TEST( !r.has_value() );
BOOST_TEST( r.has_error() );
BOOST_TEST_NOT( r );
BOOST_TEST( !r );
BOOST_TEST_THROWS( r.value(), std::system_error );
BOOST_TEST_EQ( r.operator->(), static_cast<void*>(0) );
}
return boost::report_errors();
}