mirror of
https://github.com/boostorg/system.git
synced 2026-01-19 04:42:12 +00:00
Decay return type of r | x when r is result<T&>. Refs #128.
This commit is contained in:
@@ -919,9 +919,10 @@ template<class T, class E> struct is_result< result<T, E> >: std::true_type {};
|
||||
// result | value
|
||||
|
||||
template<class T, class E, class U,
|
||||
class En = typename std::enable_if<detail::is_value_convertible_to<U, T>::value>::type
|
||||
class En = typename std::enable_if<std::is_convertible<U, typename std::decay<T>::type>::value>::type
|
||||
>
|
||||
T operator|( result<T, E> const& r, U&& u )
|
||||
typename std::decay<T>::type
|
||||
operator|( result<T, E> const& r, U&& u )
|
||||
{
|
||||
if( r )
|
||||
{
|
||||
@@ -934,9 +935,10 @@ T operator|( result<T, E> const& r, U&& u )
|
||||
}
|
||||
|
||||
template<class T, class E, class U,
|
||||
class En = typename std::enable_if<detail::is_value_convertible_to<U, T>::value>::type
|
||||
class En = typename std::enable_if<std::is_convertible<U, typename std::decay<T>::type>::value>::type
|
||||
>
|
||||
T operator|( result<T, E>&& r, U&& u )
|
||||
typename std::decay<T>::type
|
||||
operator|( result<T, E>&& r, U&& u )
|
||||
{
|
||||
if( r )
|
||||
{
|
||||
|
||||
@@ -165,8 +165,6 @@ boost_test(TYPE run SOURCES result_value_construct6.cpp)
|
||||
boost_test(TYPE run SOURCES result_value_construct7.cpp)
|
||||
boost_test(TYPE run SOURCES result_error_construct5.cpp)
|
||||
boost_test(TYPE run SOURCES result_or_value.cpp)
|
||||
boost_test(TYPE compile-fail SOURCES result_or_value_fail.cpp)
|
||||
boost_test(TYPE compile-fail SOURCES result_or_value_fail2.cpp)
|
||||
boost_test(TYPE run SOURCES result_or_fn0v.cpp)
|
||||
boost_test(TYPE run SOURCES result_or_fn0r.cpp)
|
||||
boost_test(TYPE run SOURCES result_and_fn1v.cpp)
|
||||
|
||||
@@ -198,8 +198,6 @@ run result_value_construct6.cpp ;
|
||||
run result_value_construct7.cpp ;
|
||||
run result_error_construct5.cpp ;
|
||||
run result_or_value.cpp ;
|
||||
compile-fail result_or_value_fail.cpp ;
|
||||
compile-fail result_or_value_fail2.cpp ;
|
||||
run result_or_fn0v.cpp ;
|
||||
run result_or_fn0r.cpp ;
|
||||
run result_and_fn1v.cpp ;
|
||||
|
||||
@@ -191,120 +191,102 @@ int main()
|
||||
|
||||
{
|
||||
int x1 = 1;
|
||||
int x3 = 3;
|
||||
|
||||
result<int&> r( x1 );
|
||||
|
||||
int& x = r | fri | x3;
|
||||
auto r2 = r | fri;
|
||||
|
||||
BOOST_TEST_EQ( &x, &x1 );
|
||||
BOOST_TEST( r2.has_value() ) && BOOST_TEST_EQ( &*r2, &x1 );
|
||||
}
|
||||
|
||||
{
|
||||
int x1 = 1;
|
||||
int x3 = 3;
|
||||
|
||||
result<int&> const r( x1 );
|
||||
|
||||
int& x = r | fri | x3;
|
||||
auto r2 = r | fri;
|
||||
|
||||
BOOST_TEST_EQ( &x, &x1 );
|
||||
BOOST_TEST( r2.has_value() ) && BOOST_TEST_EQ( &*r2, &x1 );
|
||||
}
|
||||
|
||||
{
|
||||
int x1 = 1;
|
||||
int x3 = 3;
|
||||
|
||||
int& x = result<int&>( x1 ) | fri | x3;
|
||||
auto r2 = result<int&>( x1 ) | fri;
|
||||
|
||||
BOOST_TEST_EQ( &x, &x1 );
|
||||
BOOST_TEST( r2.has_value() ) && BOOST_TEST_EQ( &*r2, &x1 );
|
||||
}
|
||||
|
||||
{
|
||||
int x1 = 1;
|
||||
int x3 = 3;
|
||||
|
||||
result<int&> r( x1 );
|
||||
|
||||
int& x = r | fri2 | x3;
|
||||
auto r2 = r | fri2;
|
||||
|
||||
BOOST_TEST_EQ( &x, &x1 );
|
||||
BOOST_TEST( r2.has_value() ) && BOOST_TEST_EQ( &*r2, &x1 );
|
||||
}
|
||||
|
||||
{
|
||||
int x1 = 1;
|
||||
int x3 = 3;
|
||||
|
||||
result<int&> const r( x1 );
|
||||
|
||||
int& x = r | fri2 | x3;
|
||||
auto r2 = r | fri2;
|
||||
|
||||
BOOST_TEST_EQ( &x, &x1 );
|
||||
BOOST_TEST( r2.has_value() ) && BOOST_TEST_EQ( &*r2, &x1 );
|
||||
}
|
||||
|
||||
{
|
||||
int x1 = 1;
|
||||
int x3 = 3;
|
||||
|
||||
int& x = result<int&>( x1 ) | fri2 | x3;
|
||||
auto r2 = result<int&>( x1 ) | fri2;
|
||||
|
||||
BOOST_TEST_EQ( &x, &x1 );
|
||||
BOOST_TEST( r2.has_value() ) && BOOST_TEST_EQ( &*r2, &x1 );
|
||||
}
|
||||
|
||||
{
|
||||
int x3 = 3;
|
||||
|
||||
result<int&, E> r( in_place_error );
|
||||
|
||||
int& x = r | fri | x3;
|
||||
auto r2 = r | fri;
|
||||
|
||||
BOOST_TEST_EQ( &x, &*fri() );
|
||||
BOOST_TEST( r2.has_value() ) && BOOST_TEST_EQ( &*r2, &*fri() );
|
||||
}
|
||||
|
||||
{
|
||||
int x3 = 3;
|
||||
|
||||
result<int&, E> const r( in_place_error );
|
||||
|
||||
int& x = r | fri | x3;
|
||||
auto r2 = r | fri;
|
||||
|
||||
BOOST_TEST_EQ( &x, &*fri() );
|
||||
BOOST_TEST( r2.has_value() ) && BOOST_TEST_EQ( &*r2, &*fri() );
|
||||
}
|
||||
|
||||
{
|
||||
int x3 = 3;
|
||||
auto r2 = result<int&, E>( in_place_error ) | fri;
|
||||
|
||||
int& x = result<int&, E>( in_place_error ) | fri | x3;
|
||||
|
||||
BOOST_TEST_EQ( &x, &*fri() );
|
||||
BOOST_TEST( r2.has_value() ) && BOOST_TEST_EQ( &*r2, &*fri() );
|
||||
}
|
||||
|
||||
{
|
||||
int x3 = 3;
|
||||
|
||||
result<int&, E> r( in_place_error );
|
||||
|
||||
int& x = r | fri2 | x3;
|
||||
auto r2 = r | fri2;
|
||||
|
||||
BOOST_TEST_EQ( &x, &x3 );
|
||||
BOOST_TEST( r2.has_error() );
|
||||
}
|
||||
|
||||
{
|
||||
int x3 = 3;
|
||||
|
||||
result<int&, E> const r( in_place_error );
|
||||
|
||||
int& x = r | fri2 | x3;
|
||||
auto r2 = r | fri2;
|
||||
|
||||
BOOST_TEST_EQ( &x, &x3 );
|
||||
BOOST_TEST( r2.has_error() );
|
||||
}
|
||||
|
||||
{
|
||||
int x3 = 3;
|
||||
auto r2 = result<int&, E>( in_place_error ) | fri2;
|
||||
|
||||
int& x = result<int&, E>( in_place_error ) | fri2 | x3;
|
||||
|
||||
BOOST_TEST_EQ( &x, &x3 );
|
||||
BOOST_TEST( r2.has_error() );
|
||||
}
|
||||
|
||||
{
|
||||
|
||||
@@ -4,6 +4,8 @@
|
||||
|
||||
#include <boost/system/result.hpp>
|
||||
#include <boost/core/lightweight_test.hpp>
|
||||
#include <boost/core/lightweight_test_trait.hpp>
|
||||
#include <type_traits>
|
||||
|
||||
using namespace boost::system;
|
||||
|
||||
@@ -110,9 +112,22 @@ int main()
|
||||
|
||||
result<int&> r( x1 );
|
||||
|
||||
int& x = r | x2;
|
||||
{
|
||||
auto&& x3 = r | x2;
|
||||
|
||||
BOOST_TEST_EQ( &x, &x1 );
|
||||
BOOST_TEST_TRAIT_FALSE(( std::is_lvalue_reference<decltype(x3)> ));
|
||||
|
||||
BOOST_TEST_EQ( x3, x1 );
|
||||
BOOST_TEST_NE( &x3, &x1 );
|
||||
}
|
||||
|
||||
{
|
||||
auto&& x4 = r | 3;
|
||||
|
||||
BOOST_TEST_TRAIT_FALSE(( std::is_lvalue_reference<decltype( x4 )> ));
|
||||
|
||||
BOOST_TEST_EQ( x4, x1 );
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
@@ -121,18 +136,44 @@ int main()
|
||||
|
||||
result<int&> const r( x1 );
|
||||
|
||||
int& x = r | x2;
|
||||
{
|
||||
auto&& x3 = r | x2;
|
||||
|
||||
BOOST_TEST_EQ( &x, &x1 );
|
||||
BOOST_TEST_TRAIT_FALSE(( std::is_lvalue_reference<decltype(x3)> ));
|
||||
|
||||
BOOST_TEST_EQ( x3, x1 );
|
||||
BOOST_TEST_NE( &x3, &x1 );
|
||||
}
|
||||
|
||||
{
|
||||
auto&& x4 = r | 3;
|
||||
|
||||
BOOST_TEST_TRAIT_FALSE(( std::is_lvalue_reference<decltype( x4 )> ));
|
||||
|
||||
BOOST_TEST_EQ( x4, x1 );
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
int x1 = 1;
|
||||
int x2 = 2;
|
||||
|
||||
int& x = result<int&>( x1 ) | x2;
|
||||
{
|
||||
auto&& x3 = result<int&>( x1 ) | x2;
|
||||
|
||||
BOOST_TEST_EQ( &x, &x1 );
|
||||
BOOST_TEST_TRAIT_FALSE(( std::is_lvalue_reference<decltype(x3)> ));
|
||||
|
||||
BOOST_TEST_EQ( x3, x1 );
|
||||
BOOST_TEST_NE( &x3, &x1 );
|
||||
}
|
||||
|
||||
{
|
||||
auto&& x4 = result<int&>( x1 ) | 3;
|
||||
|
||||
BOOST_TEST_TRAIT_FALSE(( std::is_lvalue_reference<decltype( x4 )> ));
|
||||
|
||||
BOOST_TEST_EQ( x4, x1 );
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
@@ -140,9 +181,22 @@ int main()
|
||||
|
||||
result<int&, E> r( in_place_error );
|
||||
|
||||
int& x = r | x2;
|
||||
{
|
||||
auto&& x3 = r | x2;
|
||||
|
||||
BOOST_TEST_EQ( &x, &x2 );
|
||||
BOOST_TEST_TRAIT_FALSE(( std::is_lvalue_reference<decltype(x3)> ));
|
||||
|
||||
BOOST_TEST_EQ( x3, x2 );
|
||||
BOOST_TEST_NE( &x3, &x2 );
|
||||
}
|
||||
|
||||
{
|
||||
auto&& x4 = r | 3;
|
||||
|
||||
BOOST_TEST_TRAIT_FALSE(( std::is_lvalue_reference<decltype( x4 )> ));
|
||||
|
||||
BOOST_TEST_EQ( x4, 3 );
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
@@ -150,17 +204,43 @@ int main()
|
||||
|
||||
result<int&, E> const r( in_place_error );
|
||||
|
||||
int& x = r | x2;
|
||||
{
|
||||
auto&& x3 = r | x2;
|
||||
|
||||
BOOST_TEST_EQ( &x, &x2 );
|
||||
BOOST_TEST_TRAIT_FALSE(( std::is_lvalue_reference<decltype(x3)> ));
|
||||
|
||||
BOOST_TEST_EQ( x3, x2 );
|
||||
BOOST_TEST_NE( &x3, &x2 );
|
||||
}
|
||||
|
||||
{
|
||||
auto&& x4 = r | 3;
|
||||
|
||||
BOOST_TEST_TRAIT_FALSE(( std::is_lvalue_reference<decltype( x4 )> ));
|
||||
|
||||
BOOST_TEST_EQ( x4, 3 );
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
int x2 = 2;
|
||||
|
||||
int& x = result<int&, E>( in_place_error ) | x2;
|
||||
{
|
||||
auto&& x3 = result<int&, E>( in_place_error ) | x2;
|
||||
|
||||
BOOST_TEST_EQ( &x, &x2 );
|
||||
BOOST_TEST_TRAIT_FALSE(( std::is_lvalue_reference<decltype(x3)> ));
|
||||
|
||||
BOOST_TEST_EQ( x3, x2 );
|
||||
BOOST_TEST_NE( &x3, &x2 );
|
||||
}
|
||||
|
||||
{
|
||||
auto&& x4 = result<int&, E>( in_place_error ) | 3;
|
||||
|
||||
BOOST_TEST_TRAIT_FALSE(( std::is_lvalue_reference<decltype( x4 )> ));
|
||||
|
||||
BOOST_TEST_EQ( x4, 3 );
|
||||
}
|
||||
}
|
||||
|
||||
return boost::report_errors();
|
||||
|
||||
@@ -1,14 +0,0 @@
|
||||
// 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>
|
||||
|
||||
using namespace boost::system;
|
||||
|
||||
int main()
|
||||
{
|
||||
int x = 1;
|
||||
result<int const&> r( x );
|
||||
r | 2;
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
// 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>
|
||||
|
||||
using namespace boost::system;
|
||||
|
||||
int main()
|
||||
{
|
||||
int x = 1;
|
||||
result<int const&>( x ) | 2;
|
||||
}
|
||||
Reference in New Issue
Block a user