mirror of
https://github.com/boostorg/system.git
synced 2026-06-11 19:51:11 +02:00
Compare commits
2 Commits
feature/drone
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
| bc7c00fa67 | |||
| 8c935dc996 |
@@ -8,6 +8,10 @@ https://www.boost.org/LICENSE_1_0.txt
|
||||
# Revision History
|
||||
:idprefix:
|
||||
|
||||
## Changes in Boost 1.92
|
||||
|
||||
* Fix `unwrap_and_invoke` for functions returning `void`.
|
||||
|
||||
## Changes in Boost 1.91
|
||||
|
||||
* The return type of `operator|(result<T&>, U)` has been changed to non-reference.
|
||||
|
||||
@@ -66,7 +66,8 @@ template<class R, class T, class E> int invoke_test( R& r, result<T, E> const& r
|
||||
|
||||
template<class F, class... A,
|
||||
class R = decltype( compat::invoke( std::declval<F>(), detail::invoke_unwrap( std::declval<A>() )... ) ),
|
||||
class E = detail::get_error_type<compat::remove_cvref_t<A>...>
|
||||
class E = detail::get_error_type<compat::remove_cvref_t<A>...>,
|
||||
class En = typename std::enable_if< !std::is_void<R>::value >::type
|
||||
>
|
||||
auto unwrap_and_invoke( F&& f, A&&... a ) -> result<R, E>
|
||||
{
|
||||
@@ -82,6 +83,28 @@ auto unwrap_and_invoke( F&& f, A&&... a ) -> result<R, E>
|
||||
return compat::invoke( std::forward<F>(f), detail::invoke_unwrap( std::forward<A>(a) )... );
|
||||
}
|
||||
|
||||
template<class F, class... A,
|
||||
class R = decltype( compat::invoke( std::declval<F>(), detail::invoke_unwrap( std::declval<A>() )... ) ),
|
||||
class E = detail::get_error_type<compat::remove_cvref_t<A>...>,
|
||||
class En1 = void,
|
||||
class En2 = typename std::enable_if< std::is_void<R>::value >::type
|
||||
>
|
||||
auto unwrap_and_invoke( F&& f, A&&... a ) -> result<R, E>
|
||||
{
|
||||
{
|
||||
result<void, E> r;
|
||||
|
||||
using Q = int[];
|
||||
(void)Q{ detail::invoke_test( r, a )... };
|
||||
|
||||
if( !r ) return r.error();
|
||||
}
|
||||
|
||||
compat::invoke( std::forward<F>(f), detail::invoke_unwrap( std::forward<A>(a) )... );
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
// unwrap_and_construct
|
||||
|
||||
namespace detail
|
||||
|
||||
@@ -228,3 +228,5 @@ run unwrap_and_construct.cpp ;
|
||||
run unwrap_and_construct2.cpp ;
|
||||
|
||||
run detail_is_aggregate_test.cpp ;
|
||||
|
||||
run unwrap_and_invoke3.cpp ;
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
// Copyright 2026 Peter Dimov
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// https://www.boost.org/LICENSE_1_0.txt
|
||||
|
||||
#include <boost/system/unwrap_and_invoke.hpp>
|
||||
#include <boost/system/result.hpp>
|
||||
#include <boost/core/lightweight_test.hpp>
|
||||
|
||||
using namespace boost::system;
|
||||
|
||||
int g_x;
|
||||
|
||||
void f( int x )
|
||||
{
|
||||
g_x += x;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
g_x = 0;
|
||||
|
||||
result<int> a1( 1 );
|
||||
result<void> r = unwrap_and_invoke( f, a1 );
|
||||
|
||||
BOOST_TEST( r );
|
||||
BOOST_TEST_EQ( g_x, 1 );
|
||||
}
|
||||
|
||||
{
|
||||
auto ec = make_error_code( errc::invalid_argument );
|
||||
|
||||
result<int> a1( ec );
|
||||
result<void> r = unwrap_and_invoke( f, a1 );
|
||||
|
||||
BOOST_TEST( r.has_error() ) && BOOST_TEST_EQ( r.error(), ec );
|
||||
}
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
Reference in New Issue
Block a user