mirror of
https://github.com/boostorg/system.git
synced 2025-12-30 18:48:05 +01:00
Compare commits
4 Commits
boost-1.82
...
feature/is
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
32dbf1b992 | ||
|
|
707b24bfa1 | ||
|
|
bb1caae0d5 | ||
|
|
c5c49894e6 |
@@ -1657,7 +1657,8 @@ public:
|
||||
|
||||
// error access
|
||||
|
||||
constexpr E error() const;
|
||||
constexpr E error() const &;
|
||||
constexpr E error() &&;
|
||||
|
||||
// emplace
|
||||
|
||||
@@ -1851,7 +1852,8 @@ Returns: ::
|
||||
#### Error Access
|
||||
|
||||
```
|
||||
constexpr E error() const;
|
||||
constexpr E error() const &;
|
||||
constexpr E error() &&;
|
||||
```
|
||||
[none]
|
||||
* {blank}
|
||||
@@ -1979,7 +1981,8 @@ public:
|
||||
|
||||
// error access
|
||||
|
||||
constexpr E error() const;
|
||||
constexpr E error() const &;
|
||||
constexpr E error() &&;
|
||||
|
||||
// emplace
|
||||
|
||||
@@ -2120,7 +2123,8 @@ Effects: ::
|
||||
#### Error Access
|
||||
|
||||
```
|
||||
constexpr E error() const;
|
||||
constexpr E error() const &;
|
||||
constexpr E error() &&;
|
||||
```
|
||||
[none]
|
||||
* {blank}
|
||||
|
||||
@@ -31,7 +31,9 @@ struct mutex
|
||||
} // namespace system
|
||||
} // namespace boost
|
||||
|
||||
#elif defined(BOOST_MSSTL_VERSION) && BOOST_MSSTL_VERSION >= 140
|
||||
#else // defined(BOOST_SYSTEM_DISABLE_THREADS)
|
||||
|
||||
#if defined(BOOST_MSSTL_VERSION) && BOOST_MSSTL_VERSION >= 140
|
||||
|
||||
// Under the MS STL, std::mutex::mutex() is not constexpr, as is
|
||||
// required by the standard, which leads to initialization order
|
||||
@@ -40,6 +42,14 @@ struct mutex
|
||||
|
||||
#include <shared_mutex>
|
||||
|
||||
#if BOOST_MSSTL_VERSION >= 142 || _HAS_SHARED_MUTEX
|
||||
# define BOOST_SYSTEM_HAS_MSSTL_SHARED_MUTEX
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
#if defined(BOOST_SYSTEM_HAS_MSSTL_SHARED_MUTEX)
|
||||
|
||||
namespace boost
|
||||
{
|
||||
namespace system
|
||||
@@ -53,7 +63,7 @@ typedef std::shared_mutex mutex;
|
||||
} // namespace system
|
||||
} // namespace boost
|
||||
|
||||
#else
|
||||
#else // defined(BOOST_SYSTEM_HAS_MSSTL_SHARED_MUTEX)
|
||||
|
||||
#include <mutex>
|
||||
|
||||
@@ -70,7 +80,8 @@ using std::mutex;
|
||||
} // namespace system
|
||||
} // namespace boost
|
||||
|
||||
#endif
|
||||
#endif // defined(BOOST_SYSTEM_HAS_MSSTL_SHARED_MUTEX)
|
||||
#endif // defined(BOOST_SYSTEM_DISABLE_THREADS)
|
||||
|
||||
namespace boost
|
||||
{
|
||||
|
||||
@@ -401,12 +401,18 @@ public:
|
||||
|
||||
// error access
|
||||
|
||||
constexpr E error() const
|
||||
constexpr E error() const &
|
||||
noexcept( std::is_nothrow_default_constructible<E>::value && std::is_nothrow_copy_constructible<E>::value )
|
||||
{
|
||||
return has_error()? variant2::unsafe_get<1>( v_ ): E();
|
||||
}
|
||||
|
||||
BOOST_CXX14_CONSTEXPR E error() &&
|
||||
noexcept( std::is_nothrow_default_constructible<E>::value && std::is_nothrow_move_constructible<E>::value )
|
||||
{
|
||||
return has_error()? std::move( variant2::unsafe_get<1>( v_ ) ): E();
|
||||
}
|
||||
|
||||
// emplace
|
||||
|
||||
template<class... A>
|
||||
@@ -581,12 +587,18 @@ public:
|
||||
|
||||
// error access
|
||||
|
||||
constexpr E error() const
|
||||
constexpr E error() const &
|
||||
noexcept( std::is_nothrow_default_constructible<E>::value && std::is_nothrow_copy_constructible<E>::value )
|
||||
{
|
||||
return has_error()? variant2::unsafe_get<1>( v_ ): E();
|
||||
}
|
||||
|
||||
BOOST_CXX14_CONSTEXPR E error() &&
|
||||
noexcept( std::is_nothrow_default_constructible<E>::value && std::is_nothrow_move_constructible<E>::value )
|
||||
{
|
||||
return has_error()? std::move( variant2::unsafe_get<1>( v_ ) ): E();
|
||||
}
|
||||
|
||||
// emplace
|
||||
|
||||
BOOST_CXX14_CONSTEXPR void emplace()
|
||||
|
||||
@@ -163,3 +163,4 @@ boost_test(TYPE run SOURCES result_emplace.cpp)
|
||||
boost_test(TYPE run SOURCES result_error_construct4.cpp)
|
||||
boost_test(TYPE run SOURCES result_value_construct4.cpp)
|
||||
boost_test(TYPE run SOURCES result_value_construct5.cpp)
|
||||
boost_test(TYPE run SOURCES result_error_move.cpp)
|
||||
|
||||
@@ -193,3 +193,4 @@ run result_emplace.cpp : : : $(CPP11) ;
|
||||
run result_error_construct4.cpp : : : $(CPP11) ;
|
||||
run result_value_construct4.cpp : : : $(CPP11) ;
|
||||
run result_value_construct5.cpp : : : $(CPP11) ;
|
||||
run result_error_move.cpp : : : $(CPP11) ;
|
||||
|
||||
91
test/result_error_move.cpp
Normal file
91
test/result_error_move.cpp
Normal file
@@ -0,0 +1,91 @@
|
||||
// Copyright 2023 Klemens Morgenstern
|
||||
// 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 <string>
|
||||
|
||||
using namespace boost::system;
|
||||
|
||||
struct X
|
||||
{
|
||||
int v_;
|
||||
|
||||
explicit X( int v = 0 ): v_( v ) {}
|
||||
|
||||
X( X const& ) = delete;
|
||||
X& operator=( X const& ) = delete;
|
||||
|
||||
X( X && ) = default;
|
||||
X& operator=( X && ) = default;
|
||||
};
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
result<std::string, X> r( 1 );
|
||||
|
||||
BOOST_TEST( !r.has_value() );
|
||||
BOOST_TEST( r.has_error() );
|
||||
|
||||
BOOST_TEST_EQ( std::move( r ).error().v_, 1 );
|
||||
}
|
||||
|
||||
{
|
||||
BOOST_TEST(( !result<std::string, X>( 1 ).has_value() ));
|
||||
BOOST_TEST(( result<std::string, X>( 1 ).has_error() ));
|
||||
|
||||
BOOST_TEST_EQ( (result<std::string, X>( 1 ).error().v_), 1 );
|
||||
}
|
||||
|
||||
{
|
||||
result<std::string, X> r( "s" );
|
||||
|
||||
BOOST_TEST( r.has_value() );
|
||||
BOOST_TEST( !r.has_error() );
|
||||
|
||||
BOOST_TEST_EQ( std::move( r ).error().v_, 0 );
|
||||
}
|
||||
|
||||
{
|
||||
BOOST_TEST(( result<std::string, X>( "s" ).has_value() ));
|
||||
BOOST_TEST(( !result<std::string, X>( "s" ).has_error() ));
|
||||
|
||||
BOOST_TEST_EQ( (result<std::string, X>( "s" ).error().v_), 0 );
|
||||
}
|
||||
|
||||
{
|
||||
result<void, X> r( 1 );
|
||||
|
||||
BOOST_TEST( !r.has_value() );
|
||||
BOOST_TEST( r.has_error() );
|
||||
|
||||
BOOST_TEST_EQ( std::move( r ).error().v_, 1 );
|
||||
}
|
||||
|
||||
{
|
||||
BOOST_TEST(( !result<void, X>( 1 ).has_value() ));
|
||||
BOOST_TEST(( result<void, X>( 1 ).has_error() ));
|
||||
|
||||
BOOST_TEST_EQ( (result<void, X>( 1 ).error().v_), 1 );
|
||||
}
|
||||
|
||||
{
|
||||
result<void, X> r;
|
||||
|
||||
BOOST_TEST( r.has_value() );
|
||||
BOOST_TEST( !r.has_error() );
|
||||
|
||||
BOOST_TEST_EQ( std::move( r ).error().v_, 0 );
|
||||
}
|
||||
|
||||
{
|
||||
BOOST_TEST(( result<void, X>().has_value() ));
|
||||
BOOST_TEST(( !result<void, X>().has_error() ));
|
||||
|
||||
BOOST_TEST_EQ( (result<void, X>().error().v_), 0 );
|
||||
}
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
Reference in New Issue
Block a user