mirror of
https://github.com/boostorg/system.git
synced 2025-12-25 16:28:05 +01:00
Compare commits
26 Commits
feature/de
...
feature/is
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a57c568324 | ||
|
|
4843453528 | ||
|
|
2e7e46a802 | ||
|
|
32dbf1b992 | ||
|
|
707b24bfa1 | ||
|
|
bb1caae0d5 | ||
|
|
c5c49894e6 | ||
|
|
ee80491cab | ||
|
|
a83319fde1 | ||
|
|
4b90524729 | ||
|
|
6ac5f23999 | ||
|
|
f332a52597 | ||
|
|
c92d50abbd | ||
|
|
805b260a7a | ||
|
|
f32ffcba48 | ||
|
|
8ce2a9f835 | ||
|
|
6a58b03eab | ||
|
|
f0b27c5826 | ||
|
|
456b3c2dad | ||
|
|
eb3f3a8e41 | ||
|
|
e6986a51d5 | ||
|
|
71ee26c188 | ||
|
|
8449c62162 | ||
|
|
4bca94ffc4 | ||
|
|
86ff47ff63 | ||
|
|
06ddfdb4a6 |
212
.github/workflows/ci.yml
vendored
212
.github/workflows/ci.yml
vendored
@@ -55,6 +55,11 @@ jobs:
|
||||
cxxstd: "03,11,14,17,20,2b"
|
||||
os: ubuntu-22.04
|
||||
install: g++-12
|
||||
- toolset: gcc-13
|
||||
cxxstd: "03,11,14,17,20,2b"
|
||||
os: ubuntu-latest
|
||||
container: ubuntu:23.04
|
||||
install: g++-13
|
||||
- toolset: clang
|
||||
compiler: clang++-3.9
|
||||
cxxstd: "03,11,14"
|
||||
@@ -115,12 +120,26 @@ jobs:
|
||||
cxxstd: "03,11,14,17,20,2b"
|
||||
os: ubuntu-22.04
|
||||
install: clang-14
|
||||
- toolset: clang
|
||||
compiler: clang++-15
|
||||
cxxstd: "03,11,14,17,20,2b"
|
||||
os: ubuntu-22.04
|
||||
install: clang-15
|
||||
- toolset: clang
|
||||
compiler: clang++-16
|
||||
cxxstd: "03,11,14,17,20,2b"
|
||||
os: ubuntu-latest
|
||||
container: ubuntu:23.04
|
||||
install: clang-16
|
||||
- toolset: clang
|
||||
cxxstd: "03,11,14,17,2a"
|
||||
os: macos-11
|
||||
- toolset: clang
|
||||
cxxstd: "03,11,14,17,2a"
|
||||
cxxstd: "03,11,14,17,20,2b"
|
||||
os: macos-12
|
||||
- toolset: clang
|
||||
cxxstd: "03,11,14,17,20,2b"
|
||||
os: macos-13
|
||||
|
||||
runs-on: ${{matrix.os}}
|
||||
container: ${{matrix.container}}
|
||||
@@ -136,11 +155,13 @@ jobs:
|
||||
if: matrix.container
|
||||
run: |
|
||||
apt-get update
|
||||
apt-get -y install sudo python git g++
|
||||
apt-get -y install sudo python3 git g++
|
||||
|
||||
- name: Install packages
|
||||
if: matrix.install
|
||||
run: sudo apt-get -y install ${{matrix.install}}
|
||||
run: |
|
||||
sudo apt-get update
|
||||
sudo apt-get -y install ${{matrix.install}}
|
||||
|
||||
- name: Setup Boost
|
||||
run: |
|
||||
@@ -160,7 +181,7 @@ jobs:
|
||||
cd boost-root
|
||||
cp -r $GITHUB_WORKSPACE/* libs/$LIBRARY
|
||||
git submodule update --init tools/boostdep
|
||||
python tools/boostdep/depinst/depinst.py --git_args "--jobs 3" $LIBRARY
|
||||
python3 tools/boostdep/depinst/depinst.py --git_args "--jobs 3" $LIBRARY
|
||||
./bootstrap.sh
|
||||
./b2 -d0 headers
|
||||
|
||||
@@ -242,6 +263,7 @@ jobs:
|
||||
- os: ubuntu-22.04
|
||||
- os: macos-11
|
||||
- os: macos-12
|
||||
- os: macos-13
|
||||
|
||||
runs-on: ${{matrix.os}}
|
||||
|
||||
@@ -289,6 +311,7 @@ jobs:
|
||||
- os: ubuntu-22.04
|
||||
- os: macos-11
|
||||
- os: macos-12
|
||||
- os: macos-13
|
||||
|
||||
runs-on: ${{matrix.os}}
|
||||
|
||||
@@ -346,6 +369,7 @@ jobs:
|
||||
- os: ubuntu-22.04
|
||||
- os: macos-11
|
||||
- os: macos-12
|
||||
- os: macos-13
|
||||
|
||||
runs-on: ${{matrix.os}}
|
||||
|
||||
@@ -391,3 +415,183 @@ jobs:
|
||||
run: |
|
||||
cd ../boost-root/__build__
|
||||
ctest --output-on-failure --no-tests=error
|
||||
|
||||
windows-cmake-subdir:
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
include:
|
||||
- os: windows-2019
|
||||
- os: windows-2022
|
||||
|
||||
runs-on: ${{matrix.os}}
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
- name: Setup Boost
|
||||
shell: cmd
|
||||
run: |
|
||||
echo GITHUB_REPOSITORY: %GITHUB_REPOSITORY%
|
||||
for /f %%i in ("%GITHUB_REPOSITORY%") do set LIBRARY=%%~nxi
|
||||
echo LIBRARY: %LIBRARY%
|
||||
echo LIBRARY=%LIBRARY%>>%GITHUB_ENV%
|
||||
echo GITHUB_BASE_REF: %GITHUB_BASE_REF%
|
||||
echo GITHUB_REF: %GITHUB_REF%
|
||||
if "%GITHUB_BASE_REF%" == "" set GITHUB_BASE_REF=%GITHUB_REF%
|
||||
set BOOST_BRANCH=develop
|
||||
for /f %%i in ("%GITHUB_BASE_REF%") do if "%%~nxi" == "master" set BOOST_BRANCH=master
|
||||
echo BOOST_BRANCH: %BOOST_BRANCH%
|
||||
cd ..
|
||||
git clone -b %BOOST_BRANCH% --depth 1 https://github.com/boostorg/boost.git boost-root
|
||||
cd boost-root
|
||||
xcopy /s /e /q %GITHUB_WORKSPACE% libs\%LIBRARY%\
|
||||
git submodule update --init tools/boostdep
|
||||
python tools/boostdep/depinst/depinst.py --git_args "--jobs 3" %LIBRARY%
|
||||
|
||||
- name: Use library with add_subdirectory (Debug)
|
||||
shell: cmd
|
||||
run: |
|
||||
cd ../boost-root/libs/%LIBRARY%/test/cmake_subdir_test
|
||||
mkdir __build__ && cd __build__
|
||||
cmake ..
|
||||
cmake --build . --config Debug
|
||||
ctest --output-on-failure --no-tests=error -C Debug
|
||||
|
||||
- name: Use library with add_subdirectory (Release)
|
||||
shell: cmd
|
||||
run: |
|
||||
cd ../boost-root/libs/%LIBRARY%/test/cmake_subdir_test/__build__
|
||||
cmake --build . --config Release
|
||||
ctest --output-on-failure --no-tests=error -C Release
|
||||
|
||||
windows-cmake-install:
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
include:
|
||||
- os: windows-2019
|
||||
- os: windows-2022
|
||||
|
||||
runs-on: ${{matrix.os}}
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
- name: Setup Boost
|
||||
shell: cmd
|
||||
run: |
|
||||
echo GITHUB_REPOSITORY: %GITHUB_REPOSITORY%
|
||||
for /f %%i in ("%GITHUB_REPOSITORY%") do set LIBRARY=%%~nxi
|
||||
echo LIBRARY: %LIBRARY%
|
||||
echo LIBRARY=%LIBRARY%>>%GITHUB_ENV%
|
||||
echo GITHUB_BASE_REF: %GITHUB_BASE_REF%
|
||||
echo GITHUB_REF: %GITHUB_REF%
|
||||
if "%GITHUB_BASE_REF%" == "" set GITHUB_BASE_REF=%GITHUB_REF%
|
||||
set BOOST_BRANCH=develop
|
||||
for /f %%i in ("%GITHUB_BASE_REF%") do if "%%~nxi" == "master" set BOOST_BRANCH=master
|
||||
echo BOOST_BRANCH: %BOOST_BRANCH%
|
||||
cd ..
|
||||
git clone -b %BOOST_BRANCH% --depth 1 https://github.com/boostorg/boost.git boost-root
|
||||
cd boost-root
|
||||
xcopy /s /e /q %GITHUB_WORKSPACE% libs\%LIBRARY%\
|
||||
git submodule update --init tools/boostdep
|
||||
python tools/boostdep/depinst/depinst.py --git_args "--jobs 3" %LIBRARY%
|
||||
|
||||
- name: Configure
|
||||
shell: cmd
|
||||
run: |
|
||||
cd ../boost-root
|
||||
mkdir __build__ && cd __build__
|
||||
cmake -DBOOST_INCLUDE_LIBRARIES=%LIBRARY% -DCMAKE_INSTALL_PREFIX=C:/cmake-prefix ..
|
||||
|
||||
- name: Install (Debug)
|
||||
shell: cmd
|
||||
run: |
|
||||
cd ../boost-root/__build__
|
||||
cmake --build . --target install --config Debug
|
||||
|
||||
- name: Install (Release)
|
||||
shell: cmd
|
||||
run: |
|
||||
cd ../boost-root/__build__
|
||||
cmake --build . --target install --config Release
|
||||
|
||||
- name: Use the installed library (Debug)
|
||||
shell: cmd
|
||||
run: |
|
||||
cd ../boost-root/libs/%LIBRARY%/test/cmake_install_test && mkdir __build__ && cd __build__
|
||||
cmake -DCMAKE_INSTALL_PREFIX=C:/cmake-prefix ..
|
||||
cmake --build . --config Debug
|
||||
ctest --output-on-failure --no-tests=error -C Debug
|
||||
|
||||
- name: Use the installed library (Release)
|
||||
shell: cmd
|
||||
run: |
|
||||
cd ../boost-root/libs/%LIBRARY%/test/cmake_install_test/__build__
|
||||
cmake --build . --config Release
|
||||
ctest --output-on-failure --no-tests=error -C Release
|
||||
|
||||
windows-cmake-test:
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
include:
|
||||
- os: windows-2019
|
||||
- os: windows-2022
|
||||
|
||||
runs-on: ${{matrix.os}}
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
- name: Setup Boost
|
||||
shell: cmd
|
||||
run: |
|
||||
echo GITHUB_REPOSITORY: %GITHUB_REPOSITORY%
|
||||
for /f %%i in ("%GITHUB_REPOSITORY%") do set LIBRARY=%%~nxi
|
||||
echo LIBRARY: %LIBRARY%
|
||||
echo LIBRARY=%LIBRARY%>>%GITHUB_ENV%
|
||||
echo GITHUB_BASE_REF: %GITHUB_BASE_REF%
|
||||
echo GITHUB_REF: %GITHUB_REF%
|
||||
if "%GITHUB_BASE_REF%" == "" set GITHUB_BASE_REF=%GITHUB_REF%
|
||||
set BOOST_BRANCH=develop
|
||||
for /f %%i in ("%GITHUB_BASE_REF%") do if "%%~nxi" == "master" set BOOST_BRANCH=master
|
||||
echo BOOST_BRANCH: %BOOST_BRANCH%
|
||||
cd ..
|
||||
git clone -b %BOOST_BRANCH% --depth 1 https://github.com/boostorg/boost.git boost-root
|
||||
cd boost-root
|
||||
xcopy /s /e /q %GITHUB_WORKSPACE% libs\%LIBRARY%\
|
||||
git submodule update --init tools/boostdep
|
||||
python tools/boostdep/depinst/depinst.py --git_args "--jobs 3" %LIBRARY%
|
||||
|
||||
- name: Configure
|
||||
shell: cmd
|
||||
run: |
|
||||
cd ../boost-root
|
||||
mkdir __build__ && cd __build__
|
||||
cmake -DBOOST_INCLUDE_LIBRARIES=%LIBRARY% -DBUILD_TESTING=ON ..
|
||||
|
||||
- name: Build tests (Debug)
|
||||
shell: cmd
|
||||
run: |
|
||||
cd ../boost-root/__build__
|
||||
cmake --build . --target tests --config Debug
|
||||
|
||||
- name: Run tests (Debug)
|
||||
shell: cmd
|
||||
run: |
|
||||
cd ../boost-root/__build__
|
||||
ctest --output-on-failure --no-tests=error -C Debug
|
||||
|
||||
- name: Build tests (Release)
|
||||
shell: cmd
|
||||
run: |
|
||||
cd ../boost-root/__build__
|
||||
cmake --build . --target tests --config Release
|
||||
|
||||
- name: Run tests (Release)
|
||||
shell: cmd
|
||||
run: |
|
||||
cd ../boost-root/__build__
|
||||
ctest --output-on-failure --no-tests=error -C Release
|
||||
|
||||
@@ -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}
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
//
|
||||
// See http://www.boost.org/libs/system for documentation.
|
||||
|
||||
#include <boost/system/detail/requires_cxx11.hpp>
|
||||
#include <boost/config.hpp>
|
||||
#include <boost/config/workaround.hpp>
|
||||
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
#include <boost/system/detail/config.hpp>
|
||||
#include <boost/cstdint.hpp>
|
||||
#include <boost/config.hpp>
|
||||
#include <boost/config/workaround.hpp>
|
||||
#include <string>
|
||||
#include <functional>
|
||||
#include <cstddef>
|
||||
@@ -116,11 +117,18 @@ protected:
|
||||
|
||||
#endif
|
||||
|
||||
BOOST_SYSTEM_CONSTEXPR error_category() BOOST_NOEXCEPT: id_( 0 ), stdcat_(), sc_init_()
|
||||
#if !BOOST_WORKAROUND(BOOST_GCC, < 40800)
|
||||
BOOST_CONSTEXPR
|
||||
#endif
|
||||
error_category() BOOST_NOEXCEPT: id_( 0 ), stdcat_(), sc_init_()
|
||||
{
|
||||
}
|
||||
|
||||
explicit BOOST_SYSTEM_CONSTEXPR error_category( boost::ulong_long_type id ) BOOST_NOEXCEPT: id_( id ), stdcat_(), sc_init_()
|
||||
explicit
|
||||
#if !BOOST_WORKAROUND(BOOST_GCC, < 40800)
|
||||
BOOST_CONSTEXPR
|
||||
#endif
|
||||
error_category( boost::ulong_long_type id ) BOOST_NOEXCEPT: id_( id ), stdcat_(), sc_init_()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
@@ -106,18 +106,6 @@ namespace boost
|
||||
namespace system
|
||||
{
|
||||
|
||||
namespace detail
|
||||
{
|
||||
|
||||
template<class = void> struct stdcat_mx_holder
|
||||
{
|
||||
static mutex mx_;
|
||||
};
|
||||
|
||||
template<class T> 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" );
|
||||
@@ -130,7 +118,13 @@ inline void error_category::init_stdcat() const
|
||||
|
||||
#endif
|
||||
|
||||
system::detail::lock_guard<system::detail::mutex> lk( system::detail::stdcat_mx_holder<>::mx_ );
|
||||
// detail::mutex has a constexpr default constructor,
|
||||
// and therefore guarantees static initialization, on
|
||||
// everything except VS 2013 (msvc-12.0)
|
||||
|
||||
static system::detail::mutex mx_;
|
||||
|
||||
system::detail::lock_guard<system::detail::mutex> lk( mx_ );
|
||||
|
||||
if( sc_init_.load( std::memory_order_acquire ) == 0 )
|
||||
{
|
||||
|
||||
@@ -31,7 +31,46 @@ struct mutex
|
||||
} // namespace system
|
||||
} // namespace boost
|
||||
|
||||
#else
|
||||
#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
|
||||
// issues. However, shared_mutex is based on SRWLock and its
|
||||
// default constructor is constexpr, so we use that instead.
|
||||
|
||||
#include <boost/winapi/config.hpp>
|
||||
|
||||
// SRWLOCK is not available when targeting Windows XP
|
||||
#if BOOST_USE_WINAPI_VERSION >= BOOST_WINAPI_VERSION_WIN6
|
||||
|
||||
#include <shared_mutex>
|
||||
|
||||
#if BOOST_MSSTL_VERSION >= 142 || _HAS_SHARED_MUTEX
|
||||
# define BOOST_SYSTEM_HAS_MSSTL_SHARED_MUTEX
|
||||
#endif
|
||||
|
||||
#endif // BOOST_MSSTL_VERSION >= 142 || _HAS_SHARED_MUTEX
|
||||
|
||||
#endif // BOOST_USE_WINAPI_VERSION >= BOOST_WINAPI_VERSION_WIN6
|
||||
|
||||
#if defined(BOOST_SYSTEM_HAS_MSSTL_SHARED_MUTEX)
|
||||
|
||||
namespace boost
|
||||
{
|
||||
namespace system
|
||||
{
|
||||
namespace detail
|
||||
{
|
||||
|
||||
typedef std::shared_mutex mutex;
|
||||
|
||||
} // namespace detail
|
||||
} // namespace system
|
||||
} // namespace boost
|
||||
|
||||
#else // defined(BOOST_SYSTEM_HAS_MSSTL_SHARED_MUTEX)
|
||||
|
||||
#include <mutex>
|
||||
|
||||
@@ -48,7 +87,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
|
||||
{
|
||||
|
||||
21
include/boost/system/detail/requires_cxx11.hpp
Normal file
21
include/boost/system/detail/requires_cxx11.hpp
Normal file
@@ -0,0 +1,21 @@
|
||||
#ifndef BOOST_SYSTEM_DETAIL_REQUIRES_CXX11_HPP_INCLUDED
|
||||
#define BOOST_SYSTEM_DETAIL_REQUIRES_CXX11_HPP_INCLUDED
|
||||
|
||||
// Copyright 2023 Peter Dimov
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// https://www.boost.org/LICENSE_1_0.txt
|
||||
|
||||
#include <boost/config.hpp>
|
||||
#include <boost/config/pragma_message.hpp>
|
||||
|
||||
#if defined(BOOST_NO_CXX11_CONSTEXPR) || \
|
||||
defined(BOOST_NO_CXX11_NOEXCEPT) || \
|
||||
defined(BOOST_NO_CXX11_EXPLICIT_CONVERSION_OPERATORS) || \
|
||||
defined(BOOST_NO_CXX11_DEFAULTED_FUNCTIONS) || \
|
||||
defined(BOOST_NO_CXX11_HDR_SYSTEM_ERROR)
|
||||
|
||||
BOOST_PRAGMA_MESSAGE("C++03 support was deprecated in Boost.System 1.82 and will be removed in Boost.System 1.84. Please open an issue in https://github.com/boostorg/system if you want it retained.")
|
||||
|
||||
#endif
|
||||
|
||||
#endif // #ifndef BOOST_SYSTEM_DETAIL_REQUIRES_CXX11_HPP_INCLUDED
|
||||
@@ -85,6 +85,10 @@ template<class T> using remove_cvref = typename std::remove_cv< typename std::re
|
||||
|
||||
template<class... T> using is_errc_t = std::is_same<mp11::mp_list<remove_cvref<T>...>, mp11::mp_list<errc::errc_t>>;
|
||||
|
||||
template<class T, class... A> struct is_constructible: std::is_constructible<T, A...> {};
|
||||
template<class A> struct is_constructible<bool, A>: std::is_convertible<A, bool> {};
|
||||
template<class A> struct is_constructible<bool const, A>: std::is_convertible<A, bool> {};
|
||||
|
||||
} // namespace detail
|
||||
|
||||
// result
|
||||
@@ -122,7 +126,7 @@ public:
|
||||
template<class A = T, typename std::enable_if<
|
||||
std::is_convertible<A, T>::value &&
|
||||
!(detail::is_errc_t<A>::value && std::is_arithmetic<T>::value) &&
|
||||
!std::is_constructible<E, A>::value, int>::type = 0>
|
||||
!std::is_convertible<A, E>::value, int>::type = 0>
|
||||
constexpr result( A&& a )
|
||||
noexcept( std::is_nothrow_constructible<T, A>::value )
|
||||
: v_( in_place_value, std::forward<A>(a) )
|
||||
@@ -132,7 +136,7 @@ public:
|
||||
// implicit, error
|
||||
template<class A = E, class = void, typename std::enable_if<
|
||||
std::is_convertible<A, E>::value &&
|
||||
!std::is_constructible<T, A>::value, int>::type = 0>
|
||||
!std::is_convertible<A, T>::value, int>::type = 0>
|
||||
constexpr result( A&& a )
|
||||
noexcept( std::is_nothrow_constructible<E, A>::value )
|
||||
: v_( in_place_error, std::forward<A>(a) )
|
||||
@@ -141,9 +145,9 @@ public:
|
||||
|
||||
// explicit, value
|
||||
template<class... A, class En = typename std::enable_if<
|
||||
std::is_constructible<T, A...>::value &&
|
||||
detail::is_constructible<T, A...>::value &&
|
||||
!(detail::is_errc_t<A...>::value && std::is_arithmetic<T>::value) &&
|
||||
!std::is_constructible<E, A...>::value &&
|
||||
!detail::is_constructible<E, A...>::value &&
|
||||
sizeof...(A) >= 1
|
||||
>::type>
|
||||
explicit constexpr result( A&&... a )
|
||||
@@ -154,8 +158,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 &&
|
||||
!detail::is_constructible<T, A...>::value &&
|
||||
detail::is_constructible<E, A...>::value &&
|
||||
sizeof...(A) >= 1
|
||||
>::type>
|
||||
explicit constexpr result( A&&... a )
|
||||
@@ -187,7 +191,8 @@ 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
|
||||
std::is_convertible<E2, E>::value &&
|
||||
!std::is_convertible<result<T2, E2> const&, T>::value
|
||||
>::type>
|
||||
BOOST_CXX14_CONSTEXPR result( result<T2, E2> const& r2 )
|
||||
noexcept(
|
||||
@@ -205,7 +210,8 @@ public:
|
||||
|
||||
template<class T2, class E2, class En = typename std::enable_if<
|
||||
std::is_convertible<T2, T>::value &&
|
||||
std::is_convertible<E2, E>::value
|
||||
std::is_convertible<E2, E>::value &&
|
||||
!std::is_convertible<result<T2, E2>&&, T>::value
|
||||
>::type>
|
||||
BOOST_CXX14_CONSTEXPR result( result<T2, E2>&& r2 )
|
||||
noexcept(
|
||||
@@ -395,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>
|
||||
@@ -575,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()
|
||||
|
||||
@@ -134,6 +134,8 @@ boost_test(TYPE run SOURCES win32_generic_test.cpp)
|
||||
|
||||
boost_test(TYPE run SOURCES ec_hash_value_test.cpp)
|
||||
|
||||
boost_test(TYPE run SOURCES std_interop_test16.cpp)
|
||||
|
||||
# result
|
||||
|
||||
set(BOOST_TEST_COMPILE_FEATURES cxx_std_11)
|
||||
@@ -152,7 +154,13 @@ 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_errc_construct.cpp)
|
||||
boost_test(TYPE run SOURCES result_convert_construct.cpp)
|
||||
boost_test(TYPE run SOURCES result_typedefs.cpp)
|
||||
boost_test(TYPE run SOURCES result_value_construct3.cpp)
|
||||
boost_test(TYPE run SOURCES result_error_construct3.cpp)
|
||||
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)
|
||||
|
||||
@@ -162,6 +162,8 @@ run win32_generic_test.cpp ;
|
||||
|
||||
run ec_hash_value_test.cpp ;
|
||||
|
||||
run std_interop_test16.cpp ;
|
||||
|
||||
# result
|
||||
|
||||
import ../../config/checks/config : requires ;
|
||||
@@ -188,3 +190,7 @@ run result_typedefs.cpp : : : $(CPP11) ;
|
||||
run result_value_construct3.cpp : : : $(CPP11) ;
|
||||
run result_error_construct3.cpp : : : $(CPP11) ;
|
||||
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) ;
|
||||
|
||||
@@ -146,8 +146,14 @@ int main()
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_constructible<result<std::string, X>, int>));
|
||||
BOOST_TEST_TRAIT_FALSE((std::is_convertible<int, result<std::string, X>>));
|
||||
|
||||
BOOST_TEST_TRAIT_FALSE((std::is_constructible<result<int, X>, int>));
|
||||
BOOST_TEST_TRAIT_FALSE((std::is_convertible<int, result<int, X>>));
|
||||
// We'd like this to be false due to the ambiguity caused by X having
|
||||
// an explicit constructor taking an int, which should be viable in this
|
||||
// context, but the implicit constructor is enabled, and there's no way to
|
||||
// disallow it
|
||||
//
|
||||
// BOOST_TEST_TRAIT_FALSE((std::is_constructible<result<int, X>, int>));
|
||||
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_convertible<int, result<int, X>>));
|
||||
}
|
||||
|
||||
{
|
||||
|
||||
49
test/result_error_construct4.cpp
Normal file
49
test/result_error_construct4.cpp
Normal file
@@ -0,0 +1,49 @@
|
||||
// Copyright 2023 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>
|
||||
|
||||
using namespace boost::system;
|
||||
|
||||
// Eigen::Matrix4d has an explicit templated constructor
|
||||
// https://github.com/boostorg/system/issues/103
|
||||
// https://github.com/boostorg/json/issues/843
|
||||
|
||||
struct X
|
||||
{
|
||||
X() {}
|
||||
template<class T> explicit X( T const& ) {}
|
||||
};
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
auto ec = make_error_code( errc::invalid_argument );
|
||||
|
||||
result<X> r = ec;
|
||||
|
||||
BOOST_TEST( !r.has_value() );
|
||||
BOOST_TEST( r.has_error() );
|
||||
|
||||
BOOST_TEST_EQ( r.error(), ec );
|
||||
}
|
||||
|
||||
#if defined(BOOST_SYSTEM_HAS_SYSTEM_ERROR)
|
||||
|
||||
{
|
||||
auto ec = make_error_code( std::errc::invalid_argument );
|
||||
|
||||
result<X> r = ec;
|
||||
|
||||
BOOST_TEST( !r.has_value() );
|
||||
BOOST_TEST( r.has_error() );
|
||||
|
||||
BOOST_TEST_EQ( r.error(), ec );
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
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();
|
||||
}
|
||||
59
test/result_value_construct4.cpp
Normal file
59
test/result_value_construct4.cpp
Normal file
@@ -0,0 +1,59 @@
|
||||
// Copyright 2023 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>
|
||||
|
||||
using namespace boost::system;
|
||||
|
||||
// Tricky mixed construction cases
|
||||
// https://github.com/boostorg/system/issues/104
|
||||
// https://brevzin.github.io//c++/2023/01/18/optional-construction/
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
result<int> r( make_error_code( errc::invalid_argument ) );
|
||||
result<result<int>> r2( r );
|
||||
|
||||
BOOST_TEST( r2.has_value() ) && BOOST_TEST_EQ( r2.value(), r );
|
||||
}
|
||||
|
||||
{
|
||||
result<int> r( 5 );
|
||||
result<result<int>> r2( r );
|
||||
|
||||
BOOST_TEST( r2.has_value() ) && BOOST_TEST_EQ( r2.value(), r );
|
||||
}
|
||||
|
||||
{
|
||||
result<int> const r( make_error_code( errc::invalid_argument ) );
|
||||
result<result<int>> r2( r );
|
||||
|
||||
BOOST_TEST( r2.has_value() ) && BOOST_TEST_EQ( r2.value(), r );
|
||||
}
|
||||
|
||||
{
|
||||
result<int> const r( 5 );
|
||||
result<result<int>> r2( r );
|
||||
|
||||
BOOST_TEST( r2.has_value() ) && BOOST_TEST_EQ( r2.value(), r );
|
||||
}
|
||||
|
||||
{
|
||||
result<int> r( make_error_code( errc::invalid_argument ) );
|
||||
result<result<int>> r2( std::move( r ) );
|
||||
|
||||
BOOST_TEST( r2.has_value() ) && BOOST_TEST_EQ( r2.value(), r );
|
||||
}
|
||||
|
||||
{
|
||||
result<int> r( 5 );
|
||||
result<result<int>> r2( std::move( r ) );
|
||||
|
||||
BOOST_TEST( r2.has_value() ) && BOOST_TEST_EQ( r2.value(), r );
|
||||
}
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
86
test/result_value_construct5.cpp
Normal file
86
test/result_value_construct5.cpp
Normal file
@@ -0,0 +1,86 @@
|
||||
// Copyright 2023 Peter Dimov.
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// https://www.boost.org/LICENSE_1_0.txt
|
||||
|
||||
#if defined(_MSC_VER) && _MSC_VER < 1910
|
||||
# pragma warning( disable: 4800 ) // forcing value to bool 'true' or 'false'
|
||||
#endif
|
||||
|
||||
#include <boost/system/result.hpp>
|
||||
#include <boost/core/lightweight_test.hpp>
|
||||
#include <boost/core/lightweight_test_trait.hpp>
|
||||
#include <utility>
|
||||
#include <type_traits>
|
||||
|
||||
using namespace boost::system;
|
||||
|
||||
// Tricky mixed construction cases
|
||||
// https://github.com/boostorg/system/issues/104
|
||||
// https://brevzin.github.io//c++/2023/01/18/optional-construction/
|
||||
|
||||
template<class R1, class R2> void test()
|
||||
{
|
||||
{
|
||||
R1 r1( make_error_code( errc::invalid_argument ) );
|
||||
R2 r2( r1 );
|
||||
|
||||
BOOST_TEST( !r2.has_value() );
|
||||
}
|
||||
|
||||
{
|
||||
R1 r1( 0 );
|
||||
R2 r2( r1 );
|
||||
|
||||
BOOST_TEST( r2.has_value() ) && BOOST_TEST_EQ( r2.value(), false );
|
||||
}
|
||||
|
||||
{
|
||||
R1 r1( 1 );
|
||||
R2 r2( r1 );
|
||||
|
||||
BOOST_TEST( r2.has_value() ) && BOOST_TEST_EQ( r2.value(), true );
|
||||
}
|
||||
|
||||
{
|
||||
R1 r1( make_error_code( errc::invalid_argument ) );
|
||||
R2 r2( std::move( r1 ) );
|
||||
|
||||
BOOST_TEST( !r2.has_value() );
|
||||
}
|
||||
|
||||
{
|
||||
R1 r1( 0 );
|
||||
R2 r2( std::move( r1 ) );
|
||||
|
||||
BOOST_TEST( r2.has_value() ) && BOOST_TEST_EQ( r2.value(), false );
|
||||
}
|
||||
|
||||
{
|
||||
R1 r1( 1 );
|
||||
R2 r2( std::move( r1 ) );
|
||||
|
||||
BOOST_TEST( r2.has_value() ) && BOOST_TEST_EQ( r2.value(), true );
|
||||
}
|
||||
}
|
||||
|
||||
struct X
|
||||
{
|
||||
};
|
||||
|
||||
int main()
|
||||
{
|
||||
test< result<int>, result<bool> >();
|
||||
test< result<int> const, result<bool> >();
|
||||
|
||||
BOOST_TEST_TRAIT_FALSE((std::is_constructible<result<bool>, result<X>&>));
|
||||
BOOST_TEST_TRAIT_FALSE((std::is_constructible<result<bool>, result<X> const&>));
|
||||
BOOST_TEST_TRAIT_FALSE((std::is_constructible<result<bool>, result<X>&&>));
|
||||
BOOST_TEST_TRAIT_FALSE((std::is_constructible<result<bool>, result<X> const&&>));
|
||||
|
||||
BOOST_TEST_TRAIT_FALSE((std::is_constructible<result<bool const>, result<X>&>));
|
||||
BOOST_TEST_TRAIT_FALSE((std::is_constructible<result<bool const>, result<X> const&>));
|
||||
BOOST_TEST_TRAIT_FALSE((std::is_constructible<result<bool const>, result<X>&&>));
|
||||
BOOST_TEST_TRAIT_FALSE((std::is_constructible<result<bool const>, result<X> const&&>));
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
57
test/std_interop_test16.cpp
Normal file
57
test/std_interop_test16.cpp
Normal file
@@ -0,0 +1,57 @@
|
||||
// Copyright 2023 Peter Dimov.
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// http://www.boost.org/LICENSE_1_0.txt
|
||||
|
||||
#include <boost/system/error_category.hpp>
|
||||
#include <boost/config/pragma_message.hpp>
|
||||
|
||||
#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 <boost/core/lightweight_test.hpp>
|
||||
#include <boost/core/snprintf.hpp>
|
||||
#include <system_error>
|
||||
|
||||
// get_user_category
|
||||
|
||||
class user_category: public boost::system::error_category
|
||||
{
|
||||
public:
|
||||
|
||||
virtual const char * name() const BOOST_NOEXCEPT
|
||||
{
|
||||
return "user";
|
||||
}
|
||||
|
||||
virtual std::string message( int ev ) const
|
||||
{
|
||||
char buffer[ 256 ];
|
||||
boost::core::snprintf( buffer, sizeof( buffer ), "user message %d", ev );
|
||||
|
||||
return buffer;
|
||||
}
|
||||
};
|
||||
|
||||
boost::system::error_category const & get_user_category()
|
||||
{
|
||||
static user_category instance;
|
||||
return instance;
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
bool init_lwt = (boost::core::lwt_init(), true);
|
||||
|
||||
std::error_category const & cat = get_user_category();
|
||||
|
||||
int main()
|
||||
{
|
||||
BOOST_TEST_CSTR_EQ( cat.name(), "user" );
|
||||
return boost::report_errors();
|
||||
}
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user