mirror of
https://github.com/boostorg/system.git
synced 2026-06-11 19:51:11 +02:00
Compare commits
20 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| e6595f0d64 | |||
| 48cc883bd3 | |||
| a66df030ae | |||
| 04ac86837c | |||
| 080b4e9961 | |||
| 571076780e | |||
| f80b9ccbf1 | |||
| 2db6b8e595 | |||
| 026862285e | |||
| f7408130d0 | |||
| 59b11b120d | |||
| 8ce9b50730 | |||
| 700f246dd3 | |||
| 78149b00c6 | |||
| 9c1c586a32 | |||
| d9248a93ab | |||
| fa3babf4e6 | |||
| 739179a494 | |||
| ee43711c1c | |||
| af53bce037 |
+54
-33
@@ -239,19 +239,26 @@ local windows_pipeline(name, image, environment, arch = "amd64") =
|
||||
),
|
||||
|
||||
linux_pipeline(
|
||||
"Linux 25.04 GCC 15 UBSAN",
|
||||
"cppalliance/droneubuntu2504:1",
|
||||
"Linux 26.04 GCC 15 UBSAN",
|
||||
"cppalliance/droneubuntu2604:1",
|
||||
{ TOOLSET: 'gcc', COMPILER: 'g++-15', CXXSTD: '11,14,17,20,23,2c' } + ubsan,
|
||||
"g++-15-multilib",
|
||||
),
|
||||
|
||||
linux_pipeline(
|
||||
"Linux 25.04 GCC 15 ASAN",
|
||||
"cppalliance/droneubuntu2504:1",
|
||||
"Linux 26.04 GCC 15 ASAN",
|
||||
"cppalliance/droneubuntu2604:1",
|
||||
{ TOOLSET: 'gcc', COMPILER: 'g++-15', CXXSTD: '11,14,17,20,23,2c' } + asan,
|
||||
"g++-15-multilib",
|
||||
),
|
||||
|
||||
linux_pipeline(
|
||||
"Linux 26.04 GCC 16",
|
||||
"cppalliance/droneubuntu2604:1",
|
||||
{ TOOLSET: 'gcc', COMPILER: 'g++-16', CXXSTD: '11,14,17,20,23,2c' },
|
||||
"g++-16-multilib",
|
||||
),
|
||||
|
||||
linux_pipeline(
|
||||
"Linux 16.04 Clang 3.5",
|
||||
"cppalliance/droneubuntu1604:1",
|
||||
@@ -280,6 +287,27 @@ local windows_pipeline(name, image, environment, arch = "amd64") =
|
||||
"clang-3.8",
|
||||
),
|
||||
|
||||
linux_pipeline(
|
||||
"Linux 18.04 Clang 3.9",
|
||||
"cppalliance/droneubuntu1804:1",
|
||||
{ TOOLSET: 'clang', COMPILER: 'clang++-3.9', CXXSTD: '11,14' },
|
||||
"clang-3.9",
|
||||
),
|
||||
|
||||
linux_pipeline(
|
||||
"Linux 18.04 Clang 4.0",
|
||||
"cppalliance/droneubuntu1804:1",
|
||||
{ TOOLSET: 'clang', COMPILER: 'clang++-4.0', CXXSTD: '11,14' },
|
||||
"clang-4.0",
|
||||
),
|
||||
|
||||
linux_pipeline(
|
||||
"Linux 18.04 Clang 5.0",
|
||||
"cppalliance/droneubuntu1804:1",
|
||||
{ TOOLSET: 'clang', COMPILER: 'clang++-5.0', CXXSTD: '11,14' },
|
||||
"clang-5.0",
|
||||
),
|
||||
|
||||
linux_pipeline(
|
||||
"Linux 22.04 Clang 13",
|
||||
"cppalliance/droneubuntu2204:1",
|
||||
@@ -316,54 +344,47 @@ local windows_pipeline(name, image, environment, arch = "amd64") =
|
||||
),
|
||||
|
||||
linux_pipeline(
|
||||
"Linux 24.04 Clang 18 UBSAN",
|
||||
"Linux 24.04 Clang 18",
|
||||
"cppalliance/droneubuntu2404:1",
|
||||
{ TOOLSET: 'clang', COMPILER: 'clang++-18', CXXSTD: '11,14,17,20,2b' } + ubsan,
|
||||
{ TOOLSET: 'clang', COMPILER: 'clang++-18', CXXSTD: '11,14,17,20,2b' },
|
||||
"clang-18",
|
||||
),
|
||||
|
||||
linux_pipeline(
|
||||
"Linux 24.04 Clang 18 ASAN",
|
||||
"Linux 24.04 Clang 19",
|
||||
"cppalliance/droneubuntu2404:1",
|
||||
{ TOOLSET: 'clang', COMPILER: 'clang++-18', CXXSTD: '11,14,17,20,2b' } + asan,
|
||||
"clang-18",
|
||||
),
|
||||
|
||||
linux_pipeline(
|
||||
"Linux 24.04 Clang 19 UBSAN",
|
||||
"cppalliance/droneubuntu2404:1",
|
||||
{ TOOLSET: 'clang', COMPILER: 'clang++-19', CXXSTD: '11,14,17,20,2b' } + ubsan,
|
||||
{ TOOLSET: 'clang', COMPILER: 'clang++-19', CXXSTD: '11,14,17,20,2b' },
|
||||
"clang-19",
|
||||
),
|
||||
|
||||
linux_pipeline(
|
||||
"Linux 24.04 Clang 19 ASAN",
|
||||
"Linux 24.04 Clang 20",
|
||||
"cppalliance/droneubuntu2404:1",
|
||||
{ TOOLSET: 'clang', COMPILER: 'clang++-19', CXXSTD: '11,14,17,20,2b' } + asan,
|
||||
"clang-19",
|
||||
),
|
||||
|
||||
linux_pipeline(
|
||||
"Linux 24.04 Clang 20 UBSAN",
|
||||
"cppalliance/droneubuntu2404:1",
|
||||
{ TOOLSET: 'clang', COMPILER: 'clang++-20', CXXSTD: '11,14,17,20,23,2c' } + ubsan,
|
||||
{ TOOLSET: 'clang', COMPILER: 'clang++-20', CXXSTD: '11,14,17,20,23,2c' },
|
||||
"clang-20",
|
||||
),
|
||||
|
||||
linux_pipeline(
|
||||
"Linux 24.04 Clang 20 ASAN",
|
||||
"cppalliance/droneubuntu2404:1",
|
||||
{ TOOLSET: 'clang', COMPILER: 'clang++-20', CXXSTD: '11,14,17,20,23,2c' } + asan,
|
||||
"clang-20",
|
||||
),
|
||||
|
||||
linux_pipeline(
|
||||
"Linux 25.10 Clang 21",
|
||||
"cppalliance/droneubuntu2510:1",
|
||||
"Linux 26.04 Clang 21",
|
||||
"cppalliance/droneubuntu2604:1",
|
||||
{ TOOLSET: 'clang', COMPILER: 'clang++-21', CXXSTD: '11,14,17,20,23,2c' },
|
||||
"clang-21",
|
||||
),
|
||||
|
||||
linux_pipeline(
|
||||
"Linux 26.04 Clang 22 UBSAN",
|
||||
"cppalliance/droneubuntu2604:1",
|
||||
{ TOOLSET: 'clang', COMPILER: 'clang++-22', CXXSTD: '11,14,17,20,23,2c' } + ubsan,
|
||||
"clang-22",
|
||||
),
|
||||
|
||||
linux_pipeline(
|
||||
"Linux 26.04 Clang 22 ASAN",
|
||||
"cppalliance/droneubuntu2604:1",
|
||||
{ TOOLSET: 'clang', COMPILER: 'clang++-22', CXXSTD: '11,14,17,20,23,2c' } + asan,
|
||||
"clang-22",
|
||||
),
|
||||
|
||||
macos_pipeline(
|
||||
"MacOS 10.15 Xcode 12.2 UBSAN",
|
||||
{ TOOLSET: 'clang', COMPILER: 'clang++', CXXSTD: '11,14,1z' } + ubsan,
|
||||
|
||||
+140
-60
@@ -17,25 +17,11 @@ jobs:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
include:
|
||||
- toolset: gcc-4.8
|
||||
cxxstd: "11"
|
||||
container: ubuntu:18.04
|
||||
os: ubuntu-latest
|
||||
install: g++-4.8
|
||||
- toolset: gcc-5
|
||||
cxxstd: "11,14,1z"
|
||||
container: ubuntu:18.04
|
||||
os: ubuntu-latest
|
||||
install: g++-5
|
||||
- toolset: gcc-6
|
||||
cxxstd: "11,14,1z"
|
||||
container: ubuntu:18.04
|
||||
os: ubuntu-latest
|
||||
install: g++-6
|
||||
- toolset: gcc-7
|
||||
cxxstd: "11,14,17"
|
||||
container: ubuntu:18.04
|
||||
container: ubuntu:20.04
|
||||
os: ubuntu-latest
|
||||
install: g++-7
|
||||
- toolset: gcc-8
|
||||
cxxstd: "11,14,17,2a"
|
||||
container: ubuntu:20.04
|
||||
@@ -52,10 +38,12 @@ jobs:
|
||||
install: g++-10
|
||||
- toolset: gcc-11
|
||||
cxxstd: "11,14,17,2a"
|
||||
os: ubuntu-22.04
|
||||
container: ubuntu:22.04
|
||||
os: ubuntu-latest
|
||||
- toolset: gcc-12
|
||||
cxxstd: "11,14,17,20,2b"
|
||||
os: ubuntu-22.04
|
||||
container: ubuntu:22.04
|
||||
os: ubuntu-latest
|
||||
install: g++-12
|
||||
- toolset: gcc-13
|
||||
cxxstd: "11,14,17,20,2b"
|
||||
@@ -69,27 +57,14 @@ jobs:
|
||||
install: g++-14
|
||||
- toolset: gcc-15
|
||||
cxxstd: "11,14,17,20,23,2c"
|
||||
container: ubuntu:25.04
|
||||
container: ubuntu:26.04
|
||||
os: ubuntu-latest
|
||||
install: g++-15
|
||||
- toolset: clang
|
||||
compiler: clang++-3.9
|
||||
cxxstd: "11,14"
|
||||
container: ubuntu:18.04
|
||||
- toolset: gcc-16
|
||||
cxxstd: "11,14,17,20,23,2c"
|
||||
container: ubuntu:26.04
|
||||
os: ubuntu-latest
|
||||
install: clang-3.9
|
||||
- toolset: clang
|
||||
compiler: clang++-4.0
|
||||
cxxstd: "11,14"
|
||||
container: ubuntu:18.04
|
||||
os: ubuntu-latest
|
||||
install: clang-4.0
|
||||
- toolset: clang
|
||||
compiler: clang++-5.0
|
||||
cxxstd: "11,14,1z"
|
||||
container: ubuntu:18.04
|
||||
os: ubuntu-latest
|
||||
install: clang-5.0
|
||||
install: g++-16
|
||||
- toolset: clang
|
||||
compiler: clang++-6.0
|
||||
cxxstd: "11,14,17"
|
||||
@@ -198,9 +173,16 @@ jobs:
|
||||
compiler: clang++-21
|
||||
cxxstd: "11,14,17,20,23,2c"
|
||||
stdlib: "native,libc++"
|
||||
container: ubuntu:25.10
|
||||
container: ubuntu:26.04
|
||||
os: ubuntu-latest
|
||||
install: clang-21 libc++-21-dev libc++abi-21-dev
|
||||
- toolset: clang
|
||||
compiler: clang++-22
|
||||
cxxstd: "11,14,17,20,23,2c"
|
||||
stdlib: "native,libc++"
|
||||
container: ubuntu:26.04
|
||||
os: ubuntu-latest
|
||||
install: clang-22 libc++-22-dev libc++abi-22-dev
|
||||
- toolset: clang
|
||||
cxxstd: "11,14,17,20,2b"
|
||||
os: macos-14
|
||||
@@ -212,12 +194,7 @@ jobs:
|
||||
os: macos-26
|
||||
|
||||
runs-on: ${{matrix.os}}
|
||||
|
||||
container:
|
||||
image: ${{matrix.container}}
|
||||
volumes:
|
||||
- /node20217:/node20217:rw,rshared
|
||||
- ${{ startsWith(matrix.container, 'ubuntu:1') && '/node20217:/__e/node20:ro,rshared' || ' ' }}
|
||||
container: ${{matrix.container}}
|
||||
|
||||
defaults:
|
||||
run:
|
||||
@@ -230,14 +207,7 @@ jobs:
|
||||
apt-get update
|
||||
apt-get -y install sudo python3 git g++ curl xz-utils
|
||||
|
||||
- name: Install nodejs20glibc2.17
|
||||
if: ${{ startsWith( matrix.container, 'ubuntu:1' ) }}
|
||||
run: |
|
||||
curl -LO https://archives.boost.io/misc/node/node-v20.9.0-linux-x64-glibc-217.tar.xz
|
||||
tar -xf node-v20.9.0-linux-x64-glibc-217.tar.xz --strip-components 1 -C /node20217
|
||||
ldd /__e/node20/bin/node
|
||||
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions/checkout@v6
|
||||
|
||||
- name: Install packages
|
||||
if: matrix.install
|
||||
@@ -286,19 +256,23 @@ jobs:
|
||||
cxxstd: "14,17,20,latest"
|
||||
addrmd: 32,64
|
||||
os: windows-2022
|
||||
- toolset: msvc-14.5
|
||||
cxxstd: "14,17,20,latest"
|
||||
addrmd: 32,64
|
||||
os: windows-2025-vs2026
|
||||
- toolset: clang-win
|
||||
cxxstd: "14,17,20,latest"
|
||||
addrmd: 32,64
|
||||
os: windows-2022
|
||||
os: windows-latest
|
||||
- toolset: gcc
|
||||
cxxstd: "11,14,17,2a"
|
||||
addrmd: 64
|
||||
os: windows-2022
|
||||
os: windows-latest
|
||||
|
||||
runs-on: ${{matrix.os}}
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions/checkout@v6
|
||||
|
||||
- name: Setup Boost
|
||||
shell: cmd
|
||||
@@ -339,7 +313,7 @@ jobs:
|
||||
runs-on: ${{matrix.os}}
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions/checkout@v6
|
||||
|
||||
- name: Install packages
|
||||
if: matrix.install
|
||||
@@ -384,7 +358,7 @@ jobs:
|
||||
runs-on: ${{matrix.os}}
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions/checkout@v6
|
||||
|
||||
- name: Install packages
|
||||
if: matrix.install
|
||||
@@ -439,7 +413,7 @@ jobs:
|
||||
runs-on: ${{matrix.os}}
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions/checkout@v6
|
||||
|
||||
- name: Install packages
|
||||
if: matrix.install
|
||||
@@ -481,6 +455,57 @@ jobs:
|
||||
cd ../boost-root/__build__
|
||||
ctest --output-on-failure --no-tests=error
|
||||
|
||||
posix-cmake-use:
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
include:
|
||||
- os: ubuntu-latest
|
||||
- os: macos-latest
|
||||
|
||||
runs-on: ${{matrix.os}}
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v6
|
||||
|
||||
- name: Install packages
|
||||
if: matrix.install
|
||||
run: sudo apt-get -y install ${{matrix.install}}
|
||||
|
||||
- name: Setup Boost
|
||||
run: |
|
||||
echo GITHUB_REPOSITORY: $GITHUB_REPOSITORY
|
||||
LIBRARY=${GITHUB_REPOSITORY#*/}
|
||||
echo LIBRARY: $LIBRARY
|
||||
echo "LIBRARY=$LIBRARY" >> $GITHUB_ENV
|
||||
echo GITHUB_BASE_REF: $GITHUB_BASE_REF
|
||||
echo GITHUB_REF: $GITHUB_REF
|
||||
REF=${GITHUB_BASE_REF:-$GITHUB_REF}
|
||||
REF=${REF#refs/heads/}
|
||||
echo REF: $REF
|
||||
BOOST_BRANCH=develop && [ "$REF" == "master" ] && BOOST_BRANCH=master || true
|
||||
echo BOOST_BRANCH: $BOOST_BRANCH
|
||||
cd ..
|
||||
git clone -b $BOOST_BRANCH --depth 1 https://github.com/boostorg/boost.git boost-root
|
||||
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
|
||||
./bootstrap.sh
|
||||
./b2 -d0 headers
|
||||
|
||||
- name: Install Boost --with-library
|
||||
run: |
|
||||
cd ../boost-root
|
||||
./b2 -j3 --with-$LIBRARY --prefix=$HOME/.local install
|
||||
|
||||
- name: Use the installed library
|
||||
run: |
|
||||
cd ../boost-root/libs/$LIBRARY/test/cmake_install_test && mkdir __build__ && cd __build__
|
||||
cmake -DCMAKE_INSTALL_PREFIX=~/.local ..
|
||||
cmake --build .
|
||||
ctest --output-on-failure --no-tests=error
|
||||
|
||||
windows-cmake-subdir:
|
||||
strategy:
|
||||
fail-fast: false
|
||||
@@ -491,7 +516,7 @@ jobs:
|
||||
runs-on: ${{matrix.os}}
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions/checkout@v6
|
||||
|
||||
- name: Setup Boost
|
||||
shell: cmd
|
||||
@@ -539,7 +564,7 @@ jobs:
|
||||
runs-on: ${{matrix.os}}
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions/checkout@v6
|
||||
|
||||
- name: Setup Boost
|
||||
shell: cmd
|
||||
@@ -605,7 +630,7 @@ jobs:
|
||||
runs-on: ${{matrix.os}}
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions/checkout@v6
|
||||
|
||||
- name: Setup Boost
|
||||
shell: cmd
|
||||
@@ -657,3 +682,58 @@ jobs:
|
||||
run: |
|
||||
cd ../boost-root/__build__
|
||||
ctest --output-on-failure --no-tests=error -C Release
|
||||
|
||||
windows-cmake-use:
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
include:
|
||||
- os: windows-latest
|
||||
|
||||
runs-on: ${{matrix.os}}
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v6
|
||||
|
||||
- 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%
|
||||
cmd /c bootstrap
|
||||
b2 -d0 headers
|
||||
|
||||
- name: Install Boost --with-library
|
||||
shell: cmd
|
||||
run: |
|
||||
cd ../boost-root
|
||||
b2 -j3 --with-%LIBRARY% install
|
||||
|
||||
- name: Use the installed library (Debug)
|
||||
shell: cmd
|
||||
run: |
|
||||
cd ../boost-root/libs/%LIBRARY%/test/cmake_install_test && mkdir __build__ && cd __build__
|
||||
cmake -DBoost_ROOT=C:/Boost ..
|
||||
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
|
||||
|
||||
@@ -19,6 +19,7 @@ https://www.boost.org/LICENSE_1_0.txt
|
||||
* Added `unsafe_value` to `result`.
|
||||
* Changed `result<>::operator*` and `result<>::operator\->` to throw when `!has_value()`,
|
||||
instead of having that as a precondition. The old behavior is now spelled `unsafe_value()`.
|
||||
* Added `boost/system/unwrap_and_invoke.hpp`.
|
||||
|
||||
## Changes in Boost 1.89
|
||||
|
||||
|
||||
@@ -2911,6 +2911,82 @@ Returns: :: `r`.
|
||||
Remarks: ::
|
||||
Only enabled when `R` is an instance of `result<void, E2>` and `E2` is convertible to `E`.
|
||||
|
||||
## <boost/system/{zwsp}unwrap_and_invoke.hpp>
|
||||
|
||||
```
|
||||
namespace boost {
|
||||
namespace system {
|
||||
|
||||
template<class F, class... A>
|
||||
auto unwrap_and_invoke( F&& f, A&&... a ) -> result</*...*/>;
|
||||
|
||||
template<class T, class... A>
|
||||
auto unwrap_and_construct( A&&... a ) -> /*...*/;
|
||||
|
||||
} // namespace system
|
||||
} // namespace boost
|
||||
```
|
||||
|
||||
### unwrap_and_invoke
|
||||
|
||||
```
|
||||
template<class F, class... A>
|
||||
auto unwrap_and_invoke( F&& f, A&&... a ) -> result</*...*/>;
|
||||
```
|
||||
[none]
|
||||
* {blank}
|
||||
+
|
||||
Mandates: ::
|
||||
At least one of the arguments in `a...` must be an instance of `result`.
|
||||
+
|
||||
All arguments in `a...` that are instances of `result` must have the same error type.
|
||||
+
|
||||
Effects: ::
|
||||
If `ai`, one of the arguments in `a...`, is an instance of `result` for which `has_error()` is `true`, returns `ai.error()`.
|
||||
+
|
||||
Otherwise, returns `f(b...)`, where `bi` is `*ai` if `ai` is an instance of `result`, `ai` otherwise.
|
||||
+
|
||||
Remarks: ::
|
||||
The return type is `result<R, E>`, where `R` is the type of the application of `f`, and `E` is the common error type of the arguments in `a...` that are instances of `result`.
|
||||
|
||||
|
||||
### unwrap_and_construct
|
||||
|
||||
```
|
||||
template<class T, class... A>
|
||||
auto unwrap_and_construct( A&&... a ) -> /*...*/;
|
||||
```
|
||||
[none]
|
||||
* {blank}
|
||||
+
|
||||
Like `unwrap_and_invoke`, but instead of a function object, invokes a constructor of the passed type `T`.
|
||||
+
|
||||
Returns: :: `unwrap_and_invoke(cf, a...)`, where `cf` is a function object such that `cf(args...)` returns `T{args...}` when `T` is an aggregate, `T(args...)` otherwise.
|
||||
+
|
||||
Example: ::
|
||||
+
|
||||
```
|
||||
struct JsonValue
|
||||
{
|
||||
result<JsonValue const&> at( std::string_view key ) const noexcept;
|
||||
};
|
||||
|
||||
result<int> int_from_json( JsonValue const& jv ) noexcept;
|
||||
|
||||
struct X
|
||||
{
|
||||
int a;
|
||||
int b;
|
||||
};
|
||||
|
||||
result<X> X_from_json( JsonValue const& jv ) noexcept
|
||||
{
|
||||
return unwrap_and_construct<X>(
|
||||
jv.at( "a" ) & int_from_json,
|
||||
jv.at( "b" ) & int_from_json );
|
||||
}
|
||||
```
|
||||
|
||||
## <boost/system.hpp>
|
||||
|
||||
This convenience header includes all the headers previously described.
|
||||
|
||||
@@ -10,5 +10,6 @@
|
||||
#include <boost/system/error_code.hpp>
|
||||
#include <boost/system/system_error.hpp>
|
||||
#include <boost/system/result.hpp>
|
||||
#include <boost/system/unwrap_and_invoke.hpp>
|
||||
|
||||
#endif // #ifndef BOOST_SYSTEM_HPP_INCLUDED
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
#ifndef BOOST_SYSTEM_DETAIL_IS_AGGREGATE_HPP_INCLUDED
|
||||
#define BOOST_SYSTEM_DETAIL_IS_AGGREGATE_HPP_INCLUDED
|
||||
|
||||
// Copyright 2026 Peter Dimov
|
||||
// Distributed under the Boost Software License, Version 1.0
|
||||
// https://www.boost.org/LICENSE_1_0.txt
|
||||
|
||||
#include <boost/config.hpp>
|
||||
#include <type_traits>
|
||||
|
||||
#if defined(__has_builtin)
|
||||
# if __has_builtin(__is_aggregate)
|
||||
# define BOOST_SYSTEM_HAS_BUILTIN_IS_AGGREGATE
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#if !defined(BOOST_SYSTEM_HAS_BUILTIN_IS_AGGREGATE) && defined(BOOST_CLANG_VERSION) && BOOST_CLANG_VERSION >= 50000
|
||||
# define BOOST_SYSTEM_HAS_BUILTIN_IS_AGGREGATE
|
||||
#endif
|
||||
|
||||
#if !defined(BOOST_SYSTEM_HAS_BUILTIN_IS_AGGREGATE) && defined(BOOST_GCC) && BOOST_GCC >= 70000
|
||||
# define BOOST_SYSTEM_HAS_BUILTIN_IS_AGGREGATE
|
||||
#endif
|
||||
|
||||
#if !defined(BOOST_SYSTEM_HAS_BUILTIN_IS_AGGREGATE) && defined(BOOST_MSVC) && BOOST_MSVC >= 1910
|
||||
# define BOOST_SYSTEM_HAS_BUILTIN_IS_AGGREGATE
|
||||
#endif
|
||||
|
||||
namespace boost
|
||||
{
|
||||
namespace system
|
||||
{
|
||||
namespace detail
|
||||
{
|
||||
|
||||
#if defined(BOOST_SYSTEM_HAS_BUILTIN_IS_AGGREGATE)
|
||||
|
||||
template<class T> struct is_aggregate: public std::integral_constant<bool, __is_aggregate(T)>
|
||||
{
|
||||
};
|
||||
|
||||
#elif defined(__cpp_lib_is_aggregate) && __cpp_lib_is_aggregate >= 201703L
|
||||
|
||||
template<class T> struct is_aggregate: public std::is_aggregate<T>
|
||||
{
|
||||
};
|
||||
|
||||
#else
|
||||
|
||||
template<class T> struct is_aggregate: public std::false_type
|
||||
{
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
} // namespace detail
|
||||
} // namespace system
|
||||
} // namespace boost
|
||||
|
||||
#endif // #ifndef BOOST_SYSTEM_DETAIL_IS_AGGREGATE_HPP_INCLUDED
|
||||
@@ -0,0 +1,124 @@
|
||||
#ifndef BOOST_SYSTEM_UNWRAP_AND_INVOKE_HPP_INCLUDED
|
||||
#define BOOST_SYSTEM_UNWRAP_AND_INVOKE_HPP_INCLUDED
|
||||
|
||||
// Copyright 2026 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/system/detail/is_aggregate.hpp>
|
||||
#include <boost/compat/type_traits.hpp>
|
||||
#include <boost/mp11/algorithm.hpp>
|
||||
#include <boost/mp11/utility.hpp>
|
||||
#include <type_traits>
|
||||
#include <utility>
|
||||
|
||||
namespace boost
|
||||
{
|
||||
namespace system
|
||||
{
|
||||
|
||||
// unwrap_and_invoke
|
||||
|
||||
namespace detail
|
||||
{
|
||||
|
||||
// get_error_type
|
||||
|
||||
template<class... T> using first_if_same =
|
||||
mp11::mp_if<mp11::mp_same<T...>, mp11::mp_first<mp11::mp_list<T...>>>;
|
||||
|
||||
template<class... A> using get_error_type =
|
||||
mp11::mp_apply<first_if_same,
|
||||
mp11::mp_transform<mp11::mp_second,
|
||||
mp11::mp_copy_if<mp11::mp_list<A...>, is_result>
|
||||
>
|
||||
>;
|
||||
|
||||
// invoke_unwrap
|
||||
|
||||
template< class T, class En = typename std::enable_if< !is_result< compat::remove_cvref_t<T> >::value >::type >
|
||||
auto invoke_unwrap( T&& t ) noexcept -> T&&
|
||||
{
|
||||
return std::forward<T>( t );
|
||||
}
|
||||
|
||||
template< class T, class = void, class En = typename std::enable_if< is_result< compat::remove_cvref_t<T> >::value >::type >
|
||||
auto invoke_unwrap( T&& t ) noexcept -> decltype( std::forward<T>( t ).unsafe_value() )
|
||||
{
|
||||
return std::forward<T>( t ).unsafe_value();
|
||||
}
|
||||
|
||||
// invoke_test
|
||||
|
||||
template<class R, class A> int invoke_test( R&, A const& )
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
template<class R, class T, class E> int invoke_test( R& r, result<T, E> const& r2 )
|
||||
{
|
||||
if( r && r2.has_error() ) r = r2.error();
|
||||
return 0;
|
||||
}
|
||||
|
||||
} // namespace detail
|
||||
|
||||
template<class F, class... A,
|
||||
class R = decltype( compat::invoke( std::declval<F>(), detail::invoke_unwrap( std::declval<A>() )... ) ),
|
||||
class E = detail::get_error_type<compat::remove_cvref_t<A>...>
|
||||
>
|
||||
auto unwrap_and_invoke( F&& f, A&&... a ) -> result<R, E>
|
||||
{
|
||||
{
|
||||
result<void, E> r;
|
||||
|
||||
using Q = int[];
|
||||
(void)Q{ detail::invoke_test( r, a )... };
|
||||
|
||||
if( !r ) return r.error();
|
||||
}
|
||||
|
||||
return compat::invoke( std::forward<F>(f), detail::invoke_unwrap( std::forward<A>(a) )... );
|
||||
}
|
||||
|
||||
// unwrap_and_construct
|
||||
|
||||
namespace detail
|
||||
{
|
||||
|
||||
template<class T> struct construct
|
||||
{
|
||||
private:
|
||||
|
||||
template<class... A> static inline T call_impl( std::false_type, A&&... a )
|
||||
{
|
||||
return T( std::forward<A>(a)... );
|
||||
}
|
||||
|
||||
template<class... A> static inline T call_impl( std::true_type, A&&... a )
|
||||
{
|
||||
return T{ std::forward<A>(a)... };
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
template<class... A> inline T operator()( A&&... a ) const
|
||||
{
|
||||
return this->call_impl( detail::is_aggregate<T>(), std::forward<A>(a)... );
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace detail
|
||||
|
||||
template<class T, class... A>
|
||||
auto unwrap_and_construct( A&&... a )
|
||||
-> decltype( unwrap_and_invoke( detail::construct<T>(), std::forward<A>(a)... ) )
|
||||
{
|
||||
return unwrap_and_invoke( detail::construct<T>(), std::forward<A>(a)... );
|
||||
}
|
||||
|
||||
} // namespace system
|
||||
} // namespace boost
|
||||
|
||||
#endif // #ifndef BOOST_SYSTEM_UNWRAP_AND_INVOKE_HPP_INCLUDED
|
||||
@@ -187,3 +187,11 @@ boost_test(TYPE compile SOURCES result_error_construct_cx2.cpp)
|
||||
|
||||
boost_test(TYPE run SOURCES result_unsafe_value_access.cpp)
|
||||
boost_test(TYPE run SOURCES result_unsafe_value_access2.cpp)
|
||||
|
||||
boost_test(TYPE run SOURCES unwrap_and_invoke.cpp)
|
||||
boost_test(TYPE run SOURCES unwrap_and_invoke2.cpp)
|
||||
|
||||
boost_test(TYPE run SOURCES unwrap_and_construct.cpp)
|
||||
boost_test(TYPE run SOURCES unwrap_and_construct2.cpp)
|
||||
|
||||
boost_test(TYPE run SOURCES detail_is_aggregate_test.cpp)
|
||||
|
||||
@@ -220,3 +220,11 @@ compile result_error_construct_cx2.cpp ;
|
||||
|
||||
run result_unsafe_value_access.cpp ;
|
||||
run result_unsafe_value_access2.cpp ;
|
||||
|
||||
run unwrap_and_invoke.cpp ;
|
||||
run unwrap_and_invoke2.cpp ;
|
||||
|
||||
run unwrap_and_construct.cpp ;
|
||||
run unwrap_and_construct2.cpp ;
|
||||
|
||||
run detail_is_aggregate_test.cpp ;
|
||||
|
||||
@@ -2,11 +2,11 @@
|
||||
# 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
|
||||
|
||||
cmake_minimum_required(VERSION 3.5...3.16)
|
||||
cmake_minimum_required(VERSION 3.5...3.31)
|
||||
|
||||
project(cmake_install_test LANGUAGES CXX)
|
||||
|
||||
find_package(boost_system REQUIRED)
|
||||
find_package(Boost COMPONENTS system REQUIRED)
|
||||
|
||||
add_executable(main main.cpp)
|
||||
target_link_libraries(main Boost::system)
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
// Copyright 2026 Peter Dimov
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// https://www.boost.org/LICENSE_1_0.txt
|
||||
|
||||
#include <boost/system/detail/is_aggregate.hpp>
|
||||
#include <boost/core/lightweight_test_trait.hpp>
|
||||
#include <boost/config/pragma_message.hpp>
|
||||
#include <string>
|
||||
|
||||
struct X1
|
||||
{
|
||||
};
|
||||
|
||||
struct X2
|
||||
{
|
||||
int a, b;
|
||||
};
|
||||
|
||||
struct X3
|
||||
{
|
||||
std::string a, b;
|
||||
};
|
||||
|
||||
struct X4
|
||||
{
|
||||
X1 x1;
|
||||
X2 x2;
|
||||
X3 x3;
|
||||
};
|
||||
|
||||
struct Y1
|
||||
{
|
||||
Y1() {}
|
||||
};
|
||||
|
||||
#if !defined(BOOST_SYSTEM_HAS_BUILTIN_IS_AGGREGATE) && !( defined(__cpp_lib_is_aggregate) && __cpp_lib_is_aggregate >= 201703L )
|
||||
|
||||
BOOST_PRAGMA_MESSAGE("Test skipped, detail::is_aggregate isn't functional")
|
||||
int main() {}
|
||||
|
||||
#else
|
||||
|
||||
int main()
|
||||
{
|
||||
using boost::system::detail::is_aggregate;
|
||||
|
||||
BOOST_TEST_TRAIT_TRUE((is_aggregate<X1>));
|
||||
BOOST_TEST_TRAIT_TRUE((is_aggregate<X2>));
|
||||
BOOST_TEST_TRAIT_TRUE((is_aggregate<X3>));
|
||||
BOOST_TEST_TRAIT_TRUE((is_aggregate<X4>));
|
||||
|
||||
BOOST_TEST_TRAIT_FALSE((is_aggregate<Y1>));
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -8,6 +8,10 @@
|
||||
|
||||
// See library home page at http://www.boost.org/libs/system
|
||||
|
||||
#if defined(__GNUC__) && __GNUC__ >= 16
|
||||
# pragma GCC diagnostic ignored "-Wformat-truncation"
|
||||
#endif
|
||||
|
||||
#include <boost/system/error_code.hpp>
|
||||
#include <boost/core/lightweight_test.hpp>
|
||||
#include <boost/core/snprintf.hpp>
|
||||
|
||||
@@ -8,6 +8,10 @@
|
||||
|
||||
// See library home page at http://www.boost.org/libs/system
|
||||
|
||||
#if defined(__GNUC__) && __GNUC__ >= 16
|
||||
# pragma GCC diagnostic ignored "-Wformat-truncation"
|
||||
#endif
|
||||
|
||||
#include <boost/system/error_category.hpp>
|
||||
#include <boost/core/lightweight_test.hpp>
|
||||
#include <boost/core/snprintf.hpp>
|
||||
|
||||
@@ -0,0 +1,109 @@
|
||||
// Copyright 2026 Peter Dimov
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// https://www.boost.org/LICENSE_1_0.txt
|
||||
|
||||
#include <boost/system/unwrap_and_invoke.hpp>
|
||||
#include <boost/system/result.hpp>
|
||||
#include <boost/core/lightweight_test_trait.hpp>
|
||||
|
||||
using namespace boost::system;
|
||||
|
||||
struct X
|
||||
{
|
||||
int v;
|
||||
};
|
||||
|
||||
struct Y
|
||||
{
|
||||
int v;
|
||||
|
||||
explicit Y( X a1 = {0}, X a2 = {0}, X a3 = {0}, X a4 = {0} ): v( a1.v + a2.v + a3.v + a4.v )
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
struct E
|
||||
{
|
||||
int w;
|
||||
};
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
auto r = unwrap_and_construct<Y>( result<X, E>( E{1} ) );
|
||||
BOOST_TEST( !r ) && BOOST_TEST_EQ( r.error().w, 1 );
|
||||
}
|
||||
|
||||
{
|
||||
auto r = unwrap_and_construct<Y>( result<X, E>( X{1} ) );
|
||||
BOOST_TEST( r ) && BOOST_TEST_EQ( r.unsafe_value().v, 1 );
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
{
|
||||
auto r = unwrap_and_construct<Y>( result<X, E>( E{1} ), result<X, E>( E{2} ) );
|
||||
BOOST_TEST( !r ) && BOOST_TEST_EQ( r.error().w, 1 );
|
||||
}
|
||||
|
||||
{
|
||||
auto r = unwrap_and_construct<Y>( result<X, E>( X{1} ), result<X, E>( E{2} ) );
|
||||
BOOST_TEST( !r ) && BOOST_TEST_EQ( r.error().w, 2 );
|
||||
}
|
||||
|
||||
{
|
||||
auto r = unwrap_and_construct<Y>( result<X, E>( X{1} ), result<X, E>( X{2} ) );
|
||||
BOOST_TEST( r ) && BOOST_TEST_EQ( r.unsafe_value().v, 3 );
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
{
|
||||
auto r = unwrap_and_construct<Y>( result<X, E>( E{1} ), result<X, E>( E{2} ), result<X, E>( E{3} ) );
|
||||
BOOST_TEST( !r ) && BOOST_TEST_EQ( r.error().w, 1 );
|
||||
}
|
||||
|
||||
{
|
||||
auto r = unwrap_and_construct<Y>( result<X, E>( X{1} ), result<X, E>( E{2} ), result<X, E>( E{3} ) );
|
||||
BOOST_TEST( !r ) && BOOST_TEST_EQ( r.error().w, 2 );
|
||||
}
|
||||
|
||||
{
|
||||
auto r = unwrap_and_construct<Y>( result<X, E>( X{1} ), result<X, E>( X{2} ), result<X, E>( E{3} ) );
|
||||
BOOST_TEST( !r ) && BOOST_TEST_EQ( r.error().w, 3 );
|
||||
}
|
||||
|
||||
{
|
||||
auto r = unwrap_and_construct<Y>( result<X, E>( X{1} ), result<X, E>( X{2} ), result<X, E>( X{3} ) );
|
||||
BOOST_TEST( r ) && BOOST_TEST_EQ( r.unsafe_value().v, 6 );
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
{
|
||||
auto r = unwrap_and_construct<Y>( result<X, E>( E{1} ), result<X, E>( E{2} ), result<X, E>( E{3} ), result<X, E>( E{4} ) );
|
||||
BOOST_TEST( !r ) && BOOST_TEST_EQ( r.error().w, 1 );
|
||||
}
|
||||
|
||||
{
|
||||
auto r = unwrap_and_construct<Y>( result<X, E>( X{1} ), result<X, E>( E{2} ), result<X, E>( E{3} ), result<X, E>( E{4} ) );
|
||||
BOOST_TEST( !r ) && BOOST_TEST_EQ( r.error().w, 2 );
|
||||
}
|
||||
|
||||
{
|
||||
auto r = unwrap_and_construct<Y>( result<X, E>( X{1} ), result<X, E>( X{2} ), result<X, E>( E{3} ), result<X, E>( E{4} ) );
|
||||
BOOST_TEST( !r ) && BOOST_TEST_EQ( r.error().w, 3 );
|
||||
}
|
||||
|
||||
{
|
||||
auto r = unwrap_and_construct<Y>( result<X, E>( X{1} ), result<X, E>( X{2} ), result<X, E>( X{3} ), result<X, E>( E{4} ) );
|
||||
BOOST_TEST( !r ) && BOOST_TEST_EQ( r.error().w, 4 );
|
||||
}
|
||||
|
||||
{
|
||||
auto r = unwrap_and_construct<Y>( result<X, E>( X{1} ), result<X, E>( X{2} ), result<X, E>( X{3} ), result<X, E>( X{4} ) );
|
||||
BOOST_TEST( r ) && BOOST_TEST_EQ( r.unsafe_value().v, 10 );
|
||||
}
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
@@ -0,0 +1,144 @@
|
||||
// Copyright 2026 Peter Dimov
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// https://www.boost.org/LICENSE_1_0.txt
|
||||
|
||||
#if defined(__GNUC__) || defined(__clang__)
|
||||
# pragma GCC diagnostic ignored "-Wmissing-field-initializers"
|
||||
#endif
|
||||
|
||||
#include <boost/system/unwrap_and_invoke.hpp>
|
||||
#include <boost/system/result.hpp>
|
||||
#include <boost/core/lightweight_test_trait.hpp>
|
||||
#include <boost/config/pragma_message.hpp>
|
||||
#include <boost/config.hpp>
|
||||
|
||||
struct X
|
||||
{
|
||||
int v;
|
||||
};
|
||||
|
||||
struct Y
|
||||
{
|
||||
X x1, x2, x3, x4;
|
||||
};
|
||||
|
||||
struct E
|
||||
{
|
||||
int w;
|
||||
};
|
||||
|
||||
#if !defined(BOOST_SYSTEM_HAS_BUILTIN_IS_AGGREGATE) && !( defined(__cpp_lib_is_aggregate) && __cpp_lib_is_aggregate >= 201703L )
|
||||
|
||||
BOOST_PRAGMA_MESSAGE("Test skipped, detail::is_aggregate isn't functional")
|
||||
int main() {}
|
||||
|
||||
#else
|
||||
|
||||
using namespace boost::system;
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
auto r = unwrap_and_construct<Y>( result<X, E>( E{1} ) );
|
||||
BOOST_TEST( !r ) && BOOST_TEST_EQ( r.error().w, 1 );
|
||||
}
|
||||
|
||||
{
|
||||
auto r = unwrap_and_construct<Y>( result<X, E>( X{1} ) );
|
||||
|
||||
BOOST_TEST( r )
|
||||
&& BOOST_TEST_EQ( r.unsafe_value().x1.v, 1 )
|
||||
&& BOOST_TEST_EQ( r.unsafe_value().x2.v, 0 )
|
||||
&& BOOST_TEST_EQ( r.unsafe_value().x3.v, 0 )
|
||||
&& BOOST_TEST_EQ( r.unsafe_value().x4.v, 0 )
|
||||
;
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
{
|
||||
auto r = unwrap_and_construct<Y>( result<X, E>( E{1} ), result<X, E>( E{2} ) );
|
||||
BOOST_TEST( !r ) && BOOST_TEST_EQ( r.error().w, 1 );
|
||||
}
|
||||
|
||||
{
|
||||
auto r = unwrap_and_construct<Y>( result<X, E>( X{1} ), result<X, E>( E{2} ) );
|
||||
BOOST_TEST( !r ) && BOOST_TEST_EQ( r.error().w, 2 );
|
||||
}
|
||||
|
||||
{
|
||||
auto r = unwrap_and_construct<Y>( result<X, E>( X{1} ), result<X, E>( X{2} ) );
|
||||
|
||||
BOOST_TEST( r )
|
||||
&& BOOST_TEST_EQ( r.unsafe_value().x1.v, 1 )
|
||||
&& BOOST_TEST_EQ( r.unsafe_value().x2.v, 2 )
|
||||
&& BOOST_TEST_EQ( r.unsafe_value().x3.v, 0 )
|
||||
&& BOOST_TEST_EQ( r.unsafe_value().x4.v, 0 )
|
||||
;
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
{
|
||||
auto r = unwrap_and_construct<Y>( result<X, E>( E{1} ), result<X, E>( E{2} ), result<X, E>( E{3} ) );
|
||||
BOOST_TEST( !r ) && BOOST_TEST_EQ( r.error().w, 1 );
|
||||
}
|
||||
|
||||
{
|
||||
auto r = unwrap_and_construct<Y>( result<X, E>( X{1} ), result<X, E>( E{2} ), result<X, E>( E{3} ) );
|
||||
BOOST_TEST( !r ) && BOOST_TEST_EQ( r.error().w, 2 );
|
||||
}
|
||||
|
||||
{
|
||||
auto r = unwrap_and_construct<Y>( result<X, E>( X{1} ), result<X, E>( X{2} ), result<X, E>( E{3} ) );
|
||||
BOOST_TEST( !r ) && BOOST_TEST_EQ( r.error().w, 3 );
|
||||
}
|
||||
|
||||
{
|
||||
auto r = unwrap_and_construct<Y>( result<X, E>( X{1} ), result<X, E>( X{2} ), result<X, E>( X{3} ) );
|
||||
|
||||
BOOST_TEST( r )
|
||||
&& BOOST_TEST_EQ( r.unsafe_value().x1.v, 1 )
|
||||
&& BOOST_TEST_EQ( r.unsafe_value().x2.v, 2 )
|
||||
&& BOOST_TEST_EQ( r.unsafe_value().x3.v, 3 )
|
||||
&& BOOST_TEST_EQ( r.unsafe_value().x4.v, 0 )
|
||||
;
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
{
|
||||
auto r = unwrap_and_construct<Y>( result<X, E>( E{1} ), result<X, E>( E{2} ), result<X, E>( E{3} ), result<X, E>( E{4} ) );
|
||||
BOOST_TEST( !r ) && BOOST_TEST_EQ( r.error().w, 1 );
|
||||
}
|
||||
|
||||
{
|
||||
auto r = unwrap_and_construct<Y>( result<X, E>( X{1} ), result<X, E>( E{2} ), result<X, E>( E{3} ), result<X, E>( E{4} ) );
|
||||
BOOST_TEST( !r ) && BOOST_TEST_EQ( r.error().w, 2 );
|
||||
}
|
||||
|
||||
{
|
||||
auto r = unwrap_and_construct<Y>( result<X, E>( X{1} ), result<X, E>( X{2} ), result<X, E>( E{3} ), result<X, E>( E{4} ) );
|
||||
BOOST_TEST( !r ) && BOOST_TEST_EQ( r.error().w, 3 );
|
||||
}
|
||||
|
||||
{
|
||||
auto r = unwrap_and_construct<Y>( result<X, E>( X{1} ), result<X, E>( X{2} ), result<X, E>( X{3} ), result<X, E>( E{4} ) );
|
||||
BOOST_TEST( !r ) && BOOST_TEST_EQ( r.error().w, 4 );
|
||||
}
|
||||
|
||||
{
|
||||
auto r = unwrap_and_construct<Y>( result<X, E>( X{1} ), result<X, E>( X{2} ), result<X, E>( X{3} ), result<X, E>( X{4} ) );
|
||||
|
||||
BOOST_TEST( r )
|
||||
&& BOOST_TEST_EQ( r.unsafe_value().x1.v, 1 )
|
||||
&& BOOST_TEST_EQ( r.unsafe_value().x2.v, 2 )
|
||||
&& BOOST_TEST_EQ( r.unsafe_value().x3.v, 3 )
|
||||
&& BOOST_TEST_EQ( r.unsafe_value().x4.v, 4 )
|
||||
;
|
||||
}
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,254 @@
|
||||
// Copyright 2026 Peter Dimov
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// https://www.boost.org/LICENSE_1_0.txt
|
||||
|
||||
#include <boost/system/unwrap_and_invoke.hpp>
|
||||
#include <boost/system/result.hpp>
|
||||
#include <boost/core/lightweight_test_trait.hpp>
|
||||
#include <memory>
|
||||
|
||||
using namespace boost::system;
|
||||
|
||||
int f( int x, int y )
|
||||
{
|
||||
return x + y;
|
||||
}
|
||||
|
||||
struct X
|
||||
{
|
||||
int x_ = 0;
|
||||
|
||||
explicit X( int x ): x_( x )
|
||||
{
|
||||
}
|
||||
|
||||
int f( int y ) const
|
||||
{
|
||||
return x_ + y;
|
||||
}
|
||||
|
||||
int g( std::unique_ptr<X> p ) const
|
||||
{
|
||||
return x_ + p->x_;
|
||||
}
|
||||
};
|
||||
|
||||
template<class T, class... A> std::unique_ptr<T> make_unique( A&&... a )
|
||||
{
|
||||
return std::unique_ptr<T>( new T( std::forward<A>(a)... ) );
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
result<int> a1( 1 );
|
||||
|
||||
auto r = unwrap_and_invoke( f, a1, 2 );
|
||||
BOOST_TEST( r ) && BOOST_TEST_EQ( *r, 3 );
|
||||
}
|
||||
|
||||
{
|
||||
result<int> const a1( 1 );
|
||||
|
||||
auto r = unwrap_and_invoke( f, a1, 2 );
|
||||
BOOST_TEST( r ) && BOOST_TEST_EQ( *r, 3 );
|
||||
}
|
||||
|
||||
{
|
||||
result<int const> a1( 1 );
|
||||
|
||||
auto r = unwrap_and_invoke( f, a1, 2 );
|
||||
BOOST_TEST( r ) && BOOST_TEST_EQ( *r, 3 );
|
||||
}
|
||||
|
||||
{
|
||||
auto r = unwrap_and_invoke( f, result<int>( 1 ), 2 );
|
||||
BOOST_TEST( r ) && BOOST_TEST_EQ( *r, 3 );
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
{
|
||||
result<int> a2( 2 );
|
||||
|
||||
auto r = unwrap_and_invoke( f, 1, a2 );
|
||||
BOOST_TEST( r ) && BOOST_TEST_EQ( *r, 3 );
|
||||
}
|
||||
|
||||
{
|
||||
result<int> const a2( 2 );
|
||||
|
||||
auto r = unwrap_and_invoke( f, 1, a2 );
|
||||
BOOST_TEST( r ) && BOOST_TEST_EQ( *r, 3 );
|
||||
}
|
||||
|
||||
{
|
||||
result<int const> a2( 2 );
|
||||
|
||||
auto r = unwrap_and_invoke( f, 1, a2 );
|
||||
BOOST_TEST( r ) && BOOST_TEST_EQ( *r, 3 );
|
||||
}
|
||||
|
||||
{
|
||||
auto r = unwrap_and_invoke( f, 1, result<int>( 2 ) );
|
||||
BOOST_TEST( r ) && BOOST_TEST_EQ( *r, 3 );
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
{
|
||||
result<int> a1( 1 );
|
||||
result<int> const a2( 2 );
|
||||
|
||||
auto r = unwrap_and_invoke( f, a1, a2 );
|
||||
BOOST_TEST( r ) && BOOST_TEST_EQ( *r, 3 );
|
||||
}
|
||||
|
||||
{
|
||||
result<int const> a1( 1 );
|
||||
|
||||
auto r = unwrap_and_invoke( f, a1, result<int>( 2 ) );
|
||||
BOOST_TEST( r ) && BOOST_TEST_EQ( *r, 3 );
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
{
|
||||
auto ec = make_error_code( errc::invalid_argument );
|
||||
|
||||
result<int> a1( ec );
|
||||
|
||||
auto r = unwrap_and_invoke( f, a1, 2 );
|
||||
BOOST_TEST( r.has_error() ) && BOOST_TEST_EQ( r.error(), ec );
|
||||
}
|
||||
|
||||
{
|
||||
auto ec = make_error_code( errc::invalid_argument );
|
||||
|
||||
result<int> const a1( ec );
|
||||
|
||||
auto r = unwrap_and_invoke( f, a1, 2 );
|
||||
BOOST_TEST( r.has_error() ) && BOOST_TEST_EQ( r.error(), ec );
|
||||
}
|
||||
|
||||
{
|
||||
auto ec = make_error_code( errc::invalid_argument );
|
||||
|
||||
result<int const> a1( ec );
|
||||
|
||||
auto r = unwrap_and_invoke( f, a1, 2 );
|
||||
BOOST_TEST( r.has_error() ) && BOOST_TEST_EQ( r.error(), ec );
|
||||
}
|
||||
|
||||
{
|
||||
auto ec = make_error_code( errc::invalid_argument );
|
||||
|
||||
auto r = unwrap_and_invoke( f, result<int>( ec ), 2 );
|
||||
BOOST_TEST( r.has_error() ) && BOOST_TEST_EQ( r.error(), ec );
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
{
|
||||
auto ec = make_error_code( errc::invalid_argument );
|
||||
|
||||
result<int> a2( ec );
|
||||
|
||||
auto r = unwrap_and_invoke( f, 1, a2 );
|
||||
BOOST_TEST( r.has_error() ) && BOOST_TEST_EQ( r.error(), ec );
|
||||
}
|
||||
|
||||
{
|
||||
auto ec = make_error_code( errc::invalid_argument );
|
||||
|
||||
result<int> const a2( ec );
|
||||
|
||||
auto r = unwrap_and_invoke( f, 1, a2 );
|
||||
BOOST_TEST( r.has_error() ) && BOOST_TEST_EQ( r.error(), ec );
|
||||
}
|
||||
|
||||
{
|
||||
auto ec = make_error_code( errc::invalid_argument );
|
||||
|
||||
result<int const> a2( ec );
|
||||
|
||||
auto r = unwrap_and_invoke( f, 1, a2 );
|
||||
BOOST_TEST( r.has_error() ) && BOOST_TEST_EQ( r.error(), ec );
|
||||
}
|
||||
|
||||
{
|
||||
auto ec = make_error_code( errc::invalid_argument );
|
||||
|
||||
auto r = unwrap_and_invoke( f, 1, result<int>( ec ) );
|
||||
BOOST_TEST( r.has_error() ) && BOOST_TEST_EQ( r.error(), ec );
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
{
|
||||
auto ec = make_error_code( errc::invalid_argument );
|
||||
|
||||
result<int> a1( ec );
|
||||
result<int> const a2( 2 );
|
||||
|
||||
auto r = unwrap_and_invoke( f, a1, a2 );
|
||||
BOOST_TEST( r.has_error() ) && BOOST_TEST_EQ( r.error(), ec );
|
||||
}
|
||||
|
||||
{
|
||||
auto ec = make_error_code( errc::invalid_argument );
|
||||
|
||||
result<int> a1( 1 );
|
||||
result<int> const a2( ec );
|
||||
|
||||
auto r = unwrap_and_invoke( f, a1, a2 );
|
||||
BOOST_TEST( r.has_error() ) && BOOST_TEST_EQ( r.error(), ec );
|
||||
}
|
||||
|
||||
{
|
||||
auto ec = make_error_code( errc::invalid_argument );
|
||||
|
||||
result<int const> a1( ec );
|
||||
|
||||
auto r = unwrap_and_invoke( f, a1, result<int>( 2 ) );
|
||||
BOOST_TEST( r.has_error() ) && BOOST_TEST_EQ( r.error(), ec );
|
||||
}
|
||||
|
||||
{
|
||||
auto ec = make_error_code( errc::invalid_argument );
|
||||
|
||||
result<int const> a1( 1 );
|
||||
|
||||
auto r = unwrap_and_invoke( f, a1, result<int>( ec ) );
|
||||
BOOST_TEST( r.has_error() ) && BOOST_TEST_EQ( r.error(), ec );
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
{
|
||||
result<X> a1( X( 1 ) );
|
||||
result<int> const a2( 2 );
|
||||
|
||||
auto r = unwrap_and_invoke( &X::f, a1, a2 );
|
||||
BOOST_TEST( r ) && BOOST_TEST_EQ( *r, 3 );
|
||||
}
|
||||
|
||||
{
|
||||
result<X const> a1( X( 1 ) );
|
||||
|
||||
auto r = unwrap_and_invoke( &X::f, a1, result<int>( 2 ) );
|
||||
BOOST_TEST( r ) && BOOST_TEST_EQ( *r, 3 );
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
{
|
||||
result< std::unique_ptr<X> > a1( ::make_unique<X>( 1 ) );
|
||||
result< std::unique_ptr<X> > a2( ::make_unique<X>( 2 ) );
|
||||
|
||||
auto r = unwrap_and_invoke( &X::g, std::move( a1 ), std::move( a2 ) );
|
||||
BOOST_TEST( r ) && BOOST_TEST_EQ( *r, 3 );
|
||||
}
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
@@ -0,0 +1,120 @@
|
||||
// Copyright 2026 Peter Dimov
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// https://www.boost.org/LICENSE_1_0.txt
|
||||
|
||||
#include <boost/system/unwrap_and_invoke.hpp>
|
||||
#include <boost/system/result.hpp>
|
||||
#include <boost/core/lightweight_test_trait.hpp>
|
||||
|
||||
using namespace boost::system;
|
||||
|
||||
struct X
|
||||
{
|
||||
int v;
|
||||
};
|
||||
|
||||
struct E
|
||||
{
|
||||
int w;
|
||||
};
|
||||
|
||||
X f1( X x1 )
|
||||
{
|
||||
return x1;
|
||||
}
|
||||
|
||||
X f2( X x1, X x2 )
|
||||
{
|
||||
return X{ x1.v + x2.v };
|
||||
}
|
||||
|
||||
X f3( X x1, X x2, X x3 )
|
||||
{
|
||||
return X{ x1.v + x2.v + x3.v };
|
||||
}
|
||||
|
||||
X f4( X x1, X x2, X x3, X x4 )
|
||||
{
|
||||
return X{ x1.v + x2.v + x3.v + x4.v };
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
auto r = unwrap_and_invoke( f1, result<X, E>( E{1} ) );
|
||||
BOOST_TEST( !r ) && BOOST_TEST_EQ( r.error().w, 1 );
|
||||
}
|
||||
|
||||
{
|
||||
auto r = unwrap_and_invoke( f1, result<X, E>( X{1} ) );
|
||||
BOOST_TEST( r ) && BOOST_TEST_EQ( r.unsafe_value().v, 1 );
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
{
|
||||
auto r = unwrap_and_invoke( f2, result<X, E>( E{1} ), result<X, E>( E{2} ) );
|
||||
BOOST_TEST( !r ) && BOOST_TEST_EQ( r.error().w, 1 );
|
||||
}
|
||||
|
||||
{
|
||||
auto r = unwrap_and_invoke( f2, result<X, E>( X{1} ), result<X, E>( E{2} ) );
|
||||
BOOST_TEST( !r ) && BOOST_TEST_EQ( r.error().w, 2 );
|
||||
}
|
||||
|
||||
{
|
||||
auto r = unwrap_and_invoke( f2, result<X, E>( X{1} ), result<X, E>( X{2} ) );
|
||||
BOOST_TEST( r ) && BOOST_TEST_EQ( r.unsafe_value().v, 3 );
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
{
|
||||
auto r = unwrap_and_invoke( f3, result<X, E>( E{1} ), result<X, E>( E{2} ), result<X, E>( E{3} ) );
|
||||
BOOST_TEST( !r ) && BOOST_TEST_EQ( r.error().w, 1 );
|
||||
}
|
||||
|
||||
{
|
||||
auto r = unwrap_and_invoke( f3, result<X, E>( X{1} ), result<X, E>( E{2} ), result<X, E>( E{3} ) );
|
||||
BOOST_TEST( !r ) && BOOST_TEST_EQ( r.error().w, 2 );
|
||||
}
|
||||
|
||||
{
|
||||
auto r = unwrap_and_invoke( f3, result<X, E>( X{1} ), result<X, E>( X{2} ), result<X, E>( E{3} ) );
|
||||
BOOST_TEST( !r ) && BOOST_TEST_EQ( r.error().w, 3 );
|
||||
}
|
||||
|
||||
{
|
||||
auto r = unwrap_and_invoke( f3, result<X, E>( X{1} ), result<X, E>( X{2} ), result<X, E>( X{3} ) );
|
||||
BOOST_TEST( r ) && BOOST_TEST_EQ( r.unsafe_value().v, 6 );
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
{
|
||||
auto r = unwrap_and_invoke( f4, result<X, E>( E{1} ), result<X, E>( E{2} ), result<X, E>( E{3} ), result<X, E>( E{4} ) );
|
||||
BOOST_TEST( !r ) && BOOST_TEST_EQ( r.error().w, 1 );
|
||||
}
|
||||
|
||||
{
|
||||
auto r = unwrap_and_invoke( f4, result<X, E>( X{1} ), result<X, E>( E{2} ), result<X, E>( E{3} ), result<X, E>( E{4} ) );
|
||||
BOOST_TEST( !r ) && BOOST_TEST_EQ( r.error().w, 2 );
|
||||
}
|
||||
|
||||
{
|
||||
auto r = unwrap_and_invoke( f4, result<X, E>( X{1} ), result<X, E>( X{2} ), result<X, E>( E{3} ), result<X, E>( E{4} ) );
|
||||
BOOST_TEST( !r ) && BOOST_TEST_EQ( r.error().w, 3 );
|
||||
}
|
||||
|
||||
{
|
||||
auto r = unwrap_and_invoke( f4, result<X, E>( X{1} ), result<X, E>( X{2} ), result<X, E>( X{3} ), result<X, E>( E{4} ) );
|
||||
BOOST_TEST( !r ) && BOOST_TEST_EQ( r.error().w, 4 );
|
||||
}
|
||||
|
||||
{
|
||||
auto r = unwrap_and_invoke( f4, result<X, E>( X{1} ), result<X, E>( X{2} ), result<X, E>( X{3} ), result<X, E>( X{4} ) );
|
||||
BOOST_TEST( r ) && BOOST_TEST_EQ( r.unsafe_value().v, 10 );
|
||||
}
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
Reference in New Issue
Block a user