mirror of
https://github.com/boostorg/system.git
synced 2025-12-25 08:18:05 +01:00
Compare commits
45 Commits
feature/gc
...
feature/is
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
19e27a73e9 | ||
|
|
19020ce925 | ||
|
|
3faf415026 | ||
|
|
a2df4d09da | ||
|
|
455c6a6332 | ||
|
|
efb7634666 | ||
|
|
2bba3fd5e2 | ||
|
|
8c740705e6 | ||
|
|
4708d95e80 | ||
|
|
867f6d06d0 | ||
|
|
ac1ed1ecc1 | ||
|
|
cc7c2f7ee4 | ||
|
|
f2e1db8021 | ||
|
|
ede243c42f | ||
|
|
1558aaa789 | ||
|
|
96b876d91a | ||
|
|
eb9ae4ac69 | ||
|
|
8fd487d496 | ||
|
|
5223c94aa9 | ||
|
|
a5ee3f291c | ||
|
|
4200b00973 | ||
|
|
533dfe1688 | ||
|
|
7dec756a6f | ||
|
|
648a35838b | ||
|
|
256fe92dbb | ||
|
|
5debb8a041 | ||
|
|
a97e5a0546 | ||
|
|
dc17edfa07 | ||
|
|
65da7dfd56 | ||
|
|
9279001b8c | ||
|
|
616e652bd7 | ||
|
|
98439855bd | ||
|
|
986efb1420 | ||
|
|
28a13571b9 | ||
|
|
65ed1eef66 | ||
|
|
6de20eeebc | ||
|
|
0a9266ea7e | ||
|
|
adb9fc54cb | ||
|
|
e197c5e803 | ||
|
|
6d7a57a970 | ||
|
|
00c71cf388 | ||
|
|
d930cea481 | ||
|
|
4f09f4adde | ||
|
|
abd62362ef | ||
|
|
8d8e6a90de |
31
.github/workflows/ci.yml
vendored
31
.github/workflows/ci.yml
vendored
@@ -47,6 +47,10 @@ jobs:
|
||||
cxxstd: "03,11,14,17,2a"
|
||||
os: ubuntu-20.04
|
||||
install: g++-11
|
||||
- toolset: gcc-12
|
||||
cxxstd: "03,11,14,17,20"
|
||||
os: ubuntu-22.04
|
||||
install: g++-12
|
||||
- toolset: clang
|
||||
compiler: clang++-3.9
|
||||
cxxstd: "03,11,14"
|
||||
@@ -92,11 +96,21 @@ jobs:
|
||||
os: ubuntu-20.04
|
||||
- toolset: clang
|
||||
compiler: clang++-12
|
||||
cxxstd: "03,11,14,17,2a"
|
||||
cxxstd: "03,11,14,17,20"
|
||||
os: ubuntu-20.04
|
||||
- toolset: clang
|
||||
compiler: clang++-13
|
||||
cxxstd: "03,11,14,17,20"
|
||||
os: ubuntu-22.04
|
||||
install: clang-13
|
||||
- toolset: clang
|
||||
compiler: clang++-14
|
||||
cxxstd: "03,11,14,17,20"
|
||||
os: ubuntu-22.04
|
||||
install: clang-14
|
||||
- toolset: clang
|
||||
cxxstd: "03,11,14,17,2a"
|
||||
os: macos-10.15
|
||||
os: macos-11
|
||||
|
||||
runs-on: ${{matrix.os}}
|
||||
|
||||
@@ -148,10 +162,6 @@ jobs:
|
||||
cxxstd: "14"
|
||||
addrmd: 32,64
|
||||
os: windows-2019
|
||||
- toolset: msvc-14.1
|
||||
cxxstd: "14,17,latest"
|
||||
addrmd: 32,64
|
||||
os: windows-2016
|
||||
- toolset: msvc-14.2
|
||||
cxxstd: "14,17,20,latest"
|
||||
addrmd: 32,64
|
||||
@@ -209,7 +219,8 @@ jobs:
|
||||
include:
|
||||
- os: ubuntu-18.04
|
||||
- os: ubuntu-20.04
|
||||
- os: macos-10.15
|
||||
- os: ubuntu-22.04
|
||||
- os: macos-11
|
||||
|
||||
runs-on: ${{matrix.os}}
|
||||
|
||||
@@ -255,7 +266,8 @@ jobs:
|
||||
include:
|
||||
- os: ubuntu-18.04
|
||||
- os: ubuntu-20.04
|
||||
- os: macos-10.15
|
||||
- os: ubuntu-22.04
|
||||
- os: macos-11
|
||||
|
||||
runs-on: ${{matrix.os}}
|
||||
|
||||
@@ -311,7 +323,8 @@ jobs:
|
||||
include:
|
||||
- os: ubuntu-18.04
|
||||
- os: ubuntu-20.04
|
||||
- os: macos-10.15
|
||||
- os: ubuntu-22.04
|
||||
- os: macos-11
|
||||
|
||||
runs-on: ${{matrix.os}}
|
||||
|
||||
|
||||
25
README.md
Normal file
25
README.md
Normal file
@@ -0,0 +1,25 @@
|
||||
# Boost.System
|
||||
|
||||
The Boost.System library, part of [Boost C++ Libraries](https://boost.org),
|
||||
implements an extensible framework for error reporting in the form of an
|
||||
`error_code` class and supporting facilities.
|
||||
|
||||
It has been proposed for the C++11 standard, has been accepted, and
|
||||
is now available as part of the standard library in the `<system_error>`
|
||||
header. However, the Boost implementation has continued to evolve and
|
||||
gain enhancements and additional functionality, such as support for
|
||||
attaching [source locations](https://www.boost.org/doc/libs/release/libs/assert/doc/html/assert.html#source_location_support)
|
||||
to `error_code`, and a `result<T>` class that can carry either a value
|
||||
or an error code.
|
||||
|
||||
See [the documentation of System](http://boost.org/libs/system) for more
|
||||
information.
|
||||
|
||||
Since `<system_error>` is a relatively undocumented portion of the C++
|
||||
standard library, the documentation of Boost.System may be useful to you
|
||||
even if you use the standard components.
|
||||
|
||||
## License
|
||||
|
||||
Distributed under the
|
||||
[Boost Software License, Version 1.0](http://boost.org/LICENSE_1_0.txt).
|
||||
@@ -24,10 +24,6 @@ environment:
|
||||
TOOLSET: msvc-14.1
|
||||
CXXSTD: 14,17,latest
|
||||
ADDRMD: 32,64
|
||||
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2019
|
||||
TOOLSET: clang-win
|
||||
CXXSTD: 14,17,latest
|
||||
ADDRMD: 32,64
|
||||
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015
|
||||
ADDPATH: C:\cygwin\bin;
|
||||
TOOLSET: gcc
|
||||
|
||||
@@ -8,12 +8,24 @@ https://www.boost.org/LICENSE_1_0.txt
|
||||
# Revision History
|
||||
:idprefix:
|
||||
|
||||
## Changes in Boost 1.80
|
||||
|
||||
* When an `error_code` is converted to `std::error_code` and then back
|
||||
to `error_code`, the original is now restored, if possible.
|
||||
* Reworked the conversion from `error_category` to `std::error_category`
|
||||
to avoid the one-time allocation that shows up on leak checkers.
|
||||
* Added a constructor that allows replacing the source location of an
|
||||
`error_code`, and a corresponding `assign`.
|
||||
* Added a converting constructor to `result`.
|
||||
|
||||
## Changes in Boost 1.79
|
||||
|
||||
* Added a `throw_exception_from_error` overload for `std::error_code`.
|
||||
* Added a `boost::source_location` parameter to `throw_exception_from_error`.
|
||||
* Added `throw_exception_from_error` overloads for `errc::errc_t`,
|
||||
`std::error_code`, `std::errc`, `std::exception_ptr`.
|
||||
* `result<T>::value` now automatically supplies `BOOST_CURRENT_LOCATION` to
|
||||
`throw_exception_from_error` via a default argument.
|
||||
* Added an `errc::make_error_code` overload taking a source location.
|
||||
|
||||
## Changes in Boost 1.78
|
||||
|
||||
|
||||
@@ -185,9 +185,13 @@ namespace errc {
|
||||
template<> struct is_error_condition_enum<errc::errc_t>
|
||||
{ static const bool value = true; };
|
||||
|
||||
constexpr error_code make_error_code( errc::errc_t e ) noexcept;
|
||||
constexpr error_condition make_error_condition( errc::errc_t e ) noexcept;
|
||||
|
||||
constexpr error_code make_error_code( errc::errc_t e ) noexcept;
|
||||
|
||||
error_code make_error_code( errc::errc_t e,
|
||||
boost::source_location const * loc ) noexcept;
|
||||
|
||||
} // namespace system
|
||||
} // namespace boost
|
||||
```
|
||||
@@ -256,6 +260,38 @@ void my_api_function( boost::system::error_code& ec )
|
||||
}
|
||||
```
|
||||
|
||||
```
|
||||
constexpr error_code make_error_code( errc::errc_t e,
|
||||
boost::source_location const * loc ) noexcept;
|
||||
```
|
||||
[none]
|
||||
* {blank}
|
||||
+
|
||||
Returns: :: `error_code( e, generic_category(), loc )`.
|
||||
|
||||
Same as the above overload, but takes a source location.
|
||||
* {blank}
|
||||
+
|
||||
```
|
||||
void my_api_function( boost::system::error_code& ec )
|
||||
{
|
||||
void* p = std::malloc( 16 );
|
||||
|
||||
if( p == 0 )
|
||||
{
|
||||
// return ENOMEM
|
||||
|
||||
BOOST_STATIC_CONSTEXPR boost::source_location loc =
|
||||
BOOST_CURRENT_LOCATION;
|
||||
|
||||
ec = make_error_code( boost::system::errc::out_of_memory, &loc );
|
||||
return;
|
||||
}
|
||||
|
||||
// use p
|
||||
}
|
||||
```
|
||||
|
||||
## <boost/system/{zwsp}error_category.hpp>
|
||||
|
||||
### error_category
|
||||
@@ -574,9 +610,8 @@ public:
|
||||
template<class ErrorCodeEnum>
|
||||
constexpr error_code( ErrorCodeEnum e ) noexcept;
|
||||
|
||||
template<class ErrorCodeEnum>
|
||||
error_code( ErrorCodeEnum e, boost::source_location const * loc )
|
||||
noexcept;
|
||||
error_code( error_code const& ec,
|
||||
boost::source_location const * loc ) noexcept;
|
||||
|
||||
error_code( std::error_code const& ec ) noexcept;
|
||||
|
||||
@@ -590,9 +625,8 @@ public:
|
||||
template<class ErrorCodeEnum>
|
||||
constexpr error_code & operator=( ErrorCodeEnum e ) noexcept;
|
||||
|
||||
template<class ErrorCodeEnum>
|
||||
void assign( ErrorCodeEnum e,
|
||||
boost::source_location const * loc ) noexcept;
|
||||
void assign( error_code const& ec,
|
||||
boost::source_location const * loc ) noexcept;
|
||||
|
||||
constexpr void clear() noexcept;
|
||||
|
||||
@@ -721,17 +755,17 @@ Ensures: :: `*this == make_error_code( e )`.
|
||||
Remarks: :: This constructor is only enabled when `is_error_code_enum<ErrorCodeEnum>::value` is `true`.
|
||||
|
||||
```
|
||||
template<class ErrorCodeEnum>
|
||||
error_code( ErrorCodeEnum e, boost::source_location const * loc ) noexcept;
|
||||
error_code( error_code const& ec,
|
||||
boost::source_location const * loc ) noexcept;
|
||||
```
|
||||
[none]
|
||||
* {blank}
|
||||
+
|
||||
Requires: :: `loc` points to a valid `boost::source_location` object with static storage duration.
|
||||
Ensures: :: `*this == make_error_code( e )`.
|
||||
Remarks: :: This constructor is only enabled when `is_error_code_enum<ErrorCodeEnum>::value` is `true`.
|
||||
When `make_error_code( e )` is not a default-constructed `error_code` and doesn't wrap a
|
||||
`std::error_code`, `has_location()` is `true` and `&location()` is `loc`.
|
||||
Requires: :: `loc` points to a valid `boost::source_location` object with static storage duration, or is `nullptr`.
|
||||
Ensures: :: `*this == ec`.
|
||||
Remarks: :: When `ec` is a default-constructed `error_code` or wraps a `std::error_code`,
|
||||
or when `loc` is `nullptr`, `*this` stores no location (`has_location()` is `false`).
|
||||
Otherwise, `*this` stores `loc` (`has_location()` is `true` and `&location()` is `loc`.)
|
||||
|
||||
```
|
||||
error_code( std::error_code const & ec ) noexcept;
|
||||
@@ -772,16 +806,13 @@ Ensures: :: `*this == make_error_code( e )`.
|
||||
Remarks: :: This operator is only enabled when `is_error_code_enum<ErrorCodeEnum>::value` is `true`.
|
||||
|
||||
```
|
||||
template<class ErrorCodeEnum>
|
||||
void assign( ErrorCodeEnum e,
|
||||
boost::source_location const * loc ) noexcept;
|
||||
void assign( error_code const& ec,
|
||||
boost::source_location const * loc ) noexcept;
|
||||
```
|
||||
[none]
|
||||
* {blank}
|
||||
+
|
||||
Requires: :: `loc` points to a valid `boost::source_location` object with static storage duration.
|
||||
Effects: :: `*this = error_code( e, loc )`.
|
||||
Remarks: :: This function is only enabled when `is_error_code_enum<ErrorCodeEnum>::value` is `true`.
|
||||
Effects: :: `*this = error_code( ec, loc )`.
|
||||
|
||||
```
|
||||
constexpr void clear() noexcept;
|
||||
@@ -1460,6 +1491,15 @@ BOOST_NORETURN inline void throw_exception_from_error( error_code const & e,
|
||||
BOOST_NORETURN inline void throw_exception_from_error( std::error_code const & e,
|
||||
boost::source_location const & loc );
|
||||
|
||||
BOOST_NORETURN inline void throw_exception_from_error( errc::errc_t const & e,
|
||||
boost::source_location const & loc );
|
||||
|
||||
BOOST_NORETURN inline void throw_exception_from_error( std::errc const & e,
|
||||
boost::source_location const & loc );
|
||||
|
||||
BOOST_NORETURN inline void throw_exception_from_error( std::exception_ptr & e,
|
||||
boost::source_location const & loc );
|
||||
|
||||
// in_place_*
|
||||
|
||||
using in_place_value_t = /*unspecified*/;
|
||||
@@ -1497,7 +1537,7 @@ BOOST_NORETURN inline void throw_exception_from_error( error_code const & e,
|
||||
* {blank}
|
||||
+
|
||||
Effects: ::
|
||||
`boost::throw_exception( system_error( e ), loc )`.
|
||||
`boost::throw_with_location( system_error( e ), loc )`.
|
||||
|
||||
```
|
||||
BOOST_NORETURN inline void throw_exception_from_error( std::error_code const & e,
|
||||
@@ -1507,7 +1547,40 @@ BOOST_NORETURN inline void throw_exception_from_error( std::error_code const & e
|
||||
* {blank}
|
||||
+
|
||||
Effects: ::
|
||||
`boost::throw_exception( std::system_error( e ), loc )`.
|
||||
`boost::throw_with_location( std::system_error( e ), loc )`.
|
||||
|
||||
```
|
||||
BOOST_NORETURN inline void throw_exception_from_error( errc::errc_t const & e,
|
||||
boost::source_location const & loc );
|
||||
```
|
||||
[none]
|
||||
* {blank}
|
||||
+
|
||||
Effects: ::
|
||||
`boost::throw_with_location( system_error( make_error_code( e ) ), loc )`.
|
||||
|
||||
```
|
||||
BOOST_NORETURN inline void throw_exception_from_error( std::errc const & e,
|
||||
boost::source_location const & loc );
|
||||
```
|
||||
[none]
|
||||
* {blank}
|
||||
+
|
||||
Effects: ::
|
||||
`boost::throw_with_location( std::system_error( make_error_code( e ) ), loc )`.
|
||||
|
||||
```
|
||||
BOOST_NORETURN inline void throw_exception_from_error( std::exception_ptr & e,
|
||||
boost::source_location const & loc );
|
||||
```
|
||||
[none]
|
||||
* {blank}
|
||||
+
|
||||
Effects: ::
|
||||
+
|
||||
[disc]
|
||||
** If `e` isn't null, `std::rethrow_exception( e )`.
|
||||
** Otherwise, `boost::throw_with_location( std::bad_exception(), loc )`.
|
||||
|
||||
### result<T, E>
|
||||
|
||||
@@ -1535,6 +1608,12 @@ public:
|
||||
template<class... A>
|
||||
constexpr result( in_place_error_t, A&&... a );
|
||||
|
||||
template<class T2, class E2>
|
||||
constexpr result( result<T2, E2> const& r2 );
|
||||
|
||||
template<class T2, class E2>
|
||||
constexpr result( result<T2, E2>&& r2 );
|
||||
|
||||
// queries
|
||||
|
||||
constexpr bool has_value() const noexcept;
|
||||
@@ -1643,6 +1722,30 @@ Ensures: ::
|
||||
Remarks: ::
|
||||
This constructor is only enabled when `std::is_constructible<E, A...>::value` is `true`.
|
||||
|
||||
```
|
||||
template<class T2, class E2>
|
||||
constexpr result( result<T2, E2> const& r2 );
|
||||
```
|
||||
[none]
|
||||
* {blank}
|
||||
+
|
||||
Ensures: ::
|
||||
If `r2.has_value()` is `true`, `*this` holds the value `T( *r2 )`, otherwise `*this` holds the value `E( r2.error() )`.
|
||||
Remarks: ::
|
||||
This constructor is only enabled when `std::is_convertible<T2, T>::value && std::is_convertible<E2, E>::value` is `true`.
|
||||
|
||||
```
|
||||
template<class T2, class E2>
|
||||
constexpr result( result<T2, E2>&& r2 );
|
||||
```
|
||||
[none]
|
||||
* {blank}
|
||||
+
|
||||
Ensures: ::
|
||||
If `r2.has_value()` is `true`, `*this` holds the value `T( std::move( *r2 ) )`, otherwise `*this` holds the value `E( r2.error() )`.
|
||||
Remarks: ::
|
||||
This constructor is only enabled when `std::is_convertible<T2, T>::value && std::is_convertible<E2, E>::value` is `true`.
|
||||
|
||||
#### Queries
|
||||
|
||||
```
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
|
||||
// BOOST_SYSTEM_HAS_SYSTEM_ERROR
|
||||
|
||||
#if !defined(BOOST_NO_CXX11_HDR_SYSTEM_ERROR) && !defined(BOOST_NO_CXX11_HDR_ATOMIC)
|
||||
#if !defined(BOOST_NO_CXX11_HDR_SYSTEM_ERROR) && !defined(BOOST_NO_CXX11_HDR_ATOMIC) && !defined(BOOST_NO_CXX11_HDR_MUTEX)
|
||||
# define BOOST_SYSTEM_HAS_SYSTEM_ERROR
|
||||
#endif
|
||||
|
||||
|
||||
@@ -48,6 +48,11 @@ class std_category;
|
||||
#pragma GCC diagnostic ignored "-Wnon-virtual-dtor"
|
||||
#endif
|
||||
|
||||
#if defined(BOOST_MSVC)
|
||||
#pragma warning(push)
|
||||
#pragma warning(disable: 4351) // new behavior: elements of array will be default initialized
|
||||
#endif
|
||||
|
||||
class BOOST_SYMBOL_VISIBLE error_category
|
||||
{
|
||||
private:
|
||||
@@ -76,13 +81,21 @@ private:
|
||||
|
||||
boost::ulong_long_type id_;
|
||||
|
||||
static std::size_t const stdcat_size_ = 4 * sizeof( void const* );
|
||||
|
||||
union
|
||||
{
|
||||
mutable unsigned char stdcat_[ stdcat_size_ ];
|
||||
void const* stdcat_align_;
|
||||
};
|
||||
|
||||
#if defined(BOOST_SYSTEM_HAS_SYSTEM_ERROR)
|
||||
|
||||
mutable std::atomic< boost::system::detail::std_category* > ps_;
|
||||
mutable std::atomic< unsigned > sc_init_;
|
||||
|
||||
#else
|
||||
|
||||
boost::system::detail::std_category* ps_;
|
||||
unsigned sc_init_;
|
||||
|
||||
#endif
|
||||
|
||||
@@ -103,11 +116,11 @@ protected:
|
||||
|
||||
#endif
|
||||
|
||||
BOOST_SYSTEM_CONSTEXPR error_category() BOOST_NOEXCEPT: id_( 0 ), ps_()
|
||||
BOOST_SYSTEM_CONSTEXPR error_category() BOOST_NOEXCEPT: id_( 0 ), stdcat_(), sc_init_()
|
||||
{
|
||||
}
|
||||
|
||||
explicit BOOST_SYSTEM_CONSTEXPR error_category( boost::ulong_long_type id ) BOOST_NOEXCEPT: id_( id ), ps_()
|
||||
explicit BOOST_SYSTEM_CONSTEXPR error_category( boost::ulong_long_type id ) BOOST_NOEXCEPT: id_( id ), stdcat_(), sc_init_()
|
||||
{
|
||||
}
|
||||
|
||||
@@ -158,14 +171,22 @@ public:
|
||||
}
|
||||
|
||||
#if defined(BOOST_SYSTEM_HAS_SYSTEM_ERROR)
|
||||
|
||||
void init_stdcat() const;
|
||||
|
||||
# if defined(__SUNPRO_CC) // trailing __global is not supported
|
||||
operator std::error_category const & () const;
|
||||
# else
|
||||
operator std::error_category const & () const BOOST_SYMBOL_VISIBLE;
|
||||
# endif
|
||||
|
||||
#endif
|
||||
};
|
||||
|
||||
#if defined(BOOST_MSVC)
|
||||
#pragma warning(pop)
|
||||
#endif
|
||||
|
||||
#if ( defined( BOOST_GCC ) && BOOST_GCC >= 40600 ) || defined( BOOST_CLANG )
|
||||
#pragma GCC diagnostic pop
|
||||
#endif
|
||||
|
||||
@@ -97,26 +97,66 @@ inline char const * error_category::message( int ev, char * buffer, std::size_t
|
||||
|
||||
#if defined(BOOST_SYSTEM_HAS_SYSTEM_ERROR)
|
||||
|
||||
#include <boost/system/detail/std_category.hpp>
|
||||
#include <boost/system/detail/std_category_impl.hpp>
|
||||
#include <mutex>
|
||||
#include <new>
|
||||
|
||||
namespace boost
|
||||
{
|
||||
namespace system
|
||||
{
|
||||
|
||||
inline error_category::operator std::error_category const & () const
|
||||
namespace detail
|
||||
{
|
||||
|
||||
template<class = void> struct stdcat_mx_holder
|
||||
{
|
||||
static std::mutex mx_;
|
||||
};
|
||||
|
||||
template<class T> std::mutex stdcat_mx_holder<T>::mx_;
|
||||
|
||||
} // namespace detail
|
||||
|
||||
inline void error_category::init_stdcat() const
|
||||
{
|
||||
static_assert( sizeof( stdcat_ ) >= sizeof( boost::system::detail::std_category ), "sizeof(stdcat_) is not enough for std_category" );
|
||||
|
||||
#if defined(BOOST_MSVC) && BOOST_MSVC < 1900
|
||||
// no alignof
|
||||
#else
|
||||
|
||||
static_assert( alignof( decltype(stdcat_align_) ) >= alignof( boost::system::detail::std_category ), "alignof(stdcat_) is not enough for std_category" );
|
||||
|
||||
#endif
|
||||
|
||||
std::lock_guard<std::mutex> lk( boost::system::detail::stdcat_mx_holder<>::mx_ );
|
||||
|
||||
if( sc_init_.load( std::memory_order_acquire ) == 0 )
|
||||
{
|
||||
::new( static_cast<void*>( stdcat_ ) ) boost::system::detail::std_category( this, 0 );
|
||||
sc_init_.store( 1, std::memory_order_release );
|
||||
}
|
||||
}
|
||||
|
||||
#if defined( BOOST_GCC ) && BOOST_GCC >= 40800 && BOOST_GCC < 70000
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wstrict-aliasing"
|
||||
#endif
|
||||
|
||||
inline BOOST_NOINLINE error_category::operator std::error_category const & () const
|
||||
{
|
||||
if( id_ == detail::generic_category_id )
|
||||
{
|
||||
// This condition must be the same as the one in error_condition.hpp
|
||||
#if defined(BOOST_SYSTEM_AVOID_STD_GENERIC_CATEGORY)
|
||||
|
||||
static const boost::system::detail::std_category generic_instance( this, 0x1F4D3 );
|
||||
return generic_instance;
|
||||
static const boost::system::detail::std_category generic_instance( this, 0x1F4D3 );
|
||||
return generic_instance;
|
||||
|
||||
#else
|
||||
|
||||
return std::generic_category();
|
||||
return std::generic_category();
|
||||
|
||||
#endif
|
||||
}
|
||||
@@ -126,36 +166,28 @@ inline error_category::operator std::error_category const & () const
|
||||
// This condition must be the same as the one in error_code.hpp
|
||||
#if defined(BOOST_SYSTEM_AVOID_STD_SYSTEM_CATEGORY)
|
||||
|
||||
static const boost::system::detail::std_category system_instance( this, 0x1F4D7 );
|
||||
return system_instance;
|
||||
static const boost::system::detail::std_category system_instance( this, 0x1F4D7 );
|
||||
return system_instance;
|
||||
|
||||
#else
|
||||
|
||||
return std::system_category();
|
||||
return std::system_category();
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
detail::std_category* p = ps_.load( std::memory_order_acquire );
|
||||
|
||||
if( p != 0 )
|
||||
if( sc_init_.load( std::memory_order_acquire ) == 0 )
|
||||
{
|
||||
return *p;
|
||||
init_stdcat();
|
||||
}
|
||||
|
||||
detail::std_category* q = new detail::std_category( this, 0 );
|
||||
|
||||
if( ps_.compare_exchange_strong( p, q, std::memory_order_release, std::memory_order_acquire ) )
|
||||
{
|
||||
return *q;
|
||||
}
|
||||
else
|
||||
{
|
||||
delete q;
|
||||
return *p;
|
||||
}
|
||||
return *static_cast<boost::system::detail::std_category const*>( static_cast<void const*>( stdcat_ ) );
|
||||
}
|
||||
|
||||
#if defined( BOOST_GCC ) && BOOST_GCC >= 40800 && BOOST_GCC < 70000
|
||||
#pragma GCC diagnostic pop
|
||||
#endif
|
||||
|
||||
} // namespace system
|
||||
} // namespace boost
|
||||
|
||||
|
||||
@@ -21,9 +21,15 @@
|
||||
#include <boost/system/detail/append_int.hpp>
|
||||
#include <boost/system/detail/snprintf.hpp>
|
||||
#include <boost/system/detail/config.hpp>
|
||||
|
||||
#if defined(BOOST_SYSTEM_HAS_SYSTEM_ERROR)
|
||||
# include <boost/system/detail/std_category.hpp>
|
||||
#endif
|
||||
|
||||
#include <boost/assert/source_location.hpp>
|
||||
#include <boost/cstdint.hpp>
|
||||
#include <boost/config.hpp>
|
||||
#include <boost/config/workaround.hpp>
|
||||
#include <ostream>
|
||||
#include <new>
|
||||
#include <cstdio>
|
||||
@@ -52,12 +58,14 @@ namespace system
|
||||
// and error_code containing a pointer to an object of a type derived
|
||||
// from error_category.
|
||||
|
||||
bool operator==( const error_code & code, const error_condition & condition ) BOOST_NOEXCEPT;
|
||||
std::size_t hash_value( error_code const & ec );
|
||||
|
||||
class error_code
|
||||
{
|
||||
private:
|
||||
|
||||
friend bool operator==( const error_code & code, const error_condition & condition ) BOOST_NOEXCEPT;
|
||||
friend std::size_t hash_value( error_code const & ec );
|
||||
|
||||
private:
|
||||
@@ -109,7 +117,10 @@ public:
|
||||
|
||||
// constructors:
|
||||
|
||||
BOOST_SYSTEM_CONSTEXPR error_code() BOOST_NOEXCEPT:
|
||||
#if !BOOST_WORKAROUND(BOOST_GCC, < 40800)
|
||||
BOOST_CONSTEXPR
|
||||
#endif
|
||||
error_code() BOOST_NOEXCEPT:
|
||||
d1_(), lc_flags_( 0 )
|
||||
{
|
||||
}
|
||||
@@ -139,28 +150,35 @@ public:
|
||||
*this = make_error_code( e );
|
||||
}
|
||||
|
||||
template<class ErrorCodeEnum> error_code( ErrorCodeEnum e, source_location const * loc,
|
||||
typename detail::enable_if<is_error_code_enum<ErrorCodeEnum>::value>::type* = 0 ) BOOST_NOEXCEPT:
|
||||
error_code( error_code const& ec, source_location const * loc ) BOOST_NOEXCEPT:
|
||||
d1_(), lc_flags_( 0 )
|
||||
{
|
||||
error_code e2 = make_error_code( e );
|
||||
*this = ec;
|
||||
|
||||
if( e2.lc_flags_ == 0 || e2.lc_flags_ == 1 )
|
||||
if( ec.lc_flags_ != 0 && ec.lc_flags_ != 1 )
|
||||
{
|
||||
*this = e2;
|
||||
}
|
||||
else
|
||||
{
|
||||
*this = error_code( e2.d1_.val_, *e2.d1_.cat_, loc );
|
||||
lc_flags_ = ( loc? reinterpret_cast<boost::uintptr_t>( loc ): 2 ) | ( ec.lc_flags_ & 1 );
|
||||
}
|
||||
}
|
||||
|
||||
#if defined(BOOST_SYSTEM_HAS_SYSTEM_ERROR)
|
||||
|
||||
error_code( std::error_code const& ec ) BOOST_NOEXCEPT:
|
||||
lc_flags_( 1 )
|
||||
d1_(), lc_flags_( 0 )
|
||||
{
|
||||
::new( d2_ ) std::error_code( ec );
|
||||
#ifndef BOOST_NO_RTTI
|
||||
|
||||
if( detail::std_category const* pc2 = dynamic_cast< detail::std_category const* >( &ec.category() ) )
|
||||
{
|
||||
*this = boost::system::error_code( ec.value(), pc2->original_category() );
|
||||
}
|
||||
else
|
||||
|
||||
#endif
|
||||
{
|
||||
::new( d2_ ) std::error_code( ec );
|
||||
lc_flags_ = 1;
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -177,6 +195,11 @@ public:
|
||||
*this = error_code( val, cat, loc );
|
||||
}
|
||||
|
||||
void assign( error_code const& ec, source_location const * loc ) BOOST_NOEXCEPT
|
||||
{
|
||||
*this = error_code( ec, loc );
|
||||
}
|
||||
|
||||
template<typename ErrorCodeEnum>
|
||||
BOOST_SYSTEM_CONSTEXPR typename detail::enable_if<is_error_code_enum<ErrorCodeEnum>::value, error_code>::type &
|
||||
operator=( ErrorCodeEnum val ) BOOST_NOEXCEPT
|
||||
@@ -185,13 +208,6 @@ public:
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<typename ErrorCodeEnum>
|
||||
typename detail::enable_if<is_error_code_enum<ErrorCodeEnum>::value, void>::type
|
||||
assign( ErrorCodeEnum val, source_location const * loc ) BOOST_NOEXCEPT
|
||||
{
|
||||
*this = error_code( val, loc );
|
||||
}
|
||||
|
||||
BOOST_SYSTEM_CONSTEXPR void clear() BOOST_NOEXCEPT
|
||||
{
|
||||
*this = error_code();
|
||||
@@ -424,48 +440,6 @@ public:
|
||||
return !( lhs == rhs );
|
||||
}
|
||||
|
||||
inline friend bool operator==( const error_code & code, const error_condition & condition ) BOOST_NOEXCEPT
|
||||
{
|
||||
#if defined(BOOST_SYSTEM_HAS_SYSTEM_ERROR)
|
||||
|
||||
if( code.lc_flags_ == 1 )
|
||||
{
|
||||
return static_cast<std::error_code>( code ) == static_cast<std::error_condition>( condition );
|
||||
}
|
||||
else
|
||||
|
||||
#endif
|
||||
{
|
||||
return code.category().equivalent( code.value(), condition ) || condition.category().equivalent( code, condition.value() );
|
||||
}
|
||||
}
|
||||
|
||||
inline friend bool operator==( const error_condition & condition, const error_code & code ) BOOST_NOEXCEPT
|
||||
{
|
||||
#if defined(BOOST_SYSTEM_HAS_SYSTEM_ERROR)
|
||||
|
||||
if( code.lc_flags_ == 1 )
|
||||
{
|
||||
return static_cast<std::error_code>( code ) == static_cast<std::error_condition>( condition );
|
||||
}
|
||||
else
|
||||
|
||||
#endif
|
||||
{
|
||||
return code.category().equivalent( code.value(), condition ) || condition.category().equivalent( code, condition.value() );
|
||||
}
|
||||
}
|
||||
|
||||
inline friend bool operator!=( const error_code & lhs, const error_condition & rhs ) BOOST_NOEXCEPT
|
||||
{
|
||||
return !( lhs == rhs );
|
||||
}
|
||||
|
||||
inline friend bool operator!=( const error_condition & lhs, const error_code & rhs ) BOOST_NOEXCEPT
|
||||
{
|
||||
return !( lhs == rhs );
|
||||
}
|
||||
|
||||
#if defined(BOOST_SYSTEM_HAS_SYSTEM_ERROR)
|
||||
|
||||
inline friend bool operator==( std::error_code const & lhs, error_code const & rhs ) BOOST_NOEXCEPT
|
||||
@@ -668,6 +642,37 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
inline bool operator==( const error_code & code, const error_condition & condition ) BOOST_NOEXCEPT
|
||||
{
|
||||
#if defined(BOOST_SYSTEM_HAS_SYSTEM_ERROR)
|
||||
|
||||
if( code.lc_flags_ == 1 )
|
||||
{
|
||||
return static_cast<std::error_code>( code ) == static_cast<std::error_condition>( condition );
|
||||
}
|
||||
else
|
||||
|
||||
#endif
|
||||
{
|
||||
return code.category().equivalent( code.value(), condition ) || condition.category().equivalent( code, condition.value() );
|
||||
}
|
||||
}
|
||||
|
||||
inline bool operator==( const error_condition & condition, const error_code & code ) BOOST_NOEXCEPT
|
||||
{
|
||||
return code == condition;
|
||||
}
|
||||
|
||||
inline bool operator!=( const error_code & lhs, const error_condition & rhs ) BOOST_NOEXCEPT
|
||||
{
|
||||
return !( lhs == rhs );
|
||||
}
|
||||
|
||||
inline bool operator!=( const error_condition & lhs, const error_code & rhs ) BOOST_NOEXCEPT
|
||||
{
|
||||
return !( lhs == rhs );
|
||||
}
|
||||
|
||||
inline std::size_t hash_value( error_code const & ec )
|
||||
{
|
||||
#if defined(BOOST_SYSTEM_HAS_SYSTEM_ERROR)
|
||||
|
||||
@@ -261,6 +261,58 @@ public:
|
||||
return !( lhs == rhs );
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
template<class E, class N = typename detail::enable_if<std::is_error_condition_enum<E>::value>::type>
|
||||
BOOST_SYSTEM_CONSTEXPR inline friend bool operator==( error_condition const & lhs, E rhs ) BOOST_NOEXCEPT
|
||||
{
|
||||
return lhs == make_error_condition( rhs );
|
||||
}
|
||||
|
||||
template<class E, class N = typename detail::enable_if<std::is_error_condition_enum<E>::value>::type>
|
||||
BOOST_SYSTEM_CONSTEXPR inline friend bool operator==( E lhs, error_condition const & rhs ) BOOST_NOEXCEPT
|
||||
{
|
||||
return make_error_condition( lhs ) == rhs;
|
||||
}
|
||||
|
||||
template<class E, class N = typename detail::enable_if<std::is_error_condition_enum<E>::value>::type>
|
||||
BOOST_SYSTEM_CONSTEXPR inline friend bool operator!=( error_condition const & lhs, E rhs ) BOOST_NOEXCEPT
|
||||
{
|
||||
return !( lhs == rhs );
|
||||
}
|
||||
|
||||
template<class E, class N = typename detail::enable_if<std::is_error_condition_enum<E>::value>::type>
|
||||
BOOST_SYSTEM_CONSTEXPR inline friend bool operator!=( E lhs, error_condition const & rhs ) BOOST_NOEXCEPT
|
||||
{
|
||||
return !( lhs == rhs );
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
template<class E, class N1 = void, class N2 = typename detail::enable_if<std::is_error_code_enum<E>::value>::type>
|
||||
inline friend bool operator==( error_condition const & lhs, E rhs ) BOOST_NOEXCEPT
|
||||
{
|
||||
return lhs == make_error_code( rhs );
|
||||
}
|
||||
|
||||
template<class E, class N1 = void, class N2 = typename detail::enable_if<std::is_error_code_enum<E>::value>::type>
|
||||
inline friend bool operator==( E lhs, error_condition const & rhs ) BOOST_NOEXCEPT
|
||||
{
|
||||
return make_error_code( lhs ) == rhs;
|
||||
}
|
||||
|
||||
template<class E, class N1 = void, class N2 = typename detail::enable_if<std::is_error_code_enum<E>::value>::type>
|
||||
inline friend bool operator!=( error_condition const & lhs, E rhs ) BOOST_NOEXCEPT
|
||||
{
|
||||
return !( lhs == rhs );
|
||||
}
|
||||
|
||||
template<class E, class N1 = void, class N2 = typename detail::enable_if<std::is_error_code_enum<E>::value>::type>
|
||||
inline friend bool operator!=( E lhs, error_condition const & rhs ) BOOST_NOEXCEPT
|
||||
{
|
||||
return !( lhs == rhs );
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
std::string to_string() const
|
||||
|
||||
@@ -11,9 +11,6 @@
|
||||
// See library home page at http://www.boost.org/libs/system
|
||||
|
||||
#include <boost/system/detail/error_category.hpp>
|
||||
#include <boost/system/detail/error_condition.hpp>
|
||||
#include <boost/system/detail/error_code.hpp>
|
||||
#include <boost/system/detail/generic_category.hpp>
|
||||
#include <system_error>
|
||||
|
||||
//
|
||||
@@ -33,6 +30,13 @@ private:
|
||||
|
||||
boost::system::error_category const * pc_;
|
||||
|
||||
public:
|
||||
|
||||
boost::system::error_category const & original_category() const BOOST_NOEXCEPT
|
||||
{
|
||||
return *pc_;
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
explicit std_category( boost::system::error_category const * pc, unsigned id ): pc_( pc )
|
||||
@@ -66,72 +70,10 @@ public:
|
||||
return pc_->default_error_condition( ev );
|
||||
}
|
||||
|
||||
bool equivalent( int code, const std::error_condition & condition ) const BOOST_NOEXCEPT BOOST_OVERRIDE;
|
||||
bool equivalent( const std::error_code & code, int condition ) const BOOST_NOEXCEPT BOOST_OVERRIDE;
|
||||
inline bool equivalent( int code, const std::error_condition & condition ) const BOOST_NOEXCEPT BOOST_OVERRIDE;
|
||||
inline bool equivalent( const std::error_code & code, int condition ) const BOOST_NOEXCEPT BOOST_OVERRIDE;
|
||||
};
|
||||
|
||||
inline bool std_category::equivalent( int code, const std::error_condition & condition ) const BOOST_NOEXCEPT
|
||||
{
|
||||
if( condition.category() == *this )
|
||||
{
|
||||
boost::system::error_condition bn( condition.value(), *pc_ );
|
||||
return pc_->equivalent( code, bn );
|
||||
}
|
||||
else if( condition.category() == std::generic_category() || condition.category() == boost::system::generic_category() )
|
||||
{
|
||||
boost::system::error_condition bn( condition.value(), boost::system::generic_category() );
|
||||
return pc_->equivalent( code, bn );
|
||||
}
|
||||
|
||||
#ifndef BOOST_NO_RTTI
|
||||
|
||||
else if( std_category const* pc2 = dynamic_cast< std_category const* >( &condition.category() ) )
|
||||
{
|
||||
boost::system::error_condition bn( condition.value(), *pc2->pc_ );
|
||||
return pc_->equivalent( code, bn );
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
else
|
||||
{
|
||||
return default_error_condition( code ) == condition;
|
||||
}
|
||||
}
|
||||
|
||||
inline bool std_category::equivalent( const std::error_code & code, int condition ) const BOOST_NOEXCEPT
|
||||
{
|
||||
if( code.category() == *this )
|
||||
{
|
||||
boost::system::error_code bc( code.value(), *pc_ );
|
||||
return pc_->equivalent( bc, condition );
|
||||
}
|
||||
else if( code.category() == std::generic_category() || code.category() == boost::system::generic_category() )
|
||||
{
|
||||
boost::system::error_code bc( code.value(), boost::system::generic_category() );
|
||||
return pc_->equivalent( bc, condition );
|
||||
}
|
||||
|
||||
#ifndef BOOST_NO_RTTI
|
||||
|
||||
else if( std_category const* pc2 = dynamic_cast< std_category const* >( &code.category() ) )
|
||||
{
|
||||
boost::system::error_code bc( code.value(), *pc2->pc_ );
|
||||
return pc_->equivalent( bc, condition );
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
else if( *pc_ == boost::system::generic_category() )
|
||||
{
|
||||
return std::generic_category().equivalent( code, condition );
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace detail
|
||||
|
||||
} // namespace system
|
||||
|
||||
97
include/boost/system/detail/std_category_impl.hpp
Normal file
97
include/boost/system/detail/std_category_impl.hpp
Normal file
@@ -0,0 +1,97 @@
|
||||
#ifndef BOOST_SYSTEM_DETAIL_STD_CATEGORY_IMPL_HPP_INCLUDED
|
||||
#define BOOST_SYSTEM_DETAIL_STD_CATEGORY_IMPL_HPP_INCLUDED
|
||||
|
||||
// Support for interoperability between Boost.System and <system_error>
|
||||
//
|
||||
// Copyright 2018, 2021 Peter Dimov
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
// See library home page at http://www.boost.org/libs/system
|
||||
|
||||
#include <boost/system/detail/std_category.hpp>
|
||||
#include <boost/system/detail/error_condition.hpp>
|
||||
#include <boost/system/detail/error_code.hpp>
|
||||
#include <boost/system/detail/generic_category.hpp>
|
||||
|
||||
//
|
||||
|
||||
namespace boost
|
||||
{
|
||||
|
||||
namespace system
|
||||
{
|
||||
|
||||
namespace detail
|
||||
{
|
||||
|
||||
inline bool std_category::equivalent( int code, const std::error_condition & condition ) const BOOST_NOEXCEPT
|
||||
{
|
||||
if( condition.category() == *this )
|
||||
{
|
||||
boost::system::error_condition bn( condition.value(), *pc_ );
|
||||
return pc_->equivalent( code, bn );
|
||||
}
|
||||
else if( condition.category() == std::generic_category() || condition.category() == boost::system::generic_category() )
|
||||
{
|
||||
boost::system::error_condition bn( condition.value(), boost::system::generic_category() );
|
||||
return pc_->equivalent( code, bn );
|
||||
}
|
||||
|
||||
#ifndef BOOST_NO_RTTI
|
||||
|
||||
else if( std_category const* pc2 = dynamic_cast< std_category const* >( &condition.category() ) )
|
||||
{
|
||||
boost::system::error_condition bn( condition.value(), *pc2->pc_ );
|
||||
return pc_->equivalent( code, bn );
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
else
|
||||
{
|
||||
return default_error_condition( code ) == condition;
|
||||
}
|
||||
}
|
||||
|
||||
inline bool std_category::equivalent( const std::error_code & code, int condition ) const BOOST_NOEXCEPT
|
||||
{
|
||||
if( code.category() == *this )
|
||||
{
|
||||
boost::system::error_code bc( code.value(), *pc_ );
|
||||
return pc_->equivalent( bc, condition );
|
||||
}
|
||||
else if( code.category() == std::generic_category() || code.category() == boost::system::generic_category() )
|
||||
{
|
||||
boost::system::error_code bc( code.value(), boost::system::generic_category() );
|
||||
return pc_->equivalent( bc, condition );
|
||||
}
|
||||
|
||||
#ifndef BOOST_NO_RTTI
|
||||
|
||||
else if( std_category const* pc2 = dynamic_cast< std_category const* >( &code.category() ) )
|
||||
{
|
||||
boost::system::error_code bc( code.value(), *pc2->pc_ );
|
||||
return pc_->equivalent( bc, condition );
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
else if( *pc_ == boost::system::generic_category() )
|
||||
{
|
||||
return std::generic_category().equivalent( code, condition );
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace detail
|
||||
|
||||
} // namespace system
|
||||
|
||||
} // namespace boost
|
||||
|
||||
#endif // #ifndef BOOST_SYSTEM_DETAIL_STD_CATEGORY_IMPL_HPP_INCLUDED
|
||||
@@ -16,6 +16,7 @@
|
||||
#include <boost/system/detail/generic_category.hpp>
|
||||
#include <boost/system/detail/error_category_impl.hpp>
|
||||
#include <boost/system/detail/config.hpp>
|
||||
#include <boost/assert/source_location.hpp>
|
||||
#include <boost/config.hpp>
|
||||
|
||||
namespace boost
|
||||
@@ -35,6 +36,12 @@ BOOST_SYSTEM_CONSTEXPR inline error_code make_error_code( errc_t e ) BOOST_NOEXC
|
||||
return error_code( e, generic_category() );
|
||||
}
|
||||
|
||||
// explicit conversion:
|
||||
inline error_code make_error_code( errc_t e, boost::source_location const * loc ) BOOST_NOEXCEPT
|
||||
{
|
||||
return error_code( e, generic_category(), loc );
|
||||
}
|
||||
|
||||
// implicit conversion:
|
||||
BOOST_SYSTEM_CONSTEXPR inline error_condition make_error_condition( errc_t e ) BOOST_NOEXCEPT
|
||||
{
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
#include <utility>
|
||||
#include <iosfwd>
|
||||
#include <system_error>
|
||||
#include <exception>
|
||||
|
||||
//
|
||||
|
||||
@@ -35,12 +36,34 @@ namespace system
|
||||
|
||||
BOOST_NORETURN BOOST_NOINLINE inline void throw_exception_from_error( error_code const & e, boost::source_location const& loc )
|
||||
{
|
||||
boost::throw_exception( system_error( e ), loc );
|
||||
boost::throw_with_location( system_error( e ), loc );
|
||||
}
|
||||
|
||||
BOOST_NORETURN BOOST_NOINLINE inline void throw_exception_from_error( errc::errc_t const & e, boost::source_location const& loc )
|
||||
{
|
||||
boost::throw_with_location( system_error( make_error_code( e ) ), loc );
|
||||
}
|
||||
|
||||
BOOST_NORETURN BOOST_NOINLINE inline void throw_exception_from_error( std::error_code const & e, boost::source_location const& loc )
|
||||
{
|
||||
boost::throw_exception( std::system_error( e ), loc );
|
||||
boost::throw_with_location( std::system_error( e ), loc );
|
||||
}
|
||||
|
||||
BOOST_NORETURN BOOST_NOINLINE inline void throw_exception_from_error( std::errc const & e, boost::source_location const& loc )
|
||||
{
|
||||
boost::throw_with_location( std::system_error( make_error_code( e ) ), loc );
|
||||
}
|
||||
|
||||
BOOST_NORETURN BOOST_NOINLINE inline void throw_exception_from_error( std::exception_ptr const & p, boost::source_location const& loc )
|
||||
{
|
||||
if( p )
|
||||
{
|
||||
std::rethrow_exception( p );
|
||||
}
|
||||
else
|
||||
{
|
||||
boost::throw_with_location( std::bad_exception(), loc );
|
||||
}
|
||||
}
|
||||
|
||||
#if defined(__GNUC__) && __GNUC__ >= 7 && __GNUC__ <= 8
|
||||
@@ -112,7 +135,8 @@ public:
|
||||
template<class... A, class En = typename std::enable_if<
|
||||
std::is_constructible<T, A...>::value &&
|
||||
!(detail::is_errc_t<A...>::value && std::is_arithmetic<T>::value) &&
|
||||
!std::is_constructible<E, A...>::value
|
||||
!std::is_constructible<E, A...>::value &&
|
||||
sizeof...(A) >= 1
|
||||
>::type>
|
||||
explicit constexpr result( A&&... a )
|
||||
noexcept( std::is_nothrow_constructible<T, A...>::value )
|
||||
@@ -123,7 +147,8 @@ public:
|
||||
// explicit, error
|
||||
template<class... A, class En2 = void, class En = typename std::enable_if<
|
||||
!std::is_constructible<T, A...>::value &&
|
||||
std::is_constructible<E, A...>::value
|
||||
std::is_constructible<E, A...>::value &&
|
||||
sizeof...(A) >= 1
|
||||
>::type>
|
||||
explicit constexpr result( A&&... a )
|
||||
noexcept( std::is_nothrow_constructible<E, A...>::value )
|
||||
@@ -151,6 +176,43 @@ public:
|
||||
{
|
||||
}
|
||||
|
||||
// converting
|
||||
template<class T2, class E2, class En = typename std::enable_if<
|
||||
std::is_convertible<T2, T>::value &&
|
||||
std::is_convertible<E2, E>::value
|
||||
>::type>
|
||||
BOOST_CXX14_CONSTEXPR result( result<T2, E2> const& r2 )
|
||||
noexcept(
|
||||
std::is_nothrow_constructible<T, T2 const&>::value &&
|
||||
std::is_nothrow_constructible<E, E2>::value &&
|
||||
std::is_nothrow_default_constructible<E2>::value &&
|
||||
std::is_nothrow_copy_constructible<E2>::value )
|
||||
: v_( in_place_error, r2.error() )
|
||||
{
|
||||
if( r2 )
|
||||
{
|
||||
v_.template emplace<0>( *r2 );
|
||||
}
|
||||
}
|
||||
|
||||
template<class T2, class E2, class En = typename std::enable_if<
|
||||
std::is_convertible<T2, T>::value &&
|
||||
std::is_convertible<E2, E>::value
|
||||
>::type>
|
||||
BOOST_CXX14_CONSTEXPR result( result<T2, E2>&& r2 )
|
||||
noexcept(
|
||||
std::is_nothrow_constructible<T, T2&&>::value &&
|
||||
std::is_nothrow_constructible<E, E2>::value &&
|
||||
std::is_nothrow_default_constructible<E2>::value &&
|
||||
std::is_nothrow_copy_constructible<E2>::value )
|
||||
: v_( in_place_error, r2.error() )
|
||||
{
|
||||
if( r2 )
|
||||
{
|
||||
v_.template emplace<0>( std::move( *r2 ) );
|
||||
}
|
||||
}
|
||||
|
||||
// queries
|
||||
|
||||
constexpr bool has_value() const noexcept
|
||||
@@ -160,7 +222,7 @@ public:
|
||||
|
||||
constexpr bool has_error() const noexcept
|
||||
{
|
||||
return v_.index() != 0;
|
||||
return v_.index() == 1;
|
||||
}
|
||||
|
||||
constexpr explicit operator bool() const noexcept
|
||||
@@ -449,7 +511,7 @@ public:
|
||||
|
||||
constexpr bool has_error() const noexcept
|
||||
{
|
||||
return v_.index() != 0;
|
||||
return v_.index() == 1;
|
||||
}
|
||||
|
||||
constexpr explicit operator bool() const noexcept
|
||||
|
||||
@@ -116,6 +116,19 @@ boost_test(TYPE run SOURCES ec_wstream_test.cpp)
|
||||
|
||||
boost_test(TYPE run SOURCES std_interop_test12.cpp)
|
||||
|
||||
boost_test(TYPE run SOURCES errc_test4.cpp)
|
||||
|
||||
boost_test(TYPE run SOURCES std_interop_test13.cpp)
|
||||
boost_test(TYPE run SOURCES std_interop_test14.cpp)
|
||||
|
||||
boost_test(TYPE run SOURCES ec_location_test3.cpp)
|
||||
boost_test(TYPE run SOURCES ec_location_test4.cpp)
|
||||
|
||||
boost_test(TYPE compile SOURCES constexpr_test2.cpp)
|
||||
|
||||
boost_test(TYPE run SOURCES error_code_test3.cpp)
|
||||
boost_test(TYPE run SOURCES std_interop_test15.cpp)
|
||||
|
||||
# result
|
||||
|
||||
set(BOOST_TEST_COMPILE_FEATURES cxx_std_11)
|
||||
@@ -134,3 +147,4 @@ boost_test(TYPE run SOURCES result_eq.cpp)
|
||||
boost_test(TYPE run SOURCES result_range_for.cpp)
|
||||
boost_test(TYPE run SOURCES result_value_construct2.cpp)
|
||||
boost_test(TYPE run SOURCES result_error_construct2.cpp)
|
||||
boost_test(TYPE run SOURCES result_convert_construct.cpp)
|
||||
|
||||
@@ -61,7 +61,11 @@ run single_instance_test.cpp single_instance_lib1 single_instance_lib2 : : : <li
|
||||
run single_instance_test.cpp single_instance_lib1 single_instance_lib2 : : : <link>shared : single_instance_lib_shared ;
|
||||
|
||||
system-run before_main_test.cpp ;
|
||||
run-fail throws_assign_fail.cpp ;
|
||||
|
||||
run-fail throws_assign_fail.cpp : : :
|
||||
# GCC 12 catches this at compile time with a warning
|
||||
<toolset>gcc,<variant>release:<build>no ;
|
||||
|
||||
system-run constexpr_test.cpp ;
|
||||
system-run win32_hresult_test.cpp ;
|
||||
|
||||
@@ -140,6 +144,19 @@ run ec_wstream_test.cpp ;
|
||||
|
||||
run std_interop_test12.cpp ;
|
||||
|
||||
run errc_test4.cpp ;
|
||||
|
||||
run std_interop_test13.cpp ;
|
||||
run std_interop_test14.cpp ;
|
||||
|
||||
run ec_location_test3.cpp ;
|
||||
run ec_location_test4.cpp ;
|
||||
|
||||
compile constexpr_test2.cpp ;
|
||||
|
||||
run error_code_test3.cpp ;
|
||||
run std_interop_test15.cpp ;
|
||||
|
||||
# result
|
||||
|
||||
import ../../config/checks/config : requires ;
|
||||
@@ -161,3 +178,4 @@ run result_range_for.cpp : : : $(CPP11) ;
|
||||
run result_value_construct2.cpp : : : $(CPP11) ;
|
||||
run result_error_construct2.cpp : : : $(CPP11) ;
|
||||
run result_errc_construct.cpp : : : $(CPP11) ;
|
||||
run result_convert_construct.cpp : : : $(CPP11) ;
|
||||
|
||||
26
test/constexpr_test2.cpp
Normal file
26
test/constexpr_test2.cpp
Normal file
@@ -0,0 +1,26 @@
|
||||
// Copyright 2022 Peter Dimov.
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// https://www.boost.org/LICENSE_1_0.txt
|
||||
|
||||
#include <boost/system/error_code.hpp>
|
||||
#include <boost/config.hpp>
|
||||
#include <boost/config/pragma_message.hpp>
|
||||
|
||||
#if defined(BOOST_GCC) && BOOST_GCC >= 40700 && BOOST_GCC < 40800
|
||||
|
||||
BOOST_PRAGMA_MESSAGE("Skipping test, BOOST_GCC is 407xx")
|
||||
|
||||
#else
|
||||
|
||||
struct X
|
||||
{
|
||||
boost::system::error_code ec;
|
||||
};
|
||||
|
||||
X const& f()
|
||||
{
|
||||
BOOST_STATIC_CONSTEXPR X x;
|
||||
return x;
|
||||
}
|
||||
|
||||
#endif
|
||||
90
test/ec_location_test3.cpp
Normal file
90
test/ec_location_test3.cpp
Normal file
@@ -0,0 +1,90 @@
|
||||
// Copyright 2021, 2022 Peter Dimov.
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// https://www.boost.org/LICENSE_1_0.txt
|
||||
|
||||
#include <boost/system.hpp>
|
||||
#include <boost/core/lightweight_test.hpp>
|
||||
#include <cerrno>
|
||||
|
||||
int main()
|
||||
{
|
||||
int const val = ENOENT;
|
||||
boost::system::error_category const & cat = boost::system::generic_category();
|
||||
|
||||
{
|
||||
boost::system::error_code ec;
|
||||
|
||||
BOOST_TEST( !ec.has_location() );
|
||||
BOOST_TEST_EQ( ec.location(), boost::source_location() );
|
||||
|
||||
BOOST_STATIC_CONSTEXPR boost::source_location loc = BOOST_CURRENT_LOCATION;
|
||||
|
||||
boost::system::error_code ec2( ec, &loc );
|
||||
|
||||
BOOST_TEST_EQ( ec2, ec );
|
||||
|
||||
BOOST_TEST( !ec2.has_location() );
|
||||
BOOST_TEST_EQ( ec2.location(), boost::source_location() );
|
||||
|
||||
boost::system::error_code ec3( ec2, 0 );
|
||||
|
||||
BOOST_TEST_EQ( ec3, ec2 );
|
||||
|
||||
BOOST_TEST( !ec3.has_location() );
|
||||
BOOST_TEST_EQ( ec3.location(), boost::source_location() );
|
||||
}
|
||||
|
||||
{
|
||||
boost::system::error_code ec( val, cat );
|
||||
|
||||
BOOST_TEST( !ec.has_location() );
|
||||
BOOST_TEST_EQ( ec.location(), boost::source_location() );
|
||||
|
||||
BOOST_STATIC_CONSTEXPR boost::source_location loc = BOOST_CURRENT_LOCATION;
|
||||
|
||||
boost::system::error_code ec2( ec, &loc );
|
||||
|
||||
BOOST_TEST_EQ( ec2, ec );
|
||||
|
||||
BOOST_TEST( ec2.has_location() );
|
||||
BOOST_TEST_EQ( ec2.location(), loc );
|
||||
|
||||
boost::system::error_code ec3( ec2, 0 );
|
||||
|
||||
BOOST_TEST_EQ( ec3, ec2 );
|
||||
|
||||
BOOST_TEST( !ec3.has_location() );
|
||||
BOOST_TEST_EQ( ec3.location(), boost::source_location() );
|
||||
}
|
||||
|
||||
#if defined(BOOST_SYSTEM_HAS_SYSTEM_ERROR)
|
||||
|
||||
{
|
||||
std::error_code e2( val, std::generic_category() );
|
||||
|
||||
boost::system::error_code ec( e2 );
|
||||
|
||||
BOOST_TEST( !ec.has_location() );
|
||||
BOOST_TEST_EQ( ec.location(), boost::source_location() );
|
||||
|
||||
BOOST_STATIC_CONSTEXPR boost::source_location loc = BOOST_CURRENT_LOCATION;
|
||||
|
||||
boost::system::error_code ec2( ec, &loc );
|
||||
|
||||
BOOST_TEST_EQ( ec2, ec );
|
||||
|
||||
BOOST_TEST( !ec2.has_location() );
|
||||
BOOST_TEST_EQ( ec2.location(), boost::source_location() );
|
||||
|
||||
boost::system::error_code ec3( ec2, 0 );
|
||||
|
||||
BOOST_TEST_EQ( ec3, ec2 );
|
||||
|
||||
BOOST_TEST( !ec3.has_location() );
|
||||
BOOST_TEST_EQ( ec3.location(), boost::source_location() );
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
93
test/ec_location_test4.cpp
Normal file
93
test/ec_location_test4.cpp
Normal file
@@ -0,0 +1,93 @@
|
||||
// Copyright 2021, 2022 Peter Dimov.
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// https://www.boost.org/LICENSE_1_0.txt
|
||||
|
||||
#include <boost/system.hpp>
|
||||
#include <boost/core/lightweight_test.hpp>
|
||||
#include <cerrno>
|
||||
|
||||
int main()
|
||||
{
|
||||
int const val = ENOENT;
|
||||
boost::system::error_category const & cat = boost::system::generic_category();
|
||||
|
||||
{
|
||||
boost::system::error_code ec;
|
||||
boost::system::error_code ec2( ec );
|
||||
|
||||
BOOST_TEST( !ec.has_location() );
|
||||
BOOST_TEST_EQ( ec.location(), boost::source_location() );
|
||||
|
||||
BOOST_STATIC_CONSTEXPR boost::source_location loc = BOOST_CURRENT_LOCATION;
|
||||
|
||||
ec.assign( ec, &loc );
|
||||
|
||||
BOOST_TEST_EQ( ec, ec2 );
|
||||
|
||||
BOOST_TEST( !ec.has_location() );
|
||||
BOOST_TEST_EQ( ec.location(), boost::source_location() );
|
||||
|
||||
ec.assign( ec, 0 );
|
||||
|
||||
BOOST_TEST_EQ( ec, ec2 );
|
||||
|
||||
BOOST_TEST( !ec.has_location() );
|
||||
BOOST_TEST_EQ( ec.location(), boost::source_location() );
|
||||
}
|
||||
|
||||
{
|
||||
boost::system::error_code ec( val, cat );
|
||||
boost::system::error_code ec2( ec );
|
||||
|
||||
BOOST_TEST( !ec.has_location() );
|
||||
BOOST_TEST_EQ( ec.location(), boost::source_location() );
|
||||
|
||||
BOOST_STATIC_CONSTEXPR boost::source_location loc = BOOST_CURRENT_LOCATION;
|
||||
|
||||
ec.assign( ec, &loc );
|
||||
|
||||
BOOST_TEST_EQ( ec, ec2 );
|
||||
|
||||
BOOST_TEST( ec.has_location() );
|
||||
BOOST_TEST_EQ( ec.location(), loc );
|
||||
|
||||
ec.assign( ec, 0 );
|
||||
|
||||
BOOST_TEST_EQ( ec, ec2 );
|
||||
|
||||
BOOST_TEST( !ec.has_location() );
|
||||
BOOST_TEST_EQ( ec.location(), boost::source_location() );
|
||||
}
|
||||
|
||||
#if defined(BOOST_SYSTEM_HAS_SYSTEM_ERROR)
|
||||
|
||||
{
|
||||
std::error_code e2( val, std::generic_category() );
|
||||
|
||||
boost::system::error_code ec( e2 );
|
||||
boost::system::error_code ec2( ec );
|
||||
|
||||
BOOST_TEST( !ec.has_location() );
|
||||
BOOST_TEST_EQ( ec.location(), boost::source_location() );
|
||||
|
||||
BOOST_STATIC_CONSTEXPR boost::source_location loc = BOOST_CURRENT_LOCATION;
|
||||
|
||||
ec.assign( ec, &loc );
|
||||
|
||||
BOOST_TEST_EQ( ec, ec2 );
|
||||
|
||||
BOOST_TEST( !ec.has_location() );
|
||||
BOOST_TEST_EQ( ec.location(), boost::source_location() );
|
||||
|
||||
ec.assign( ec, 0 );
|
||||
|
||||
BOOST_TEST_EQ( ec, ec2 );
|
||||
|
||||
BOOST_TEST( !ec.has_location() );
|
||||
BOOST_TEST_EQ( ec.location(), boost::source_location() );
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
17
test/errc_test4.cpp
Normal file
17
test/errc_test4.cpp
Normal file
@@ -0,0 +1,17 @@
|
||||
// Copyright 2022 Peter Dimov.
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// http://www.boost.org/LICENSE_1_0.txt
|
||||
|
||||
#include <boost/system/errc.hpp>
|
||||
#include <boost/assert/source_location.hpp>
|
||||
#include <boost/core/lightweight_test.hpp>
|
||||
|
||||
int main()
|
||||
{
|
||||
BOOST_STATIC_CONSTEXPR boost::source_location loc = BOOST_CURRENT_LOCATION;
|
||||
|
||||
BOOST_TEST( make_error_code( boost::system::errc::no_such_file_or_directory, &loc ).has_location() );
|
||||
BOOST_TEST_EQ( make_error_code( boost::system::errc::no_such_file_or_directory, &loc ).location().to_string(), loc.to_string() );
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
69
test/error_code_test3.cpp
Normal file
69
test/error_code_test3.cpp
Normal file
@@ -0,0 +1,69 @@
|
||||
// Copyright 2022 Peter Dimov.
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// http://www.boost.org/LICENSE_1_0.txt
|
||||
|
||||
#include <boost/system/error_code.hpp>
|
||||
#include <boost/system/error_condition.hpp>
|
||||
#include <boost/system/generic_category.hpp>
|
||||
#include <boost/core/lightweight_test.hpp>
|
||||
|
||||
namespace sys = boost::system;
|
||||
|
||||
enum my_errc
|
||||
{
|
||||
enomem_c = ENOMEM
|
||||
};
|
||||
|
||||
enum my_errn
|
||||
{
|
||||
enomem_n = ENOMEM
|
||||
};
|
||||
|
||||
namespace boost {
|
||||
namespace system {
|
||||
|
||||
template<> struct is_error_code_enum<my_errc>
|
||||
{
|
||||
static const bool value = true;
|
||||
};
|
||||
|
||||
template<> struct is_error_condition_enum<my_errn>
|
||||
{
|
||||
static const bool value = true;
|
||||
};
|
||||
|
||||
} // namespace system
|
||||
} // namespace boost
|
||||
|
||||
sys::error_code make_error_code( my_errc e )
|
||||
{
|
||||
return sys::error_code( e, sys::generic_category() );
|
||||
}
|
||||
|
||||
sys::error_condition make_error_condition( my_errn e )
|
||||
{
|
||||
return sys::error_condition( e, sys::generic_category() );
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
sys::error_code ec = make_error_code( sys::errc::not_enough_memory );
|
||||
sys::error_condition en( sys::errc::not_enough_memory );
|
||||
|
||||
BOOST_TEST_EQ( ec, en );
|
||||
BOOST_TEST_EQ( en, ec );
|
||||
|
||||
BOOST_TEST_EQ( ec, enomem_c );
|
||||
BOOST_TEST_EQ( enomem_c, ec );
|
||||
|
||||
BOOST_TEST_EQ( ec, enomem_n );
|
||||
BOOST_TEST_EQ( enomem_n, ec );
|
||||
|
||||
BOOST_TEST_EQ( en, enomem_c );
|
||||
BOOST_TEST_EQ( enomem_c, en );
|
||||
|
||||
BOOST_TEST_EQ( en, enomem_n );
|
||||
BOOST_TEST_EQ( enomem_n, en );
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
202
test/result_convert_construct.cpp
Normal file
202
test/result_convert_construct.cpp
Normal file
@@ -0,0 +1,202 @@
|
||||
// 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>
|
||||
|
||||
using namespace boost::system;
|
||||
|
||||
struct X
|
||||
{
|
||||
static int instances;
|
||||
|
||||
int v_;
|
||||
|
||||
X(): v_() { ++instances; }
|
||||
|
||||
X( int v ): v_( v ) { ++instances; }
|
||||
|
||||
X( X const& r ): v_( r.v_ ) { ++instances; }
|
||||
|
||||
X& operator=( X const& ) = delete;
|
||||
|
||||
~X() { --instances; }
|
||||
};
|
||||
|
||||
bool operator==( X const & x1, X const & x2 )
|
||||
{
|
||||
return x1.v_ == x2.v_;
|
||||
}
|
||||
|
||||
std::ostream& operator<<( std::ostream& os, X const & x )
|
||||
{
|
||||
os << "X:" << x.v_;
|
||||
return os;
|
||||
}
|
||||
|
||||
int X::instances = 0;
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
result<int> r( 5 );
|
||||
result<long> r2 = r;
|
||||
|
||||
BOOST_TEST( r2 ) && BOOST_TEST_EQ( *r2, 5 );
|
||||
}
|
||||
|
||||
{
|
||||
result<int> const r( 6 );
|
||||
result<long> r2 = r;
|
||||
|
||||
BOOST_TEST( r2 ) && BOOST_TEST_EQ( *r2, 6 );
|
||||
}
|
||||
|
||||
{
|
||||
result<long> r2 = result<int>( 7 );
|
||||
|
||||
BOOST_TEST( r2 ) && BOOST_TEST_EQ( *r2, 7 );
|
||||
}
|
||||
|
||||
BOOST_TEST_EQ( X::instances, 0 );
|
||||
|
||||
{
|
||||
result<int> r( 5 );
|
||||
result<X> r2 = r;
|
||||
|
||||
BOOST_TEST( r2 ) && BOOST_TEST_EQ( *r2, 5 );
|
||||
BOOST_TEST_EQ( X::instances, 1 );
|
||||
}
|
||||
|
||||
BOOST_TEST_EQ( X::instances, 0 );
|
||||
|
||||
{
|
||||
result<int> const r( 6 );
|
||||
result<X> r2 = r;
|
||||
|
||||
BOOST_TEST( r2 ) && BOOST_TEST_EQ( *r2, 6 );
|
||||
BOOST_TEST_EQ( X::instances, 1 );
|
||||
}
|
||||
|
||||
BOOST_TEST_EQ( X::instances, 0 );
|
||||
|
||||
{
|
||||
result<X> r2 = result<int>( 7 );
|
||||
|
||||
BOOST_TEST( r2 ) && BOOST_TEST_EQ( *r2, 7 );
|
||||
BOOST_TEST_EQ( X::instances, 1 );
|
||||
}
|
||||
|
||||
BOOST_TEST_EQ( X::instances, 0 );
|
||||
|
||||
{
|
||||
auto ec = make_error_code( errc::invalid_argument );
|
||||
|
||||
result<int> r( ec );
|
||||
result<long> r2 = r;
|
||||
|
||||
BOOST_TEST( !r2 );
|
||||
BOOST_TEST_EQ( r2.error(), ec );
|
||||
}
|
||||
|
||||
{
|
||||
auto ec = make_error_code( errc::invalid_argument );
|
||||
|
||||
result<int> r( ec );
|
||||
result<long> r2 = r;
|
||||
|
||||
BOOST_TEST( !r2 );
|
||||
BOOST_TEST_EQ( r2.error(), ec );
|
||||
}
|
||||
|
||||
{
|
||||
auto ec = make_error_code( errc::invalid_argument );
|
||||
|
||||
result<long> r2 = result<int>( ec );
|
||||
|
||||
BOOST_TEST( !r2 );
|
||||
BOOST_TEST_EQ( r2.error(), ec );
|
||||
}
|
||||
|
||||
BOOST_TEST_EQ( X::instances, 0 );
|
||||
|
||||
{
|
||||
result<char const*, int> r( "test" );
|
||||
result<std::string, X> r2 = r;
|
||||
|
||||
BOOST_TEST( r2 ) && BOOST_TEST_EQ( *r2, std::string( "test" ) );
|
||||
BOOST_TEST_EQ( X::instances, 0 );
|
||||
}
|
||||
|
||||
BOOST_TEST_EQ( X::instances, 0 );
|
||||
|
||||
{
|
||||
result<char const*, int> const r( "test" );
|
||||
result<std::string, X> r2 = r;
|
||||
|
||||
BOOST_TEST( r2 ) && BOOST_TEST_EQ( *r2, std::string( "test" ) );
|
||||
BOOST_TEST_EQ( X::instances, 0 );
|
||||
}
|
||||
|
||||
BOOST_TEST_EQ( X::instances, 0 );
|
||||
|
||||
{
|
||||
result<std::string, X> r2 = result<char const*, int>( "test" );
|
||||
|
||||
BOOST_TEST( r2 ) && BOOST_TEST_EQ( *r2, std::string( "test" ) );
|
||||
BOOST_TEST_EQ( X::instances, 0 );
|
||||
}
|
||||
|
||||
BOOST_TEST_EQ( X::instances, 0 );
|
||||
|
||||
{
|
||||
result<char const*, int> r( 5 );
|
||||
result<std::string, X> r2 = r;
|
||||
|
||||
BOOST_TEST( !r2 );
|
||||
BOOST_TEST_EQ( r2.error(), X(5) );
|
||||
BOOST_TEST_EQ( X::instances, 1 );
|
||||
}
|
||||
|
||||
BOOST_TEST_EQ( X::instances, 0 );
|
||||
|
||||
{
|
||||
result<char const*, int> const r( 6 );
|
||||
result<std::string, X> r2 = r;
|
||||
|
||||
BOOST_TEST( !r2 );
|
||||
BOOST_TEST_EQ( r2.error(), X(6) );
|
||||
BOOST_TEST_EQ( X::instances, 1 );
|
||||
}
|
||||
|
||||
{
|
||||
result<std::string, X> r2 = result<char const*, int>( 7 );
|
||||
|
||||
BOOST_TEST( !r2 );
|
||||
BOOST_TEST_EQ( r2.error(), X(7) );
|
||||
BOOST_TEST_EQ( X::instances, 1 );
|
||||
}
|
||||
|
||||
BOOST_TEST_EQ( X::instances, 0 );
|
||||
|
||||
{
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_constructible<result<long>, result<int>>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_convertible<result<int>, result<long>>));
|
||||
|
||||
BOOST_TEST_TRAIT_FALSE((std::is_constructible<result<int>, result<void*>>));
|
||||
BOOST_TEST_TRAIT_FALSE((std::is_convertible<result<void*>, result<int>>));
|
||||
|
||||
BOOST_TEST_TRAIT_FALSE((std::is_constructible<result<int>, result<void>>));
|
||||
BOOST_TEST_TRAIT_FALSE((std::is_convertible<result<void>, result<int>>));
|
||||
|
||||
BOOST_TEST_TRAIT_FALSE((std::is_constructible<result<void>, result<int>>));
|
||||
BOOST_TEST_TRAIT_FALSE((std::is_convertible<result<int>, result<void>>));
|
||||
|
||||
BOOST_TEST_TRAIT_FALSE((std::is_constructible<result<int, void*>, result<int, int>>));
|
||||
BOOST_TEST_TRAIT_FALSE((std::is_convertible<result<int, int>, result<int, void*>>));
|
||||
}
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
@@ -12,6 +12,11 @@ struct X
|
||||
{
|
||||
};
|
||||
|
||||
struct Y
|
||||
{
|
||||
Y( int );
|
||||
};
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
@@ -37,5 +42,17 @@ int main()
|
||||
BOOST_TEST( !r.has_error() );
|
||||
}
|
||||
|
||||
{
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_default_constructible<result<int>>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_default_constructible<result<int, int>>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_default_constructible<result<X>>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_default_constructible<result<X, int>>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_default_constructible<result<void>>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_default_constructible<result<void, int>>));
|
||||
|
||||
BOOST_TEST_TRAIT_FALSE((std::is_default_constructible<result<Y>>));
|
||||
BOOST_TEST_TRAIT_FALSE((std::is_default_constructible<result<Y, int>>));
|
||||
}
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
|
||||
@@ -62,13 +62,13 @@ int main()
|
||||
BOOST_TEST( !r.has_value() );
|
||||
BOOST_TEST( r.has_error() );
|
||||
|
||||
BOOST_TEST_EQ( r.error(), std::error_code( EINVAL, generic_category() ) );
|
||||
BOOST_TEST_EQ( r.error(), error_code( EINVAL, generic_category() ) );
|
||||
}
|
||||
|
||||
{
|
||||
auto ec = make_error_code( errc::invalid_argument );
|
||||
|
||||
result<std::error_code> r( in_place_error, ec );
|
||||
result<error_code> r( in_place_error, ec );
|
||||
|
||||
BOOST_TEST( !r.has_value() );
|
||||
BOOST_TEST( r.has_error() );
|
||||
@@ -77,12 +77,12 @@ int main()
|
||||
}
|
||||
|
||||
{
|
||||
result<std::error_code> r( in_place_error, EINVAL, generic_category() );
|
||||
result<error_code> r( in_place_error, EINVAL, generic_category() );
|
||||
|
||||
BOOST_TEST( !r.has_value() );
|
||||
BOOST_TEST( r.has_error() );
|
||||
|
||||
BOOST_TEST_EQ( r.error(), std::error_code( EINVAL, generic_category() ) );
|
||||
BOOST_TEST_EQ( r.error(), error_code( EINVAL, generic_category() ) );
|
||||
}
|
||||
|
||||
BOOST_TEST_EQ( X::instances, 0 );
|
||||
@@ -140,8 +140,8 @@ int main()
|
||||
BOOST_TEST_EQ( X::instances, 0 );
|
||||
|
||||
{
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_constructible<result<int>, std::error_code>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_convertible<std::error_code, result<int>>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_constructible<result<int>, error_code>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_convertible<error_code, result<int>>));
|
||||
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_constructible<result<std::string, X>, int>));
|
||||
BOOST_TEST_TRAIT_FALSE((std::is_convertible<int, result<std::string, X>>));
|
||||
@@ -178,7 +178,7 @@ int main()
|
||||
BOOST_TEST( !r.has_value() );
|
||||
BOOST_TEST( r.has_error() );
|
||||
|
||||
BOOST_TEST_EQ( r.error(), std::error_code( EINVAL, generic_category() ) );
|
||||
BOOST_TEST_EQ( r.error(), error_code( EINVAL, generic_category() ) );
|
||||
}
|
||||
|
||||
return boost::report_errors();
|
||||
|
||||
@@ -41,7 +41,7 @@ int main()
|
||||
BOOST_TEST( !r.has_value() );
|
||||
BOOST_TEST( r.has_error() );
|
||||
|
||||
BOOST_TEST_EQ( r.error(), std::error_code( EINVAL, generic_category() ) );
|
||||
BOOST_TEST_EQ( r.error(), error_code( EINVAL, generic_category() ) );
|
||||
}
|
||||
|
||||
{
|
||||
|
||||
@@ -32,6 +32,10 @@ BOOST_NORETURN void throw_exception_from_error( Y const &, boost::source_locatio
|
||||
throw E();
|
||||
}
|
||||
|
||||
struct E2
|
||||
{
|
||||
};
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
@@ -182,6 +186,62 @@ int main()
|
||||
BOOST_TEST_EQ( r.operator->(), static_cast<int*>(0) );
|
||||
}
|
||||
|
||||
{
|
||||
result<int, errc::errc_t> const r( in_place_error, errc::invalid_argument );
|
||||
|
||||
BOOST_TEST( !r.has_value() );
|
||||
BOOST_TEST( r.has_error() );
|
||||
|
||||
BOOST_TEST_NOT( r );
|
||||
BOOST_TEST( !r );
|
||||
|
||||
BOOST_TEST_THROWS( r.value(), system_error );
|
||||
|
||||
BOOST_TEST_EQ( r.operator->(), static_cast<int*>(0) );
|
||||
}
|
||||
|
||||
{
|
||||
result<int, std::errc> const r( std::errc::invalid_argument );
|
||||
|
||||
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<int, std::exception_ptr> const r( std::make_exception_ptr( E2() ) );
|
||||
|
||||
BOOST_TEST( !r.has_value() );
|
||||
BOOST_TEST( r.has_error() );
|
||||
|
||||
BOOST_TEST_NOT( r );
|
||||
BOOST_TEST( !r );
|
||||
|
||||
BOOST_TEST_THROWS( r.value(), E2 );
|
||||
|
||||
BOOST_TEST_EQ( r.operator->(), static_cast<int*>(0) );
|
||||
}
|
||||
|
||||
{
|
||||
result<int, std::exception_ptr> const r( in_place_error );
|
||||
|
||||
BOOST_TEST( !r.has_value() );
|
||||
BOOST_TEST( r.has_error() );
|
||||
|
||||
BOOST_TEST_NOT( r );
|
||||
BOOST_TEST( !r );
|
||||
|
||||
BOOST_TEST_THROWS( r.value(), std::bad_exception );
|
||||
|
||||
BOOST_TEST_EQ( r.operator->(), static_cast<int*>(0) );
|
||||
}
|
||||
|
||||
{
|
||||
result<X> r( 1 );
|
||||
|
||||
@@ -374,5 +434,61 @@ int main()
|
||||
BOOST_TEST_EQ( r.operator->(), static_cast<void*>(0) );
|
||||
}
|
||||
|
||||
{
|
||||
result<void, errc::errc_t> const r( in_place_error, errc::invalid_argument );
|
||||
|
||||
BOOST_TEST( !r.has_value() );
|
||||
BOOST_TEST( r.has_error() );
|
||||
|
||||
BOOST_TEST_NOT( r );
|
||||
BOOST_TEST( !r );
|
||||
|
||||
BOOST_TEST_THROWS( r.value(), system_error );
|
||||
|
||||
BOOST_TEST_EQ( r.operator->(), static_cast<void*>(0) );
|
||||
}
|
||||
|
||||
{
|
||||
result<void, std::errc> const r( std::errc::invalid_argument );
|
||||
|
||||
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) );
|
||||
}
|
||||
|
||||
{
|
||||
result<void, std::exception_ptr> const r( std::make_exception_ptr( E2() ) );
|
||||
|
||||
BOOST_TEST( !r.has_value() );
|
||||
BOOST_TEST( r.has_error() );
|
||||
|
||||
BOOST_TEST_NOT( r );
|
||||
BOOST_TEST( !r );
|
||||
|
||||
BOOST_TEST_THROWS( r.value(), E2 );
|
||||
|
||||
BOOST_TEST_EQ( r.operator->(), static_cast<void*>(0) );
|
||||
}
|
||||
|
||||
{
|
||||
result<void, std::exception_ptr> const r( in_place_error );
|
||||
|
||||
BOOST_TEST( !r.has_value() );
|
||||
BOOST_TEST( r.has_error() );
|
||||
|
||||
BOOST_TEST_NOT( r );
|
||||
BOOST_TEST( !r );
|
||||
|
||||
BOOST_TEST_THROWS( r.value(), std::bad_exception );
|
||||
|
||||
BOOST_TEST_EQ( r.operator->(), static_cast<void*>(0) );
|
||||
}
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
|
||||
77
test/std_interop_test13.cpp
Normal file
77
test/std_interop_test13.cpp
Normal file
@@ -0,0 +1,77 @@
|
||||
// Copyright 2021, 2022 Peter Dimov.
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// http://www.boost.org/LICENSE_1_0.txt
|
||||
|
||||
#include <boost/system/error_code.hpp>
|
||||
#include <boost/system/error_category.hpp>
|
||||
#include <boost/core/lightweight_test.hpp>
|
||||
#include <boost/config/pragma_message.hpp>
|
||||
#include <boost/config.hpp>
|
||||
#include <cerrno>
|
||||
|
||||
#if !defined(BOOST_SYSTEM_HAS_SYSTEM_ERROR)
|
||||
|
||||
BOOST_PRAGMA_MESSAGE( "BOOST_SYSTEM_HAS_SYSTEM_ERROR not defined, test will be skipped" )
|
||||
int main() {}
|
||||
|
||||
#else
|
||||
|
||||
#include <system_error>
|
||||
|
||||
class my_category_impl: public std::error_category
|
||||
{
|
||||
public:
|
||||
|
||||
char const* name() const BOOST_NOEXCEPT
|
||||
{
|
||||
return "mycat";
|
||||
}
|
||||
|
||||
std::string message( int /*ev*/ ) const
|
||||
{
|
||||
return "Unknown error";
|
||||
}
|
||||
};
|
||||
|
||||
std::error_category const& my_category()
|
||||
{
|
||||
static my_category_impl mycat;
|
||||
return mycat;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
std::error_code e1( 5, boost::system::system_category() );
|
||||
boost::system::error_code e2( e1 );
|
||||
std::error_code e3( e2 );
|
||||
|
||||
BOOST_TEST_EQ( e1, e3 );
|
||||
BOOST_TEST_EQ( e1.value(), e3.value() );
|
||||
BOOST_TEST_EQ( &e1.category(), &e3.category() );
|
||||
}
|
||||
|
||||
{
|
||||
std::error_code e1( 5, boost::system::generic_category() );
|
||||
boost::system::error_code e2( e1 );
|
||||
std::error_code e3( e2 );
|
||||
|
||||
BOOST_TEST_EQ( e1, e3 );
|
||||
BOOST_TEST_EQ( e1.value(), e3.value() );
|
||||
BOOST_TEST_EQ( &e1.category(), &e3.category() );
|
||||
}
|
||||
|
||||
{
|
||||
std::error_code e1( 5, my_category() );
|
||||
boost::system::error_code e2( e1 );
|
||||
std::error_code e3( e2 );
|
||||
|
||||
BOOST_TEST_EQ( e1, e3 );
|
||||
BOOST_TEST_EQ( e1.value(), e3.value() );
|
||||
BOOST_TEST_EQ( &e1.category(), &e3.category() );
|
||||
}
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
|
||||
#endif
|
||||
57
test/std_interop_test14.cpp
Normal file
57
test/std_interop_test14.cpp
Normal file
@@ -0,0 +1,57 @@
|
||||
// Copyright 2021, 2022 Peter Dimov.
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// http://www.boost.org/LICENSE_1_0.txt
|
||||
|
||||
#include <boost/system/error_code.hpp>
|
||||
#include <boost/system/error_category.hpp>
|
||||
#include <boost/core/lightweight_test.hpp>
|
||||
#include <boost/config/pragma_message.hpp>
|
||||
#include <boost/config.hpp>
|
||||
#include <cerrno>
|
||||
|
||||
#if !defined(BOOST_SYSTEM_HAS_SYSTEM_ERROR)
|
||||
|
||||
BOOST_PRAGMA_MESSAGE( "BOOST_SYSTEM_HAS_SYSTEM_ERROR not defined, test will be skipped" )
|
||||
int main() {}
|
||||
|
||||
#else
|
||||
|
||||
#include <system_error>
|
||||
|
||||
class my_category_impl: public boost::system::error_category
|
||||
{
|
||||
public:
|
||||
|
||||
char const* name() const BOOST_NOEXCEPT
|
||||
{
|
||||
return "mycat";
|
||||
}
|
||||
|
||||
std::string message( int /*ev*/ ) const
|
||||
{
|
||||
return "Unknown error";
|
||||
}
|
||||
};
|
||||
|
||||
boost::system::error_category const& my_category()
|
||||
{
|
||||
static my_category_impl mycat;
|
||||
return mycat;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
boost::system::error_code e1( 5, my_category() );
|
||||
std::error_code e2( e1 );
|
||||
boost::system::error_code e3( e2 );
|
||||
|
||||
BOOST_TEST_EQ( e1, e3 );
|
||||
BOOST_TEST_EQ( e1.value(), e3.value() );
|
||||
BOOST_TEST_EQ( &e1.category(), &e3.category() );
|
||||
}
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
|
||||
#endif
|
||||
94
test/std_interop_test15.cpp
Normal file
94
test/std_interop_test15.cpp
Normal file
@@ -0,0 +1,94 @@
|
||||
// Copyright 2021, 2022 Peter Dimov.
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// http://www.boost.org/LICENSE_1_0.txt
|
||||
|
||||
#include <boost/system/error_code.hpp>
|
||||
#include <boost/system/error_condition.hpp>
|
||||
#include <boost/core/lightweight_test.hpp>
|
||||
#include <boost/config/pragma_message.hpp>
|
||||
#include <boost/config.hpp>
|
||||
#include <boost/config/workaround.hpp>
|
||||
|
||||
#if !defined(BOOST_SYSTEM_HAS_SYSTEM_ERROR)
|
||||
|
||||
BOOST_PRAGMA_MESSAGE( "BOOST_SYSTEM_HAS_SYSTEM_ERROR not defined, test will be skipped" )
|
||||
int main() {}
|
||||
|
||||
#elif defined(BOOST_SYSTEM_AVOID_STD_GENERIC_CATEGORY)
|
||||
|
||||
BOOST_PRAGMA_MESSAGE( "Skipping test, BOOST_SYSTEM_AVOID_STD_GENERIC_CATEGORY is defined" )
|
||||
int main() {}
|
||||
|
||||
#else
|
||||
|
||||
#include <system_error>
|
||||
|
||||
namespace sys = boost::system;
|
||||
|
||||
enum my_errc
|
||||
{
|
||||
enomem_c = ENOMEM
|
||||
};
|
||||
|
||||
enum my_errn
|
||||
{
|
||||
enomem_n = ENOMEM
|
||||
};
|
||||
|
||||
namespace std {
|
||||
|
||||
template<> struct is_error_code_enum<my_errc>
|
||||
{
|
||||
static const bool value = true;
|
||||
};
|
||||
|
||||
template<> struct is_error_condition_enum<my_errn>
|
||||
{
|
||||
static const bool value = true;
|
||||
};
|
||||
|
||||
} // namespace std
|
||||
|
||||
std::error_code make_error_code( my_errc e )
|
||||
{
|
||||
return std::error_code( e, std::generic_category() );
|
||||
}
|
||||
|
||||
std::error_condition make_error_condition( my_errn e )
|
||||
{
|
||||
return std::error_condition( e, std::generic_category() );
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
sys::error_code ec = make_error_code( sys::errc::not_enough_memory );
|
||||
sys::error_condition en( sys::errc::not_enough_memory );
|
||||
|
||||
BOOST_TEST_EQ( ec, en );
|
||||
BOOST_TEST_EQ( en, ec );
|
||||
|
||||
BOOST_TEST_EQ( ec, enomem_c );
|
||||
BOOST_TEST_EQ( enomem_c, ec );
|
||||
|
||||
BOOST_TEST_EQ( ec, enomem_n );
|
||||
BOOST_TEST_EQ( enomem_n, ec );
|
||||
|
||||
BOOST_TEST_EQ( en, enomem_c );
|
||||
BOOST_TEST_EQ( enomem_c, en );
|
||||
|
||||
#if BOOST_WORKAROUND(BOOST_MSVC, == 1800)
|
||||
|
||||
// msvc-12.0 has op== as a member of std::error_condition
|
||||
|
||||
#else
|
||||
|
||||
BOOST_TEST_EQ( en, enomem_n );
|
||||
|
||||
#endif
|
||||
|
||||
BOOST_TEST_EQ( enomem_n, en );
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user