mirror of
https://github.com/boostorg/system.git
synced 2025-12-25 16:28:05 +01:00
Compare commits
221 Commits
feature/re
...
feature/re
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
951b3fe7b4 | ||
|
|
a57c568324 | ||
|
|
4843453528 | ||
|
|
2e7e46a802 | ||
|
|
32dbf1b992 | ||
|
|
707b24bfa1 | ||
|
|
bb1caae0d5 | ||
|
|
c5c49894e6 | ||
|
|
ee80491cab | ||
|
|
a83319fde1 | ||
|
|
4b90524729 | ||
|
|
6ac5f23999 | ||
|
|
f332a52597 | ||
|
|
c92d50abbd | ||
|
|
805b260a7a | ||
|
|
f32ffcba48 | ||
|
|
8ce2a9f835 | ||
|
|
6a58b03eab | ||
|
|
f0b27c5826 | ||
|
|
456b3c2dad | ||
|
|
eb3f3a8e41 | ||
|
|
e6986a51d5 | ||
|
|
fb648760b5 | ||
|
|
71ee26c188 | ||
|
|
8449c62162 | ||
|
|
4bca94ffc4 | ||
|
|
3e6af15652 | ||
|
|
86ff47ff63 | ||
|
|
06ddfdb4a6 | ||
|
|
bb60a27b18 | ||
|
|
e478ba1a2b | ||
|
|
50100b0e81 | ||
|
|
bb502f5d67 | ||
|
|
fa2349eee7 | ||
|
|
3d9acaf082 | ||
|
|
c6795eb9d0 | ||
|
|
57c295bbf7 | ||
|
|
36e3b2c6ae | ||
|
|
583cd8dba2 | ||
|
|
0c2de4cb2a | ||
|
|
3d595a6e79 | ||
|
|
b3faedfe3e | ||
|
|
32bf67f748 | ||
|
|
5d15aa1267 | ||
|
|
36e1236a0f | ||
|
|
2c20b6e7e5 | ||
|
|
103f3b4f00 | ||
|
|
14f779e234 | ||
|
|
bfccd4b4d9 | ||
|
|
7ae6b317f3 | ||
|
|
9a6d79b841 | ||
|
|
ece71199a9 | ||
|
|
1e4c050d6c | ||
|
|
21115121bb | ||
|
|
956fa92a53 | ||
|
|
ee318f937f | ||
|
|
19f99264de | ||
|
|
3261bae6de | ||
|
|
20ce51858b | ||
|
|
52d7429473 | ||
|
|
53c00841fc | ||
|
|
19e27a73e9 | ||
|
|
19020ce925 | ||
|
|
3faf415026 | ||
|
|
a2df4d09da | ||
|
|
455c6a6332 | ||
|
|
efb7634666 | ||
|
|
2bba3fd5e2 | ||
|
|
8c740705e6 | ||
|
|
4708d95e80 | ||
|
|
867f6d06d0 | ||
|
|
ac1ed1ecc1 | ||
|
|
fe48c3058d | ||
|
|
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 | ||
|
|
716c2ed8ef | ||
|
|
46a5ecd490 | ||
|
|
79f4ef0416 | ||
|
|
d0a8f7fbb7 | ||
|
|
bc07ab1e25 | ||
|
|
c6bff94709 | ||
|
|
ae079810be | ||
|
|
928de55563 | ||
|
|
442138de0a | ||
|
|
de610efd53 | ||
|
|
4b143cdacc | ||
|
|
a1cb578f52 | ||
|
|
96b5073b79 | ||
|
|
2bff5c7071 | ||
|
|
137128176d | ||
|
|
e0e0f56eae | ||
|
|
58d55a67e5 | ||
|
|
34dcb59ee8 | ||
|
|
33f6ecba31 | ||
|
|
23fbfb1ffa | ||
|
|
5366407135 | ||
|
|
72a79b1dcb | ||
|
|
a5c1ab042e | ||
|
|
c2beb75d66 | ||
|
|
54d9f4f38a | ||
|
|
b92be6417a | ||
|
|
245fff8af3 | ||
|
|
c359af3141 | ||
|
|
50cad72fac | ||
|
|
9554d8bbd3 | ||
|
|
cf9d986871 | ||
|
|
a5d68e52e6 | ||
|
|
9c6a09f41d | ||
|
|
b9c26b9fa0 | ||
|
|
2e2430c4fa | ||
|
|
4b1caad727 | ||
|
|
5b96abbaa8 | ||
|
|
2e1c800d82 | ||
|
|
04a79d710f | ||
|
|
5700936367 | ||
|
|
86b031cab9 | ||
|
|
204e65f725 | ||
|
|
01ce081470 | ||
|
|
8c9ceba775 | ||
|
|
91c0dd9a74 | ||
|
|
189fff42fe | ||
|
|
3b4045c149 | ||
|
|
3d877a1fca | ||
|
|
128bdf9db2 | ||
|
|
0e84860604 | ||
|
|
83a306f3bf | ||
|
|
7dce2e3f42 | ||
|
|
292c6825c6 | ||
|
|
0d90d3d883 | ||
|
|
81fec2b171 | ||
|
|
4e15afe5be | ||
|
|
8d1a866920 | ||
|
|
09466c85b4 | ||
|
|
baef8e50ea | ||
|
|
5034f11a3a | ||
|
|
f78b036665 | ||
|
|
9b0d735040 | ||
|
|
bfebaf53d7 | ||
|
|
8338e80295 | ||
|
|
2b23aaab16 | ||
|
|
7933300b6f | ||
|
|
4ec1e54099 | ||
|
|
5217e58a7d | ||
|
|
ce37e23491 | ||
|
|
420a262733 | ||
|
|
e15bccc09b | ||
|
|
bb775c071a | ||
|
|
01676ae42f | ||
|
|
eefcc5dcf6 | ||
|
|
f2d3a0decf | ||
|
|
0ccf08509b | ||
|
|
7a72aee355 | ||
|
|
a8df99e927 | ||
|
|
85c7d92302 | ||
|
|
4c201d26b2 | ||
|
|
1659dfbeba | ||
|
|
d2b8b54356 | ||
|
|
41f7ea49cb | ||
|
|
0b22dc595f | ||
|
|
aab58b0d5b | ||
|
|
ad66ea43a3 | ||
|
|
811564f186 | ||
|
|
a7e4879e55 | ||
|
|
9b11d864be | ||
|
|
cc6a61b6c5 | ||
|
|
9151633c95 | ||
|
|
5e0db22075 | ||
|
|
60a20eeeb9 | ||
|
|
1c8128e4cb | ||
|
|
1879ba6d35 | ||
|
|
b1dec88674 | ||
|
|
5fd2535d9f | ||
|
|
b39f239b3d | ||
|
|
abb13e707d | ||
|
|
bf34091cfe | ||
|
|
e3f198e52c | ||
|
|
05581aba03 | ||
|
|
47137ad116 | ||
|
|
c02cd2b004 | ||
|
|
c8c5ad1ce5 | ||
|
|
361834e49c | ||
|
|
360effcf1d | ||
|
|
aaa893b5d6 | ||
|
|
ff0bd3294f | ||
|
|
aedadc27ce | ||
|
|
aad1212cfd | ||
|
|
c15c2eeb74 | ||
|
|
0ea47dd886 | ||
|
|
a688d7834a |
319
.drone.jsonnet
Normal file
319
.drone.jsonnet
Normal file
@@ -0,0 +1,319 @@
|
||||
# Copyright 2022 Peter Dimov
|
||||
# Distributed under the Boost Software License, Version 1.0.
|
||||
# https://www.boost.org/LICENSE_1_0.txt
|
||||
|
||||
local library = "system";
|
||||
|
||||
local triggers =
|
||||
{
|
||||
branch: [ "master", "develop", "feature/*" ]
|
||||
};
|
||||
|
||||
local ubsan = { UBSAN: '1', UBSAN_OPTIONS: 'print_stacktrace=1' };
|
||||
local asan = { ASAN: '1' };
|
||||
|
||||
local linux_pipeline(name, image, environment, packages = "", sources = [], arch = "amd64") =
|
||||
{
|
||||
name: name,
|
||||
kind: "pipeline",
|
||||
type: "docker",
|
||||
trigger: triggers,
|
||||
platform:
|
||||
{
|
||||
os: "linux",
|
||||
arch: arch
|
||||
},
|
||||
steps:
|
||||
[
|
||||
{
|
||||
name: "everything",
|
||||
image: image,
|
||||
environment: environment,
|
||||
commands:
|
||||
[
|
||||
'set -e',
|
||||
'wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | apt-key add -',
|
||||
] +
|
||||
(if sources != [] then [ ('apt-add-repository "' + source + '"') for source in sources ] else []) +
|
||||
(if packages != "" then [ 'apt-get update', 'apt-get -y install ' + packages ] else []) +
|
||||
[
|
||||
'export LIBRARY=' + library,
|
||||
'./.drone/drone.sh',
|
||||
]
|
||||
}
|
||||
]
|
||||
};
|
||||
|
||||
local macos_pipeline(name, environment, xcode_version = "12.2", osx_version = "catalina", arch = "amd64") =
|
||||
{
|
||||
name: name,
|
||||
kind: "pipeline",
|
||||
type: "exec",
|
||||
trigger: triggers,
|
||||
platform: {
|
||||
"os": "darwin",
|
||||
"arch": arch
|
||||
},
|
||||
node: {
|
||||
"os": osx_version
|
||||
},
|
||||
steps: [
|
||||
{
|
||||
name: "everything",
|
||||
environment: environment + { "DEVELOPER_DIR": "/Applications/Xcode-" + xcode_version + ".app/Contents/Developer" },
|
||||
commands:
|
||||
[
|
||||
'export LIBRARY=' + library,
|
||||
'./.drone/drone.sh',
|
||||
]
|
||||
}
|
||||
]
|
||||
};
|
||||
|
||||
local windows_pipeline(name, image, environment, arch = "amd64") =
|
||||
{
|
||||
name: name,
|
||||
kind: "pipeline",
|
||||
type: "docker",
|
||||
trigger: triggers,
|
||||
platform:
|
||||
{
|
||||
os: "windows",
|
||||
arch: arch
|
||||
},
|
||||
"steps":
|
||||
[
|
||||
{
|
||||
name: "everything",
|
||||
image: image,
|
||||
environment: environment,
|
||||
commands:
|
||||
[
|
||||
'cmd /C .drone\\\\drone.bat ' + library,
|
||||
]
|
||||
}
|
||||
]
|
||||
};
|
||||
|
||||
[
|
||||
linux_pipeline(
|
||||
"Linux 14.04 GCC 4.4",
|
||||
"cppalliance/droneubuntu1404:1",
|
||||
{ TOOLSET: 'gcc', COMPILER: 'g++-4.4', CXXSTD: '98,0x' },
|
||||
"g++-4.4",
|
||||
[ "ppa:ubuntu-toolchain-r/test" ],
|
||||
),
|
||||
|
||||
linux_pipeline(
|
||||
"Linux 14.04 GCC 4.6",
|
||||
"cppalliance/droneubuntu1404:1",
|
||||
{ TOOLSET: 'gcc', COMPILER: 'g++-4.6', CXXSTD: '98,0x' },
|
||||
"g++-4.6",
|
||||
[ "ppa:ubuntu-toolchain-r/test" ],
|
||||
),
|
||||
|
||||
linux_pipeline(
|
||||
"Linux 14.04 GCC 4.7",
|
||||
"cppalliance/droneubuntu1404:1",
|
||||
{ TOOLSET: 'gcc', COMPILER: 'g++-4.7', CXXSTD: '98,0x' },
|
||||
"g++-4.7",
|
||||
[ "ppa:ubuntu-toolchain-r/test" ],
|
||||
),
|
||||
|
||||
linux_pipeline(
|
||||
"Linux 14.04 GCC 4.8*",
|
||||
"cppalliance/droneubuntu1404:1",
|
||||
{ TOOLSET: 'gcc', COMPILER: 'g++', CXXSTD: '03,11' },
|
||||
),
|
||||
|
||||
linux_pipeline(
|
||||
"Linux 14.04 GCC 4.9",
|
||||
"cppalliance/droneubuntu1404:1",
|
||||
{ TOOLSET: 'gcc', COMPILER: 'g++-4.9', CXXSTD: '03,11' },
|
||||
"g++-4.9",
|
||||
[ "ppa:ubuntu-toolchain-r/test" ],
|
||||
),
|
||||
|
||||
linux_pipeline(
|
||||
"Linux 16.04 GCC 5*",
|
||||
"cppalliance/droneubuntu1604:1",
|
||||
{ TOOLSET: 'gcc', COMPILER: 'g++', CXXSTD: '03,11,14' },
|
||||
),
|
||||
|
||||
linux_pipeline(
|
||||
"Linux 18.04 GCC 6",
|
||||
"cppalliance/droneubuntu1804:1",
|
||||
{ TOOLSET: 'gcc', COMPILER: 'g++-6', CXXSTD: '03,11,14' },
|
||||
"g++-6",
|
||||
),
|
||||
|
||||
linux_pipeline(
|
||||
"Linux 18.04 GCC 7* 32/64",
|
||||
"cppalliance/droneubuntu1804:1",
|
||||
{ TOOLSET: 'gcc', COMPILER: 'g++', CXXSTD: '03,11,14,17', ADDRMD: '32,64' },
|
||||
),
|
||||
|
||||
linux_pipeline(
|
||||
"Linux 18.04 GCC 8",
|
||||
"cppalliance/droneubuntu1804:1",
|
||||
{ TOOLSET: 'gcc', COMPILER: 'g++-8', CXXSTD: '03,11,14,17' },
|
||||
"g++-8",
|
||||
),
|
||||
|
||||
linux_pipeline(
|
||||
"Linux 20.04 GCC 9* 32",
|
||||
"cppalliance/droneubuntu2004:1",
|
||||
{ TOOLSET: 'gcc', COMPILER: 'g++', CXXSTD: '03,11,14,17,2a', ADDRMD: '32' },
|
||||
),
|
||||
|
||||
linux_pipeline(
|
||||
"Linux 20.04 GCC 9* 64",
|
||||
"cppalliance/droneubuntu2004:1",
|
||||
{ TOOLSET: 'gcc', COMPILER: 'g++', CXXSTD: '03,11,14,17,2a', ADDRMD: '64' },
|
||||
),
|
||||
|
||||
linux_pipeline(
|
||||
"Linux 20.04 GCC 9* ARM64",
|
||||
"cppalliance/droneubuntu2004:multiarch",
|
||||
{ TOOLSET: 'gcc', COMPILER: 'g++', CXXSTD: '03,11,14,17,2a' },
|
||||
arch="arm64",
|
||||
),
|
||||
|
||||
linux_pipeline(
|
||||
"Linux 20.04 GCC 9* S390x",
|
||||
"cppalliance/droneubuntu2004:multiarch",
|
||||
{ TOOLSET: 'gcc', COMPILER: 'g++', CXXSTD: '03,11,14,17,2a' },
|
||||
arch="s390x",
|
||||
),
|
||||
|
||||
linux_pipeline(
|
||||
"Linux 20.04 GCC 10 32",
|
||||
"cppalliance/droneubuntu2004:1",
|
||||
{ TOOLSET: 'gcc', COMPILER: 'g++-10', CXXSTD: '03,11,14,17,20', ADDRMD: '32' },
|
||||
"g++-10-multilib",
|
||||
),
|
||||
|
||||
linux_pipeline(
|
||||
"Linux 20.04 GCC 10 64",
|
||||
"cppalliance/droneubuntu2004:1",
|
||||
{ TOOLSET: 'gcc', COMPILER: 'g++-10', CXXSTD: '03,11,14,17,20', ADDRMD: '64' },
|
||||
"g++-10-multilib",
|
||||
),
|
||||
|
||||
linux_pipeline(
|
||||
"Linux 22.04 GCC 11* 32",
|
||||
"cppalliance/droneubuntu2204:1",
|
||||
{ TOOLSET: 'gcc', COMPILER: 'g++', CXXSTD: '03,11,14,17,2a', ADDRMD: '32' },
|
||||
),
|
||||
|
||||
linux_pipeline(
|
||||
"Linux 22.04 GCC 11* 64",
|
||||
"cppalliance/droneubuntu2204:1",
|
||||
{ TOOLSET: 'gcc', COMPILER: 'g++', CXXSTD: '03,11,14,17,2a', ADDRMD: '64' },
|
||||
),
|
||||
|
||||
linux_pipeline(
|
||||
"Linux 22.04 GCC 12 32 ASAN",
|
||||
"cppalliance/droneubuntu2204:1",
|
||||
{ TOOLSET: 'gcc', COMPILER: 'g++-12', CXXSTD: '03,11,14,17,20,2b', ADDRMD: '32' } + asan,
|
||||
"g++-12-multilib",
|
||||
),
|
||||
|
||||
linux_pipeline(
|
||||
"Linux 22.04 GCC 12 64 ASAN",
|
||||
"cppalliance/droneubuntu2204:1",
|
||||
{ TOOLSET: 'gcc', COMPILER: 'g++-12', CXXSTD: '03,11,14,17,20,2b', ADDRMD: '64' } + asan,
|
||||
"g++-12-multilib",
|
||||
),
|
||||
|
||||
linux_pipeline(
|
||||
"Linux 16.04 Clang 3.5",
|
||||
"cppalliance/droneubuntu1604:1",
|
||||
{ TOOLSET: 'clang', COMPILER: 'clang++-3.5', CXXSTD: '03,11' },
|
||||
"clang-3.5",
|
||||
),
|
||||
|
||||
linux_pipeline(
|
||||
"Linux 16.04 Clang 3.6",
|
||||
"cppalliance/droneubuntu1604:1",
|
||||
{ TOOLSET: 'clang', COMPILER: 'clang++-3.6', CXXSTD: '03,11,14' },
|
||||
"clang-3.6",
|
||||
),
|
||||
|
||||
linux_pipeline(
|
||||
"Linux 16.04 Clang 3.7",
|
||||
"cppalliance/droneubuntu1604:1",
|
||||
{ TOOLSET: 'clang', COMPILER: 'clang++-3.7', CXXSTD: '03,11,14' },
|
||||
"clang-3.7",
|
||||
),
|
||||
|
||||
linux_pipeline(
|
||||
"Linux 16.04 Clang 3.8",
|
||||
"cppalliance/droneubuntu1604:1",
|
||||
{ TOOLSET: 'clang', COMPILER: 'clang++-3.8', CXXSTD: '03,11,14' },
|
||||
"clang-3.8",
|
||||
),
|
||||
|
||||
linux_pipeline(
|
||||
"Linux 22.04 Clang 13",
|
||||
"cppalliance/droneubuntu2204:1",
|
||||
{ TOOLSET: 'clang', COMPILER: 'clang++-13', CXXSTD: '03,11,14,17,20' },
|
||||
"clang-13",
|
||||
),
|
||||
|
||||
linux_pipeline(
|
||||
"Linux 22.04 Clang 14 UBSAN",
|
||||
"cppalliance/droneubuntu2204:1",
|
||||
{ TOOLSET: 'clang', COMPILER: 'clang++-14', CXXSTD: '03,11,14,17,20' } + ubsan,
|
||||
"clang-14",
|
||||
),
|
||||
|
||||
linux_pipeline(
|
||||
"Linux 22.04 Clang 14 ASAN",
|
||||
"cppalliance/droneubuntu2204:1",
|
||||
{ TOOLSET: 'clang', COMPILER: 'clang++-14', CXXSTD: '03,11,14,17,20' } + asan,
|
||||
"clang-14",
|
||||
),
|
||||
|
||||
linux_pipeline(
|
||||
"Linux 22.04 Clang 15",
|
||||
"cppalliance/droneubuntu2204:1",
|
||||
{ TOOLSET: 'clang', COMPILER: 'clang++-15', CXXSTD: '03,11,14,17,20,2b' },
|
||||
"clang-15",
|
||||
["deb http://apt.llvm.org/jammy/ llvm-toolchain-jammy-15 main"],
|
||||
),
|
||||
|
||||
macos_pipeline(
|
||||
"MacOS 10.15 Xcode 12.2 UBSAN",
|
||||
{ TOOLSET: 'clang', COMPILER: 'clang++', CXXSTD: '03,11,14,1z' } + ubsan,
|
||||
),
|
||||
|
||||
macos_pipeline(
|
||||
"MacOS 10.15 Xcode 12.2 ASAN",
|
||||
{ TOOLSET: 'clang', COMPILER: 'clang++', CXXSTD: '03,11,14,1z' } + asan,
|
||||
),
|
||||
|
||||
windows_pipeline(
|
||||
"Windows VS2015 msvc-14.0",
|
||||
"cppalliance/dronevs2015",
|
||||
{ TOOLSET: 'msvc-14.0', CXXSTD: '14,latest' },
|
||||
),
|
||||
|
||||
windows_pipeline(
|
||||
"Windows VS2017 msvc-14.1",
|
||||
"cppalliance/dronevs2017",
|
||||
{ TOOLSET: 'msvc-14.1', CXXSTD: '14,17,latest' },
|
||||
),
|
||||
|
||||
windows_pipeline(
|
||||
"Windows VS2019 msvc-14.2",
|
||||
"cppalliance/dronevs2019",
|
||||
{ TOOLSET: 'msvc-14.2', CXXSTD: '14,17,20,latest' },
|
||||
),
|
||||
|
||||
windows_pipeline(
|
||||
"Windows VS2022 msvc-14.3",
|
||||
"cppalliance/dronevs2022:1",
|
||||
{ TOOLSET: 'msvc-14.3', CXXSTD: '14,17,20,latest' },
|
||||
),
|
||||
]
|
||||
23
.drone/drone.bat
Normal file
23
.drone/drone.bat
Normal file
@@ -0,0 +1,23 @@
|
||||
@REM Copyright 2022 Peter Dimov
|
||||
@REM Distributed under the Boost Software License, Version 1.0.
|
||||
@REM https://www.boost.org/LICENSE_1_0.txt
|
||||
|
||||
@ECHO ON
|
||||
|
||||
set LIBRARY=%1
|
||||
set DRONE_BUILD_DIR=%CD%
|
||||
|
||||
set BOOST_BRANCH=develop
|
||||
if "%DRONE_BRANCH%" == "master" set BOOST_BRANCH=master
|
||||
cd ..
|
||||
git clone -b %BOOST_BRANCH% --depth 1 https://github.com/boostorg/boost.git boost-root
|
||||
cd boost-root
|
||||
git submodule update --init tools/boostdep
|
||||
xcopy /s /e /q %DRONE_BUILD_DIR% libs\%LIBRARY%\
|
||||
python tools/boostdep/depinst/depinst.py %LIBRARY%
|
||||
cmd /c bootstrap
|
||||
b2 -d0 headers
|
||||
|
||||
if not "%CXXSTD%" == "" set CXXSTD=cxxstd=%CXXSTD%
|
||||
if not "%ADDRMD%" == "" set ADDRMD=address-model=%ADDRMD%
|
||||
b2 -j3 libs/%LIBRARY%/test toolset=%TOOLSET% %CXXSTD% %ADDRMD% variant=debug,release embed-manifest-via=linker
|
||||
24
.drone/drone.sh
Executable file
24
.drone/drone.sh
Executable file
@@ -0,0 +1,24 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Copyright 2022 Peter Dimov
|
||||
# Distributed under the Boost Software License, Version 1.0.
|
||||
# https://www.boost.org/LICENSE_1_0.txt
|
||||
|
||||
set -ex
|
||||
|
||||
DRONE_BUILD_DIR=$(pwd)
|
||||
|
||||
BOOST_BRANCH=develop
|
||||
if [ "$DRONE_BRANCH" = "master" ]; then BOOST_BRANCH=master; fi
|
||||
|
||||
cd ..
|
||||
git clone -b $BOOST_BRANCH --depth 1 https://github.com/boostorg/boost.git boost-root
|
||||
cd boost-root
|
||||
git submodule update --init tools/boostdep
|
||||
cp -r $DRONE_BUILD_DIR/* libs/$LIBRARY
|
||||
python tools/boostdep/depinst/depinst.py $LIBRARY
|
||||
./bootstrap.sh
|
||||
./b2 -d0 headers
|
||||
|
||||
echo "using $TOOLSET : : $COMPILER ;" > ~/user-config.jam
|
||||
./b2 -j3 libs/$LIBRARY/test toolset=$TOOLSET cxxstd=$CXXSTD variant=debug,release ${ADDRMD:+address-model=$ADDRMD} ${UBSAN:+undefined-sanitizer=norecover debug-symbols=on} ${ASAN:+address-sanitizer=norecover debug-symbols=on} ${LINKFLAGS:+linkflags=$LINKFLAGS}
|
||||
452
.github/workflows/ci.yml
vendored
452
.github/workflows/ci.yml
vendored
@@ -19,22 +19,26 @@ jobs:
|
||||
include:
|
||||
- toolset: gcc-4.8
|
||||
cxxstd: "03,11"
|
||||
os: ubuntu-18.04
|
||||
os: ubuntu-latest
|
||||
container: ubuntu:18.04
|
||||
install: g++-4.8
|
||||
- toolset: gcc-5
|
||||
cxxstd: "03,11,14,1z"
|
||||
os: ubuntu-18.04
|
||||
os: ubuntu-latest
|
||||
container: ubuntu:18.04
|
||||
install: g++-5
|
||||
- toolset: gcc-6
|
||||
cxxstd: "03,11,14,1z"
|
||||
os: ubuntu-18.04
|
||||
os: ubuntu-latest
|
||||
container: ubuntu:18.04
|
||||
install: g++-6
|
||||
- toolset: gcc-7
|
||||
cxxstd: "03,11,14,17"
|
||||
os: ubuntu-18.04
|
||||
os: ubuntu-latest
|
||||
container: ubuntu:18.04
|
||||
- toolset: gcc-8
|
||||
cxxstd: "03,11,14,17,2a"
|
||||
os: ubuntu-18.04
|
||||
os: ubuntu-20.04
|
||||
install: g++-8
|
||||
- toolset: gcc-9
|
||||
cxxstd: "03,11,14,17,2a"
|
||||
@@ -47,30 +51,42 @@ jobs:
|
||||
cxxstd: "03,11,14,17,2a"
|
||||
os: ubuntu-20.04
|
||||
install: g++-11
|
||||
- toolset: gcc-12
|
||||
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"
|
||||
os: ubuntu-18.04
|
||||
os: ubuntu-latest
|
||||
container: ubuntu:18.04
|
||||
install: clang-3.9
|
||||
- toolset: clang
|
||||
compiler: clang++-4.0
|
||||
cxxstd: "03,11,14"
|
||||
os: ubuntu-18.04
|
||||
os: ubuntu-latest
|
||||
container: ubuntu:18.04
|
||||
install: clang-4.0
|
||||
- toolset: clang
|
||||
compiler: clang++-5.0
|
||||
cxxstd: "03,11,14,1z"
|
||||
os: ubuntu-18.04
|
||||
os: ubuntu-latest
|
||||
container: ubuntu:18.04
|
||||
install: clang-5.0
|
||||
- toolset: clang
|
||||
compiler: clang++-6.0
|
||||
cxxstd: "03,11,14,17"
|
||||
os: ubuntu-18.04
|
||||
os: ubuntu-20.04
|
||||
install: clang-6.0
|
||||
- toolset: clang
|
||||
compiler: clang++-7
|
||||
cxxstd: "03,11,14,17"
|
||||
os: ubuntu-18.04
|
||||
os: ubuntu-20.04
|
||||
install: clang-7
|
||||
- toolset: clang
|
||||
compiler: clang++-8
|
||||
@@ -92,20 +108,60 @@ 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,2b"
|
||||
os: ubuntu-22.04
|
||||
install: clang-13
|
||||
- toolset: clang
|
||||
compiler: clang++-14
|
||||
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-10.15
|
||||
os: macos-11
|
||||
- toolset: clang
|
||||
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}}
|
||||
|
||||
defaults:
|
||||
run:
|
||||
shell: bash
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
- name: Setup container environment
|
||||
if: matrix.container
|
||||
run: |
|
||||
apt-get update
|
||||
apt-get -y install sudo python3 git g++
|
||||
|
||||
- name: Install packages
|
||||
if: matrix.install
|
||||
run: sudo apt install ${{matrix.install}}
|
||||
run: |
|
||||
sudo apt-get update
|
||||
sudo apt-get -y install ${{matrix.install}}
|
||||
|
||||
- name: Setup Boost
|
||||
run: |
|
||||
@@ -125,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
|
||||
|
||||
@@ -144,14 +200,22 @@ jobs:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
include:
|
||||
- toolset: msvc-14.1
|
||||
cxxstd: "14,17,latest"
|
||||
addrmd: 32,64
|
||||
os: windows-2016
|
||||
- toolset: msvc-14.2
|
||||
cxxstd: "14,17,latest"
|
||||
- toolset: msvc-14.0
|
||||
cxxstd: "14"
|
||||
addrmd: 32,64
|
||||
os: windows-2019
|
||||
- toolset: msvc-14.2
|
||||
cxxstd: "14,17,20,latest"
|
||||
addrmd: 32,64
|
||||
os: windows-2019
|
||||
- toolset: msvc-14.3
|
||||
cxxstd: "14,17,20,latest"
|
||||
addrmd: 32,64
|
||||
os: windows-2022
|
||||
- toolset: clang-win
|
||||
cxxstd: "14,17,latest"
|
||||
addrmd: 32,64
|
||||
os: windows-2022
|
||||
- toolset: gcc
|
||||
cxxstd: "03,11,14,17,2a"
|
||||
addrmd: 64
|
||||
@@ -160,7 +224,7 @@ jobs:
|
||||
runs-on: ${{matrix.os}}
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
- name: Setup Boost
|
||||
shell: cmd
|
||||
@@ -188,4 +252,346 @@ jobs:
|
||||
shell: cmd
|
||||
run: |
|
||||
cd ../boost-root
|
||||
b2 -j3 libs/%LIBRARY%/test toolset=${{matrix.toolset}} cxxstd=${{matrix.cxxstd}} address-model=${{matrix.addrmd}} variant=debug,release
|
||||
b2 -j3 libs/%LIBRARY%/test toolset=${{matrix.toolset}} cxxstd=${{matrix.cxxstd}} address-model=${{matrix.addrmd}} variant=debug,release embed-manifest-via=linker
|
||||
|
||||
posix-cmake-subdir:
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
include:
|
||||
- os: ubuntu-20.04
|
||||
- os: ubuntu-22.04
|
||||
- os: macos-11
|
||||
- os: macos-12
|
||||
- os: macos-13
|
||||
|
||||
runs-on: ${{matrix.os}}
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
- 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
|
||||
|
||||
- name: Use library with add_subdirectory
|
||||
run: |
|
||||
cd ../boost-root/libs/$LIBRARY/test/cmake_subdir_test
|
||||
mkdir __build__ && cd __build__
|
||||
cmake ..
|
||||
cmake --build .
|
||||
ctest --output-on-failure --no-tests=error
|
||||
|
||||
posix-cmake-install:
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
include:
|
||||
- os: ubuntu-20.04
|
||||
- os: ubuntu-22.04
|
||||
- os: macos-11
|
||||
- os: macos-12
|
||||
- os: macos-13
|
||||
|
||||
runs-on: ${{matrix.os}}
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
- 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
|
||||
|
||||
- name: Configure
|
||||
run: |
|
||||
cd ../boost-root
|
||||
mkdir __build__ && cd __build__
|
||||
cmake -DBOOST_INCLUDE_LIBRARIES=$LIBRARY -DCMAKE_INSTALL_PREFIX=~/.local ..
|
||||
|
||||
- name: Install
|
||||
run: |
|
||||
cd ../boost-root/__build__
|
||||
cmake --build . --target 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
|
||||
|
||||
posix-cmake-test:
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
include:
|
||||
- os: ubuntu-20.04
|
||||
- os: ubuntu-22.04
|
||||
- os: macos-11
|
||||
- os: macos-12
|
||||
- os: macos-13
|
||||
|
||||
runs-on: ${{matrix.os}}
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
- 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
|
||||
|
||||
- name: Configure
|
||||
run: |
|
||||
cd ../boost-root
|
||||
mkdir __build__ && cd __build__
|
||||
cmake -DBOOST_INCLUDE_LIBRARIES=$LIBRARY -DBUILD_TESTING=ON ..
|
||||
|
||||
- name: Build tests
|
||||
run: |
|
||||
cd ../boost-root/__build__
|
||||
cmake --build . --target tests
|
||||
|
||||
- name: Run tests
|
||||
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
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
# Copyright 2018-2020 Peter Dimov
|
||||
# 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
|
||||
|
||||
cmake_minimum_required(VERSION 3.5...3.16)
|
||||
cmake_minimum_required(VERSION 3.5...3.20)
|
||||
|
||||
project(boost_system VERSION "${BOOST_SUPERPROJECT_VERSION}" LANGUAGES CXX)
|
||||
|
||||
@@ -13,10 +13,22 @@ target_include_directories(boost_system INTERFACE include)
|
||||
|
||||
target_link_libraries(boost_system
|
||||
INTERFACE
|
||||
Boost::assert
|
||||
Boost::config
|
||||
Boost::throw_exception
|
||||
Boost::variant2
|
||||
Boost::winapi
|
||||
)
|
||||
|
||||
if(CMAKE_VERSION VERSION_GREATER 3.18 AND CMAKE_GENERATOR MATCHES "Visual Studio")
|
||||
|
||||
file(GLOB_RECURSE boost_system_IDEFILES CONFIGURE_DEPENDS include/*.hpp)
|
||||
source_group(TREE ${PROJECT_SOURCE_DIR}/include FILES ${boost_system_IDEFILES} PREFIX "Header Files")
|
||||
list(APPEND boost_system_IDEFILES extra/boost_system.natvis)
|
||||
target_sources(boost_system PRIVATE ${boost_system_IDEFILES})
|
||||
|
||||
endif()
|
||||
|
||||
if(BUILD_TESTING)
|
||||
|
||||
add_subdirectory(test)
|
||||
|
||||
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).
|
||||
43
appveyor.yml
43
appveyor.yml
@@ -22,20 +22,8 @@ environment:
|
||||
ADDRMD: 32,64
|
||||
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017
|
||||
TOOLSET: msvc-14.1
|
||||
CXXSTD: 14,17
|
||||
ADDRMD: 32,64
|
||||
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017
|
||||
TOOLSET: clang-win
|
||||
CXXSTD: 14,17
|
||||
ADDRMD: 64
|
||||
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2019
|
||||
TOOLSET: msvc-14.2
|
||||
CXXSTD: 14,17,latest
|
||||
ADDRMD: 32,64
|
||||
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2019
|
||||
TOOLSET: clang-win
|
||||
CXXSTD: 14,17,latest
|
||||
ADDRMD: 64
|
||||
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015
|
||||
ADDPATH: C:\cygwin\bin;
|
||||
TOOLSET: gcc
|
||||
@@ -52,6 +40,12 @@ environment:
|
||||
ADDPATH: C:\mingw-w64\x86_64-6.3.0-posix-seh-rt_v5-rev1\mingw64\bin;
|
||||
TOOLSET: gcc
|
||||
CXXSTD: 03,11,14,1z
|
||||
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015
|
||||
CMAKE: 1
|
||||
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017
|
||||
CMAKE_SUBDIR: 1
|
||||
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2019
|
||||
CMAKE_INSTALL: 1
|
||||
|
||||
install:
|
||||
- set BOOST_BRANCH=develop
|
||||
@@ -71,4 +65,27 @@ test_script:
|
||||
- PATH=%ADDPATH%%PATH%
|
||||
- if not "%CXXSTD%" == "" set CXXSTD=cxxstd=%CXXSTD%
|
||||
- if not "%ADDRMD%" == "" set ADDRMD=address-model=%ADDRMD%
|
||||
- b2 -j3 libs/system/test toolset=%TOOLSET% %CXXSTD% %ADDRMD% variant=debug,release embed-manifest-via=linker
|
||||
- if "%CMAKE%%CMAKE_SUBDIR%%CMAKE_INSTALL%" == "" b2 -j3 libs/system/test toolset=%TOOLSET% %CXXSTD% %ADDRMD% variant=debug,release embed-manifest-via=linker
|
||||
|
||||
- if not "%CMAKE%" == "" mkdir __build__ && cd __build__
|
||||
- if not "%CMAKE%" == "" cmake -DBUILD_TESTING=ON -DBOOST_INCLUDE_LIBRARIES=system -DBoost_VERBOSE=ON ..
|
||||
- if not "%CMAKE%" == "" cmake --build . --target tests -j 3 --config Debug & ctest --output-on-failure --no-tests=error -j 3 -C Debug
|
||||
- if not "%CMAKE%" == "" cmake --build . --target tests -j 3 --config Release & ctest --output-on-failure --no-tests=error -j 3 -C Release
|
||||
- if not "%CMAKE%" == "" cmake --build . --target tests -j 3 --config MinSizeRel & ctest --output-on-failure --no-tests=error -j 3 -C MinSizeRel
|
||||
- if not "%CMAKE%" == "" cmake --build . --target tests -j 3 --config RelWithDebInfo & ctest --output-on-failure --no-tests=error -j 3 -C RelWithDebInfo
|
||||
|
||||
- if not "%CMAKE_SUBDIR%" == "" cd libs/system/test/cmake_subdir_test && mkdir __build__ && cd __build__
|
||||
- if not "%CMAKE_SUBDIR%" == "" cmake ..
|
||||
- if not "%CMAKE_SUBDIR%" == "" cmake --build . --config Debug && cmake --build . --target check --config Debug
|
||||
- if not "%CMAKE_SUBDIR%" == "" cmake --build . --config Release && cmake --build . --target check --config Release
|
||||
- if not "%CMAKE_SUBDIR%" == "" cmake --build . --config MinSizeRel && cmake --build . --target check --config MinSizeRel
|
||||
- if not "%CMAKE_SUBDIR%" == "" cmake --build . --config RelWithDebInfo && cmake --build . --target check --config RelWithDebInfo
|
||||
|
||||
- if not "%CMAKE_INSTALL%" == "" mkdir __build__ && cd __build__
|
||||
- if not "%CMAKE_INSTALL%" == "" cmake -DBOOST_INCLUDE_LIBRARIES=system -DCMAKE_INSTALL_PREFIX=C:/cmake-prefix ..
|
||||
- if not "%CMAKE_INSTALL%" == "" cmake --build . --target install --config Debug
|
||||
- if not "%CMAKE_INSTALL%" == "" cmake --build . --target install --config Release
|
||||
- if not "%CMAKE_INSTALL%" == "" cd ../libs/system/test/cmake_install_test && mkdir __build__ && cd __build__
|
||||
- if not "%CMAKE_INSTALL%" == "" cmake -DCMAKE_INSTALL_PREFIX=C:/cmake-prefix ..
|
||||
- if not "%CMAKE_INSTALL%" == "" cmake --build . --config Debug && cmake --build . --target check --config Debug
|
||||
- if not "%CMAKE_INSTALL%" == "" cmake --build . --config Release && cmake --build . --target check --config Release
|
||||
|
||||
@@ -13,10 +13,13 @@ Beman Dawes, Christopher Kohlhoff, Peter Dimov
|
||||
:toclevels: 4
|
||||
:idprefix:
|
||||
:docinfo: private-footer
|
||||
:source-highlighter: rouge
|
||||
:source-language: c++
|
||||
|
||||
:leveloffset: +1
|
||||
|
||||
include::system/introduction.adoc[]
|
||||
include::system/usage.adoc[]
|
||||
include::system/changes.adoc[]
|
||||
include::system/rationale.adoc[]
|
||||
include::system/reference.adoc[]
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
////
|
||||
Copyright 2018-2021 Peter Dimov
|
||||
Copyright 2018-2022 Peter Dimov
|
||||
Distributed under the Boost Software License, Version 1.0.
|
||||
https://www.boost.org/LICENSE_1_0.txt
|
||||
////
|
||||
@@ -8,10 +8,37 @@ https://www.boost.org/LICENSE_1_0.txt
|
||||
# Revision History
|
||||
:idprefix:
|
||||
|
||||
## Changes in Boost 1.81
|
||||
|
||||
* The macro `BOOST_SYSTEM_DISABLE_THREADS` can now be defined to disable
|
||||
the use of `<mutex>` (e.g. on single-threaded libstdc++).
|
||||
* Added `value_type`, `error_type`, `in_place_value`, `in_place_error`
|
||||
to `result<>`.
|
||||
* Added `emplace` to `result<>`.
|
||||
|
||||
## 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 `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
|
||||
|
||||
* Added support for source locations to `error_code`.
|
||||
* Added `error_code::to_string`.
|
||||
* Added `error_code::to_string`, `error_condition::to_string`, `error_code::what`.
|
||||
* `system_error::what()` now contains the source location, if present.
|
||||
* Added `result<T, E = error_code>`, a class holding either a value or an
|
||||
error, defined in `<boost/system/result.hpp>`.
|
||||
|
||||
@@ -14,6 +14,6 @@ http://www.boost.org/LICENSE_1_0.txt
|
||||
This documentation is
|
||||
|
||||
* Copyright 2003-2017 Beman Dawes
|
||||
* Copyright 2018-2021 Peter Dimov
|
||||
* Copyright 2018-2022 Peter Dimov
|
||||
|
||||
and is distributed under the http://www.boost.org/LICENSE_1_0.txt[Boost Software License, Version 1.0].
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
////
|
||||
Copyright 2003-2017 Beman Dawes
|
||||
Copyright 2018 Peter Dimov
|
||||
Copyright 2018, 2021 Peter Dimov
|
||||
|
||||
Distributed under the Boost Software License, Version 1.0.
|
||||
|
||||
@@ -12,39 +12,67 @@ http://www.boost.org/LICENSE_1_0.txt
|
||||
# Introduction
|
||||
:idprefix: intro_
|
||||
|
||||
Error conditions originating from the operating system or other low-level
|
||||
application program interfaces (API's) are typically reported via an integer
|
||||
representing an error code. When these low-level API calls are wrapped in
|
||||
portable code, such as in a portable library, some users want to deal with the
|
||||
error codes in portable ways. Other users need to get at the system specific
|
||||
error codes, so they can deal with system specific needs. The Boost System
|
||||
library provides simple, light-weight `error_code` objects that encapsulate
|
||||
system-specific error code values, yet also provide access to more abstract
|
||||
and portable error conditions via `error_condition` objects.
|
||||
Errors originating from the operating system or other low-level application
|
||||
program interfaces (APIs) are typically reported via an integer representing
|
||||
an error code, either by returning the code directly from the function (e.g.
|
||||
`pthread_mutex_init`) or by using a side channel such as the `errno`
|
||||
pseudo-variable under POSIX or `GetLastError()` under Windows.
|
||||
|
||||
Because `error_code` objects can represent errors from sources other than the
|
||||
operating system, including user-defined sources, each `error_code` and
|
||||
`error_condition` has an associated `error_category`.
|
||||
However, these integer error values can only be interpreted when their source
|
||||
is known. The value 5 under Windows means `ERROR_ACCESS_DENIED` when returned
|
||||
by `GetLastError()`, but `EIO` when retrieved from `errno`. And conversely,
|
||||
the same error condition "access denied" is represented by the value 5 when
|
||||
returned by `GetLastError()` and 13 (`EACCES`) when retrieved from `errno`.
|
||||
|
||||
An exception class, `system_error`, is provided. Derived from
|
||||
`std::runtime_error`, it captures the underlying `error_code` for the problem
|
||||
causing the exception so that this important information is not lost.
|
||||
This means that in order for code to be able to handle errors from both
|
||||
sources (to retrieve a text message describing the error, or to check whether
|
||||
the error means "access denied"), it needs to know where the integer error
|
||||
value originated. For this to be possible, the integer error value needs to
|
||||
be accompanied by a piece of information identifying the source.
|
||||
|
||||
While exceptions are the preferred {cpp} default error code reporting
|
||||
mechanism, users of libraries dependent on low-level API's often need overloads
|
||||
reporting error conditions via error code arguments and/or return values rather
|
||||
than via throwing exceptions. Otherwise, when errors are not exceptional
|
||||
occurrences and must be dealt with as they arise, programs become littered with
|
||||
try/catch blocks, unreadable, and inefficient. The Boost System library
|
||||
supports both error reporting by exception and by error code.
|
||||
Boost.System provides a framework in which this is possible. Errors are
|
||||
represented by a class `error_code` which contains both the error value and
|
||||
a pointer to their source (called "category"), represented as a class derived
|
||||
from `error_category`.
|
||||
|
||||
In addition to portable errors codes and conditions supported by the
|
||||
`error_code.hpp` header, system-specific headers support the Cygwin, Linux,
|
||||
and Windows platforms. These headers are effectively no-ops if included for
|
||||
platforms other than their intended target.
|
||||
The category provides member functions such as `message`, which returns a text
|
||||
message for a specific error value, and `equivalent`, which can be used to test
|
||||
whether a specific error value correspond to an error condition such as "access
|
||||
denied". `error_code` uses these category-provided functions in the
|
||||
implementation of its `message` and `operator==` member functions.
|
||||
|
||||
Boost.System is part of the {cpp}11 Standard Library.
|
||||
A number of changes, particularly to names, were made by the C++ committee
|
||||
during standardization. The Boost implementation has been tracking those changes.
|
||||
See <<#ref_deprecated_names,Deprecated Names>> for synonyms provided to prevent
|
||||
breakage of existing user code.
|
||||
Boost.System contains two predefined category classes, the generic category
|
||||
(a reference to which is returned by `generic_category()`) and the system
|
||||
category (`system_category()`). The generic category represents the error
|
||||
values of the portable subset of `errno` values defined by the POSIX standard,
|
||||
whereas the system category is OS dependent. Under POSIX, the system category
|
||||
represents the `errno` values returned by the OS APIs (a superset of those in
|
||||
the generic category), whereas under Windows, the system category represents
|
||||
the error values returned by `GetLastError()`.
|
||||
|
||||
The framework is extensible. Users can define their own categories by
|
||||
deriving a class from `error_category` and implementing a function that
|
||||
returns a reference to an instance of it. This capability is useful both for
|
||||
describing library-defined error values, and for adapting existing C API
|
||||
libraries that return integer error values.
|
||||
|
||||
For those who prefer error reporting via exceptions, Boost.System provides
|
||||
a standard exception class `system_error` that stores an `error_code`.
|
||||
|
||||
Boost.System was standardized in {cpp}11 as `<system_error>`. For a while,
|
||||
the two were equivalent, but Boost.System has evolved since then and now
|
||||
contains a number of extensions over its standard sibling:
|
||||
|
||||
* A non-allocating overload of `message`;
|
||||
* Support for nonzero error codes meaning success, via the `failed` member
|
||||
functions;
|
||||
* Support for 64 bit category identifiers, as a solution to the problem
|
||||
that sometimes it's not possible to ensure that only one instance of a
|
||||
category exists in the program;
|
||||
* Support for attaching source locations (file/line/function) to error codes;
|
||||
* A class `result<T>` that can be used to return either a value or an error
|
||||
code from a function;
|
||||
* Various other minor improvements.
|
||||
|
||||
`boost::system::error_code` can be converted to, and constructed from,
|
||||
`std::error_code`.
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
////
|
||||
Copyright 2003-2017 Beman Dawes
|
||||
Copyright 2018-2021 Peter Dimov
|
||||
Copyright 2018-2022 Peter Dimov
|
||||
|
||||
Distributed under the Boost Software License, Version 1.0.
|
||||
|
||||
@@ -29,6 +29,11 @@ When `BOOST_SYSTEM_USE_UTF8` is defined, on Windows the library returns
|
||||
UTF-8 messages using code page `CP_UTF8` instead of the default `CP_ACP`.
|
||||
This macro has no effect on POSIX.
|
||||
|
||||
When `BOOST_SYSTEM_DISABLE_THREADS` is defined, the library assumes that
|
||||
the current platform doesn't support multiple threads and disables the use
|
||||
of the standard header `<mutex>`, eliminating the mutex locks. The single
|
||||
threaded `libstdc++` is one such platform.
|
||||
|
||||
## Deprecated Names
|
||||
|
||||
In the process of adding Boost.System to the {cpp}11 standard library, the
|
||||
@@ -175,7 +180,7 @@ namespace errc {
|
||||
too_many_files_open_in_system, //ENFILE
|
||||
too_many_files_open, //EMFILE
|
||||
too_many_links, //EMLINK
|
||||
too_many_synbolic_link_levels, //ELOOP
|
||||
too_many_symbolic_link_levels, //ELOOP
|
||||
value_too_large, //EOVERFLOW
|
||||
wrong_protocol_type //EPROTOTYPE
|
||||
};
|
||||
@@ -185,9 +190,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 +265,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
|
||||
@@ -571,9 +612,12 @@ public:
|
||||
error_code( int val, const error_category & cat,
|
||||
boost::source_location const * loc ) noexcept;
|
||||
|
||||
template <class ErrorCodeEnum>
|
||||
template<class ErrorCodeEnum>
|
||||
constexpr error_code( ErrorCodeEnum e ) noexcept;
|
||||
|
||||
error_code( error_code const& ec,
|
||||
boost::source_location const * loc ) noexcept;
|
||||
|
||||
error_code( std::error_code const& ec ) noexcept;
|
||||
|
||||
// modifiers
|
||||
@@ -583,9 +627,12 @@ public:
|
||||
void assign( int val, const error_category & cat,
|
||||
boost::source_location const * loc ) noexcept;
|
||||
|
||||
template<typename ErrorCodeEnum>
|
||||
template<class ErrorCodeEnum>
|
||||
constexpr error_code & operator=( ErrorCodeEnum e ) noexcept;
|
||||
|
||||
void assign( error_code const& ec,
|
||||
boost::source_location const * loc ) noexcept;
|
||||
|
||||
constexpr void clear() noexcept;
|
||||
|
||||
// observers
|
||||
@@ -657,9 +704,13 @@ public:
|
||||
|
||||
// stream insertion
|
||||
|
||||
template <class charT, class traits>
|
||||
template<class charT, class traits>
|
||||
friend std::basic_ostream<charT, traits>&
|
||||
operator<<( basic_ostream<charT, traits>& os, const error_code & ec );
|
||||
|
||||
// what
|
||||
|
||||
std::string what() const;
|
||||
};
|
||||
|
||||
// non-member functions
|
||||
@@ -699,7 +750,7 @@ Requires: :: `loc` points to a valid `boost::source_location` object with static
|
||||
Ensures: :: `value() == val`; `category() == cat`; `has_location()`; `&location() == loc`.
|
||||
|
||||
```
|
||||
template <class ErrorCodeEnum>
|
||||
template<class ErrorCodeEnum>
|
||||
constexpr error_code( ErrorCodeEnum e ) noexcept;
|
||||
```
|
||||
[none]
|
||||
@@ -708,6 +759,19 @@ template <class ErrorCodeEnum>
|
||||
Ensures: :: `*this == make_error_code( e )`.
|
||||
Remarks: :: This constructor is only enabled when `is_error_code_enum<ErrorCodeEnum>::value` is `true`.
|
||||
|
||||
```
|
||||
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, 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;
|
||||
```
|
||||
@@ -725,7 +789,7 @@ constexpr void assign( int val, const error_category & cat ) noexcept;
|
||||
[none]
|
||||
* {blank}
|
||||
+
|
||||
Effects: :: `*this = error_code( val, cat );`.
|
||||
Effects: :: `*this = error_code( val, cat )`.
|
||||
|
||||
```
|
||||
void assign( int val, const error_category & cat,
|
||||
@@ -734,10 +798,10 @@ void assign( int val, const error_category & cat,
|
||||
[none]
|
||||
* {blank}
|
||||
+
|
||||
Effects: :: `*this = error_code( val, cat, loc );`.
|
||||
Effects: :: `*this = error_code( val, cat, loc )`.
|
||||
|
||||
```
|
||||
template<typename ErrorCodeEnum>
|
||||
template<class ErrorCodeEnum>
|
||||
constexpr error_code & operator=( ErrorCodeEnum e ) noexcept;
|
||||
```
|
||||
[none]
|
||||
@@ -746,6 +810,15 @@ template<typename ErrorCodeEnum>
|
||||
Ensures: :: `*this == make_error_code( e )`.
|
||||
Remarks: :: This operator is only enabled when `is_error_code_enum<ErrorCodeEnum>::value` is `true`.
|
||||
|
||||
```
|
||||
void assign( error_code const& ec,
|
||||
boost::source_location const * loc ) noexcept;
|
||||
```
|
||||
[none]
|
||||
* {blank}
|
||||
+
|
||||
Effects: :: `*this = error_code( ec, loc )`.
|
||||
|
||||
```
|
||||
constexpr void clear() noexcept;
|
||||
```
|
||||
@@ -753,7 +826,7 @@ constexpr void clear() noexcept;
|
||||
* {blank}
|
||||
+
|
||||
Effects: ::
|
||||
`*this = error_code();`.
|
||||
`*this = error_code()`.
|
||||
|
||||
#### Observers
|
||||
|
||||
@@ -1021,6 +1094,18 @@ template <class charT, class traits>
|
||||
Effects: :: `os << to_string()`.
|
||||
Returns: :: `os`.
|
||||
|
||||
#### what
|
||||
|
||||
```
|
||||
std::string what() const;
|
||||
```
|
||||
[none]
|
||||
* {blank}
|
||||
+
|
||||
Returns: :: A string representation of `*this`, suitable for logging and
|
||||
diagnostic output. Typically incorporates `message()`, `to_string()`, and
|
||||
`location().to_string()` (if available.)
|
||||
|
||||
#### Nonmembers
|
||||
|
||||
```
|
||||
@@ -1096,6 +1181,10 @@ public:
|
||||
|
||||
operator std::error_condition() const;
|
||||
|
||||
// to_string
|
||||
|
||||
std::string to_string() const;
|
||||
|
||||
// stream insertion
|
||||
|
||||
template <class charT, class traits>
|
||||
@@ -1284,6 +1373,17 @@ operator std::error_condition() const;
|
||||
Returns: ::
|
||||
`std::error_condition( value(), category() )`.
|
||||
|
||||
#### to_string
|
||||
|
||||
```
|
||||
std::string to_string() const;
|
||||
```
|
||||
[none]
|
||||
* {blank}
|
||||
+
|
||||
Returns: :: The concatenation of `"cond:"`, `category().name()`, `':'`,
|
||||
and the string representation of `value()`.
|
||||
|
||||
#### Stream Insertion
|
||||
|
||||
```
|
||||
@@ -1294,7 +1394,7 @@ template <class charT, class traits>
|
||||
[none]
|
||||
* {blank}
|
||||
+
|
||||
Effects: :: `os << "cond:" << en.category().name() << ':' << en.value()`.
|
||||
Effects: :: `os << en.to_string()`.
|
||||
Returns: ::
|
||||
`os`.
|
||||
|
||||
@@ -1390,7 +1490,20 @@ namespace system {
|
||||
|
||||
// throw_exception_from_error
|
||||
|
||||
BOOST_NORETURN inline void throw_exception_from_error( error_code const & e );
|
||||
BOOST_NORETURN inline void throw_exception_from_error( error_code const & e,
|
||||
boost::source_location const & loc );
|
||||
|
||||
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_*
|
||||
|
||||
@@ -1422,13 +1535,57 @@ If `result<T, E>` is used with other error types, the user is expected to provid
|
||||
an appropriate overload of `throw_exception_from_error` in the namespace of `E`.
|
||||
|
||||
```
|
||||
BOOST_NORETURN inline void throw_exception_from_error( error_code const & e );
|
||||
BOOST_NORETURN inline void throw_exception_from_error( error_code const & e,
|
||||
boost::source_location const & loc );
|
||||
```
|
||||
[none]
|
||||
* {blank}
|
||||
+
|
||||
Effects: ::
|
||||
`boost::throw_exception( system_error( e ) )`.
|
||||
`boost::throw_with_location( system_error( e ), loc )`.
|
||||
|
||||
```
|
||||
BOOST_NORETURN inline void throw_exception_from_error( std::error_code const & e,
|
||||
boost::source_location const & loc );
|
||||
```
|
||||
[none]
|
||||
* {blank}
|
||||
+
|
||||
Effects: ::
|
||||
`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>
|
||||
|
||||
@@ -1443,6 +1600,12 @@ template<class T, class E = error_code> class result
|
||||
{
|
||||
public:
|
||||
|
||||
using value_type = T;
|
||||
using error_type = E;
|
||||
|
||||
static constexpr in_place_value_t in_place_value{};
|
||||
static constexpr in_place_error_t in_place_error{};
|
||||
|
||||
// constructors
|
||||
|
||||
constexpr result();
|
||||
@@ -1456,6 +1619,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;
|
||||
@@ -1464,10 +1633,17 @@ public:
|
||||
|
||||
// checked value access
|
||||
|
||||
constexpr T& value() & ;
|
||||
constexpr T const& value() const& ;
|
||||
constexpr T&& value() && ;
|
||||
constexpr T const&& value() const&& ;
|
||||
constexpr T& value( boost::source_location const & loc =
|
||||
BOOST_CURRENT_LOCATION ) & ;
|
||||
|
||||
constexpr T const& value( boost::source_location const & loc =
|
||||
BOOST_CURRENT_LOCATION ) const& ;
|
||||
|
||||
constexpr T&& value( boost::source_location const & loc =
|
||||
BOOST_CURRENT_LOCATION ) && ;
|
||||
|
||||
constexpr T const&& value( boost::source_location const & loc =
|
||||
BOOST_CURRENT_LOCATION ) const&& ;
|
||||
|
||||
// unchecked value access
|
||||
|
||||
@@ -1481,7 +1657,13 @@ public:
|
||||
|
||||
// error access
|
||||
|
||||
constexpr E error() const;
|
||||
constexpr E error() const &;
|
||||
constexpr E error() &&;
|
||||
|
||||
// emplace
|
||||
|
||||
template<class... A>
|
||||
constexpr T& emplace( A&&... a );
|
||||
|
||||
// swap
|
||||
|
||||
@@ -1557,6 +1739,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
|
||||
|
||||
```
|
||||
@@ -1589,10 +1795,17 @@ Returns: ::
|
||||
#### Checked Value Access
|
||||
|
||||
```
|
||||
constexpr T& value() & ;
|
||||
constexpr T const& value() const& ;
|
||||
constexpr T&& value() && ;
|
||||
constexpr T const&& value() const&& ;
|
||||
constexpr T& value(
|
||||
boost::source_location const & loc = BOOST_CURRENT_LOCATION ) & ;
|
||||
|
||||
constexpr T const& value(
|
||||
boost::source_location const & loc = BOOST_CURRENT_LOCATION ) const& ;
|
||||
|
||||
constexpr T&& value(
|
||||
boost::source_location const & loc = BOOST_CURRENT_LOCATION ) && ;
|
||||
|
||||
constexpr T const&& value(
|
||||
boost::source_location const & loc = BOOST_CURRENT_LOCATION ) const&& ;
|
||||
```
|
||||
[none]
|
||||
* {blank}
|
||||
@@ -1600,7 +1813,7 @@ constexpr T const&& value() const&& ;
|
||||
Effects: ::
|
||||
If `*this` holds a value, returns a reference to it. Otherwise,
|
||||
calls `throw_exception_from_error`, passing it a reference to
|
||||
the held error.
|
||||
the held error, and `loc`.
|
||||
|
||||
#### Unchecked Value Access
|
||||
|
||||
@@ -1639,7 +1852,8 @@ Returns: ::
|
||||
#### Error Access
|
||||
|
||||
```
|
||||
constexpr E error() const;
|
||||
constexpr E error() const &;
|
||||
constexpr E error() &&;
|
||||
```
|
||||
[none]
|
||||
* {blank}
|
||||
@@ -1647,6 +1861,20 @@ constexpr E error() const;
|
||||
Effects: ::
|
||||
If `*this` holds an error, returns it. Otherwise, returns `E()`.
|
||||
|
||||
#### emplace
|
||||
|
||||
```
|
||||
template<class... A>
|
||||
constexpr T& emplace( A&&... a );
|
||||
```
|
||||
[none]
|
||||
* {blank}
|
||||
+
|
||||
Ensures: ::
|
||||
`*this` holds the value `T( std::forward<A>(a)... )`.
|
||||
Returns: ::
|
||||
A reference to the contained value.
|
||||
|
||||
#### swap
|
||||
|
||||
```
|
||||
@@ -1700,8 +1928,8 @@ template<class Ch, class Tr, class T, class E>
|
||||
* {blank}
|
||||
+
|
||||
Effects: ::
|
||||
- If `*this` holds a value `t`, `os << "value:" << t;`.
|
||||
- If `*this` holds an error `e`, `os << "error:" << e;`.
|
||||
- If `*this` holds a value `t`, `os << "value:" << t`.
|
||||
- If `*this` holds an error `e`, `os << "error:" << e`.
|
||||
Returns: ::
|
||||
`os`.
|
||||
|
||||
@@ -1715,6 +1943,12 @@ template<class E> class result<void, E>
|
||||
{
|
||||
public:
|
||||
|
||||
using value_type = void;
|
||||
using error_type = E;
|
||||
|
||||
static constexpr in_place_value_t in_place_value{};
|
||||
static constexpr in_place_error_t in_place_error{};
|
||||
|
||||
// constructors
|
||||
|
||||
constexpr result() noexcept;
|
||||
@@ -1735,7 +1969,8 @@ public:
|
||||
|
||||
// checked value access
|
||||
|
||||
constexpr void value() const;
|
||||
constexpr void value( boost::source_location const & loc =
|
||||
BOOST_CURRENT_LOCATION ) const;
|
||||
|
||||
// unchecked value access
|
||||
|
||||
@@ -1746,7 +1981,12 @@ public:
|
||||
|
||||
// error access
|
||||
|
||||
constexpr E error() const;
|
||||
constexpr E error() const &;
|
||||
constexpr E error() &&;
|
||||
|
||||
// emplace
|
||||
|
||||
constexpr void emplace();
|
||||
|
||||
// swap
|
||||
|
||||
@@ -1848,14 +2088,15 @@ Returns: ::
|
||||
#### Checked Value Access
|
||||
|
||||
```
|
||||
constexpr void value() const;
|
||||
constexpr void value(
|
||||
boost::source_location const & loc = BOOST_CURRENT_LOCATION ) const;
|
||||
```
|
||||
[none]
|
||||
* {blank}
|
||||
+
|
||||
Effects: ::
|
||||
If `*this` doesn't hold a value, calls `throw_exception_from_error`,
|
||||
passing it a reference to the held error.
|
||||
passing it a reference to the held error, and `loc`.
|
||||
|
||||
#### Unchecked Value Access
|
||||
|
||||
@@ -1882,7 +2123,8 @@ Effects: ::
|
||||
#### Error Access
|
||||
|
||||
```
|
||||
constexpr E error() const;
|
||||
constexpr E error() const &;
|
||||
constexpr E error() &&;
|
||||
```
|
||||
[none]
|
||||
* {blank}
|
||||
@@ -1890,6 +2132,17 @@ constexpr E error() const;
|
||||
Effects: ::
|
||||
If `*this` holds an error, returns it. Otherwise, returns `E()`.
|
||||
|
||||
#### emplace
|
||||
|
||||
```
|
||||
constexpr void emplace();
|
||||
```
|
||||
[none]
|
||||
* {blank}
|
||||
+
|
||||
Ensures: ::
|
||||
`*this` holds an unspecified value.
|
||||
|
||||
#### swap
|
||||
|
||||
```
|
||||
@@ -1943,8 +2196,8 @@ template<class Ch, class Tr, class E>
|
||||
* {blank}
|
||||
+
|
||||
Effects: ::
|
||||
- If `*this` holds a value, `os << "value:void";`.
|
||||
- If `*this` holds an error `e`, `os << "error:" << e;`.
|
||||
- If `*this` holds a value, `os << "value:void"`.
|
||||
- If `*this` holds an error `e`, `os << "error:" << e`.
|
||||
Returns: ::
|
||||
`os`.
|
||||
|
||||
|
||||
1414
doc/system/usage.adoc
Normal file
1414
doc/system/usage.adoc
Normal file
File diff suppressed because it is too large
Load Diff
53
extra/boost_system.natvis
Normal file
53
extra/boost_system.natvis
Normal file
@@ -0,0 +1,53 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<AutoVisualizer xmlns="http://schemas.microsoft.com/vstudio/debugger/natvis/2010">
|
||||
|
||||
<Type Name="boost::system::error_category">
|
||||
<DisplayString Condition="id_ == 0xb2ab117a257edfd0">[generic]</DisplayString>
|
||||
<DisplayString Condition="id_ == 0xb2ab117a257edfd1">[system]</DisplayString>
|
||||
<DisplayString Condition="id_ == 0xb2ab117a257edfd2">[interop]</DisplayString>
|
||||
<DisplayString Condition="id_ != 0">[{id_,x}]</DisplayString>
|
||||
<DisplayString>@{((uintptr_t)this),x}</DisplayString>
|
||||
</Type>
|
||||
|
||||
<Type Name="boost::system::error_code">
|
||||
<DisplayString Condition="lc_flags_ == 0">{d1_.val_} [system] ✓</DisplayString>
|
||||
|
||||
<DisplayString Condition="lc_flags_ == 1 && ((std::error_code*)d2_)->_Mycat->_Addr==1">{((std::error_code*)d2_)->_Myval} [std:future]</DisplayString>
|
||||
<DisplayString Condition="lc_flags_ == 1 && ((std::error_code*)d2_)->_Mycat->_Addr==3">{((std::error_code*)d2_)->_Myval} [std:generic]</DisplayString>
|
||||
<DisplayString Condition="lc_flags_ == 1 && ((std::error_code*)d2_)->_Mycat->_Addr==5">{((std::error_code*)d2_)->_Myval} [std:iostream]</DisplayString>
|
||||
<DisplayString Condition="lc_flags_ == 1 && ((std::error_code*)d2_)->_Mycat->_Addr==7">{((std::error_code*)d2_)->_Myval} [std:system]</DisplayString>
|
||||
<DisplayString Condition="lc_flags_ == 1">{((std::error_code*)d2_)->_Myval} std@{((uintptr_t)((std::error_code*)d2_)->_Mycat),x}</DisplayString>
|
||||
|
||||
<DisplayString Condition="d1_.cat_->id_ == 0xb2ab117a257edfd0 &&
|
||||
(lc_flags_ == 2 || (lc_flags_ > 3 && ( lc_flags_ % 2 == 0 )))">{d1_.val_} [generic] ✓</DisplayString>
|
||||
<DisplayString Condition="d1_.cat_->id_ == 0xb2ab117a257edfd1 &&
|
||||
(lc_flags_ == 2 || (lc_flags_ > 3 && ( lc_flags_ % 2 == 0 )))">{d1_.val_} [system] ✓</DisplayString>
|
||||
<DisplayString Condition="d1_.cat_->id_ == 0xb2ab117a257edfd2 &&
|
||||
(lc_flags_ == 2 || (lc_flags_ > 3 && ( lc_flags_ % 2 == 0 )))">{d1_.val_} [interop] ✓</DisplayString>
|
||||
<DisplayString Condition="d1_.cat_->id_ != 0 &&
|
||||
(lc_flags_ == 2 || (lc_flags_ > 3 && ( lc_flags_ % 2 == 0 )))">{d1_.val_} [{d1_.cat_->id_,x}] ✓</DisplayString>
|
||||
<DisplayString Condition=
|
||||
"lc_flags_ == 2 || (lc_flags_ > 3 && ( lc_flags_ % 2 == 0 ))">{d1_.val_} @{((uintptr_t)d1_.cat_),x} ✓</DisplayString>
|
||||
|
||||
<DisplayString Condition="d1_.cat_->id_ == 0xb2ab117a257edfd0 &&
|
||||
(lc_flags_ >= 3 && ( lc_flags_ % 2 == 1 ))">{d1_.val_} [generic]</DisplayString>
|
||||
<DisplayString Condition="d1_.cat_->id_ == 0xb2ab117a257edfd1 &&
|
||||
(lc_flags_ >= 3 && ( lc_flags_ % 2 == 1 ))">{d1_.val_} [system]</DisplayString>
|
||||
<DisplayString Condition="d1_.cat_->id_ == 0xb2ab117a257edfd2 &&
|
||||
(lc_flags_ >= 3 && ( lc_flags_ % 2 == 1 ))">{d1_.val_} [interop]</DisplayString>
|
||||
<DisplayString Condition="d1_.cat_->id_ != 0 &&
|
||||
(lc_flags_ >= 3 && ( lc_flags_ % 2 == 1 ))">{d1_.val_} [{d1_.cat_->id_,x}]</DisplayString>
|
||||
<DisplayString Condition=
|
||||
"lc_flags_ >= 3 && ( lc_flags_ % 2 == 1 )">{d1_.val_} @{((uintptr_t)d1_.cat_),x}</DisplayString>
|
||||
|
||||
<Expand>
|
||||
<Item Name="std::error_code" Condition="lc_flags_ == 1">(std::error_code*)d2_</Item>
|
||||
<Item Name="[location]" Condition="lc_flags_ > 3">*((boost::source_location*)(lc_flags_ & ~1))</Item>
|
||||
</Expand>
|
||||
</Type>
|
||||
|
||||
<Type Name="boost::system::result<*,*>">
|
||||
<DisplayString>{v_}</DisplayString>
|
||||
</Type>
|
||||
|
||||
</AutoVisualizer>
|
||||
@@ -9,8 +9,9 @@
|
||||
|
||||
#include <boost/system/error_code.hpp>
|
||||
#include <boost/system/system_error.hpp>
|
||||
#include <boost/config.hpp>
|
||||
|
||||
#if (__cplusplus >= 201103L) || (defined(_MSC_VER) && _MSC_VER >= 1900)
|
||||
#if (__cplusplus >= 201103L) && !(defined(BOOST_GCC) && BOOST_GCC < 40800) || (defined(_MSC_VER) && _MSC_VER >= 1900)
|
||||
# include <boost/system/result.hpp>
|
||||
#endif
|
||||
|
||||
|
||||
32
include/boost/system/detail/append_int.hpp
Normal file
32
include/boost/system/detail/append_int.hpp
Normal file
@@ -0,0 +1,32 @@
|
||||
#ifndef BOOST_SYSTEM_DETAIL_APPEND_INT_HPP_INCLUDED
|
||||
#define BOOST_SYSTEM_DETAIL_APPEND_INT_HPP_INCLUDED
|
||||
|
||||
// Copyright 2021 Peter Dimov
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// https://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#include <boost/system/detail/snprintf.hpp>
|
||||
#include <string>
|
||||
|
||||
//
|
||||
|
||||
namespace boost
|
||||
{
|
||||
namespace system
|
||||
{
|
||||
namespace detail
|
||||
{
|
||||
|
||||
inline void append_int( std::string& s, int v )
|
||||
{
|
||||
char buffer[ 32 ];
|
||||
detail::snprintf( buffer, sizeof( buffer ), ":%d", v );
|
||||
|
||||
s += buffer;
|
||||
}
|
||||
|
||||
} // namespace detail
|
||||
} // namespace system
|
||||
} // namespace boost
|
||||
|
||||
#endif // #ifndef BOOST_SYSTEM_DETAIL_APPEND_INT_HPP_INCLUDED
|
||||
@@ -1,19 +1,26 @@
|
||||
#ifndef BOOST_SYSTEM_DETAIL_CONFIG_HPP_INCLUDED
|
||||
#define BOOST_SYSTEM_DETAIL_CONFIG_HPP_INCLUDED
|
||||
|
||||
// Copyright 2018 Peter Dimov
|
||||
// Copyright 2018-2022 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 http://www.boost.org/libs/system for documentation.
|
||||
|
||||
#include <boost/system/detail/requires_cxx11.hpp>
|
||||
#include <boost/config.hpp>
|
||||
#include <boost/config/workaround.hpp>
|
||||
|
||||
// BOOST_SYSTEM_HAS_SYSTEM_ERROR
|
||||
//
|
||||
// The macro BOOST_SYSTEM_DISABLE_THREADS can be defined on configurations
|
||||
// that provide <system_error> and <atomic>, but not <mutex>, such as the
|
||||
// single-threaded libstdc++.
|
||||
//
|
||||
// https://github.com/boostorg/system/issues/92
|
||||
|
||||
#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) || defined(BOOST_SYSTEM_DISABLE_THREADS) )
|
||||
# define BOOST_SYSTEM_HAS_SYSTEM_ERROR
|
||||
#endif
|
||||
|
||||
@@ -58,8 +65,26 @@
|
||||
|
||||
// BOOST_SYSTEM_CLANG_6
|
||||
|
||||
#if defined(__clang__) && (__clang_major__ < 7 || (defined(__APPLE__) && __clang_major__ < 11))
|
||||
// Android NDK r18b has Clang 7.0.2 that still needs the workaround
|
||||
// https://github.com/boostorg/system/issues/100
|
||||
#if defined(__clang__) && (__clang_major__ < 7 || (defined(__APPLE__) && __clang_major__ < 11) || (defined(__ANDROID__) && __clang_major__ == 7))
|
||||
# define BOOST_SYSTEM_CLANG_6
|
||||
#endif
|
||||
|
||||
//
|
||||
|
||||
#if defined(BOOST_LIBSTDCXX_VERSION) && BOOST_LIBSTDCXX_VERSION < 50000
|
||||
# define BOOST_SYSTEM_AVOID_STD_GENERIC_CATEGORY
|
||||
#endif
|
||||
|
||||
#if defined(__CYGWIN__) || defined(__MINGW32__) || (defined(_MSC_VER) && _MSC_VER == 1800) || (defined(BOOST_LIBSTDCXX_VERSION) && BOOST_LIBSTDCXX_VERSION < 90000)
|
||||
|
||||
// Under Cygwin (and MinGW!), std::system_category() is POSIX
|
||||
// Under VS2013, std::system_category() isn't quite right
|
||||
// Under libstdc++ before 7.4, before 8.3, before 9.1, default_error_condition
|
||||
// for the system category returns a condition from the system category
|
||||
|
||||
# define BOOST_SYSTEM_AVOID_STD_SYSTEM_CATEGORY
|
||||
#endif
|
||||
|
||||
#endif // BOOST_SYSTEM_DETAIL_CONFIG_HPP_INCLUDED
|
||||
|
||||
@@ -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>
|
||||
@@ -48,6 +49,11 @@ class std_category;
|
||||
#pragma GCC diagnostic ignored "-Wnon-virtual-dtor"
|
||||
#endif
|
||||
|
||||
#if defined(BOOST_MSVC) && BOOST_MSVC < 1900
|
||||
#pragma warning(push)
|
||||
#pragma warning(disable: 4351) // new behavior: elements of array will be default initialized
|
||||
#endif
|
||||
|
||||
class BOOST_SYMBOL_VISIBLE error_category
|
||||
{
|
||||
private:
|
||||
@@ -55,6 +61,9 @@ private:
|
||||
friend std::size_t hash_value( error_code const & ec );
|
||||
friend BOOST_SYSTEM_CONSTEXPR bool detail::failed_impl( int ev, error_category const & cat );
|
||||
|
||||
friend class error_code;
|
||||
friend class error_condition;
|
||||
|
||||
#if !defined(BOOST_NO_CXX11_DELETED_FUNCTIONS)
|
||||
public:
|
||||
|
||||
@@ -73,13 +82,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
|
||||
|
||||
@@ -100,11 +117,18 @@ protected:
|
||||
|
||||
#endif
|
||||
|
||||
BOOST_SYSTEM_CONSTEXPR error_category() BOOST_NOEXCEPT: id_( 0 ), ps_()
|
||||
#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 ), ps_()
|
||||
explicit
|
||||
#if !BOOST_WORKAROUND(BOOST_GCC, < 40800)
|
||||
BOOST_CONSTEXPR
|
||||
#endif
|
||||
error_category( boost::ulong_long_type id ) BOOST_NOEXCEPT: id_( id ), stdcat_(), sc_init_()
|
||||
{
|
||||
}
|
||||
|
||||
@@ -155,14 +179,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) && BOOST_MSVC < 1900
|
||||
#pragma warning(pop)
|
||||
#endif
|
||||
|
||||
#if ( defined( BOOST_GCC ) && BOOST_GCC >= 40600 ) || defined( BOOST_CLANG )
|
||||
#pragma GCC diagnostic pop
|
||||
#endif
|
||||
@@ -170,9 +202,9 @@ public:
|
||||
namespace detail
|
||||
{
|
||||
|
||||
static const boost::ulong_long_type generic_category_id = ( boost::ulong_long_type( 0xB2AB117A ) << 32 ) + 0x257EDF0D;
|
||||
static const boost::ulong_long_type system_category_id = ( boost::ulong_long_type( 0x8FAFD21E ) << 32 ) + 0x25C5E09B;
|
||||
static const boost::ulong_long_type interop_category_id = ( boost::ulong_long_type( 0x943F2817 ) << 32 ) + 0xFD3A8FAF;
|
||||
static const boost::ulong_long_type generic_category_id = ( boost::ulong_long_type( 0xB2AB117A ) << 32 ) + 0x257EDFD0;
|
||||
static const boost::ulong_long_type system_category_id = generic_category_id + 1;
|
||||
static const boost::ulong_long_type interop_category_id = generic_category_id + 2;
|
||||
|
||||
BOOST_SYSTEM_CONSTEXPR inline bool failed_impl( int ev, error_category const & cat )
|
||||
{
|
||||
|
||||
@@ -14,13 +14,13 @@
|
||||
#include <boost/system/detail/error_condition.hpp>
|
||||
#include <boost/system/detail/error_code.hpp>
|
||||
#include <boost/system/detail/snprintf.hpp>
|
||||
#include <boost/system/detail/config.hpp>
|
||||
#include <boost/config.hpp>
|
||||
#include <string>
|
||||
#include <cstring>
|
||||
|
||||
namespace boost
|
||||
{
|
||||
|
||||
namespace system
|
||||
{
|
||||
|
||||
@@ -38,7 +38,7 @@ inline bool error_category::equivalent( int code, const error_condition & condit
|
||||
|
||||
inline bool error_category::equivalent( const error_code & code, int condition ) const BOOST_NOEXCEPT
|
||||
{
|
||||
return *this == code.category() && code.value() == condition;
|
||||
return code.equals( condition, *this );
|
||||
}
|
||||
|
||||
inline char const * error_category::message( int ev, char * buffer, std::size_t len ) const BOOST_NOEXCEPT
|
||||
@@ -91,49 +91,100 @@ inline char const * error_category::message( int ev, char * buffer, std::size_t
|
||||
}
|
||||
|
||||
} // namespace system
|
||||
|
||||
} // namespace boost
|
||||
|
||||
// interoperability with std::error_code, std::error_condition
|
||||
|
||||
#if defined(BOOST_SYSTEM_HAS_SYSTEM_ERROR)
|
||||
|
||||
#include <boost/system/detail/std_category.hpp>
|
||||
#include <boost/system/detail/std_category_impl.hpp>
|
||||
#include <boost/system/detail/mutex.hpp>
|
||||
#include <new>
|
||||
|
||||
inline boost::system::error_category::operator std::error_category const & () const
|
||||
namespace boost
|
||||
{
|
||||
namespace system
|
||||
{
|
||||
if( id_ == boost::system::detail::system_category_id )
|
||||
{
|
||||
static const boost::system::detail::std_category system_instance( this, 0x1F4D7 );
|
||||
return system_instance;
|
||||
}
|
||||
|
||||
if( id_ == boost::system::detail::generic_category_id )
|
||||
{
|
||||
static const boost::system::detail::std_category generic_instance( this, 0x1F4D3 );
|
||||
return generic_instance;
|
||||
}
|
||||
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" );
|
||||
|
||||
boost::system::detail::std_category* p = ps_.load( std::memory_order_acquire );
|
||||
#if defined(BOOST_MSVC) && BOOST_MSVC < 1900
|
||||
// no alignof
|
||||
#else
|
||||
|
||||
if( p != 0 )
|
||||
{
|
||||
return *p;
|
||||
}
|
||||
static_assert( alignof( decltype(stdcat_align_) ) >= alignof( boost::system::detail::std_category ), "alignof(stdcat_) is not enough for std_category" );
|
||||
|
||||
boost::system::detail::std_category* q = new detail::std_category( this, 0 );
|
||||
#endif
|
||||
|
||||
if( ps_.compare_exchange_strong( p, q, std::memory_order_release, std::memory_order_acquire ) )
|
||||
// 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 )
|
||||
{
|
||||
return *q;
|
||||
}
|
||||
else
|
||||
{
|
||||
delete q;
|
||||
return *p;
|
||||
::new( static_cast<void*>( stdcat_ ) ) boost::system::detail::std_category( this, system::detail::id_wrapper<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, system::detail::id_wrapper<0x1F4D3>() );
|
||||
return generic_instance;
|
||||
|
||||
#else
|
||||
|
||||
return std::generic_category();
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
if( id_ == detail::system_category_id )
|
||||
{
|
||||
// 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, system::detail::id_wrapper<0x1F4D7>() );
|
||||
return system_instance;
|
||||
|
||||
#else
|
||||
|
||||
return std::system_category();
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
if( sc_init_.load( std::memory_order_acquire ) == 0 )
|
||||
{
|
||||
init_stdcat();
|
||||
}
|
||||
|
||||
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
|
||||
|
||||
#endif // #if defined(BOOST_SYSTEM_HAS_SYSTEM_ERROR)
|
||||
|
||||
#endif // #ifndef BOOST_SYSTEM_DETAIL_ERROR_CATEGORY_IMPL_HPP_INCLUDED
|
||||
|
||||
@@ -18,11 +18,18 @@
|
||||
#include <boost/system/detail/interop_category.hpp>
|
||||
#include <boost/system/detail/enable_if.hpp>
|
||||
#include <boost/system/detail/is_same.hpp>
|
||||
#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>
|
||||
@@ -51,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:
|
||||
@@ -82,11 +91,36 @@ private:
|
||||
// >3: pointer to source_location, failed_ in lsb
|
||||
boost::uintptr_t lc_flags_;
|
||||
|
||||
private:
|
||||
|
||||
char const* category_name() const BOOST_NOEXCEPT
|
||||
{
|
||||
// return category().name();
|
||||
|
||||
if( lc_flags_ == 0 )
|
||||
{
|
||||
// must match detail::system_error_category::name()
|
||||
return "system";
|
||||
}
|
||||
else if( lc_flags_ == 1 )
|
||||
{
|
||||
// must match detail::interop_error_category::name()
|
||||
return "std:unknown";
|
||||
}
|
||||
else
|
||||
{
|
||||
return d1_.cat_->name();
|
||||
}
|
||||
}
|
||||
|
||||
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 )
|
||||
{
|
||||
}
|
||||
@@ -106,18 +140,45 @@ public:
|
||||
}
|
||||
|
||||
template<class ErrorCodeEnum> BOOST_SYSTEM_CONSTEXPR error_code( ErrorCodeEnum e,
|
||||
typename detail::enable_if<is_error_code_enum<ErrorCodeEnum>::value>::type* = 0 ) BOOST_NOEXCEPT:
|
||||
d1_(), lc_flags_( 0 )
|
||||
typename detail::enable_if<
|
||||
is_error_code_enum<ErrorCodeEnum>::value
|
||||
#if defined(BOOST_SYSTEM_HAS_SYSTEM_ERROR)
|
||||
|| std::is_error_code_enum<ErrorCodeEnum>::value
|
||||
#endif
|
||||
>::type* = 0 ) BOOST_NOEXCEPT: d1_(), lc_flags_( 0 )
|
||||
{
|
||||
*this = make_error_code( e );
|
||||
}
|
||||
|
||||
error_code( error_code const& ec, source_location const * loc ) BOOST_NOEXCEPT:
|
||||
d1_(), lc_flags_( 0 )
|
||||
{
|
||||
*this = ec;
|
||||
|
||||
if( ec.lc_flags_ != 0 && ec.lc_flags_ != 1 )
|
||||
{
|
||||
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
|
||||
@@ -134,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
|
||||
@@ -160,7 +226,11 @@ public:
|
||||
#if defined(BOOST_SYSTEM_HAS_SYSTEM_ERROR)
|
||||
|
||||
std::error_code const& ec = *reinterpret_cast<std::error_code const*>( d2_ );
|
||||
return ec.value() + 1000 * static_cast<unsigned>( reinterpret_cast<boost::uintptr_t>( &ec.category() ) % 2097143 ); // 2^21-9, prime
|
||||
|
||||
unsigned cv = static_cast<unsigned>( ec.value() );
|
||||
unsigned ch = static_cast<unsigned>( reinterpret_cast<boost::uintptr_t>( &ec.category() ) % 2097143 ); // 2^21-9, prime
|
||||
|
||||
return static_cast<int>( cv + 1000 * ch );
|
||||
#else
|
||||
|
||||
return -1;
|
||||
@@ -202,7 +272,14 @@ public:
|
||||
|
||||
#endif
|
||||
|
||||
return category().message( value() );
|
||||
if( lc_flags_ == 0 )
|
||||
{
|
||||
return detail::system_error_category_message( value() );
|
||||
}
|
||||
else
|
||||
{
|
||||
return category().message( value() );
|
||||
}
|
||||
}
|
||||
|
||||
char const * message( char * buffer, std::size_t len ) const BOOST_NOEXCEPT
|
||||
@@ -210,23 +287,33 @@ public:
|
||||
#if defined(BOOST_SYSTEM_HAS_SYSTEM_ERROR)
|
||||
if( lc_flags_ == 1 )
|
||||
{
|
||||
std::error_code const& ec = *reinterpret_cast<std::error_code const*>( d2_ );
|
||||
|
||||
#if !defined(BOOST_NO_EXCEPTIONS)
|
||||
try
|
||||
#endif
|
||||
{
|
||||
std::error_code const& ec = *reinterpret_cast<std::error_code const*>( d2_ );
|
||||
detail::snprintf( buffer, len, "%s", ec.message().c_str() );
|
||||
return buffer;
|
||||
}
|
||||
#if !defined(BOOST_NO_EXCEPTIONS)
|
||||
catch( ... )
|
||||
{
|
||||
detail::snprintf( buffer, len, "No message text available for error std:%s:%d", ec.category().name(), ec.value() );
|
||||
return buffer;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
return category().message( value(), buffer, len );
|
||||
if( lc_flags_ == 0 )
|
||||
{
|
||||
return detail::system_error_category_message( value(), buffer, len );
|
||||
}
|
||||
else
|
||||
{
|
||||
return category().message( value(), buffer, len );
|
||||
}
|
||||
}
|
||||
|
||||
BOOST_SYSTEM_CONSTEXPR bool failed() const BOOST_NOEXCEPT
|
||||
@@ -285,6 +372,30 @@ public:
|
||||
|
||||
// relationals:
|
||||
|
||||
private:
|
||||
|
||||
// private equality for use in error_category::equivalent
|
||||
|
||||
friend class error_category;
|
||||
|
||||
BOOST_SYSTEM_CONSTEXPR bool equals( int val, error_category const& cat ) const BOOST_NOEXCEPT
|
||||
{
|
||||
if( lc_flags_ == 0 )
|
||||
{
|
||||
return val == 0 && cat.id_ == detail::system_category_id;
|
||||
}
|
||||
else if( lc_flags_ == 1 )
|
||||
{
|
||||
return cat.id_ == detail::interop_category_id && val == value();
|
||||
}
|
||||
else
|
||||
{
|
||||
return val == d1_.val_ && cat == *d1_.cat_;
|
||||
}
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
// the more symmetrical non-member syntax allows enum
|
||||
// conversions work for both rhs and lhs.
|
||||
|
||||
@@ -292,7 +403,12 @@ public:
|
||||
{
|
||||
#if defined(BOOST_SYSTEM_HAS_SYSTEM_ERROR)
|
||||
|
||||
if( lhs.lc_flags_ == 1 && rhs.lc_flags_ == 1 )
|
||||
bool s1 = lhs.lc_flags_ == 1;
|
||||
bool s2 = rhs.lc_flags_ == 1;
|
||||
|
||||
if( s1 != s2 ) return false;
|
||||
|
||||
if( s1 && s2 )
|
||||
{
|
||||
std::error_code const& e1 = *reinterpret_cast<std::error_code const*>( lhs.d2_ );
|
||||
std::error_code const& e2 = *reinterpret_cast<std::error_code const*>( rhs.d2_ );
|
||||
@@ -310,7 +426,13 @@ public:
|
||||
{
|
||||
#if defined(BOOST_SYSTEM_HAS_SYSTEM_ERROR)
|
||||
|
||||
if( lhs.lc_flags_ == 1 && rhs.lc_flags_ == 1 )
|
||||
bool s1 = lhs.lc_flags_ == 1;
|
||||
bool s2 = rhs.lc_flags_ == 1;
|
||||
|
||||
if( s1 < s2 ) return true;
|
||||
if( s2 < s1 ) return false;
|
||||
|
||||
if( s1 && s2 )
|
||||
{
|
||||
std::error_code const& e1 = *reinterpret_cast<std::error_code const*>( lhs.d2_ );
|
||||
std::error_code const& e2 = *reinterpret_cast<std::error_code const*>( rhs.d2_ );
|
||||
@@ -329,48 +451,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
|
||||
@@ -479,8 +559,16 @@ public:
|
||||
}
|
||||
else if( lc_flags_ == 0 )
|
||||
{
|
||||
//return std::error_code();
|
||||
// This condition must be the same as the one in error_category_impl.hpp
|
||||
#if defined(BOOST_SYSTEM_AVOID_STD_SYSTEM_CATEGORY)
|
||||
|
||||
return std::error_code( 0, boost::system::system_category() );
|
||||
|
||||
#else
|
||||
|
||||
return std::error_code();
|
||||
|
||||
#endif
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -525,18 +613,18 @@ public:
|
||||
{
|
||||
std::error_code const& e2 = *reinterpret_cast<std::error_code const*>( d2_ );
|
||||
|
||||
char buffer[ 32 ];
|
||||
detail::snprintf( buffer, sizeof( buffer ), "%d", e2.value() );
|
||||
std::string r( "std:" );
|
||||
r += e2.category().name();
|
||||
detail::append_int( r, e2.value() );
|
||||
|
||||
return std::string( "std:" ) + e2.category().name() + ":" + buffer;
|
||||
return r;
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
char buffer[ 32 ];
|
||||
detail::snprintf( buffer, sizeof( buffer ), "%d", value() );
|
||||
|
||||
return std::string( category().name() ) + ":" + buffer;
|
||||
std::string r = category_name();
|
||||
detail::append_int( r, value() );
|
||||
return r;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -544,10 +632,58 @@ public:
|
||||
inline friend std::basic_ostream<Ch, Tr>&
|
||||
operator<< (std::basic_ostream<Ch, Tr>& os, error_code const & ec)
|
||||
{
|
||||
return os << ec.to_string();
|
||||
return os << ec.to_string().c_str();
|
||||
}
|
||||
|
||||
std::string what() const
|
||||
{
|
||||
std::string r = message();
|
||||
|
||||
r += " [";
|
||||
r += to_string();
|
||||
|
||||
if( has_location() )
|
||||
{
|
||||
r += " at ";
|
||||
r += location().to_string();
|
||||
}
|
||||
|
||||
r += "]";
|
||||
return r;
|
||||
}
|
||||
};
|
||||
|
||||
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)
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
#include <boost/system/detail/enable_if.hpp>
|
||||
#include <boost/system/detail/is_same.hpp>
|
||||
#include <boost/system/detail/errc.hpp>
|
||||
#include <boost/system/detail/append_int.hpp>
|
||||
#include <boost/system/is_error_condition_enum.hpp>
|
||||
#include <boost/system/detail/config.hpp>
|
||||
#include <boost/config.hpp>
|
||||
@@ -47,6 +48,13 @@ private:
|
||||
int val_;
|
||||
error_category const * cat_;
|
||||
|
||||
private:
|
||||
|
||||
boost::ulong_long_type cat_id() const BOOST_NOEXCEPT
|
||||
{
|
||||
return cat_? cat_->id_: detail::generic_category_id;
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
// constructors:
|
||||
@@ -122,7 +130,7 @@ public:
|
||||
}
|
||||
else
|
||||
{
|
||||
return generic_category().message( value() );
|
||||
return detail::generic_error_category_message( value() );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -134,7 +142,7 @@ public:
|
||||
}
|
||||
else
|
||||
{
|
||||
return generic_category().message( value(), buffer, len );
|
||||
return detail::generic_error_category_message( value(), buffer, len );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -180,7 +188,22 @@ public:
|
||||
|
||||
BOOST_SYSTEM_CONSTEXPR inline friend bool operator==( const error_condition & lhs, const error_condition & rhs ) BOOST_NOEXCEPT
|
||||
{
|
||||
return lhs.val_ == rhs.val_ && lhs.category() == rhs.category();
|
||||
if( lhs.val_ != rhs.val_ )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else if( lhs.cat_ == 0 )
|
||||
{
|
||||
return rhs.cat_id() == detail::generic_category_id;
|
||||
}
|
||||
else if( rhs.cat_ == 0 )
|
||||
{
|
||||
return lhs.cat_id() == detail::generic_category_id;
|
||||
}
|
||||
else
|
||||
{
|
||||
return *lhs.cat_ == *rhs.cat_;
|
||||
}
|
||||
}
|
||||
|
||||
BOOST_SYSTEM_CONSTEXPR inline friend bool operator<( const error_condition & lhs, const error_condition & rhs ) BOOST_NOEXCEPT
|
||||
@@ -199,7 +222,23 @@ public:
|
||||
|
||||
operator std::error_condition () const
|
||||
{
|
||||
// This condition must be the same as the one in error_category_impl.hpp
|
||||
#if defined(BOOST_SYSTEM_AVOID_STD_GENERIC_CATEGORY)
|
||||
|
||||
return std::error_condition( value(), category() );
|
||||
|
||||
#else
|
||||
|
||||
if( cat_ )
|
||||
{
|
||||
return std::error_condition( val_, *cat_ );
|
||||
}
|
||||
else
|
||||
{
|
||||
return std::error_condition( val_, std::generic_category() );
|
||||
}
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
inline friend bool operator==( std::error_code const & lhs, error_condition const & rhs ) BOOST_NOEXCEPT
|
||||
@@ -222,16 +261,83 @@ 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
|
||||
{
|
||||
std::string r( "cond:" );
|
||||
|
||||
if( cat_ )
|
||||
{
|
||||
r += cat_->name();
|
||||
}
|
||||
else
|
||||
{
|
||||
r += "generic";
|
||||
}
|
||||
|
||||
detail::append_int( r, value() );
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
template<class Ch, class Tr>
|
||||
inline friend std::basic_ostream<Ch, Tr>&
|
||||
operator<< (std::basic_ostream<Ch, Tr>& os, error_condition const & en)
|
||||
{
|
||||
{
|
||||
os << "cond:" << en.category().name() << ':' << en.value();
|
||||
}
|
||||
|
||||
os << en.to_string();
|
||||
return os;
|
||||
}
|
||||
};
|
||||
|
||||
128
include/boost/system/detail/mutex.hpp
Normal file
128
include/boost/system/detail/mutex.hpp
Normal file
@@ -0,0 +1,128 @@
|
||||
#ifndef BOOST_SYSTEM_DETAIL_MUTEX_HPP_INCLUDED
|
||||
#define BOOST_SYSTEM_DETAIL_MUTEX_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>
|
||||
|
||||
#if defined(BOOST_SYSTEM_DISABLE_THREADS)
|
||||
|
||||
namespace boost
|
||||
{
|
||||
namespace system
|
||||
{
|
||||
namespace detail
|
||||
{
|
||||
|
||||
struct mutex
|
||||
{
|
||||
void lock()
|
||||
{
|
||||
}
|
||||
|
||||
void unlock()
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace detail
|
||||
} // namespace system
|
||||
} // namespace boost
|
||||
|
||||
#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>
|
||||
|
||||
namespace boost
|
||||
{
|
||||
namespace system
|
||||
{
|
||||
namespace detail
|
||||
{
|
||||
|
||||
using std::mutex;
|
||||
|
||||
} // namespace detail
|
||||
} // namespace system
|
||||
} // namespace boost
|
||||
|
||||
#endif // defined(BOOST_SYSTEM_HAS_MSSTL_SHARED_MUTEX)
|
||||
#endif // defined(BOOST_SYSTEM_DISABLE_THREADS)
|
||||
|
||||
namespace boost
|
||||
{
|
||||
namespace system
|
||||
{
|
||||
namespace detail
|
||||
{
|
||||
|
||||
template<class Mtx> class lock_guard
|
||||
{
|
||||
private:
|
||||
|
||||
Mtx& mtx_;
|
||||
|
||||
private:
|
||||
|
||||
lock_guard( lock_guard const& );
|
||||
lock_guard& operator=( lock_guard const& );
|
||||
|
||||
public:
|
||||
|
||||
explicit lock_guard( Mtx& mtx ): mtx_( mtx )
|
||||
{
|
||||
mtx_.lock();
|
||||
}
|
||||
|
||||
~lock_guard()
|
||||
{
|
||||
mtx_.unlock();
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace detail
|
||||
} // namespace system
|
||||
} // namespace boost
|
||||
|
||||
#endif // #ifndef BOOST_SYSTEM_DETAIL_MUTEX_HPP_INCLUDED
|
||||
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
|
||||
@@ -49,6 +49,9 @@ inline void snprintf( char * buffer, std::size_t len, char const * format, ... )
|
||||
|
||||
#else
|
||||
|
||||
#if defined(__GNUC__) && __GNUC__ >= 3
|
||||
__attribute__((__format__ (__printf__, 3, 4)))
|
||||
#endif
|
||||
inline void snprintf( char * buffer, std::size_t len, char const * format, ... )
|
||||
{
|
||||
va_list args;
|
||||
|
||||
@@ -11,9 +11,7 @@
|
||||
// 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 <boost/config.hpp>
|
||||
#include <system_error>
|
||||
|
||||
//
|
||||
@@ -27,6 +25,8 @@ namespace system
|
||||
namespace detail
|
||||
{
|
||||
|
||||
template<unsigned Id> struct id_wrapper {};
|
||||
|
||||
class BOOST_SYMBOL_VISIBLE std_category: public std::error_category
|
||||
{
|
||||
private:
|
||||
@@ -35,20 +35,29 @@ private:
|
||||
|
||||
public:
|
||||
|
||||
explicit std_category( boost::system::error_category const * pc, unsigned id ): pc_( pc )
|
||||
boost::system::error_category const & original_category() const BOOST_NOEXCEPT
|
||||
{
|
||||
return *pc_;
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
template<unsigned Id>
|
||||
explicit std_category( boost::system::error_category const * pc, id_wrapper<Id> ): pc_( pc )
|
||||
{
|
||||
if( id != 0 )
|
||||
{
|
||||
#if defined(_MSC_VER) && defined(_CPPLIB_VER) && _MSC_VER >= 1900 && _MSC_VER < 2000
|
||||
|
||||
// Poking into the protected _Addr member of std::error_category
|
||||
// is not a particularly good programming practice, but what can
|
||||
// you do
|
||||
// We used to assign to the protected _Addr member of std::error_category
|
||||
// here when Id != 0, but this should never happen now because this code
|
||||
// path is no longer used
|
||||
|
||||
_Addr = id;
|
||||
#if !defined(BOOST_NO_CXX11_STATIC_ASSERT)
|
||||
|
||||
static_assert( Id == 0, "This constructor should only be called with Id == 0 under MS STL 14.0+" );
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
const char * name() const BOOST_NOEXCEPT BOOST_OVERRIDE
|
||||
@@ -66,72 +75,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
|
||||
@@ -59,6 +59,7 @@ inline int system_category_condition_win32( int ev ) BOOST_NOEXCEPT
|
||||
case ERROR_ACCESS_DENIED_: return permission_denied;
|
||||
case ERROR_ALREADY_EXISTS_: return file_exists;
|
||||
case ERROR_BAD_NETPATH_: return no_such_file_or_directory;
|
||||
case ERROR_BAD_NET_NAME_: return no_such_file_or_directory;
|
||||
case ERROR_BAD_UNIT_: return no_such_device;
|
||||
case ERROR_BROKEN_PIPE_: return broken_pipe;
|
||||
case ERROR_BUFFER_OVERFLOW_: return filename_too_long;
|
||||
@@ -75,6 +76,7 @@ inline int system_category_condition_win32( int ev ) BOOST_NOEXCEPT
|
||||
case ERROR_DIR_NOT_EMPTY_: return directory_not_empty;
|
||||
case ERROR_DIRECTORY_: return invalid_argument; // WinError.h: "The directory name is invalid"
|
||||
case ERROR_DISK_FULL_: return no_space_on_device;
|
||||
case ERROR_FILENAME_EXCED_RANGE_: return filename_too_long;
|
||||
case ERROR_FILE_EXISTS_: return file_exists;
|
||||
case ERROR_FILE_NOT_FOUND_: return no_such_file_or_directory;
|
||||
case ERROR_HANDLE_DISK_FULL_: return no_space_on_device;
|
||||
@@ -100,12 +102,16 @@ inline int system_category_condition_win32( int ev ) BOOST_NOEXCEPT
|
||||
case ERROR_REPARSE_TAG_INVALID_: return invalid_argument;
|
||||
case ERROR_RETRY_: return resource_unavailable_try_again;
|
||||
case ERROR_SEEK_: return io_error;
|
||||
case ERROR_SEM_TIMEOUT_: return timed_out;
|
||||
case ERROR_SHARING_VIOLATION_: return permission_denied;
|
||||
case ERROR_NOT_SUPPORTED_: return not_supported; // WinError.h: "The request is not supported."
|
||||
case ERROR_TIMEOUT_: return timed_out;
|
||||
case ERROR_TOO_MANY_OPEN_FILES_: return too_many_files_open;
|
||||
case ERROR_WRITE_FAULT_: return io_error;
|
||||
case ERROR_WRITE_PROTECT_: return permission_denied;
|
||||
|
||||
case 258: return timed_out; // WAIT_TIMEOUT
|
||||
|
||||
case WSAEACCES_: return permission_denied;
|
||||
case WSAEADDRINUSE_: return address_in_use;
|
||||
case WSAEADDRNOTAVAIL_: return address_not_available;
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
// See library home page at http://www.boost.org/libs/system
|
||||
|
||||
#include <boost/system/detail/system_category.hpp>
|
||||
#include <boost/system/detail/system_category_message.hpp>
|
||||
#include <boost/system/detail/error_condition.hpp>
|
||||
#include <boost/system/api_config.hpp>
|
||||
|
||||
@@ -22,7 +23,6 @@
|
||||
|
||||
#if defined(BOOST_WINDOWS_API)
|
||||
|
||||
#include <boost/system/detail/system_category_message_win32.hpp>
|
||||
#include <boost/system/detail/system_category_condition_win32.hpp>
|
||||
|
||||
inline boost::system::error_condition boost::system::detail::system_error_category::default_error_condition( int ev ) const BOOST_NOEXCEPT
|
||||
@@ -39,35 +39,23 @@ inline boost::system::error_condition boost::system::detail::system_error_catego
|
||||
}
|
||||
}
|
||||
|
||||
inline std::string boost::system::detail::system_error_category::message( int ev ) const
|
||||
{
|
||||
return system_category_message_win32( ev );
|
||||
}
|
||||
|
||||
inline char const * boost::system::detail::system_error_category::message( int ev, char * buffer, std::size_t len ) const BOOST_NOEXCEPT
|
||||
{
|
||||
return system_category_message_win32( ev, buffer, len );
|
||||
}
|
||||
|
||||
#else // #if defined(BOOST_WINDOWS_API)
|
||||
|
||||
#include <boost/system/detail/generic_category_message.hpp>
|
||||
|
||||
inline boost::system::error_condition boost::system::detail::system_error_category::default_error_condition( int ev ) const BOOST_NOEXCEPT
|
||||
{
|
||||
return error_condition( boost::system::detail::generic_value_tag( ev ) );
|
||||
}
|
||||
|
||||
#endif // #if defined(BOOST_WINDOWS_API)
|
||||
|
||||
inline std::string boost::system::detail::system_error_category::message( int ev ) const
|
||||
{
|
||||
return generic_error_category_message( ev );
|
||||
return system_error_category_message( ev );
|
||||
}
|
||||
|
||||
inline char const * boost::system::detail::system_error_category::message( int ev, char * buffer, std::size_t len ) const BOOST_NOEXCEPT
|
||||
{
|
||||
return generic_error_category_message( ev, buffer, len );
|
||||
return system_error_category_message( ev, buffer, len );
|
||||
}
|
||||
|
||||
#endif // #if defined(BOOST_WINDOWS_API)
|
||||
|
||||
#endif // #ifndef BOOST_SYSTEM_DETAIL_SYSTEM_CATEGORY_IMPL_HPP_INCLUDED
|
||||
|
||||
71
include/boost/system/detail/system_category_message.hpp
Normal file
71
include/boost/system/detail/system_category_message.hpp
Normal file
@@ -0,0 +1,71 @@
|
||||
#ifndef BOOST_SYSTEM_DETAIL_SYSTEM_CATEGORY_MESSAGE_HPP_INCLUDED
|
||||
#define BOOST_SYSTEM_DETAIL_SYSTEM_CATEGORY_MESSAGE_HPP_INCLUDED
|
||||
|
||||
// Implementation of system_error_category_message
|
||||
//
|
||||
// Copyright 2018, 2022 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/api_config.hpp>
|
||||
|
||||
#if !defined(BOOST_POSIX_API) && !defined(BOOST_WINDOWS_API)
|
||||
# error BOOST_POSIX_API or BOOST_WINDOWS_API must be defined
|
||||
#endif
|
||||
|
||||
#if defined(BOOST_WINDOWS_API)
|
||||
|
||||
#include <boost/system/detail/system_category_message_win32.hpp>
|
||||
|
||||
namespace boost
|
||||
{
|
||||
namespace system
|
||||
{
|
||||
namespace detail
|
||||
{
|
||||
|
||||
inline std::string system_error_category_message( int ev )
|
||||
{
|
||||
return system_category_message_win32( ev );
|
||||
}
|
||||
|
||||
inline char const * system_error_category_message( int ev, char * buffer, std::size_t len ) BOOST_NOEXCEPT
|
||||
{
|
||||
return system_category_message_win32( ev, buffer, len );
|
||||
}
|
||||
|
||||
} // namespace detail
|
||||
} // namespace system
|
||||
} // namespace boost
|
||||
|
||||
#else // #if defined(BOOST_WINDOWS_API)
|
||||
|
||||
#include <boost/system/detail/generic_category_message.hpp>
|
||||
|
||||
namespace boost
|
||||
{
|
||||
namespace system
|
||||
{
|
||||
namespace detail
|
||||
{
|
||||
|
||||
inline std::string system_error_category_message( int ev )
|
||||
{
|
||||
return generic_error_category_message( ev );
|
||||
}
|
||||
|
||||
inline char const * system_error_category_message( int ev, char * buffer, std::size_t len ) BOOST_NOEXCEPT
|
||||
{
|
||||
return generic_error_category_message( ev, buffer, len );
|
||||
}
|
||||
|
||||
} // namespace detail
|
||||
} // namespace system
|
||||
} // namespace boost
|
||||
|
||||
#endif // #if defined(BOOST_WINDOWS_API)
|
||||
|
||||
#endif // #ifndef BOOST_SYSTEM_DETAIL_SYSTEM_CATEGORY_MESSAGE_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
|
||||
{
|
||||
|
||||
@@ -10,13 +10,6 @@
|
||||
#ifndef BOOST_SYSTEM_LINUX_ERROR_HPP
|
||||
#define BOOST_SYSTEM_LINUX_ERROR_HPP
|
||||
|
||||
#include <boost/config/pragma_message.hpp>
|
||||
|
||||
#if !defined(BOOST_ALLOW_DEPRECATED_HEADERS)
|
||||
BOOST_PRAGMA_MESSAGE("This header is deprecated and is slated for removal."
|
||||
" If you want it retained, please open an issue in github.com/boostorg/system.")
|
||||
#endif
|
||||
|
||||
// This header is effectively empty for compiles on operating systems where
|
||||
// it is not applicable.
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#ifndef BOOST_SYSTEM_RESULT_HPP_INCLUDED
|
||||
#define BOOST_SYSTEM_RESULT_HPP_INCLUDED
|
||||
|
||||
// Copyright 2017, 2021 Peter Dimov.
|
||||
// Copyright 2017, 2021, 2022 Peter Dimov.
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// https://www.boost.org/LICENSE_1_0.txt
|
||||
|
||||
@@ -11,11 +11,14 @@
|
||||
#include <boost/system/detail/error_category_impl.hpp>
|
||||
#include <boost/variant2/variant.hpp>
|
||||
#include <boost/throw_exception.hpp>
|
||||
#include <boost/assert/source_location.hpp>
|
||||
#include <boost/assert.hpp>
|
||||
#include <boost/config.hpp>
|
||||
#include <type_traits>
|
||||
#include <utility>
|
||||
#include <iosfwd>
|
||||
#include <system_error>
|
||||
#include <exception>
|
||||
|
||||
//
|
||||
|
||||
@@ -26,11 +29,47 @@ namespace system
|
||||
|
||||
// throw_exception_from_error
|
||||
|
||||
BOOST_NORETURN inline void throw_exception_from_error( error_code const & e )
|
||||
#if defined(__GNUC__) && __GNUC__ >= 7 && __GNUC__ <= 8
|
||||
# pragma GCC diagnostic push
|
||||
# pragma GCC diagnostic ignored "-Wattributes"
|
||||
#endif
|
||||
|
||||
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 ) );
|
||||
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_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
|
||||
# pragma GCC diagnostic pop
|
||||
#endif
|
||||
|
||||
// in_place_*
|
||||
|
||||
using in_place_value_t = variant2::in_place_index_t<0>;
|
||||
@@ -39,6 +78,19 @@ constexpr in_place_value_t in_place_value{};
|
||||
using in_place_error_t = variant2::in_place_index_t<1>;
|
||||
constexpr in_place_error_t in_place_error{};
|
||||
|
||||
namespace detail
|
||||
{
|
||||
|
||||
template<class T> using remove_cvref = typename std::remove_cv< typename std::remove_reference<T>::type >::type;
|
||||
|
||||
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
|
||||
|
||||
template<class T, class E = error_code> class result
|
||||
@@ -47,6 +99,14 @@ private:
|
||||
|
||||
variant2::variant<T, E> v_;
|
||||
|
||||
public:
|
||||
|
||||
using value_type = T;
|
||||
using error_type = E;
|
||||
|
||||
static constexpr in_place_value_t in_place_value{};
|
||||
static constexpr in_place_error_t in_place_error{};
|
||||
|
||||
public:
|
||||
|
||||
// constructors
|
||||
@@ -62,35 +122,11 @@ public:
|
||||
{
|
||||
}
|
||||
|
||||
// explicit, value
|
||||
template<class A, class En = typename std::enable_if<
|
||||
std::is_constructible<T, A>::value &&
|
||||
!std::is_convertible<A, T>::value &&
|
||||
!std::is_constructible<E, A>::value
|
||||
>::type>
|
||||
explicit constexpr result( A&& a )
|
||||
noexcept( std::is_nothrow_constructible<T, A>::value )
|
||||
: v_( in_place_value, std::forward<A>(a) )
|
||||
{
|
||||
}
|
||||
|
||||
// explicit, error
|
||||
template<class A, class En2 = void, class En = typename std::enable_if<
|
||||
std::is_constructible<E, A>::value &&
|
||||
!std::is_convertible<A, E>::value &&
|
||||
!std::is_constructible<T, A>::value
|
||||
>::type>
|
||||
explicit constexpr result( A&& a )
|
||||
noexcept( std::is_nothrow_constructible<E, A>::value )
|
||||
: v_( in_place_error, std::forward<A>(a) )
|
||||
{
|
||||
}
|
||||
|
||||
// implicit, value
|
||||
template<class A, class En2 = void, class En3 = void, class En = typename std::enable_if<
|
||||
template<class A = T, typename std::enable_if<
|
||||
std::is_convertible<A, T>::value &&
|
||||
!std::is_constructible<E, A>::value
|
||||
>::type>
|
||||
!(detail::is_errc_t<A>::value && std::is_arithmetic<T>::value) &&
|
||||
!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) )
|
||||
@@ -98,35 +134,35 @@ public:
|
||||
}
|
||||
|
||||
// implicit, error
|
||||
template<class A, class En2 = void, class En3 = void, class En4 = void, class En = typename std::enable_if<
|
||||
template<class A = E, class = void, typename std::enable_if<
|
||||
std::is_convertible<A, E>::value &&
|
||||
!std::is_constructible<T, A>::value
|
||||
>::type>
|
||||
!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) )
|
||||
{
|
||||
}
|
||||
|
||||
// more than one arg, value
|
||||
// explicit, value
|
||||
template<class... A, class En = typename std::enable_if<
|
||||
std::is_constructible<T, A...>::value &&
|
||||
!std::is_constructible<E, A...>::value &&
|
||||
sizeof...(A) >= 2
|
||||
detail::is_constructible<T, A...>::value &&
|
||||
!(detail::is_errc_t<A...>::value && std::is_arithmetic<T>::value) &&
|
||||
!detail::is_constructible<E, A...>::value &&
|
||||
sizeof...(A) >= 1
|
||||
>::type>
|
||||
constexpr result( A&&... a )
|
||||
explicit constexpr result( A&&... a )
|
||||
noexcept( std::is_nothrow_constructible<T, A...>::value )
|
||||
: v_( in_place_value, std::forward<A>(a)... )
|
||||
{
|
||||
}
|
||||
|
||||
// more than one arg, error
|
||||
// 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 &&
|
||||
sizeof...(A) >= 2
|
||||
!detail::is_constructible<T, A...>::value &&
|
||||
detail::is_constructible<E, A...>::value &&
|
||||
sizeof...(A) >= 1
|
||||
>::type>
|
||||
constexpr result( A&&... a )
|
||||
explicit constexpr result( A&&... a )
|
||||
noexcept( std::is_nothrow_constructible<E, A...>::value )
|
||||
: v_( in_place_error, std::forward<A>(a)... )
|
||||
{
|
||||
@@ -152,6 +188,45 @@ 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<result<T2, E2> const&, T>::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 &&
|
||||
!std::is_convertible<result<T2, E2>&&, T>::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
|
||||
@@ -161,7 +236,7 @@ public:
|
||||
|
||||
constexpr bool has_error() const noexcept
|
||||
{
|
||||
return v_.index() != 0;
|
||||
return v_.index() == 1;
|
||||
}
|
||||
|
||||
constexpr explicit operator bool() const noexcept
|
||||
@@ -172,7 +247,7 @@ public:
|
||||
// checked value access
|
||||
#if defined( BOOST_NO_CXX11_REF_QUALIFIERS )
|
||||
|
||||
BOOST_CXX14_CONSTEXPR T value() const
|
||||
BOOST_CXX14_CONSTEXPR T value( boost::source_location const& loc = BOOST_CURRENT_LOCATION ) const
|
||||
{
|
||||
if( has_value() )
|
||||
{
|
||||
@@ -180,13 +255,13 @@ public:
|
||||
}
|
||||
else
|
||||
{
|
||||
throw_exception_from_error( variant2::unsafe_get<1>( v_ ) );
|
||||
throw_exception_from_error( variant2::unsafe_get<1>( v_ ), loc );
|
||||
}
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
BOOST_CXX14_CONSTEXPR T& value() &
|
||||
BOOST_CXX14_CONSTEXPR T& value( boost::source_location const& loc = BOOST_CURRENT_LOCATION ) &
|
||||
{
|
||||
if( has_value() )
|
||||
{
|
||||
@@ -194,11 +269,11 @@ public:
|
||||
}
|
||||
else
|
||||
{
|
||||
throw_exception_from_error( variant2::unsafe_get<1>( v_ ) );
|
||||
throw_exception_from_error( variant2::unsafe_get<1>( v_ ), loc );
|
||||
}
|
||||
}
|
||||
|
||||
BOOST_CXX14_CONSTEXPR T const& value() const&
|
||||
BOOST_CXX14_CONSTEXPR T const& value( boost::source_location const& loc = BOOST_CURRENT_LOCATION ) const&
|
||||
{
|
||||
if( has_value() )
|
||||
{
|
||||
@@ -206,18 +281,37 @@ public:
|
||||
}
|
||||
else
|
||||
{
|
||||
throw_exception_from_error( variant2::unsafe_get<1>( v_ ) );
|
||||
throw_exception_from_error( variant2::unsafe_get<1>( v_ ), loc );
|
||||
}
|
||||
}
|
||||
|
||||
BOOST_CXX14_CONSTEXPR T&& value() &&
|
||||
template<class U = T>
|
||||
BOOST_CXX14_CONSTEXPR
|
||||
typename std::enable_if<std::is_move_constructible<U>::value, T>::type
|
||||
value( boost::source_location const& loc = BOOST_CURRENT_LOCATION ) &&
|
||||
{
|
||||
return std::move( value() );
|
||||
return std::move( value( loc ) );
|
||||
}
|
||||
|
||||
BOOST_CXX14_CONSTEXPR T const&& value() const&&
|
||||
template<class U = T>
|
||||
BOOST_CXX14_CONSTEXPR
|
||||
typename std::enable_if<!std::is_move_constructible<U>::value, T&&>::type
|
||||
value( boost::source_location const& loc = BOOST_CURRENT_LOCATION ) &&
|
||||
{
|
||||
return std::move( value() );
|
||||
return std::move( value( loc ) );
|
||||
}
|
||||
|
||||
template<class U = T>
|
||||
BOOST_CXX14_CONSTEXPR
|
||||
typename std::enable_if<std::is_move_constructible<U>::value, T>::type
|
||||
value() const && = delete;
|
||||
|
||||
template<class U = T>
|
||||
BOOST_CXX14_CONSTEXPR
|
||||
typename std::enable_if<!std::is_move_constructible<U>::value, T const&&>::type
|
||||
value( boost::source_location const& loc = BOOST_CURRENT_LOCATION ) const &&
|
||||
{
|
||||
return std::move( value( loc ) );
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -274,12 +368,31 @@ public:
|
||||
return *p;
|
||||
}
|
||||
|
||||
BOOST_CXX14_CONSTEXPR T&& operator*() && noexcept
|
||||
template<class U = T>
|
||||
BOOST_CXX14_CONSTEXPR
|
||||
typename std::enable_if<std::is_move_constructible<U>::value, T>::type
|
||||
operator*() && noexcept(std::is_nothrow_move_constructible<T>::value)
|
||||
{
|
||||
return std::move(**this);
|
||||
}
|
||||
|
||||
BOOST_CXX14_CONSTEXPR T const&& operator*() const && noexcept
|
||||
template<class U = T>
|
||||
BOOST_CXX14_CONSTEXPR
|
||||
typename std::enable_if<!std::is_move_constructible<U>::value, T&&>::type
|
||||
operator*() && noexcept
|
||||
{
|
||||
return std::move(**this);
|
||||
}
|
||||
|
||||
template<class U = T>
|
||||
BOOST_CXX14_CONSTEXPR
|
||||
typename std::enable_if<std::is_move_constructible<U>::value, T>::type
|
||||
operator*() const && noexcept = delete;
|
||||
|
||||
template<class U = T>
|
||||
BOOST_CXX14_CONSTEXPR
|
||||
typename std::enable_if<!std::is_move_constructible<U>::value, T const&&>::type
|
||||
operator*() const && noexcept
|
||||
{
|
||||
return std::move(**this);
|
||||
}
|
||||
@@ -288,12 +401,26 @@ 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>
|
||||
BOOST_CXX14_CONSTEXPR T& emplace( A&&... a )
|
||||
{
|
||||
return v_.template emplace<0>( std::forward<A>(a)... );
|
||||
}
|
||||
|
||||
// swap
|
||||
|
||||
BOOST_CXX14_CONSTEXPR void swap( result& r )
|
||||
@@ -345,6 +472,14 @@ private:
|
||||
|
||||
variant2::variant<variant2::monostate, E> v_;
|
||||
|
||||
public:
|
||||
|
||||
using value_type = void;
|
||||
using error_type = E;
|
||||
|
||||
static constexpr in_place_value_t in_place_value{};
|
||||
static constexpr in_place_error_t in_place_error{};
|
||||
|
||||
public:
|
||||
|
||||
// constructors
|
||||
@@ -412,7 +547,7 @@ public:
|
||||
|
||||
constexpr bool has_error() const noexcept
|
||||
{
|
||||
return v_.index() != 0;
|
||||
return v_.index() == 1;
|
||||
}
|
||||
|
||||
constexpr explicit operator bool() const noexcept
|
||||
@@ -422,14 +557,14 @@ public:
|
||||
|
||||
// checked value access
|
||||
|
||||
BOOST_CXX14_CONSTEXPR void value() const
|
||||
BOOST_CXX14_CONSTEXPR void value( boost::source_location const& loc = BOOST_CURRENT_LOCATION ) const
|
||||
{
|
||||
if( has_value() )
|
||||
{
|
||||
}
|
||||
else
|
||||
{
|
||||
throw_exception_from_error( variant2::unsafe_get<1>( v_ ) );
|
||||
throw_exception_from_error( variant2::unsafe_get<1>( v_ ), loc );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -452,12 +587,25 @@ 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()
|
||||
{
|
||||
v_.template emplace<0>();
|
||||
}
|
||||
|
||||
// swap
|
||||
|
||||
BOOST_CXX14_CONSTEXPR void swap( result& r )
|
||||
@@ -501,6 +649,224 @@ template<class Ch, class Tr, class E> std::basic_ostream<Ch, Tr>& operator<<( st
|
||||
return os;
|
||||
}
|
||||
|
||||
// result<T&, E>
|
||||
|
||||
namespace detail
|
||||
{
|
||||
|
||||
template<class U, class A> struct reference_to_temporary: std::integral_constant<bool,
|
||||
!std::is_reference<A>::value ||
|
||||
!std::is_convertible<typename std::remove_reference<A>::type*, U*>::value
|
||||
> {};
|
||||
|
||||
} // namespace detail
|
||||
|
||||
template<class U, class E> class result<U&, E>
|
||||
{
|
||||
private:
|
||||
|
||||
variant2::variant<U*, E> v_;
|
||||
|
||||
public:
|
||||
|
||||
using value_type = U&;
|
||||
using error_type = E;
|
||||
|
||||
static constexpr in_place_value_t in_place_value{};
|
||||
static constexpr in_place_error_t in_place_error{};
|
||||
|
||||
public:
|
||||
|
||||
// constructors
|
||||
|
||||
// implicit, value
|
||||
template<class A, typename std::enable_if<
|
||||
std::is_convertible<A, U&>::value &&
|
||||
!detail::reference_to_temporary<U, A>::value &&
|
||||
!std::is_convertible<A, E>::value, int>::type = 0>
|
||||
constexpr result( A&& a )
|
||||
noexcept( std::is_nothrow_constructible<U&, A>::value )
|
||||
: v_( in_place_value, &static_cast<U&>( std::forward<A>(a) ) )
|
||||
{
|
||||
}
|
||||
|
||||
// implicit, error
|
||||
template<class A = E, class = void, typename std::enable_if<
|
||||
std::is_convertible<A, E>::value &&
|
||||
!std::is_convertible<A, U&>::value, int>::type = 0>
|
||||
constexpr result( A&& a )
|
||||
noexcept( std::is_nothrow_constructible<E, A>::value )
|
||||
: v_( in_place_error, std::forward<A>(a) )
|
||||
{
|
||||
}
|
||||
|
||||
// explicit, value
|
||||
template<class A, class En = typename std::enable_if<
|
||||
detail::is_constructible<U&, A>::value &&
|
||||
!std::is_convertible<A, U&>::value &&
|
||||
!detail::reference_to_temporary<U, A>::value &&
|
||||
!detail::is_constructible<E, A>::value
|
||||
>::type>
|
||||
explicit constexpr result( A&& a )
|
||||
noexcept( std::is_nothrow_constructible<U&, A>::value )
|
||||
: v_( in_place_value, &static_cast<U&>( std::forward<A>(a) ) )
|
||||
{
|
||||
}
|
||||
|
||||
// explicit, error
|
||||
template<class... A, class En2 = void, class En = typename std::enable_if<
|
||||
!detail::is_constructible<U&, A...>::value &&
|
||||
detail::is_constructible<E, A...>::value &&
|
||||
sizeof...(A) >= 1
|
||||
>::type>
|
||||
explicit constexpr result( A&&... a )
|
||||
noexcept( std::is_nothrow_constructible<E, A...>::value )
|
||||
: v_( in_place_error, std::forward<A>(a)... )
|
||||
{
|
||||
}
|
||||
|
||||
// tagged, value
|
||||
template<class A, class En = typename std::enable_if<
|
||||
std::is_constructible<U&, A>::value
|
||||
>::type>
|
||||
constexpr result( in_place_value_t, A&& a )
|
||||
noexcept( std::is_nothrow_constructible<U&, A>::value )
|
||||
: v_( in_place_value, &static_cast<U&>( std::forward<A>(a) ) )
|
||||
{
|
||||
}
|
||||
|
||||
// tagged, error
|
||||
template<class... A, class En = typename std::enable_if<
|
||||
std::is_constructible<E, A...>::value
|
||||
>::type>
|
||||
constexpr result( in_place_error_t, A&&... a )
|
||||
noexcept( std::is_nothrow_constructible<E, A...>::value )
|
||||
: v_( in_place_error, std::forward<A>(a)... )
|
||||
{
|
||||
}
|
||||
|
||||
// converting
|
||||
template<class U2, class E2, class En = typename std::enable_if<
|
||||
std::is_convertible<U2&, U&>::value &&
|
||||
!detail::reference_to_temporary<U, U2&>::value &&
|
||||
std::is_convertible<E2, E>::value &&
|
||||
!std::is_convertible<result<U2&, E2> const&, U&>::value
|
||||
>::type>
|
||||
BOOST_CXX14_CONSTEXPR result( result<U2&, E2> const& r2 )
|
||||
noexcept(
|
||||
std::is_nothrow_constructible<U&, U2&>::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 )
|
||||
{
|
||||
this->emplace( *r2 );
|
||||
}
|
||||
}
|
||||
|
||||
// queries
|
||||
|
||||
constexpr bool has_value() const noexcept
|
||||
{
|
||||
return v_.index() == 0;
|
||||
}
|
||||
|
||||
constexpr bool has_error() const noexcept
|
||||
{
|
||||
return v_.index() == 1;
|
||||
}
|
||||
|
||||
constexpr explicit operator bool() const noexcept
|
||||
{
|
||||
return v_.index() == 0;
|
||||
}
|
||||
|
||||
// checked value access
|
||||
|
||||
BOOST_CXX14_CONSTEXPR U& value( boost::source_location const& loc = BOOST_CURRENT_LOCATION ) const
|
||||
{
|
||||
if( has_value() )
|
||||
{
|
||||
return *variant2::unsafe_get<0>( v_ );
|
||||
}
|
||||
else
|
||||
{
|
||||
throw_exception_from_error( variant2::unsafe_get<1>( v_ ), loc );
|
||||
}
|
||||
}
|
||||
|
||||
// unchecked value access
|
||||
|
||||
BOOST_CXX14_CONSTEXPR U* operator->() const noexcept
|
||||
{
|
||||
return has_value()? variant2::unsafe_get<0>( v_ ): 0;
|
||||
}
|
||||
|
||||
BOOST_CXX14_CONSTEXPR U& operator*() const noexcept
|
||||
{
|
||||
U* p = operator->();
|
||||
|
||||
BOOST_ASSERT( p != 0 );
|
||||
|
||||
return *p;
|
||||
}
|
||||
|
||||
// error access
|
||||
|
||||
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, class En = typename std::enable_if<
|
||||
detail::is_constructible<U&, A>::value &&
|
||||
!detail::reference_to_temporary<U, A>::value
|
||||
>::type>
|
||||
BOOST_CXX14_CONSTEXPR U& emplace( A&& a )
|
||||
{
|
||||
return *v_.template emplace<0>( &static_cast<U&>( a ) );
|
||||
}
|
||||
|
||||
// swap
|
||||
|
||||
BOOST_CXX14_CONSTEXPR void swap( result& r )
|
||||
noexcept( noexcept( v_.swap( r.v_ ) ) )
|
||||
{
|
||||
v_.swap( r.v_ );
|
||||
}
|
||||
|
||||
friend BOOST_CXX14_CONSTEXPR void swap( result & r1, result & r2 )
|
||||
noexcept( noexcept( r1.swap( r2 ) ) )
|
||||
{
|
||||
r1.swap( r2 );
|
||||
}
|
||||
|
||||
// equality
|
||||
|
||||
friend constexpr bool operator==( result const & r1, result const & r2 )
|
||||
noexcept( noexcept( r1 && r2? *r1 == *r2: r1.v_ == r2.v_ ) )
|
||||
{
|
||||
return r1 && r2? *r1 == *r2: r1.v_ == r2.v_;
|
||||
}
|
||||
|
||||
friend constexpr bool operator!=( result const & r1, result const & r2 )
|
||||
noexcept( noexcept( !( r1 == r2 ) ) )
|
||||
{
|
||||
return !( r1 == r2 );
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace system
|
||||
} // namespace boost
|
||||
|
||||
|
||||
@@ -6,9 +6,8 @@
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// https://www.boost.org/LICENSE_1_0.txt
|
||||
|
||||
#include <boost/system/errc.hpp>
|
||||
#include <boost/system/detail/error_code.hpp>
|
||||
#include <boost/system/detail/error_category_impl.hpp>
|
||||
#include <boost/system/detail/snprintf.hpp>
|
||||
#include <string>
|
||||
#include <stdexcept>
|
||||
#include <cassert>
|
||||
@@ -24,79 +23,25 @@ private:
|
||||
|
||||
error_code code_;
|
||||
|
||||
private:
|
||||
|
||||
static std::string to_string( int v )
|
||||
{
|
||||
char buffer[ 32 ];
|
||||
detail::snprintf( buffer, sizeof( buffer ), "%d", v );
|
||||
|
||||
return buffer;
|
||||
}
|
||||
|
||||
static std::string build_message( char const * prefix, error_code const & ec )
|
||||
{
|
||||
std::string r;
|
||||
|
||||
if( prefix )
|
||||
{
|
||||
r += prefix;
|
||||
r += ": ";
|
||||
}
|
||||
|
||||
r += ec.message();
|
||||
|
||||
if( ec.has_location() )
|
||||
{
|
||||
r += " [";
|
||||
r += ec.to_string();
|
||||
r += " at ";
|
||||
|
||||
boost::source_location loc = ec.location();
|
||||
|
||||
r += loc.file_name();
|
||||
|
||||
r += ':';
|
||||
r += to_string( loc.line() );
|
||||
|
||||
if( loc.column() != 0 )
|
||||
{
|
||||
r += ':';
|
||||
r += to_string( loc.column() );
|
||||
}
|
||||
|
||||
r += " in function '";
|
||||
r += loc.function_name();
|
||||
r += "\']";
|
||||
}
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
static std::string build_message( char const * prefix, int ev, error_category const & cat )
|
||||
{
|
||||
return build_message( prefix, error_code( ev, cat ) );
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
explicit system_error( error_code const & ec )
|
||||
: std::runtime_error( build_message( 0, ec ) ), code_( ec ) {}
|
||||
explicit system_error( error_code const & ec ):
|
||||
std::runtime_error( ec.what() ), code_( ec ) {}
|
||||
|
||||
system_error( error_code const & ec, std::string const & prefix )
|
||||
: std::runtime_error( build_message( prefix.c_str(), ec ) ), code_( ec ) {}
|
||||
system_error( error_code const & ec, std::string const & prefix ):
|
||||
std::runtime_error( prefix + ": " + ec.what() ), code_( ec ) {}
|
||||
|
||||
system_error( error_code const & ec, char const * prefix )
|
||||
: std::runtime_error( build_message( prefix, ec ) ), code_( ec ) {}
|
||||
system_error( error_code const & ec, char const * prefix ):
|
||||
std::runtime_error( std::string( prefix ) + ": " + ec.what() ), code_( ec ) {}
|
||||
|
||||
system_error( int ev, error_category const & ecat )
|
||||
: std::runtime_error( build_message( 0, ev, ecat ) ), code_( ev, ecat ) {}
|
||||
system_error( int ev, error_category const & ecat ):
|
||||
std::runtime_error( error_code( ev, ecat ).what() ), code_( ev, ecat ) {}
|
||||
|
||||
system_error( int ev, error_category const & ecat, std::string const & prefix )
|
||||
: std::runtime_error( build_message( prefix.c_str(), ev, ecat ) ), code_( ev, ecat ) {}
|
||||
system_error( int ev, error_category const & ecat, std::string const & prefix ):
|
||||
std::runtime_error( prefix + ": " + error_code( ev, ecat ).what() ), code_( ev, ecat ) {}
|
||||
|
||||
system_error( int ev, error_category const & ecat, char const * prefix )
|
||||
: std::runtime_error( build_message( prefix, ev, ecat ) ), code_( ev, ecat ) {}
|
||||
system_error( int ev, error_category const & ecat, char const * prefix ):
|
||||
std::runtime_error( std::string( prefix ) + ": " + error_code( ev, ecat ).what() ), code_( ev, ecat ) {}
|
||||
|
||||
error_code code() const BOOST_NOEXCEPT
|
||||
{
|
||||
|
||||
@@ -4,9 +4,14 @@
|
||||
"authors": [
|
||||
"Beman Dawes"
|
||||
],
|
||||
"description": "Operating system support, including the diagnostics support that will be part of the C++0x standard library.",
|
||||
"maintainers": [
|
||||
"Peter Dimov <pdimov -at- gmail.com>"
|
||||
],
|
||||
"description": "Extensible error reporting.",
|
||||
"category": [
|
||||
"System"
|
||||
"System",
|
||||
"Error-handling",
|
||||
"Programming"
|
||||
],
|
||||
"cxxstd": "03"
|
||||
}
|
||||
|
||||
@@ -15,6 +15,7 @@ macro(system_run s1)
|
||||
boost_test(SOURCES ${s1} ${ARGN})
|
||||
boost_test(SOURCES ${s1} ${ARGN} COMPILE_DEFINITIONS BOOST_NO_ANSI_APIS NAME ${n1}_no_ansi)
|
||||
boost_test(SOURCES ${s1} ${ARGN} COMPILE_DEFINITIONS BOOST_SYSTEM_USE_UTF8 NAME ${n1}_utf8)
|
||||
boost_test(SOURCES ${s1} ${ARGN} COMPILE_DEFINITIONS BOOST_SYSTEM_DISABLE_THREADS NAME ${n1}_nthr)
|
||||
|
||||
endmacro()
|
||||
|
||||
@@ -98,3 +99,71 @@ boost_test(TYPE run SOURCES std_interop_test6.cpp)
|
||||
boost_test(TYPE run SOURCES std_interop_test7.cpp)
|
||||
boost_test(TYPE run SOURCES std_interop_test8.cpp)
|
||||
boost_test(TYPE run SOURCES std_interop_test9.cpp)
|
||||
|
||||
boost_test(TYPE run SOURCES ec_location_test.cpp)
|
||||
|
||||
boost_test(TYPE run SOURCES error_condition_test3.cpp)
|
||||
boost_test(TYPE run SOURCES error_code_test2.cpp)
|
||||
boost_test(TYPE run SOURCES system_error_test2.cpp)
|
||||
boost_test(TYPE run SOURCES std_interop_test10.cpp)
|
||||
|
||||
boost_test(TYPE run SOURCES ec_location_test2.cpp)
|
||||
boost_test(TYPE run SOURCES ec_what_test.cpp)
|
||||
boost_test(TYPE run SOURCES system_error_test3.cpp)
|
||||
|
||||
boost_test(TYPE run SOURCES std_interop_test11.cpp)
|
||||
|
||||
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)
|
||||
|
||||
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)
|
||||
|
||||
boost_test(TYPE run SOURCES result_default_construct.cpp)
|
||||
boost_test(TYPE run SOURCES result_value_construct.cpp)
|
||||
boost_test(TYPE run SOURCES result_error_construct.cpp)
|
||||
boost_test(TYPE run SOURCES result_copy_construct.cpp)
|
||||
boost_test(TYPE run SOURCES result_move_construct.cpp)
|
||||
boost_test(TYPE run SOURCES result_copy_assign.cpp)
|
||||
boost_test(TYPE run SOURCES result_move_assign.cpp)
|
||||
boost_test(TYPE run SOURCES result_value_access.cpp)
|
||||
boost_test(TYPE run SOURCES result_error_access.cpp)
|
||||
boost_test(TYPE run SOURCES result_swap.cpp)
|
||||
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)
|
||||
boost_test(TYPE run SOURCES result_value_construct6.cpp)
|
||||
boost_test(TYPE run SOURCES result_value_construct7.cpp)
|
||||
boost_test(TYPE run SOURCES result_error_construct5.cpp)
|
||||
|
||||
@@ -20,6 +20,8 @@ project
|
||||
<toolset>msvc:<warnings-as-errors>on
|
||||
<toolset>gcc:<warnings-as-errors>on
|
||||
<toolset>clang:<warnings-as-errors>on
|
||||
|
||||
<toolset>gcc-4.4:<cxxflags>-Wno-sign-compare
|
||||
;
|
||||
|
||||
rule system-run ( sources + )
|
||||
@@ -31,6 +33,7 @@ rule system-run ( sources + )
|
||||
result += [ run $(sources) : : : <library>/boost/system//boost_system <link>shared : $(sources[1]:B)_shared ] ;
|
||||
result += [ run $(sources) : : : <define>BOOST_NO_ANSI_APIS : $(sources[1]:B)_no_ansi ] ;
|
||||
result += [ run $(sources) : : : <define>BOOST_SYSTEM_USE_UTF8 : $(sources[1]:B)_utf8 ] ;
|
||||
result += [ run $(sources) : : : <define>BOOST_SYSTEM_DISABLE_THREADS : $(sources[1]:B)_nthr ] ;
|
||||
|
||||
return $(result) ;
|
||||
}
|
||||
@@ -59,7 +62,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 ;
|
||||
|
||||
@@ -73,8 +80,8 @@ system-run failed_constexpr_test.cpp ;
|
||||
# Quick (CI) test
|
||||
run quick.cpp ;
|
||||
|
||||
compile warnings_test.cpp
|
||||
: <warnings>pedantic
|
||||
run warnings_test.cpp
|
||||
: : : <warnings>pedantic
|
||||
<toolset>msvc:<warnings-as-errors>on
|
||||
<toolset>gcc:<warnings-as-errors>on
|
||||
<toolset>clang:<warnings-as-errors>on ;
|
||||
@@ -123,11 +130,45 @@ run std_interop_test9.cpp ;
|
||||
|
||||
run ec_location_test.cpp ;
|
||||
|
||||
run error_condition_test3.cpp ;
|
||||
run error_code_test2.cpp ;
|
||||
run system_error_test2.cpp ;
|
||||
run std_interop_test10.cpp ;
|
||||
|
||||
run ec_location_test2.cpp ;
|
||||
run ec_what_test.cpp ;
|
||||
run system_error_test3.cpp ;
|
||||
|
||||
run std_interop_test11.cpp ;
|
||||
|
||||
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 ;
|
||||
|
||||
run win32_generic_test.cpp ;
|
||||
|
||||
run ec_hash_value_test.cpp ;
|
||||
|
||||
run std_interop_test16.cpp ;
|
||||
|
||||
# result
|
||||
|
||||
import ../../config/checks/config : requires ;
|
||||
|
||||
CPP11 = [ requires cxx11_variadic_templates cxx11_template_aliases cxx11_decltype cxx11_constexpr cxx11_noexcept ] ;
|
||||
CPP11 = [ requires cxx11_variadic_templates cxx11_template_aliases cxx11_decltype cxx11_constexpr cxx11_noexcept ] <toolset>gcc-4.7:<build>no ;
|
||||
|
||||
run result_default_construct.cpp : : : $(CPP11) ;
|
||||
run result_value_construct.cpp : : : $(CPP11) ;
|
||||
@@ -140,3 +181,19 @@ run result_value_access.cpp : : : $(CPP11) ;
|
||||
run result_error_access.cpp : : : $(CPP11) ;
|
||||
run result_swap.cpp : : : $(CPP11) <toolset>gcc-10:<cxxflags>"-Wno-maybe-uninitialized" ;
|
||||
run result_eq.cpp : : : $(CPP11) ;
|
||||
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) ;
|
||||
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) ;
|
||||
run result_value_construct6.cpp : : : $(CPP11) ;
|
||||
run result_value_construct7.cpp : : : $(CPP11) ;
|
||||
run result_error_construct5.cpp : : : $(CPP11) ;
|
||||
|
||||
@@ -40,5 +40,5 @@ int main()
|
||||
boost::system::system_error x( bc, "prefix" );
|
||||
|
||||
BOOST_TEST_EQ( x.code(), bc );
|
||||
BOOST_TEST_EQ( std::string( x.what() ), "prefix: " + bc.message() );
|
||||
BOOST_TEST_EQ( std::string( x.what() ), "prefix: " + bc.what() );
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
# Copyright 2018, 2019 Peter Dimov
|
||||
# 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
|
||||
|
||||
cmake_minimum_required(VERSION 3.5...3.16)
|
||||
cmake_minimum_required(VERSION 3.5...3.20)
|
||||
|
||||
project(cmake_subdir_test LANGUAGES CXX)
|
||||
|
||||
@@ -10,7 +10,11 @@ add_subdirectory(../.. boostorg/system)
|
||||
add_subdirectory(../../../assert boostorg/assert)
|
||||
add_subdirectory(../../../config boostorg/config)
|
||||
add_subdirectory(../../../core boostorg/core)
|
||||
add_subdirectory(../../../mp11 boostorg/mp11)
|
||||
add_subdirectory(../../../predef boostorg/predef)
|
||||
add_subdirectory(../../../static_assert boostorg/static_assert)
|
||||
add_subdirectory(../../../throw_exception boostorg/throw_exception)
|
||||
add_subdirectory(../../../variant2 boostorg/variant2)
|
||||
add_subdirectory(../../../winapi boostorg/winapi)
|
||||
|
||||
add_executable(quick ../quick.cpp)
|
||||
@@ -19,4 +23,4 @@ target_link_libraries(quick Boost::system Boost::core)
|
||||
enable_testing()
|
||||
add_test(quick quick)
|
||||
|
||||
add_custom_target(check COMMAND ${CMAKE_CTEST_COMMAND} --output-on-failure -C $<CONFIG>)
|
||||
add_custom_target(check COMMAND ${CMAKE_CTEST_COMMAND} --output-on-failure --no-tests=error -C $<CONFIG>)
|
||||
|
||||
35
test/constexpr_test2.cpp
Normal file
35
test/constexpr_test2.cpp
Normal file
@@ -0,0 +1,35 @@
|
||||
// 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()
|
||||
{
|
||||
#if defined(BOOST_CLANG_VERSION) && BOOST_CLANG_VERSION < 30900
|
||||
|
||||
BOOST_STATIC_CONSTEXPR X x = {};
|
||||
return x;
|
||||
|
||||
#else
|
||||
|
||||
BOOST_STATIC_CONSTEXPR X x;
|
||||
return x;
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif
|
||||
132
test/ec_hash_value_test.cpp
Normal file
132
test/ec_hash_value_test.cpp
Normal file
@@ -0,0 +1,132 @@
|
||||
// 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/generic_category.hpp>
|
||||
#include <boost/system/system_category.hpp>
|
||||
#include <boost/core/lightweight_test.hpp>
|
||||
#include <cerrno>
|
||||
#if defined(BOOST_SYSTEM_HAS_SYSTEM_ERROR)
|
||||
#include <system_error>
|
||||
#endif
|
||||
|
||||
namespace sys = boost::system;
|
||||
|
||||
int main()
|
||||
{
|
||||
// normal against normal (equal, system)
|
||||
{
|
||||
sys::error_code e2( 0, sys::system_category() );
|
||||
sys::error_code e3( e2.value(), e2.category() );
|
||||
|
||||
BOOST_TEST( e2 != e3 || hash_value( e2 ) == hash_value( e3 ) );
|
||||
BOOST_TEST( e2 == e3 || hash_value( e2 ) != hash_value( e3 ) );
|
||||
}
|
||||
|
||||
// normal against normal (equal, generic)
|
||||
{
|
||||
sys::error_code e2( EINVAL, sys::generic_category() );
|
||||
sys::error_code e3( e2.value(), e2.category() );
|
||||
|
||||
BOOST_TEST( e2 != e3 || hash_value( e2 ) == hash_value( e3 ) );
|
||||
BOOST_TEST( e2 == e3 || hash_value( e2 ) != hash_value( e3 ) );
|
||||
}
|
||||
|
||||
// normal against normal (inequal, value, generic)
|
||||
{
|
||||
sys::error_code e2( 0, sys::generic_category() );
|
||||
sys::error_code e3( EINVAL, sys::generic_category() );
|
||||
|
||||
BOOST_TEST( e2 != e3 || hash_value( e2 ) == hash_value( e3 ) );
|
||||
BOOST_TEST( e2 == e3 || hash_value( e2 ) != hash_value( e3 ) );
|
||||
}
|
||||
|
||||
// normal against normal (inequal, value, system)
|
||||
{
|
||||
sys::error_code e2( 1, sys::system_category() );
|
||||
sys::error_code e3( 2, sys::system_category() );
|
||||
|
||||
BOOST_TEST( e2 != e3 || hash_value( e2 ) == hash_value( e3 ) );
|
||||
BOOST_TEST( e2 == e3 || hash_value( e2 ) != hash_value( e3 ) );
|
||||
}
|
||||
|
||||
// normal against normal (inequal, category)
|
||||
{
|
||||
sys::error_code e2( 0, sys::system_category() );
|
||||
sys::error_code e3( 0, sys::generic_category() );
|
||||
|
||||
BOOST_TEST( e2 != e3 || hash_value( e2 ) == hash_value( e3 ) );
|
||||
BOOST_TEST( e2 == e3 || hash_value( e2 ) != hash_value( e3 ) );
|
||||
}
|
||||
|
||||
// empty against normal
|
||||
{
|
||||
sys::error_code e2;
|
||||
sys::error_code e3( e2.value(), e2.category() );
|
||||
|
||||
BOOST_TEST( e2 != e3 || hash_value( e2 ) == hash_value( e3 ) );
|
||||
BOOST_TEST( e2 == e3 || hash_value( e2 ) != hash_value( e3 ) );
|
||||
}
|
||||
|
||||
#if defined(BOOST_SYSTEM_HAS_SYSTEM_ERROR)
|
||||
|
||||
// std:: wrapping against normal
|
||||
{
|
||||
std::error_code e1( EINVAL, std::generic_category() );
|
||||
|
||||
sys::error_code e2( e1 );
|
||||
sys::error_code e3( e2.value(), e2.category() );
|
||||
|
||||
BOOST_TEST( e2 != e3 || hash_value( e2 ) == hash_value( e3 ) );
|
||||
BOOST_TEST( e2 == e3 || hash_value( e2 ) != hash_value( e3 ) );
|
||||
}
|
||||
|
||||
// empty against wrapping std:: empty
|
||||
{
|
||||
std::error_code e1;
|
||||
|
||||
sys::error_code e2( e1 );
|
||||
sys::error_code e3;
|
||||
|
||||
BOOST_TEST( e2 != e3 || hash_value( e2 ) == hash_value( e3 ) );
|
||||
BOOST_TEST( e2 == e3 || hash_value( e2 ) != hash_value( e3 ) );
|
||||
}
|
||||
|
||||
// empty against roundtrip via std
|
||||
{
|
||||
sys::error_code e2;
|
||||
|
||||
std::error_code e1( e2 );
|
||||
sys::error_code e3( e1 );
|
||||
|
||||
BOOST_TEST( e2 != e3 || hash_value( e2 ) == hash_value( e3 ) );
|
||||
BOOST_TEST( e2 == e3 || hash_value( e2 ) != hash_value( e3 ) );
|
||||
}
|
||||
|
||||
// normal/generic against roundtrip via std
|
||||
{
|
||||
sys::error_code e2( EINVAL, boost::system::generic_category() );
|
||||
|
||||
std::error_code e1( e2 );
|
||||
sys::error_code e3( e1 );
|
||||
|
||||
BOOST_TEST( e2 != e3 || hash_value( e2 ) == hash_value( e3 ) );
|
||||
BOOST_TEST( e2 == e3 || hash_value( e2 ) != hash_value( e3 ) );
|
||||
}
|
||||
|
||||
// normal/system against roundtrip via std
|
||||
{
|
||||
sys::error_code e2( 0, boost::system::system_category() );
|
||||
|
||||
std::error_code e1( e2 );
|
||||
sys::error_code e3( e1 );
|
||||
|
||||
BOOST_TEST( e2 != e3 || hash_value( e2 ) == hash_value( e3 ) );
|
||||
BOOST_TEST( e2 == e3 || hash_value( e2 ) != hash_value( e3 ) );
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
287
test/ec_location_test2.cpp
Normal file
287
test/ec_location_test2.cpp
Normal file
@@ -0,0 +1,287 @@
|
||||
// Copyright 2021 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>
|
||||
|
||||
namespace sys = boost::system;
|
||||
|
||||
enum E
|
||||
{
|
||||
none = 0,
|
||||
einval = EINVAL
|
||||
};
|
||||
|
||||
namespace boost
|
||||
{
|
||||
namespace system
|
||||
{
|
||||
|
||||
template<> struct is_error_code_enum< ::E >
|
||||
{
|
||||
static const bool value = true;
|
||||
};
|
||||
|
||||
} // namespace system
|
||||
} // namespace boost
|
||||
|
||||
sys::error_code make_error_code( E e )
|
||||
{
|
||||
return e == 0? sys::error_code(): sys::error_code( e, sys::generic_category() );
|
||||
}
|
||||
|
||||
#if defined(BOOST_SYSTEM_HAS_SYSTEM_ERROR)
|
||||
|
||||
enum E2
|
||||
{
|
||||
e2inval = EINVAL
|
||||
};
|
||||
|
||||
namespace boost
|
||||
{
|
||||
namespace system
|
||||
{
|
||||
|
||||
template<> struct is_error_code_enum< ::E2 >
|
||||
{
|
||||
static const bool value = true;
|
||||
};
|
||||
|
||||
} // namespace system
|
||||
} // namespace boost
|
||||
|
||||
std::error_code make_error_code( E2 e )
|
||||
{
|
||||
return std::error_code( e, std::generic_category() );
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
sys::error_code ec( einval );
|
||||
|
||||
BOOST_TEST_EQ( ec.value(), EINVAL );
|
||||
BOOST_TEST_EQ( &ec.category(), &sys::generic_category() );
|
||||
|
||||
BOOST_TEST( ec.failed() );
|
||||
|
||||
BOOST_TEST( !ec.has_location() );
|
||||
BOOST_TEST_EQ( ec.location().line(), 0 );
|
||||
}
|
||||
|
||||
{
|
||||
BOOST_STATIC_CONSTEXPR boost::source_location loc = BOOST_CURRENT_LOCATION;
|
||||
|
||||
sys::error_code ec( einval, &loc );
|
||||
|
||||
BOOST_TEST_EQ( ec.value(), EINVAL );
|
||||
BOOST_TEST_EQ( &ec.category(), &sys::generic_category() );
|
||||
|
||||
BOOST_TEST( ec.failed() );
|
||||
|
||||
BOOST_TEST( ec.has_location() );
|
||||
BOOST_TEST_EQ( ec.location().line(), 77 );
|
||||
}
|
||||
|
||||
{
|
||||
sys::error_code ec( none );
|
||||
|
||||
BOOST_TEST_EQ( ec.value(), 0 );
|
||||
BOOST_TEST_EQ( &ec.category(), &sys::system_category() );
|
||||
|
||||
BOOST_TEST( !ec.failed() );
|
||||
|
||||
BOOST_TEST( !ec.has_location() );
|
||||
BOOST_TEST_EQ( ec.location().line(), 0 );
|
||||
}
|
||||
|
||||
{
|
||||
BOOST_STATIC_CONSTEXPR boost::source_location loc = BOOST_CURRENT_LOCATION;
|
||||
|
||||
sys::error_code ec( none, &loc );
|
||||
|
||||
BOOST_TEST_EQ( ec.value(), 0 );
|
||||
BOOST_TEST_EQ( &ec.category(), &sys::system_category() );
|
||||
|
||||
BOOST_TEST( !ec.failed() );
|
||||
|
||||
BOOST_TEST( !ec.has_location() );
|
||||
BOOST_TEST_EQ( ec.location().line(), 0 );
|
||||
}
|
||||
|
||||
{
|
||||
sys::error_code ec;
|
||||
|
||||
BOOST_TEST_EQ( ec.value(), 0 );
|
||||
BOOST_TEST_EQ( &ec.category(), &sys::system_category() );
|
||||
|
||||
BOOST_TEST( !ec.failed() );
|
||||
|
||||
BOOST_TEST( !ec.has_location() );
|
||||
BOOST_TEST_EQ( ec.location().line(), 0 );
|
||||
|
||||
BOOST_STATIC_CONSTEXPR boost::source_location loc = BOOST_CURRENT_LOCATION;
|
||||
|
||||
ec = sys::error_code( einval, &loc );
|
||||
|
||||
BOOST_TEST_EQ( ec.value(), EINVAL );
|
||||
BOOST_TEST_EQ( &ec.category(), &sys::generic_category() );
|
||||
|
||||
BOOST_TEST( ec.failed() );
|
||||
|
||||
BOOST_TEST( ec.has_location() );
|
||||
BOOST_TEST_EQ( ec.location().line(), 127 );
|
||||
}
|
||||
|
||||
{
|
||||
sys::error_code ec;
|
||||
|
||||
BOOST_TEST_EQ( ec.value(), 0 );
|
||||
BOOST_TEST_EQ( &ec.category(), &sys::system_category() );
|
||||
|
||||
BOOST_TEST( !ec.failed() );
|
||||
|
||||
BOOST_TEST( !ec.has_location() );
|
||||
BOOST_TEST_EQ( ec.location().line(), 0 );
|
||||
|
||||
BOOST_STATIC_CONSTEXPR boost::source_location loc = BOOST_CURRENT_LOCATION;
|
||||
|
||||
ec = sys::error_code( none, &loc );
|
||||
|
||||
BOOST_TEST_EQ( ec.value(), 0 );
|
||||
BOOST_TEST_EQ( &ec.category(), &sys::system_category() );
|
||||
|
||||
BOOST_TEST( !ec.failed() );
|
||||
|
||||
BOOST_TEST( !ec.has_location() );
|
||||
BOOST_TEST_EQ( ec.location().line(), 0 );
|
||||
}
|
||||
|
||||
{
|
||||
sys::error_code ec;
|
||||
|
||||
BOOST_TEST_EQ( ec.value(), 0 );
|
||||
BOOST_TEST_EQ( &ec.category(), &sys::system_category() );
|
||||
|
||||
BOOST_TEST( !ec.failed() );
|
||||
|
||||
BOOST_TEST( !ec.has_location() );
|
||||
BOOST_TEST_EQ( ec.location().line(), 0 );
|
||||
|
||||
BOOST_STATIC_CONSTEXPR boost::source_location loc = BOOST_CURRENT_LOCATION;
|
||||
|
||||
ec.assign( einval, &loc );
|
||||
|
||||
BOOST_TEST_EQ( ec.value(), EINVAL );
|
||||
BOOST_TEST_EQ( &ec.category(), &sys::generic_category() );
|
||||
|
||||
BOOST_TEST( ec.failed() );
|
||||
|
||||
BOOST_TEST( ec.has_location() );
|
||||
BOOST_TEST_EQ( ec.location().line(), 175 );
|
||||
}
|
||||
|
||||
{
|
||||
sys::error_code ec;
|
||||
|
||||
BOOST_TEST_EQ( ec.value(), 0 );
|
||||
BOOST_TEST_EQ( &ec.category(), &sys::system_category() );
|
||||
|
||||
BOOST_TEST( !ec.failed() );
|
||||
|
||||
BOOST_TEST( !ec.has_location() );
|
||||
BOOST_TEST_EQ( ec.location().line(), 0 );
|
||||
|
||||
BOOST_STATIC_CONSTEXPR boost::source_location loc = BOOST_CURRENT_LOCATION;
|
||||
|
||||
ec.assign( none, &loc );
|
||||
|
||||
BOOST_TEST_EQ( ec.value(), 0 );
|
||||
BOOST_TEST_EQ( &ec.category(), &sys::system_category() );
|
||||
|
||||
BOOST_TEST( !ec.failed() );
|
||||
|
||||
BOOST_TEST( !ec.has_location() );
|
||||
BOOST_TEST_EQ( ec.location().line(), 0 );
|
||||
}
|
||||
|
||||
#if defined(BOOST_SYSTEM_HAS_SYSTEM_ERROR)
|
||||
|
||||
{
|
||||
sys::error_code ec( e2inval );
|
||||
|
||||
BOOST_TEST_EQ( ec, std::error_code( EINVAL, std::generic_category() ) );
|
||||
|
||||
BOOST_TEST( ec.failed() );
|
||||
|
||||
BOOST_TEST( !ec.has_location() );
|
||||
BOOST_TEST_EQ( ec.location().line(), 0 );
|
||||
}
|
||||
|
||||
{
|
||||
BOOST_STATIC_CONSTEXPR boost::source_location loc = BOOST_CURRENT_LOCATION;
|
||||
|
||||
sys::error_code ec( e2inval, &loc );
|
||||
|
||||
BOOST_TEST_EQ( ec, std::error_code( EINVAL, std::generic_category() ) );
|
||||
|
||||
BOOST_TEST( ec.failed() );
|
||||
|
||||
BOOST_TEST( !ec.has_location() );
|
||||
BOOST_TEST_EQ( ec.location().line(), 0 );
|
||||
}
|
||||
|
||||
{
|
||||
sys::error_code ec;
|
||||
|
||||
BOOST_TEST_EQ( ec.value(), 0 );
|
||||
BOOST_TEST_EQ( &ec.category(), &sys::system_category() );
|
||||
|
||||
BOOST_TEST( !ec.failed() );
|
||||
|
||||
BOOST_TEST( !ec.has_location() );
|
||||
BOOST_TEST_EQ( ec.location().line(), 0 );
|
||||
|
||||
BOOST_STATIC_CONSTEXPR boost::source_location loc = BOOST_CURRENT_LOCATION;
|
||||
|
||||
ec = sys::error_code( e2inval, &loc );
|
||||
|
||||
BOOST_TEST_EQ( ec, std::error_code( EINVAL, std::generic_category() ) );
|
||||
|
||||
BOOST_TEST( ec.failed() );
|
||||
|
||||
BOOST_TEST( !ec.has_location() );
|
||||
BOOST_TEST_EQ( ec.location().line(), 0 );
|
||||
}
|
||||
|
||||
{
|
||||
sys::error_code ec;
|
||||
|
||||
BOOST_TEST_EQ( ec.value(), 0 );
|
||||
BOOST_TEST_EQ( &ec.category(), &sys::system_category() );
|
||||
|
||||
BOOST_TEST( !ec.failed() );
|
||||
|
||||
BOOST_TEST( !ec.has_location() );
|
||||
BOOST_TEST_EQ( ec.location().line(), 0 );
|
||||
|
||||
BOOST_STATIC_CONSTEXPR boost::source_location loc = BOOST_CURRENT_LOCATION;
|
||||
|
||||
ec.assign( e2inval, &loc );
|
||||
|
||||
BOOST_TEST_EQ( ec, std::error_code( EINVAL, std::generic_category() ) );
|
||||
|
||||
BOOST_TEST( ec.failed() );
|
||||
|
||||
BOOST_TEST( !ec.has_location() );
|
||||
BOOST_TEST_EQ( ec.location().line(), 0 );
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
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();
|
||||
}
|
||||
91
test/ec_what_test.cpp
Normal file
91
test/ec_what_test.cpp
Normal file
@@ -0,0 +1,91 @@
|
||||
// Copyright 2020, 2021 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/generic_category.hpp>
|
||||
#include <boost/system/system_category.hpp>
|
||||
#include <boost/core/lightweight_test.hpp>
|
||||
|
||||
namespace sys = boost::system;
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
sys::error_code ec;
|
||||
|
||||
BOOST_TEST_EQ( ec.value(), 0 );
|
||||
BOOST_TEST( ec.category() == sys::system_category() );
|
||||
|
||||
BOOST_TEST_EQ( ec.what(), ec.message() + " [system:0]" );
|
||||
}
|
||||
|
||||
{
|
||||
sys::error_code ec( 5, sys::generic_category() );
|
||||
|
||||
BOOST_TEST_EQ( ec.value(), 5 );
|
||||
BOOST_TEST( ec.category() == sys::generic_category() );
|
||||
|
||||
BOOST_TEST_EQ( ec.what(), ec.message() + " [generic:5]" );
|
||||
}
|
||||
|
||||
{
|
||||
sys::error_code ec( 5, sys::system_category() );
|
||||
|
||||
BOOST_TEST_EQ( ec.value(), 5 );
|
||||
BOOST_TEST( ec.category() == sys::system_category() );
|
||||
|
||||
BOOST_TEST_EQ( ec.what(), ec.message() + " [system:5]" );
|
||||
}
|
||||
|
||||
{
|
||||
BOOST_STATIC_CONSTEXPR boost::source_location loc = BOOST_CURRENT_LOCATION;
|
||||
|
||||
sys::error_code ec( 5, sys::generic_category(), &loc );
|
||||
|
||||
BOOST_TEST_EQ( ec.value(), 5 );
|
||||
BOOST_TEST( ec.category() == sys::generic_category() );
|
||||
BOOST_TEST_EQ( &ec.location(), &loc );
|
||||
|
||||
BOOST_TEST_EQ( ec.what(), ec.message() + " [generic:5 at " + loc.to_string() + "]" );
|
||||
}
|
||||
|
||||
{
|
||||
BOOST_STATIC_CONSTEXPR boost::source_location loc = BOOST_CURRENT_LOCATION;
|
||||
|
||||
sys::error_code ec( 5, sys::system_category(), &loc );
|
||||
|
||||
BOOST_TEST_EQ( ec.value(), 5 );
|
||||
BOOST_TEST( ec.category() == sys::system_category() );
|
||||
BOOST_TEST_EQ( &ec.location(), &loc );
|
||||
|
||||
BOOST_TEST_EQ( ec.what(), ec.message() + " [system:5 at " + loc.to_string() + "]" );
|
||||
}
|
||||
|
||||
#if defined(BOOST_SYSTEM_HAS_SYSTEM_ERROR)
|
||||
|
||||
{
|
||||
std::error_code ec;
|
||||
sys::error_code ec2( ec );
|
||||
|
||||
BOOST_TEST_EQ( ec2.what(), ec2.message() + " [std:system:0]" );
|
||||
}
|
||||
|
||||
{
|
||||
std::error_code ec( 5, std::generic_category() );
|
||||
sys::error_code ec2( ec );
|
||||
|
||||
BOOST_TEST_EQ( ec2.what(), ec2.message() + " [std:generic:5]" );
|
||||
}
|
||||
|
||||
{
|
||||
std::error_code ec( 5, std::system_category() );
|
||||
sys::error_code ec2( ec );
|
||||
|
||||
BOOST_TEST_EQ( ec2.what(), ec2.message() + " [std:system:5]" );
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
21
test/ec_wstream_test.cpp
Normal file
21
test/ec_wstream_test.cpp
Normal file
@@ -0,0 +1,21 @@
|
||||
// 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/core/lightweight_test.hpp>
|
||||
#include <sstream>
|
||||
|
||||
namespace sys = boost::system;
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
std::wostringstream os;
|
||||
os << sys::error_code();
|
||||
|
||||
BOOST_TEST( os.str() == L"system:0" );
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
@@ -8,11 +8,9 @@
|
||||
|
||||
// See library home page at http://www.boost.org/libs/system
|
||||
|
||||
// Avoid spurious VC++ warnings
|
||||
# define _CRT_SECURE_NO_WARNINGS
|
||||
|
||||
#include <boost/system/error_code.hpp>
|
||||
#include <boost/core/lightweight_test.hpp>
|
||||
#include <boost/core/snprintf.hpp>
|
||||
#include <cstdio>
|
||||
|
||||
//
|
||||
@@ -31,7 +29,7 @@ public:
|
||||
virtual std::string message( int ev ) const
|
||||
{
|
||||
char buffer[ 256 ];
|
||||
std::sprintf( buffer, "user message %d", ev );
|
||||
boost::core::snprintf( buffer, sizeof( buffer ), "user message %d", ev );
|
||||
|
||||
return buffer;
|
||||
}
|
||||
|
||||
@@ -8,11 +8,9 @@
|
||||
|
||||
// See library home page at http://www.boost.org/libs/system
|
||||
|
||||
// Avoid spurious VC++ warnings
|
||||
#define _CRT_SECURE_NO_WARNINGS
|
||||
|
||||
#include <boost/system/error_category.hpp>
|
||||
#include <boost/core/lightweight_test.hpp>
|
||||
#include <boost/core/snprintf.hpp>
|
||||
#include <cstdio>
|
||||
|
||||
//
|
||||
@@ -31,7 +29,7 @@ public:
|
||||
virtual std::string message( int ev ) const
|
||||
{
|
||||
char buffer[ 256 ];
|
||||
std::sprintf( buffer, "user message %d", ev );
|
||||
boost::core::snprintf( buffer, sizeof( buffer ), "user message %d", ev );
|
||||
|
||||
return buffer;
|
||||
}
|
||||
|
||||
94
test/error_code_test2.cpp
Normal file
94
test/error_code_test2.cpp
Normal file
@@ -0,0 +1,94 @@
|
||||
// Copyright 2020, 2021 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/generic_category.hpp>
|
||||
#include <boost/system/system_category.hpp>
|
||||
#include <boost/core/lightweight_test.hpp>
|
||||
|
||||
namespace sys = boost::system;
|
||||
|
||||
int main()
|
||||
{
|
||||
char buffer[ 1024 ];
|
||||
|
||||
sys::error_code ec;
|
||||
|
||||
BOOST_TEST_EQ( ec.value(), 0 );
|
||||
BOOST_TEST( ec.category() == sys::system_category() );
|
||||
BOOST_TEST_EQ( ec.message(), ec.category().message( ec.value() ) );
|
||||
BOOST_TEST_CSTR_EQ( ec.message( buffer, sizeof( buffer ) ), ec.category().message( ec.value(), buffer, sizeof( buffer ) ) );
|
||||
BOOST_TEST( !ec.failed() );
|
||||
BOOST_TEST( !ec );
|
||||
|
||||
BOOST_TEST_EQ( ec.to_string(), std::string( "system:0" ) );
|
||||
|
||||
{
|
||||
sys::error_code ec2( ec );
|
||||
|
||||
BOOST_TEST_EQ( ec2.value(), 0 );
|
||||
BOOST_TEST( ec2.category() == sys::system_category() );
|
||||
BOOST_TEST_EQ( ec2.message(), ec2.category().message( ec2.value() ) );
|
||||
BOOST_TEST_CSTR_EQ( ec2.message( buffer, sizeof( buffer ) ), ec2.category().message( ec2.value(), buffer, sizeof( buffer ) ) );
|
||||
BOOST_TEST( !ec2.failed() );
|
||||
BOOST_TEST( !ec2 );
|
||||
|
||||
BOOST_TEST_EQ( ec, ec2 );
|
||||
BOOST_TEST_NOT( ec != ec2 );
|
||||
|
||||
BOOST_TEST_EQ( ec2.to_string(), std::string( "system:0" ) );
|
||||
}
|
||||
|
||||
{
|
||||
sys::error_code ec2( ec.value(), ec.category() );
|
||||
|
||||
BOOST_TEST_EQ( ec2.value(), 0 );
|
||||
BOOST_TEST( ec2.category() == sys::system_category() );
|
||||
BOOST_TEST_EQ( ec2.message(), ec2.category().message( ec2.value() ) );
|
||||
BOOST_TEST_CSTR_EQ( ec2.message( buffer, sizeof( buffer ) ), ec2.category().message( ec2.value(), buffer, sizeof( buffer ) ) );
|
||||
BOOST_TEST( !ec2.failed() );
|
||||
BOOST_TEST( !ec2 );
|
||||
|
||||
BOOST_TEST_EQ( ec, ec2 );
|
||||
BOOST_TEST_NOT( ec != ec2 );
|
||||
|
||||
BOOST_TEST_EQ( ec2.to_string(), std::string( "system:0" ) );
|
||||
}
|
||||
|
||||
{
|
||||
sys::error_code ec2( 5, sys::generic_category() );
|
||||
|
||||
BOOST_TEST_EQ( ec2.value(), 5 );
|
||||
BOOST_TEST( ec2.category() == sys::generic_category() );
|
||||
BOOST_TEST_EQ( ec2.message(), ec2.category().message( ec2.value() ) );
|
||||
BOOST_TEST_CSTR_EQ( ec2.message( buffer, sizeof( buffer ) ), ec2.category().message( ec2.value(), buffer, sizeof( buffer ) ) );
|
||||
BOOST_TEST( ec2.failed() );
|
||||
BOOST_TEST( ec2 );
|
||||
BOOST_TEST_NOT( !ec2 );
|
||||
|
||||
BOOST_TEST_NE( ec, ec2 );
|
||||
BOOST_TEST_NOT( ec == ec2 );
|
||||
|
||||
BOOST_TEST_EQ( ec2.to_string(), std::string( "generic:5" ) );
|
||||
}
|
||||
|
||||
{
|
||||
sys::error_code ec2( 5, sys::system_category() );
|
||||
|
||||
BOOST_TEST_EQ( ec2.value(), 5 );
|
||||
BOOST_TEST( ec2.category() == sys::system_category() );
|
||||
BOOST_TEST_EQ( ec2.message(), ec2.category().message( ec2.value() ) );
|
||||
BOOST_TEST_CSTR_EQ( ec2.message( buffer, sizeof( buffer ) ), ec2.category().message( ec2.value(), buffer, sizeof( buffer ) ) );
|
||||
BOOST_TEST( ec2.failed() );
|
||||
BOOST_TEST( ec2 );
|
||||
BOOST_TEST_NOT( !ec2 );
|
||||
|
||||
BOOST_TEST_NE( ec, ec2 );
|
||||
BOOST_TEST_NOT( ec == ec2 );
|
||||
|
||||
BOOST_TEST_EQ( ec2.to_string(), std::string( "system:5" ) );
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
94
test/error_condition_test3.cpp
Normal file
94
test/error_condition_test3.cpp
Normal file
@@ -0,0 +1,94 @@
|
||||
// Copyright 2020, 2021 Peter Dimov.
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// http://www.boost.org/LICENSE_1_0.txt
|
||||
|
||||
#include <boost/system/error_condition.hpp>
|
||||
#include <boost/system/generic_category.hpp>
|
||||
#include <boost/system/system_category.hpp>
|
||||
#include <boost/core/lightweight_test.hpp>
|
||||
|
||||
namespace sys = boost::system;
|
||||
|
||||
int main()
|
||||
{
|
||||
char buffer[ 1024 ];
|
||||
|
||||
sys::error_condition en;
|
||||
|
||||
BOOST_TEST_EQ( en.value(), 0 );
|
||||
BOOST_TEST( en.category() == sys::generic_category() );
|
||||
BOOST_TEST_EQ( en.message(), en.category().message( en.value() ) );
|
||||
BOOST_TEST_CSTR_EQ( en.message( buffer, sizeof( buffer ) ), en.category().message( en.value(), buffer, sizeof( buffer ) ) );
|
||||
BOOST_TEST( !en.failed() );
|
||||
BOOST_TEST( !en );
|
||||
|
||||
BOOST_TEST_EQ( en.to_string(), std::string( "cond:generic:0" ) );
|
||||
|
||||
{
|
||||
sys::error_condition en2( en );
|
||||
|
||||
BOOST_TEST_EQ( en2.value(), 0 );
|
||||
BOOST_TEST( en2.category() == sys::generic_category() );
|
||||
BOOST_TEST_EQ( en2.message(), en2.category().message( en2.value() ) );
|
||||
BOOST_TEST_CSTR_EQ( en2.message( buffer, sizeof( buffer ) ), en2.category().message( en2.value(), buffer, sizeof( buffer ) ) );
|
||||
BOOST_TEST( !en2.failed() );
|
||||
BOOST_TEST( !en2 );
|
||||
|
||||
BOOST_TEST_EQ( en, en2 );
|
||||
BOOST_TEST_NOT( en != en2 );
|
||||
|
||||
BOOST_TEST_EQ( en2.to_string(), std::string( "cond:generic:0" ) );
|
||||
}
|
||||
|
||||
{
|
||||
sys::error_condition en2( en.value(), en.category() );
|
||||
|
||||
BOOST_TEST_EQ( en2.value(), 0 );
|
||||
BOOST_TEST( en2.category() == sys::generic_category() );
|
||||
BOOST_TEST_EQ( en2.message(), en2.category().message( en2.value() ) );
|
||||
BOOST_TEST_CSTR_EQ( en2.message( buffer, sizeof( buffer ) ), en2.category().message( en2.value(), buffer, sizeof( buffer ) ) );
|
||||
BOOST_TEST( !en2.failed() );
|
||||
BOOST_TEST( !en2 );
|
||||
|
||||
BOOST_TEST_EQ( en, en2 );
|
||||
BOOST_TEST_NOT( en != en2 );
|
||||
|
||||
BOOST_TEST_EQ( en2.to_string(), std::string( "cond:generic:0" ) );
|
||||
}
|
||||
|
||||
{
|
||||
sys::error_condition en2( 5, sys::generic_category() );
|
||||
|
||||
BOOST_TEST_EQ( en2.value(), 5 );
|
||||
BOOST_TEST( en2.category() == sys::generic_category() );
|
||||
BOOST_TEST_EQ( en2.message(), en2.category().message( en2.value() ) );
|
||||
BOOST_TEST_CSTR_EQ( en2.message( buffer, sizeof( buffer ) ), en2.category().message( en2.value(), buffer, sizeof( buffer ) ) );
|
||||
BOOST_TEST( en2.failed() );
|
||||
BOOST_TEST( en2 );
|
||||
BOOST_TEST_NOT( !en2 );
|
||||
|
||||
BOOST_TEST_NE( en, en2 );
|
||||
BOOST_TEST_NOT( en == en2 );
|
||||
|
||||
BOOST_TEST_EQ( en2.to_string(), std::string( "cond:generic:5" ) );
|
||||
}
|
||||
|
||||
{
|
||||
sys::error_condition en2( 5, sys::system_category() );
|
||||
|
||||
BOOST_TEST_EQ( en2.value(), 5 );
|
||||
BOOST_TEST( en2.category() == sys::system_category() );
|
||||
BOOST_TEST_EQ( en2.message(), en2.category().message( en2.value() ) );
|
||||
BOOST_TEST_CSTR_EQ( en2.message( buffer, sizeof( buffer ) ), en2.category().message( en2.value(), buffer, sizeof( buffer ) ) );
|
||||
BOOST_TEST( en2.failed() );
|
||||
BOOST_TEST( en2 );
|
||||
BOOST_TEST_NOT( !en2 );
|
||||
|
||||
BOOST_TEST_NE( en, en2 );
|
||||
BOOST_TEST_NOT( en == en2 );
|
||||
|
||||
BOOST_TEST_EQ( en2.to_string(), std::string( "cond:system:5" ) );
|
||||
}
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
@@ -2,11 +2,9 @@
|
||||
// Copyright 2018 Peter Dimov.
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
|
||||
// Avoid spurious VC++ warnings
|
||||
#define _CRT_SECURE_NO_WARNINGS
|
||||
|
||||
#include <boost/system/error_code.hpp>
|
||||
#include <boost/core/lightweight_test.hpp>
|
||||
#include <boost/core/snprintf.hpp>
|
||||
#include <cstdio>
|
||||
|
||||
using namespace boost::system;
|
||||
@@ -28,7 +26,7 @@ struct http_category_impl: public error_category
|
||||
{
|
||||
char buffer[ 32 ];
|
||||
|
||||
std::sprintf( buffer, "HTTP/1.0 %d", ev );
|
||||
boost::core::snprintf( buffer, sizeof( buffer ), "HTTP/1.0 %d", ev );
|
||||
return buffer;
|
||||
}
|
||||
|
||||
|
||||
@@ -37,7 +37,7 @@ int main()
|
||||
boost::system::system_error x( bc, "prefix" );
|
||||
|
||||
BOOST_TEST_EQ( x.code(), bc );
|
||||
BOOST_TEST_EQ( std::string( x.what() ), "prefix: " + bc.message() );
|
||||
BOOST_TEST_EQ( std::string( x.what() ), "prefix: " + bc.what() );
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
|
||||
242
test/result_convert_construct.cpp
Normal file
242
test/result_convert_construct.cpp
Normal file
@@ -0,0 +1,242 @@
|
||||
// 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 );
|
||||
|
||||
//
|
||||
|
||||
{
|
||||
int x = 5;
|
||||
|
||||
result<int&> r( x );
|
||||
result<int const&> r2 = r;
|
||||
|
||||
BOOST_TEST( r2 ) && BOOST_TEST_EQ( *r2, 5 );
|
||||
}
|
||||
|
||||
{
|
||||
int x = 6;
|
||||
|
||||
result<int&> const r( x );
|
||||
result<int const&> r2 = r;
|
||||
|
||||
BOOST_TEST( r2 ) && BOOST_TEST_EQ( *r2, 6 );
|
||||
}
|
||||
|
||||
{
|
||||
int x = 7;
|
||||
|
||||
result<int const&> r2 = result<int&>( x );
|
||||
|
||||
BOOST_TEST( r2 ) && BOOST_TEST_EQ( *r2, 7 );
|
||||
}
|
||||
|
||||
{
|
||||
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*>>));
|
||||
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_constructible<result<int const&>, result<int&>>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_convertible<result<int&>, result<int const&>>));
|
||||
|
||||
BOOST_TEST_TRAIT_FALSE((std::is_constructible<result<int const&>, result<int>>));
|
||||
BOOST_TEST_TRAIT_FALSE((std::is_convertible<result<int>, result<int const&>>));
|
||||
|
||||
BOOST_TEST_TRAIT_FALSE((std::is_constructible<result<int const&>, result<long&>>));
|
||||
BOOST_TEST_TRAIT_FALSE((std::is_convertible<result<long&>, result<int const&>>));
|
||||
|
||||
BOOST_TEST_TRAIT_FALSE((std::is_constructible<result<int const&>, result<long const&>>));
|
||||
BOOST_TEST_TRAIT_FALSE((std::is_convertible<result<long const&>, result<int const&>>));
|
||||
}
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
@@ -682,5 +682,151 @@ int main()
|
||||
BOOST_TEST_EQ( r, r2 );
|
||||
}
|
||||
|
||||
// reference
|
||||
|
||||
{
|
||||
int x1 = 1;
|
||||
int x2 = 2;
|
||||
|
||||
result<int&> r1( x1 );
|
||||
result<int&> r2( x2 );
|
||||
|
||||
r2 = r1;
|
||||
|
||||
BOOST_TEST_EQ( x1, 1 );
|
||||
BOOST_TEST_EQ( x2, 2 );
|
||||
|
||||
BOOST_TEST_EQ( r1, r2 );
|
||||
BOOST_TEST_EQ( &*r1, &*r2 );
|
||||
}
|
||||
|
||||
{
|
||||
int const x1 = 1;
|
||||
int const x2 = 2;
|
||||
|
||||
result<int const&> r1( x1 );
|
||||
result<int const&> r2( x2 );
|
||||
|
||||
r2 = r1;
|
||||
|
||||
BOOST_TEST_EQ( x1, 1 );
|
||||
BOOST_TEST_EQ( x2, 2 );
|
||||
|
||||
BOOST_TEST_EQ( r1, r2 );
|
||||
BOOST_TEST_EQ( &*r1, &*r2 );
|
||||
}
|
||||
|
||||
{
|
||||
int x1 = 1;
|
||||
|
||||
result<int&> r1( x1 );
|
||||
result<int&> r2( ENOENT, generic_category() );
|
||||
|
||||
r2 = r1;
|
||||
|
||||
BOOST_TEST_EQ( x1, 1 );
|
||||
|
||||
BOOST_TEST_EQ( r1, r2 );
|
||||
BOOST_TEST_EQ( &*r1, &*r2 );
|
||||
}
|
||||
|
||||
{
|
||||
int x1 = 1;
|
||||
int x2 = 2;
|
||||
|
||||
result<int&> const r1( x1 );
|
||||
result<int&> r2( x2 );
|
||||
|
||||
r2 = r1;
|
||||
|
||||
BOOST_TEST_EQ( x1, 1 );
|
||||
BOOST_TEST_EQ( x2, 2 );
|
||||
|
||||
BOOST_TEST_EQ( r1, r2 );
|
||||
BOOST_TEST_EQ( &*r1, &*r2 );
|
||||
}
|
||||
|
||||
{
|
||||
int const x1 = 1;
|
||||
int const x2 = 2;
|
||||
|
||||
result<int const &> const r1( x1 );
|
||||
result<int const &> r2( x2 );
|
||||
|
||||
r2 = r1;
|
||||
|
||||
BOOST_TEST_EQ( x1, 1 );
|
||||
BOOST_TEST_EQ( x2, 2 );
|
||||
|
||||
BOOST_TEST_EQ( r1, r2 );
|
||||
BOOST_TEST_EQ( &*r1, &*r2 );
|
||||
}
|
||||
|
||||
{
|
||||
int x1 = 1;
|
||||
|
||||
result<int&> const r1( x1 );
|
||||
result<int&> r2( ENOENT, generic_category() );
|
||||
|
||||
r2 = r1;
|
||||
|
||||
BOOST_TEST_EQ( x1, 1 );
|
||||
|
||||
BOOST_TEST_EQ( r1, r2 );
|
||||
BOOST_TEST_EQ( &*r1, &*r2 );
|
||||
}
|
||||
|
||||
{
|
||||
int x2 = 2;
|
||||
|
||||
auto ec = make_error_code( errc::invalid_argument );
|
||||
|
||||
result<int&> r1( ec );
|
||||
result<int&> r2( x2 );
|
||||
|
||||
r2 = r1;
|
||||
|
||||
BOOST_TEST_EQ( x2, 2 );
|
||||
|
||||
BOOST_TEST_EQ( r1, r2 );
|
||||
}
|
||||
|
||||
{
|
||||
auto ec = make_error_code( errc::invalid_argument );
|
||||
|
||||
result<int&> r1( ec );
|
||||
result<int&> r2( ENOENT, generic_category() );
|
||||
|
||||
r2 = r1;
|
||||
|
||||
BOOST_TEST_EQ( r1, r2 );
|
||||
}
|
||||
|
||||
{
|
||||
int x2 = 2;
|
||||
|
||||
auto ec = make_error_code( errc::invalid_argument );
|
||||
|
||||
result<int&> const r1( ec );
|
||||
result<int&> r2( x2 );
|
||||
|
||||
r2 = r1;
|
||||
|
||||
BOOST_TEST_EQ( x2, 2 );
|
||||
|
||||
BOOST_TEST_EQ( r1, r2 );
|
||||
}
|
||||
|
||||
{
|
||||
auto ec = make_error_code( errc::invalid_argument );
|
||||
|
||||
result<int&> const r1( ec );
|
||||
result<int&> r2( ENOENT, generic_category() );
|
||||
|
||||
r2 = r1;
|
||||
|
||||
BOOST_TEST_EQ( r1, r2 );
|
||||
}
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
|
||||
@@ -145,6 +145,8 @@ int main()
|
||||
|
||||
BOOST_TEST_EQ( X::instances, 0 );
|
||||
|
||||
//
|
||||
|
||||
{
|
||||
result<void> r;
|
||||
result<void> r2( r );
|
||||
@@ -177,5 +179,121 @@ int main()
|
||||
BOOST_TEST_EQ( r, r2 );
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
{
|
||||
int x1 = 1;
|
||||
|
||||
result<int&> r1( x1 );
|
||||
result<int&> r2( r1 );
|
||||
|
||||
BOOST_TEST_EQ( r1, r2 );
|
||||
BOOST_TEST_EQ( &*r2, &x1 );
|
||||
}
|
||||
|
||||
{
|
||||
int x1 = 1;
|
||||
|
||||
result<int&> const r1( x1 );
|
||||
result<int&> r2( r1 );
|
||||
|
||||
BOOST_TEST_EQ( r1, r2 );
|
||||
BOOST_TEST_EQ( &*r2, &x1 );
|
||||
}
|
||||
|
||||
{
|
||||
int const x1 = 1;
|
||||
|
||||
result<int const&> r1( x1 );
|
||||
result<int const&> r2( r1 );
|
||||
|
||||
BOOST_TEST_EQ( r1, r2 );
|
||||
BOOST_TEST_EQ( &*r2, &x1 );
|
||||
}
|
||||
|
||||
{
|
||||
int const x1 = 1;
|
||||
|
||||
result<int const&> const r1( x1 );
|
||||
result<int const&> r2( r1 );
|
||||
|
||||
BOOST_TEST_EQ( r1, r2 );
|
||||
BOOST_TEST_EQ( &*r2, &x1 );
|
||||
}
|
||||
|
||||
BOOST_TEST_EQ( X::instances, 0 );
|
||||
|
||||
{
|
||||
X x1( 1 );
|
||||
|
||||
result<X&> r1( x1 );
|
||||
result<X&> r2( r1 );
|
||||
|
||||
BOOST_TEST_EQ( r1, r2 );
|
||||
BOOST_TEST_EQ( &*r2, &x1 );
|
||||
BOOST_TEST_EQ( X::instances, 1 );
|
||||
}
|
||||
|
||||
BOOST_TEST_EQ( X::instances, 0 );
|
||||
|
||||
{
|
||||
X x1( 1 );
|
||||
|
||||
result<X&> const r1( x1 );
|
||||
result<X&> r2( r1 );
|
||||
|
||||
BOOST_TEST_EQ( r1, r2 );
|
||||
BOOST_TEST_EQ( &*r2, &x1 );
|
||||
BOOST_TEST_EQ( X::instances, 1 );
|
||||
}
|
||||
|
||||
BOOST_TEST_EQ( X::instances, 0 );
|
||||
|
||||
{
|
||||
X const x1( 1 );
|
||||
|
||||
result<X const&> r1( x1 );
|
||||
result<X const&> r2( r1 );
|
||||
|
||||
BOOST_TEST_EQ( r1, r2 );
|
||||
BOOST_TEST_EQ( &*r2, &x1 );
|
||||
BOOST_TEST_EQ( X::instances, 1 );
|
||||
}
|
||||
|
||||
BOOST_TEST_EQ( X::instances, 0 );
|
||||
|
||||
{
|
||||
X const x1( 1 );
|
||||
|
||||
result<X const&> const r1( x1 );
|
||||
result<X const&> r2( r1 );
|
||||
|
||||
BOOST_TEST_EQ( r1, r2 );
|
||||
BOOST_TEST_EQ( &*r2, &x1 );
|
||||
BOOST_TEST_EQ( X::instances, 1 );
|
||||
}
|
||||
|
||||
BOOST_TEST_EQ( X::instances, 0 );
|
||||
|
||||
{
|
||||
auto ec = make_error_code( errc::invalid_argument );
|
||||
|
||||
result<int&> r1( ec );
|
||||
result<int&> r2( r1 );
|
||||
|
||||
BOOST_TEST_EQ( r1, r2 );
|
||||
}
|
||||
|
||||
{
|
||||
auto ec = make_error_code( errc::invalid_argument );
|
||||
|
||||
result<int&> const r1( ec );
|
||||
result<int&> r2( r1 );
|
||||
|
||||
BOOST_TEST_EQ( r1, r2 );
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
|
||||
@@ -12,6 +12,11 @@ struct X
|
||||
{
|
||||
};
|
||||
|
||||
struct Y
|
||||
{
|
||||
Y( int );
|
||||
};
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
@@ -37,5 +42,20 @@ 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>>));
|
||||
|
||||
BOOST_TEST_TRAIT_FALSE((std::is_default_constructible<result<int&>>));
|
||||
BOOST_TEST_TRAIT_FALSE((std::is_default_constructible<result<int&, int>>));
|
||||
}
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
|
||||
218
test/result_emplace.cpp
Normal file
218
test/result_emplace.cpp
Normal file
@@ -0,0 +1,218 @@
|
||||
// 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 <cerrno>
|
||||
|
||||
using namespace boost::system;
|
||||
|
||||
struct X
|
||||
{
|
||||
static int instances;
|
||||
|
||||
int v_;
|
||||
|
||||
explicit X( int v ): v_( v ) { ++instances; }
|
||||
|
||||
X( int v1, int v2 ): v_( v1+v2 ) { ++instances; }
|
||||
X( int v1, int v2, int v3 ): v_( v1+v2+v3 ) { ++instances; }
|
||||
|
||||
X( X const& ) = delete;
|
||||
X& operator=( X const& ) = delete;
|
||||
|
||||
~X() { --instances; }
|
||||
};
|
||||
|
||||
int X::instances = 0;
|
||||
|
||||
struct Y
|
||||
{
|
||||
static int instances;
|
||||
|
||||
Y() noexcept { ++instances; }
|
||||
|
||||
Y( Y const& ) noexcept { ++instances; }
|
||||
|
||||
Y& operator=( Y const& ) = default;
|
||||
|
||||
~Y() { --instances; }
|
||||
};
|
||||
|
||||
int Y::instances = 0;
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
result<int> r;
|
||||
|
||||
BOOST_TEST( r.has_value() );
|
||||
|
||||
r.emplace( 1 );
|
||||
|
||||
BOOST_TEST( r.has_value() );
|
||||
BOOST_TEST_EQ( r.value(), 1 );
|
||||
}
|
||||
|
||||
{
|
||||
result<int> r( ENOENT, generic_category() );
|
||||
|
||||
BOOST_TEST( !r.has_value() );
|
||||
|
||||
r.emplace( 1 );
|
||||
|
||||
BOOST_TEST( r.has_value() );
|
||||
BOOST_TEST_EQ( r.value(), 1 );
|
||||
}
|
||||
|
||||
BOOST_TEST_EQ( X::instances, 0 );
|
||||
|
||||
{
|
||||
result<X> r( 0 );
|
||||
|
||||
BOOST_TEST( r.has_value() );
|
||||
BOOST_TEST_EQ( r.value().v_, 0 );
|
||||
BOOST_TEST_EQ( X::instances, 1 );
|
||||
|
||||
r.emplace( 1 );
|
||||
BOOST_TEST( r.has_value() );
|
||||
BOOST_TEST_EQ( r.value().v_, 1 );
|
||||
BOOST_TEST_EQ( X::instances, 1 );
|
||||
|
||||
r.emplace( 1, 2 );
|
||||
BOOST_TEST( r.has_value() );
|
||||
BOOST_TEST_EQ( r.value().v_, 1+2 );
|
||||
BOOST_TEST_EQ( X::instances, 1 );
|
||||
|
||||
r.emplace( 1, 2, 3 );
|
||||
BOOST_TEST( r.has_value() );
|
||||
BOOST_TEST_EQ( r.value().v_, 1+2+3 );
|
||||
BOOST_TEST_EQ( X::instances, 1 );
|
||||
}
|
||||
|
||||
BOOST_TEST_EQ( X::instances, 0 );
|
||||
|
||||
{
|
||||
result<X> r( ENOENT, generic_category() );
|
||||
|
||||
BOOST_TEST( !r.has_value() );
|
||||
BOOST_TEST_EQ( X::instances, 0 );
|
||||
|
||||
r.emplace( 1, 2 );
|
||||
BOOST_TEST( r.has_value() );
|
||||
BOOST_TEST_EQ( r.value().v_, 1+2 );
|
||||
BOOST_TEST_EQ( X::instances, 1 );
|
||||
}
|
||||
|
||||
BOOST_TEST_EQ( X::instances, 0 );
|
||||
BOOST_TEST_EQ( Y::instances, 0 );
|
||||
|
||||
{
|
||||
result<int, Y> r( Y{} );
|
||||
|
||||
BOOST_TEST( !r.has_value() );
|
||||
BOOST_TEST_EQ( Y::instances, 1 );
|
||||
|
||||
r.emplace( 1 );
|
||||
BOOST_TEST( r.has_value() );
|
||||
BOOST_TEST_EQ( *r, 1 );
|
||||
BOOST_TEST_EQ( Y::instances, 0 );
|
||||
}
|
||||
|
||||
BOOST_TEST_EQ( X::instances, 0 );
|
||||
BOOST_TEST_EQ( Y::instances, 0 );
|
||||
|
||||
{
|
||||
result<X, Y> r( in_place_error );
|
||||
|
||||
BOOST_TEST( !r.has_value() );
|
||||
BOOST_TEST_EQ( X::instances, 0 );
|
||||
BOOST_TEST_EQ( Y::instances, 1 );
|
||||
|
||||
r.emplace( 1, 2, 3 );
|
||||
|
||||
BOOST_TEST( r.has_value() );
|
||||
BOOST_TEST_EQ( r->v_, 1+2+3 );
|
||||
BOOST_TEST_EQ( X::instances, 1 );
|
||||
BOOST_TEST_EQ( Y::instances, 0 );
|
||||
}
|
||||
|
||||
BOOST_TEST_EQ( X::instances, 0 );
|
||||
BOOST_TEST_EQ( Y::instances, 0 );
|
||||
|
||||
{
|
||||
result<void> r;
|
||||
|
||||
BOOST_TEST( r.has_value() );
|
||||
|
||||
r.emplace();
|
||||
BOOST_TEST( r.has_value() );
|
||||
}
|
||||
|
||||
{
|
||||
result<void> r( ENOENT, generic_category() );
|
||||
|
||||
BOOST_TEST( !r.has_value() );
|
||||
|
||||
r.emplace();
|
||||
BOOST_TEST( r.has_value() );
|
||||
}
|
||||
|
||||
BOOST_TEST_EQ( Y::instances, 0 );
|
||||
|
||||
{
|
||||
result<void, Y> r( in_place_error );
|
||||
|
||||
BOOST_TEST( !r.has_value() );
|
||||
BOOST_TEST_EQ( Y::instances, 1 );
|
||||
|
||||
r.emplace();
|
||||
BOOST_TEST( r.has_value() );
|
||||
BOOST_TEST_EQ( Y::instances, 0 );
|
||||
}
|
||||
|
||||
{
|
||||
int x1 = 1;
|
||||
result<int&> r( x1 );
|
||||
|
||||
BOOST_TEST( r.has_value() );
|
||||
BOOST_TEST_EQ( r.value(), 1 );
|
||||
|
||||
int x2 = 2;
|
||||
r.emplace( x2 );
|
||||
|
||||
BOOST_TEST( r.has_value() );
|
||||
BOOST_TEST_EQ( r.value(), 2 );
|
||||
}
|
||||
|
||||
{
|
||||
result<int&> r( ENOENT, generic_category() );
|
||||
|
||||
BOOST_TEST( !r.has_value() );
|
||||
|
||||
int x2 = 2;
|
||||
r.emplace( x2 );
|
||||
|
||||
BOOST_TEST( r.has_value() );
|
||||
BOOST_TEST_EQ( r.value(), 2 );
|
||||
}
|
||||
|
||||
BOOST_TEST_EQ( Y::instances, 0 );
|
||||
|
||||
{
|
||||
result<int&, Y> r( in_place_error );
|
||||
|
||||
BOOST_TEST( !r.has_value() );
|
||||
BOOST_TEST_EQ( Y::instances, 1 );
|
||||
|
||||
int x2 = 2;
|
||||
r.emplace( x2 );
|
||||
|
||||
BOOST_TEST( r.has_value() );
|
||||
BOOST_TEST_EQ( *r, 2 );
|
||||
BOOST_TEST_EQ( Y::instances, 0 );
|
||||
}
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
@@ -149,5 +149,83 @@ int main()
|
||||
BOOST_TEST_NE( r1, r2 );
|
||||
}
|
||||
|
||||
{
|
||||
int x1 = 1;
|
||||
int x2 = 2;
|
||||
|
||||
result<int&> r1( x1 );
|
||||
result<int&> r2( x2 );
|
||||
|
||||
BOOST_TEST_EQ( r1, r1 );
|
||||
BOOST_TEST_NE( r1, r2 );
|
||||
}
|
||||
|
||||
{
|
||||
int x1 = 1;
|
||||
int x2 = 1;
|
||||
|
||||
result<int&> r1( x1 );
|
||||
result<int&> r2( x2 );
|
||||
|
||||
BOOST_TEST_EQ( r1, r2 );
|
||||
}
|
||||
|
||||
{
|
||||
result<int&> r1( 1, generic_category() );
|
||||
result<int&> r2( 2, generic_category() );
|
||||
|
||||
BOOST_TEST_EQ( r1, r1 );
|
||||
BOOST_TEST_NE( r1, r2 );
|
||||
}
|
||||
|
||||
{
|
||||
int x1 = 1;
|
||||
|
||||
result<int&> r1( x1 );
|
||||
result<int&> r2( 2, generic_category() );
|
||||
|
||||
BOOST_TEST_EQ( r1, r1 );
|
||||
BOOST_TEST_NE( r1, r2 );
|
||||
}
|
||||
|
||||
{
|
||||
X x1( 1 );
|
||||
X x2( 2 );
|
||||
|
||||
result<X&, Y> r1( x1 );
|
||||
result<X&, Y> r2( x2 );
|
||||
|
||||
BOOST_TEST_EQ( r1, r1 );
|
||||
BOOST_TEST_NE( r1, r2 );
|
||||
}
|
||||
|
||||
{
|
||||
X x1( 1 );
|
||||
X x2( 1 );
|
||||
|
||||
result<X&, Y> r1( x1 );
|
||||
result<X&, Y> r2( x2 );
|
||||
|
||||
BOOST_TEST_EQ( r1, r2 );
|
||||
}
|
||||
|
||||
{
|
||||
result<X&, Y> r1( in_place_error, 1 );
|
||||
result<X&, Y> r2( in_place_error, 2 );
|
||||
|
||||
BOOST_TEST_EQ( r1, r1 );
|
||||
BOOST_TEST_NE( r1, r2 );
|
||||
}
|
||||
|
||||
{
|
||||
X x1( 1 );
|
||||
|
||||
result<X&, Y> r1( x1 );
|
||||
result<X&, Y> r2( in_place_error, 2 );
|
||||
|
||||
BOOST_TEST_EQ( r1, r1 );
|
||||
BOOST_TEST_NE( r1, r2 );
|
||||
}
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
|
||||
32
test/result_errc_construct.cpp
Normal file
32
test/result_errc_construct.cpp
Normal file
@@ -0,0 +1,32 @@
|
||||
// Copyright 2021 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_trait.hpp>
|
||||
#include <type_traits>
|
||||
|
||||
using namespace boost::system;
|
||||
|
||||
int main()
|
||||
{
|
||||
BOOST_TEST_TRAIT_FALSE((std::is_convertible<errc::errc_t, result<int>>));
|
||||
BOOST_TEST_TRAIT_FALSE((std::is_constructible<result<int>, errc::errc_t>));
|
||||
|
||||
BOOST_TEST_TRAIT_FALSE((std::is_convertible<errc::errc_t, result<double>>));
|
||||
BOOST_TEST_TRAIT_FALSE((std::is_constructible<result<double>, errc::errc_t>));
|
||||
|
||||
BOOST_TEST_TRAIT_FALSE((std::is_convertible<errc::errc_t, result<bool>>));
|
||||
BOOST_TEST_TRAIT_FALSE((std::is_constructible<result<bool>, errc::errc_t>));
|
||||
|
||||
BOOST_TEST_TRAIT_FALSE((std::is_convertible<errc::errc_t, result<int const&>>));
|
||||
BOOST_TEST_TRAIT_FALSE((std::is_constructible<result<int const&>, errc::errc_t>));
|
||||
|
||||
BOOST_TEST_TRAIT_FALSE((std::is_convertible<errc::errc_t, result<double const&>>));
|
||||
BOOST_TEST_TRAIT_FALSE((std::is_constructible<result<double const&>, errc::errc_t>));
|
||||
|
||||
BOOST_TEST_TRAIT_FALSE((std::is_convertible<errc::errc_t, result<bool const&>>));
|
||||
BOOST_TEST_TRAIT_FALSE((std::is_constructible<result<bool const&>, errc::errc_t>));
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
@@ -152,6 +152,8 @@ int main()
|
||||
BOOST_TEST_EQ( (result<std::string, X>( "s" ).error().v_), 0 );
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
{
|
||||
result<void> r;
|
||||
|
||||
@@ -208,5 +210,71 @@ int main()
|
||||
BOOST_TEST_EQ( result<void>( ec ).error(), ec );
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
{
|
||||
int x1 = 1;
|
||||
|
||||
result<int&> r( x1 );
|
||||
|
||||
BOOST_TEST( r.has_value() );
|
||||
BOOST_TEST( !r.has_error() );
|
||||
|
||||
BOOST_TEST_EQ( r.error(), error_code() );
|
||||
}
|
||||
|
||||
{
|
||||
int x1 = 1;
|
||||
|
||||
result<int&> const r( x1 );
|
||||
|
||||
BOOST_TEST( r.has_value() );
|
||||
BOOST_TEST( !r.has_error() );
|
||||
|
||||
BOOST_TEST_EQ( r.error(), error_code() );
|
||||
}
|
||||
|
||||
{
|
||||
int x1 = 1;
|
||||
|
||||
BOOST_TEST( result<int&>( x1 ).has_value() );
|
||||
BOOST_TEST( !result<int&>( x1 ).has_error() );
|
||||
|
||||
BOOST_TEST_EQ( result<int&>( x1 ).error(), error_code() );
|
||||
}
|
||||
|
||||
{
|
||||
auto ec = make_error_code( errc::invalid_argument );
|
||||
|
||||
result<int&> r( ec );
|
||||
|
||||
BOOST_TEST( !r.has_value() );
|
||||
BOOST_TEST( r.has_error() );
|
||||
|
||||
BOOST_TEST_EQ( r.error(), ec );
|
||||
}
|
||||
|
||||
{
|
||||
auto ec = make_error_code( errc::invalid_argument );
|
||||
|
||||
result<int&> const r( ec );
|
||||
|
||||
BOOST_TEST( !r.has_value() );
|
||||
BOOST_TEST( r.has_error() );
|
||||
|
||||
BOOST_TEST_EQ( r.error(), ec );
|
||||
}
|
||||
|
||||
{
|
||||
auto ec = make_error_code( errc::invalid_argument );
|
||||
|
||||
BOOST_TEST( !result<int&>( ec ).has_value() );
|
||||
BOOST_TEST( result<int&>( ec ).has_error() );
|
||||
|
||||
BOOST_TEST_EQ( result<int&>( ec ).error(), ec );
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
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,14 +140,20 @@ 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>>));
|
||||
|
||||
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>>));
|
||||
}
|
||||
|
||||
{
|
||||
@@ -178,7 +184,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();
|
||||
|
||||
57
test/result_error_construct2.cpp
Normal file
57
test/result_error_construct2.cpp
Normal file
@@ -0,0 +1,57 @@
|
||||
// Copyright 2021 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 <string>
|
||||
|
||||
using namespace boost::system;
|
||||
|
||||
struct X
|
||||
{
|
||||
int a, b;
|
||||
};
|
||||
|
||||
result<X> fx1()
|
||||
{
|
||||
return {{ EINVAL, generic_category() }};
|
||||
}
|
||||
|
||||
struct Y
|
||||
{
|
||||
std::string v;
|
||||
};
|
||||
|
||||
struct E
|
||||
{
|
||||
int v;
|
||||
};
|
||||
|
||||
result<Y, E> fy1()
|
||||
{
|
||||
return {{ 42 }};
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
result<X> r = fx1();
|
||||
|
||||
BOOST_TEST( !r.has_value() );
|
||||
BOOST_TEST( r.has_error() );
|
||||
|
||||
BOOST_TEST_EQ( r.error(), error_code( EINVAL, generic_category() ) );
|
||||
}
|
||||
|
||||
{
|
||||
result<Y, E> r = fy1();
|
||||
|
||||
BOOST_TEST( !r.has_value() );
|
||||
BOOST_TEST( r.has_error() );
|
||||
|
||||
BOOST_TEST_EQ( r.error().v, 42 );
|
||||
}
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
183
test/result_error_construct3.cpp
Normal file
183
test/result_error_construct3.cpp
Normal file
@@ -0,0 +1,183 @@
|
||||
// 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 <string>
|
||||
#include <cerrno>
|
||||
|
||||
using namespace boost::system;
|
||||
|
||||
struct X
|
||||
{
|
||||
static int instances;
|
||||
|
||||
int v_;
|
||||
|
||||
X(): v_() { ++instances; }
|
||||
|
||||
explicit X( int v ): v_( v ) { ++instances; }
|
||||
|
||||
X( int v1, int v2 ): v_( v1+v2 ) { ++instances; }
|
||||
X( int v1, int v2, int v3 ): v_( v1+v2+v3 ) { ++instances; }
|
||||
|
||||
X( X const& r ): v_( r.v_ ) { ++instances; }
|
||||
|
||||
X& operator=( X const& ) = delete;
|
||||
|
||||
~X() { --instances; }
|
||||
};
|
||||
|
||||
int X::instances = 0;
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
auto ec = make_error_code( errc::invalid_argument );
|
||||
|
||||
using R = result<int>;
|
||||
R r( R::in_place_error, ec );
|
||||
|
||||
BOOST_TEST( !r.has_value() );
|
||||
BOOST_TEST( r.has_error() );
|
||||
|
||||
BOOST_TEST_EQ( r.error(), ec );
|
||||
}
|
||||
|
||||
{
|
||||
using R = result<int>;
|
||||
R r( R::in_place_error, EINVAL, generic_category() );
|
||||
|
||||
BOOST_TEST( !r.has_value() );
|
||||
BOOST_TEST( r.has_error() );
|
||||
|
||||
BOOST_TEST_EQ( r.error(), error_code( EINVAL, generic_category() ) );
|
||||
}
|
||||
|
||||
{
|
||||
auto ec = make_error_code( errc::invalid_argument );
|
||||
|
||||
using R = result<error_code>;
|
||||
R r( R::in_place_error, ec );
|
||||
|
||||
BOOST_TEST( !r.has_value() );
|
||||
BOOST_TEST( r.has_error() );
|
||||
|
||||
BOOST_TEST_EQ( r.error(), ec );
|
||||
}
|
||||
|
||||
{
|
||||
using R = result<error_code>;
|
||||
R r( R::in_place_error, EINVAL, generic_category() );
|
||||
|
||||
BOOST_TEST( !r.has_value() );
|
||||
BOOST_TEST( r.has_error() );
|
||||
|
||||
BOOST_TEST_EQ( r.error(), error_code( EINVAL, generic_category() ) );
|
||||
}
|
||||
|
||||
BOOST_TEST_EQ( X::instances, 0 );
|
||||
|
||||
{
|
||||
using R = result<std::string, X>;
|
||||
R r( R::in_place_error, 1 );
|
||||
|
||||
BOOST_TEST( !r.has_value() );
|
||||
BOOST_TEST( r.has_error() );
|
||||
|
||||
BOOST_TEST_EQ( r.error().v_, 1 );
|
||||
|
||||
BOOST_TEST_EQ( X::instances, 1 );
|
||||
}
|
||||
|
||||
BOOST_TEST_EQ( X::instances, 0 );
|
||||
|
||||
{
|
||||
using R = result<int, X>;
|
||||
R r( R::in_place_error, 1, 2 );
|
||||
|
||||
BOOST_TEST( !r.has_value() );
|
||||
BOOST_TEST( r.has_error() );
|
||||
|
||||
BOOST_TEST_EQ( r.error().v_, 1+2 );
|
||||
|
||||
BOOST_TEST_EQ( X::instances, 1 );
|
||||
}
|
||||
|
||||
BOOST_TEST_EQ( X::instances, 0 );
|
||||
|
||||
{
|
||||
using R = result<int, X>;
|
||||
R r( R::in_place_error, 1, 2, 3 );
|
||||
|
||||
BOOST_TEST( !r.has_value() );
|
||||
BOOST_TEST( r.has_error() );
|
||||
|
||||
BOOST_TEST_EQ( r.error().v_, 1+2+3 );
|
||||
|
||||
BOOST_TEST_EQ( X::instances, 1 );
|
||||
}
|
||||
|
||||
BOOST_TEST_EQ( X::instances, 0 );
|
||||
|
||||
{
|
||||
using R = result<X, X>;
|
||||
R r( R::in_place_error, 1 );
|
||||
|
||||
BOOST_TEST( !r.has_value() );
|
||||
BOOST_TEST( r.has_error() );
|
||||
|
||||
BOOST_TEST_EQ( r.error().v_, 1 );
|
||||
|
||||
BOOST_TEST_EQ( X::instances, 1 );
|
||||
}
|
||||
|
||||
BOOST_TEST_EQ( X::instances, 0 );
|
||||
|
||||
{
|
||||
auto ec = make_error_code( errc::invalid_argument );
|
||||
|
||||
using R = result<void>;
|
||||
R r( R::in_place_error, ec );
|
||||
|
||||
BOOST_TEST( !r.has_value() );
|
||||
BOOST_TEST( r.has_error() );
|
||||
|
||||
BOOST_TEST_EQ( r.error(), ec );
|
||||
}
|
||||
|
||||
{
|
||||
using R = result<void>;
|
||||
R r( R::in_place_error, EINVAL, generic_category() );
|
||||
|
||||
BOOST_TEST( !r.has_value() );
|
||||
BOOST_TEST( r.has_error() );
|
||||
|
||||
BOOST_TEST_EQ( r.error(), error_code( EINVAL, generic_category() ) );
|
||||
}
|
||||
|
||||
{
|
||||
auto ec = make_error_code( errc::invalid_argument );
|
||||
|
||||
using R = result<int&>;
|
||||
R r( R::in_place_error, ec );
|
||||
|
||||
BOOST_TEST( !r.has_value() );
|
||||
BOOST_TEST( r.has_error() );
|
||||
|
||||
BOOST_TEST_EQ( r.error(), ec );
|
||||
}
|
||||
|
||||
{
|
||||
using R = result<int&>;
|
||||
R r( R::in_place_error, EINVAL, generic_category() );
|
||||
|
||||
BOOST_TEST( !r.has_value() );
|
||||
BOOST_TEST( r.has_error() );
|
||||
|
||||
BOOST_TEST_EQ( r.error(), error_code( EINVAL, generic_category() ) );
|
||||
}
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
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();
|
||||
}
|
||||
160
test/result_error_construct5.cpp
Normal file
160
test/result_error_construct5.cpp
Normal file
@@ -0,0 +1,160 @@
|
||||
// Copyright 2017, 2021 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>
|
||||
#include <string>
|
||||
#include <cerrno>
|
||||
|
||||
using namespace boost::system;
|
||||
|
||||
struct X
|
||||
{
|
||||
static int instances;
|
||||
|
||||
int v_;
|
||||
|
||||
X(): v_() { ++instances; }
|
||||
|
||||
explicit X( int v ): v_( v ) { ++instances; }
|
||||
|
||||
X( int v1, int v2 ): v_( v1+v2 ) { ++instances; }
|
||||
X( int v1, int v2, int v3 ): v_( v1+v2+v3 ) { ++instances; }
|
||||
|
||||
X( X const& r ): v_( r.v_ ) { ++instances; }
|
||||
|
||||
X& operator=( X const& ) = delete;
|
||||
|
||||
~X() { --instances; }
|
||||
};
|
||||
|
||||
int X::instances = 0;
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
auto ec = make_error_code( errc::invalid_argument );
|
||||
|
||||
result<int&> r( ec );
|
||||
|
||||
BOOST_TEST( !r.has_value() );
|
||||
BOOST_TEST( r.has_error() );
|
||||
|
||||
BOOST_TEST_EQ( r.error(), ec );
|
||||
}
|
||||
|
||||
{
|
||||
auto ec = make_error_code( errc::invalid_argument );
|
||||
|
||||
result<int&> r = ec;
|
||||
|
||||
BOOST_TEST( !r.has_value() );
|
||||
BOOST_TEST( r.has_error() );
|
||||
|
||||
BOOST_TEST_EQ( r.error(), ec );
|
||||
}
|
||||
|
||||
{
|
||||
result<int&> r( EINVAL, generic_category() );
|
||||
|
||||
BOOST_TEST( !r.has_value() );
|
||||
BOOST_TEST( r.has_error() );
|
||||
|
||||
BOOST_TEST_EQ( r.error(), error_code( EINVAL, generic_category() ) );
|
||||
}
|
||||
|
||||
{
|
||||
auto ec = make_error_code( errc::invalid_argument );
|
||||
|
||||
result<error_code&> r( in_place_error, ec );
|
||||
|
||||
BOOST_TEST( !r.has_value() );
|
||||
BOOST_TEST( r.has_error() );
|
||||
|
||||
BOOST_TEST_EQ( r.error(), ec );
|
||||
}
|
||||
|
||||
{
|
||||
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(), error_code( EINVAL, generic_category() ) );
|
||||
}
|
||||
|
||||
BOOST_TEST_EQ( X::instances, 0 );
|
||||
|
||||
{
|
||||
result<std::string&, X> r( 1 );
|
||||
|
||||
BOOST_TEST( !r.has_value() );
|
||||
BOOST_TEST( r.has_error() );
|
||||
|
||||
BOOST_TEST_EQ( r.error().v_, 1 );
|
||||
|
||||
BOOST_TEST_EQ( X::instances, 1 );
|
||||
}
|
||||
|
||||
BOOST_TEST_EQ( X::instances, 0 );
|
||||
|
||||
{
|
||||
result<int&, X> r( 1, 2 );
|
||||
|
||||
BOOST_TEST( !r.has_value() );
|
||||
BOOST_TEST( r.has_error() );
|
||||
|
||||
BOOST_TEST_EQ( r.error().v_, 1+2 );
|
||||
|
||||
BOOST_TEST_EQ( X::instances, 1 );
|
||||
}
|
||||
|
||||
BOOST_TEST_EQ( X::instances, 0 );
|
||||
|
||||
{
|
||||
result<int&, X> r( 1, 2, 3 );
|
||||
|
||||
BOOST_TEST( !r.has_value() );
|
||||
BOOST_TEST( r.has_error() );
|
||||
|
||||
BOOST_TEST_EQ( r.error().v_, 1+2+3 );
|
||||
|
||||
BOOST_TEST_EQ( X::instances, 1 );
|
||||
}
|
||||
|
||||
BOOST_TEST_EQ( X::instances, 0 );
|
||||
|
||||
{
|
||||
result<X&, X> r( in_place_error, 1 );
|
||||
|
||||
BOOST_TEST( !r.has_value() );
|
||||
BOOST_TEST( r.has_error() );
|
||||
|
||||
BOOST_TEST_EQ( r.error().v_, 1 );
|
||||
|
||||
BOOST_TEST_EQ( X::instances, 1 );
|
||||
}
|
||||
|
||||
BOOST_TEST_EQ( X::instances, 0 );
|
||||
|
||||
{
|
||||
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>>));
|
||||
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_constructible<result<int&, X>, int>));
|
||||
BOOST_TEST_TRAIT_FALSE((std::is_convertible<int, result<int&, X>>));
|
||||
|
||||
// There's an ambiguity here between int& and X, but since is_convertible
|
||||
// is true, is_constructible can't be false.
|
||||
|
||||
// BOOST_TEST_TRAIT_FALSE((std::is_constructible<result<int&, X>, int&>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_convertible<int&, result<int&, X>>));
|
||||
}
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
133
test/result_error_move.cpp
Normal file
133
test/result_error_move.cpp
Normal file
@@ -0,0 +1,133 @@
|
||||
// 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 );
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
{
|
||||
result<double&, 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<double&, X>( 1 ).has_value() ));
|
||||
BOOST_TEST(( result<double&, X>( 1 ).has_error() ));
|
||||
|
||||
BOOST_TEST_EQ( (result<double&, X>( 1 ).error().v_), 1 );
|
||||
}
|
||||
|
||||
{
|
||||
double x = 1.0;
|
||||
|
||||
result<double&, X> r( x );
|
||||
|
||||
BOOST_TEST( r.has_value() );
|
||||
BOOST_TEST( !r.has_error() );
|
||||
|
||||
BOOST_TEST_EQ( std::move( r ).error().v_, 0 );
|
||||
}
|
||||
|
||||
{
|
||||
double x = 1.0;
|
||||
|
||||
BOOST_TEST(( result<double&, X>( x ).has_value() ));
|
||||
BOOST_TEST(( !result<double&, X>( x ).has_error() ));
|
||||
|
||||
BOOST_TEST_EQ( (result<double&, X>( x ).error().v_), 0 );
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
@@ -508,6 +508,8 @@ int main()
|
||||
|
||||
BOOST_TEST_EQ( Y::instances, 0 );
|
||||
|
||||
//
|
||||
|
||||
{
|
||||
result<void> r;
|
||||
result<void> r2;
|
||||
@@ -600,5 +602,110 @@ int main()
|
||||
BOOST_TEST_EQ( r2.error(), ec );
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
{
|
||||
int x1 = 1;
|
||||
int x2 = 2;
|
||||
|
||||
result<int&> r1( x1 );
|
||||
result<int&> r2( x2 );
|
||||
|
||||
r2 = std::move( r1 );
|
||||
|
||||
BOOST_TEST_EQ( x1, 1 );
|
||||
BOOST_TEST_EQ( x2, 2 );
|
||||
|
||||
BOOST_TEST( r2.has_value() );
|
||||
BOOST_TEST( !r2.has_error() );
|
||||
|
||||
BOOST_TEST_EQ( r2.value(), 1 );
|
||||
|
||||
BOOST_TEST_EQ( r1, r2 );
|
||||
BOOST_TEST_EQ( &*r1, &*r2 );
|
||||
}
|
||||
|
||||
{
|
||||
int x1 = 1;
|
||||
|
||||
result<int&> r1( x1 );
|
||||
result<int&> r2( ENOENT, generic_category() );
|
||||
|
||||
r2 = std::move( r1 );
|
||||
|
||||
BOOST_TEST_EQ( x1, 1 );
|
||||
|
||||
BOOST_TEST( r2.has_value() );
|
||||
BOOST_TEST( !r2.has_error() );
|
||||
|
||||
BOOST_TEST_EQ( r2.value(), 1 );
|
||||
|
||||
BOOST_TEST_EQ( r1, r2 );
|
||||
}
|
||||
|
||||
{
|
||||
int x1 = 1;
|
||||
|
||||
auto ec = make_error_code( errc::invalid_argument );
|
||||
|
||||
result<int&> r1( ec );
|
||||
result<int&> r2( x1 );
|
||||
|
||||
r2 = std::move( r1 );
|
||||
|
||||
BOOST_TEST_EQ( x1, 1 );
|
||||
|
||||
BOOST_TEST( !r2.has_value() );
|
||||
BOOST_TEST( r2.has_error() );
|
||||
|
||||
BOOST_TEST_EQ( r2.error(), ec );
|
||||
}
|
||||
|
||||
{
|
||||
int x1 = 1;
|
||||
|
||||
auto ec = make_error_code( errc::invalid_argument );
|
||||
|
||||
result<int&> r2( x1 );
|
||||
|
||||
r2 = result<int&>( ec );
|
||||
|
||||
BOOST_TEST_EQ( x1, 1 );
|
||||
|
||||
BOOST_TEST( !r2.has_value() );
|
||||
BOOST_TEST( r2.has_error() );
|
||||
|
||||
BOOST_TEST_EQ( r2.error(), ec );
|
||||
}
|
||||
|
||||
{
|
||||
auto ec = make_error_code( errc::invalid_argument );
|
||||
|
||||
result<int&> r1( ec );
|
||||
result<int&> r2( ENOENT, generic_category() );
|
||||
|
||||
r2 = std::move( r1 );
|
||||
|
||||
BOOST_TEST( !r2.has_value() );
|
||||
BOOST_TEST( r2.has_error() );
|
||||
|
||||
BOOST_TEST_EQ( r2.error(), ec );
|
||||
}
|
||||
|
||||
{
|
||||
auto ec = make_error_code( errc::invalid_argument );
|
||||
|
||||
result<int&> r2( ENOENT, generic_category() );
|
||||
|
||||
r2 = result<int&>( ec );
|
||||
|
||||
BOOST_TEST( !r2.has_value() );
|
||||
BOOST_TEST( r2.has_error() );
|
||||
|
||||
BOOST_TEST_EQ( r2.error(), ec );
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
|
||||
@@ -207,6 +207,8 @@ int main()
|
||||
|
||||
BOOST_TEST_EQ( X::instances, 0 );
|
||||
|
||||
//
|
||||
|
||||
{
|
||||
result<void> r;
|
||||
result<void> r2( std::move( r ) );
|
||||
@@ -245,5 +247,149 @@ int main()
|
||||
BOOST_TEST_EQ( r2.error(), ec );
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
{
|
||||
int x1 = 1;
|
||||
|
||||
result<int&> r1( x1 );
|
||||
result<int&> r2( std::move( r1 ) );
|
||||
|
||||
BOOST_TEST( r1.has_value() );
|
||||
BOOST_TEST( !r1.has_error() );
|
||||
|
||||
BOOST_TEST_EQ( r1.value(), 1 );
|
||||
BOOST_TEST_EQ( &*r1, &x1 );
|
||||
|
||||
BOOST_TEST( r2.has_value() );
|
||||
BOOST_TEST( !r2.has_error() );
|
||||
|
||||
BOOST_TEST_EQ( r2.value(), 1 );
|
||||
BOOST_TEST_EQ( &*r2, &x1 );
|
||||
}
|
||||
|
||||
{
|
||||
int const x1 = 1;
|
||||
|
||||
result<int const&> r1( x1 );
|
||||
result<int const&> r2( std::move( r1 ) );
|
||||
|
||||
BOOST_TEST( r1.has_value() );
|
||||
BOOST_TEST( !r1.has_error() );
|
||||
|
||||
BOOST_TEST_EQ( r1.value(), 1 );
|
||||
BOOST_TEST_EQ( &*r1, &x1 );
|
||||
|
||||
BOOST_TEST( r2.has_value() );
|
||||
BOOST_TEST( !r2.has_error() );
|
||||
|
||||
BOOST_TEST_EQ( r2.value(), 1 );
|
||||
BOOST_TEST_EQ( &*r2, &x1 );
|
||||
}
|
||||
|
||||
{
|
||||
int x1 = 1;
|
||||
|
||||
result<int&> r2(( result<int&>( x1 ) ));
|
||||
|
||||
BOOST_TEST( r2.has_value() );
|
||||
BOOST_TEST( !r2.has_error() );
|
||||
|
||||
BOOST_TEST_EQ( r2.value(), 1 );
|
||||
BOOST_TEST_EQ( &*r2, &x1 );
|
||||
}
|
||||
|
||||
{
|
||||
int const x1 = 1;
|
||||
|
||||
result<int const&> r2(( result<int const&>( x1 ) ));
|
||||
|
||||
BOOST_TEST( r2.has_value() );
|
||||
BOOST_TEST( !r2.has_error() );
|
||||
|
||||
BOOST_TEST_EQ( r2.value(), 1 );
|
||||
BOOST_TEST_EQ( &*r2, &x1 );
|
||||
}
|
||||
|
||||
{
|
||||
X x1( 1 );
|
||||
|
||||
result<X&> r1( x1 );
|
||||
result<X&> r2( std::move( r1 ) );
|
||||
|
||||
BOOST_TEST( r1.has_value() );
|
||||
BOOST_TEST( !r1.has_error() );
|
||||
|
||||
BOOST_TEST_EQ( r1.value().v_, 1 );
|
||||
BOOST_TEST_EQ( &*r1, &x1 );
|
||||
|
||||
BOOST_TEST( r2.has_value() );
|
||||
BOOST_TEST( !r2.has_error() );
|
||||
|
||||
BOOST_TEST_EQ( r2.value().v_, 1 );
|
||||
BOOST_TEST_EQ( &*r2, &x1 );
|
||||
|
||||
BOOST_TEST_EQ( X::instances, 1 );
|
||||
}
|
||||
|
||||
BOOST_TEST_EQ( X::instances, 0 );
|
||||
|
||||
{
|
||||
X x1( 1 );
|
||||
|
||||
result<X&> r2(( result<X&>( x1 ) ));
|
||||
|
||||
BOOST_TEST( r2.has_value() );
|
||||
BOOST_TEST( !r2.has_error() );
|
||||
|
||||
BOOST_TEST_EQ( r2.value().v_, 1 );
|
||||
BOOST_TEST_EQ( &*r2, &x1 );
|
||||
|
||||
BOOST_TEST_EQ( X::instances, 1 );
|
||||
}
|
||||
|
||||
BOOST_TEST_EQ( X::instances, 0 );
|
||||
|
||||
{
|
||||
X const x1( 1 );
|
||||
|
||||
result<X const&> r1( x1 );
|
||||
result<X const&> r2( std::move( r1 ) );
|
||||
|
||||
BOOST_TEST( r1.has_value() );
|
||||
BOOST_TEST( !r1.has_error() );
|
||||
|
||||
BOOST_TEST_EQ( r1.value().v_, 1 );
|
||||
BOOST_TEST_EQ( &*r1, &x1 );
|
||||
|
||||
BOOST_TEST( r2.has_value() );
|
||||
BOOST_TEST( !r2.has_error() );
|
||||
|
||||
BOOST_TEST_EQ( r2.value().v_, 1 );
|
||||
BOOST_TEST_EQ( &*r2, &x1 );
|
||||
|
||||
BOOST_TEST_EQ( X::instances, 1 );
|
||||
}
|
||||
|
||||
BOOST_TEST_EQ( X::instances, 0 );
|
||||
|
||||
{
|
||||
X const x1( 1 );
|
||||
|
||||
result<X const&> r2(( result<X const&>( x1 ) ));
|
||||
|
||||
BOOST_TEST( r2.has_value() );
|
||||
BOOST_TEST( !r2.has_error() );
|
||||
|
||||
BOOST_TEST_EQ( r2.value().v_, 1 );
|
||||
BOOST_TEST_EQ( &*r2, &x1 );
|
||||
|
||||
BOOST_TEST_EQ( X::instances, 1 );
|
||||
}
|
||||
|
||||
BOOST_TEST_EQ( X::instances, 0 );
|
||||
|
||||
//
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
|
||||
30
test/result_range_for.cpp
Normal file
30
test/result_range_for.cpp
Normal file
@@ -0,0 +1,30 @@
|
||||
// Copyright 2021 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 <vector>
|
||||
|
||||
using namespace boost::system;
|
||||
|
||||
result<std::vector<int>> f()
|
||||
{
|
||||
return std::vector<int>{ 1, 2, 3 };
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
int s = 0;
|
||||
|
||||
for( int x: f().value() )
|
||||
{
|
||||
s += x;
|
||||
}
|
||||
|
||||
BOOST_TEST_EQ( s, 6 );
|
||||
}
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
@@ -259,5 +259,55 @@ int main()
|
||||
BOOST_TEST_EQ( r2, r2c );
|
||||
}
|
||||
|
||||
{
|
||||
int x1 = 1;
|
||||
int x2 = 2;
|
||||
|
||||
result<int&> r1( x1 ), r1c( r1 );
|
||||
result<int&> r2( x2 ), r2c( r2 );
|
||||
|
||||
r1.swap( r2 );
|
||||
|
||||
BOOST_TEST_EQ( r1, r2c );
|
||||
BOOST_TEST_EQ( r2, r1c );
|
||||
|
||||
swap( r1, r2 );
|
||||
|
||||
BOOST_TEST_EQ( r1, r1c );
|
||||
BOOST_TEST_EQ( r2, r2c );
|
||||
}
|
||||
|
||||
{
|
||||
result<int&> r1( 1, generic_category() ), r1c( r1 );
|
||||
result<int&> r2( 2, generic_category() ), r2c( r2 );
|
||||
|
||||
r1.swap( r2 );
|
||||
|
||||
BOOST_TEST_EQ( r1, r2c );
|
||||
BOOST_TEST_EQ( r2, r1c );
|
||||
|
||||
swap( r1, r2 );
|
||||
|
||||
BOOST_TEST_EQ( r1, r1c );
|
||||
BOOST_TEST_EQ( r2, r2c );
|
||||
}
|
||||
|
||||
{
|
||||
int x1 = 1;
|
||||
|
||||
result<int&> r1( x1 ), r1c( r1 );
|
||||
result<int&> r2( 2, generic_category() ), r2c( r2 );
|
||||
|
||||
r1.swap( r2 );
|
||||
|
||||
BOOST_TEST_EQ( r1, r2c );
|
||||
BOOST_TEST_EQ( r2, r1c );
|
||||
|
||||
swap( r1, r2 );
|
||||
|
||||
BOOST_TEST_EQ( r1, r1c );
|
||||
BOOST_TEST_EQ( r2, r2c );
|
||||
}
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
|
||||
39
test/result_typedefs.cpp
Normal file
39
test/result_typedefs.cpp
Normal file
@@ -0,0 +1,39 @@
|
||||
// Copyright 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_trait.hpp>
|
||||
|
||||
using namespace boost::system;
|
||||
|
||||
struct X {};
|
||||
|
||||
int main()
|
||||
{
|
||||
BOOST_TEST_TRAIT_SAME( result<int>::value_type, int );
|
||||
BOOST_TEST_TRAIT_SAME( result<int>::error_type, error_code );
|
||||
|
||||
BOOST_TEST_TRAIT_SAME( result<X>::value_type, X );
|
||||
BOOST_TEST_TRAIT_SAME( result<X>::error_type, error_code );
|
||||
|
||||
BOOST_TEST_TRAIT_SAME( result<void>::value_type, void );
|
||||
BOOST_TEST_TRAIT_SAME( result<void>::error_type, error_code );
|
||||
|
||||
BOOST_TEST_TRAIT_SAME( result<int&>::value_type, int& );
|
||||
BOOST_TEST_TRAIT_SAME( result<int&>::error_type, error_code );
|
||||
|
||||
BOOST_TEST_TRAIT_SAME( result<int, X>::value_type, int );
|
||||
BOOST_TEST_TRAIT_SAME( result<int, X>::error_type, X );
|
||||
|
||||
BOOST_TEST_TRAIT_SAME( result<X, X>::value_type, X );
|
||||
BOOST_TEST_TRAIT_SAME( result<X, X>::error_type, X );
|
||||
|
||||
BOOST_TEST_TRAIT_SAME( result<void, X>::value_type, void );
|
||||
BOOST_TEST_TRAIT_SAME( result<void, X>::error_type, X );
|
||||
|
||||
BOOST_TEST_TRAIT_SAME( result<int&, X>::value_type, int& );
|
||||
BOOST_TEST_TRAIT_SAME( result<int&, X>::error_type, X );
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
@@ -1,10 +1,12 @@
|
||||
// Copyright 2017, 2021 Peter Dimov.
|
||||
// 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>
|
||||
#include <boost/config.hpp>
|
||||
#include <system_error>
|
||||
|
||||
using namespace boost::system;
|
||||
|
||||
@@ -26,11 +28,15 @@ struct E
|
||||
{
|
||||
};
|
||||
|
||||
BOOST_NORETURN void throw_exception_from_error( Y const & )
|
||||
BOOST_NORETURN void throw_exception_from_error( Y const &, boost::source_location const& )
|
||||
{
|
||||
throw E();
|
||||
}
|
||||
|
||||
struct E2
|
||||
{
|
||||
};
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
@@ -165,6 +171,81 @@ int main()
|
||||
BOOST_TEST_EQ( result<int>( ec ).operator->(), static_cast<int*>(0) );
|
||||
}
|
||||
|
||||
{
|
||||
auto ec = make_error_code( std::errc::invalid_argument );
|
||||
|
||||
result<int, std::error_code> const r( ec );
|
||||
|
||||
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, 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 );
|
||||
|
||||
#if defined(BOOST_CLANG_VERSION) && BOOST_CLANG_VERSION < 30600
|
||||
#else
|
||||
BOOST_TEST_THROWS( r.value(), E2 );
|
||||
#endif
|
||||
|
||||
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 );
|
||||
|
||||
@@ -255,6 +336,8 @@ int main()
|
||||
BOOST_TEST_EQ( (result<X, Y>( ec ).operator->()), static_cast<X*>(0) );
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
{
|
||||
result<void> r;
|
||||
|
||||
@@ -341,5 +424,254 @@ int main()
|
||||
BOOST_TEST_EQ( result<void>( ec ).operator->(), static_cast<void*>(0) );
|
||||
}
|
||||
|
||||
{
|
||||
auto ec = make_error_code( std::errc::invalid_argument );
|
||||
|
||||
result<void, std::error_code> const r( ec );
|
||||
|
||||
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, 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 );
|
||||
|
||||
#if defined(BOOST_CLANG_VERSION) && BOOST_CLANG_VERSION < 30600
|
||||
#else
|
||||
BOOST_TEST_THROWS( r.value(), E2 );
|
||||
#endif
|
||||
|
||||
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) );
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
{
|
||||
int x1 = 1;
|
||||
|
||||
result<int&> r( x1 );
|
||||
|
||||
BOOST_TEST( r.has_value() );
|
||||
BOOST_TEST( !r.has_error() );
|
||||
|
||||
BOOST_TEST( r );
|
||||
BOOST_TEST_NOT( !r );
|
||||
|
||||
BOOST_TEST_EQ( r.value(), 1 );
|
||||
BOOST_TEST_EQ( *r, 1 );
|
||||
|
||||
BOOST_TEST_EQ( r.operator->(), &*r );
|
||||
}
|
||||
|
||||
{
|
||||
int x1 = 1;
|
||||
|
||||
result<int&> const r( x1 );
|
||||
|
||||
BOOST_TEST( r.has_value() );
|
||||
BOOST_TEST( !r.has_error() );
|
||||
|
||||
BOOST_TEST( r );
|
||||
BOOST_TEST_NOT( !r );
|
||||
|
||||
BOOST_TEST_EQ( r.value(), 1 );
|
||||
BOOST_TEST_EQ( *r, 1 );
|
||||
|
||||
BOOST_TEST_EQ( r.operator->(), &*r );
|
||||
}
|
||||
|
||||
{
|
||||
int x1 = 1;
|
||||
|
||||
BOOST_TEST( result<int&>( x1 ).has_value() );
|
||||
BOOST_TEST( !result<int&>( x1 ).has_error() );
|
||||
|
||||
BOOST_TEST( result<int&>( x1 ) );
|
||||
BOOST_TEST_NOT( !result<int&>( x1 ) );
|
||||
|
||||
BOOST_TEST_EQ( result<int&>( x1 ).value(), 1 );
|
||||
BOOST_TEST_EQ( *result<int&>( x1 ), 1 );
|
||||
|
||||
BOOST_TEST_EQ( result<int&>( x1 ).operator->(), &x1 );
|
||||
}
|
||||
|
||||
{
|
||||
auto ec = make_error_code( errc::invalid_argument );
|
||||
|
||||
result<int&> r( ec );
|
||||
|
||||
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) );
|
||||
}
|
||||
|
||||
{
|
||||
auto ec = make_error_code( errc::invalid_argument );
|
||||
|
||||
result<int&> const r( ec );
|
||||
|
||||
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) );
|
||||
}
|
||||
|
||||
{
|
||||
auto ec = make_error_code( errc::invalid_argument );
|
||||
|
||||
BOOST_TEST( !result<int&>( ec ).has_value() );
|
||||
BOOST_TEST( result<int&>( ec ).has_error() );
|
||||
|
||||
BOOST_TEST_NOT( result<int&>( ec ) );
|
||||
BOOST_TEST( !result<int&>( ec ) );
|
||||
|
||||
BOOST_TEST_THROWS( result<int&>( ec ).value(), system_error );
|
||||
|
||||
BOOST_TEST_EQ( result<int&>( ec ).operator->(), static_cast<int*>(0) );
|
||||
}
|
||||
|
||||
{
|
||||
auto ec = make_error_code( std::errc::invalid_argument );
|
||||
|
||||
result<int&, std::error_code> const r( ec );
|
||||
|
||||
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&, 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 );
|
||||
|
||||
#if defined(BOOST_CLANG_VERSION) && BOOST_CLANG_VERSION < 30600
|
||||
#else
|
||||
BOOST_TEST_THROWS( r.value(), E2 );
|
||||
#endif
|
||||
|
||||
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) );
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
|
||||
152
test/result_value_construct2.cpp
Normal file
152
test/result_value_construct2.cpp
Normal file
@@ -0,0 +1,152 @@
|
||||
// Copyright 2021 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 <vector>
|
||||
#include <string>
|
||||
|
||||
using namespace boost::system;
|
||||
|
||||
struct X
|
||||
{
|
||||
int a;
|
||||
};
|
||||
|
||||
struct Y
|
||||
{
|
||||
int a, b;
|
||||
};
|
||||
|
||||
struct E
|
||||
{
|
||||
std::string v;
|
||||
};
|
||||
|
||||
result<X> fx0()
|
||||
{
|
||||
return {};
|
||||
}
|
||||
|
||||
result<X> fx1()
|
||||
{
|
||||
return {{ 1 }};
|
||||
}
|
||||
|
||||
result<Y> fy0()
|
||||
{
|
||||
return {};
|
||||
}
|
||||
|
||||
result<Y> fy2()
|
||||
{
|
||||
return {{ 1, 2 }};
|
||||
}
|
||||
|
||||
result<X, E> fxe0()
|
||||
{
|
||||
return {};
|
||||
}
|
||||
|
||||
result<X, E> fxe1()
|
||||
{
|
||||
return {{ 1 }};
|
||||
}
|
||||
|
||||
result<std::vector<int>> fv0()
|
||||
{
|
||||
return {};
|
||||
}
|
||||
|
||||
result<std::vector<int>> fv1()
|
||||
{
|
||||
return {{ 1 }};
|
||||
}
|
||||
|
||||
result<std::vector<int>> fv2()
|
||||
{
|
||||
return {{ 1, 2 }};
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
result<X> r = fx0();
|
||||
|
||||
BOOST_TEST( r.has_value() );
|
||||
|
||||
BOOST_TEST_EQ( r->a, 0 );
|
||||
}
|
||||
|
||||
{
|
||||
result<X> r = fx1();
|
||||
|
||||
BOOST_TEST( r.has_value() );
|
||||
|
||||
BOOST_TEST_EQ( r->a, 1 );
|
||||
}
|
||||
|
||||
{
|
||||
result<Y> r = fy0();
|
||||
|
||||
BOOST_TEST( r.has_value() );
|
||||
|
||||
BOOST_TEST_EQ( r->a, 0 );
|
||||
BOOST_TEST_EQ( r->b, 0 );
|
||||
}
|
||||
|
||||
{
|
||||
result<Y> r = fy2();
|
||||
|
||||
BOOST_TEST( r.has_value() );
|
||||
|
||||
BOOST_TEST_EQ( r->a, 1 );
|
||||
BOOST_TEST_EQ( r->b, 2 );
|
||||
}
|
||||
|
||||
{
|
||||
result<X, E> r = fxe0();
|
||||
|
||||
BOOST_TEST( r.has_value() );
|
||||
|
||||
BOOST_TEST_EQ( r->a, 0 );
|
||||
}
|
||||
|
||||
{
|
||||
result<X, E> r = fxe1();
|
||||
|
||||
BOOST_TEST( r.has_value() );
|
||||
|
||||
BOOST_TEST_EQ( r->a, 1 );
|
||||
}
|
||||
|
||||
{
|
||||
result<std::vector<int>> r = fv0();
|
||||
|
||||
BOOST_TEST( r.has_value() );
|
||||
|
||||
BOOST_TEST_EQ( r->size(), 0 );
|
||||
}
|
||||
|
||||
{
|
||||
result<std::vector<int>> r = fv1();
|
||||
|
||||
BOOST_TEST( r.has_value() );
|
||||
|
||||
BOOST_TEST_EQ( r->size(), 1 );
|
||||
BOOST_TEST_EQ( r->at(0), 1 );
|
||||
}
|
||||
|
||||
{
|
||||
result<std::vector<int>> r = fv2();
|
||||
|
||||
BOOST_TEST( r.has_value() );
|
||||
|
||||
BOOST_TEST_EQ( r->size(), 2 );
|
||||
BOOST_TEST_EQ( r->at(0), 1 );
|
||||
BOOST_TEST_EQ( r->at(1), 2 );
|
||||
}
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
142
test/result_value_construct3.cpp
Normal file
142
test/result_value_construct3.cpp
Normal file
@@ -0,0 +1,142 @@
|
||||
// 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>
|
||||
|
||||
using namespace boost::system;
|
||||
|
||||
struct X
|
||||
{
|
||||
static int instances;
|
||||
|
||||
int v_;
|
||||
|
||||
explicit X( int v ): v_( v ) { ++instances; }
|
||||
|
||||
X( int v1, int v2 ): v_( v1+v2 ) { ++instances; }
|
||||
X( int v1, int v2, int v3 ): v_( v1+v2+v3 ) { ++instances; }
|
||||
|
||||
X( X const& ) = delete;
|
||||
X& operator=( X const& ) = delete;
|
||||
|
||||
~X() { --instances; }
|
||||
};
|
||||
|
||||
int X::instances = 0;
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
using R = result<int>;
|
||||
R r( R::in_place_value, 0 );
|
||||
|
||||
BOOST_TEST( r.has_value() );
|
||||
BOOST_TEST( !r.has_error() );
|
||||
|
||||
BOOST_TEST_EQ( r.value(), 0 );
|
||||
}
|
||||
|
||||
{
|
||||
using R = result<int, int>;
|
||||
R r( R::in_place_value, 1 );
|
||||
|
||||
BOOST_TEST( r.has_value() );
|
||||
BOOST_TEST( !r.has_error() );
|
||||
|
||||
BOOST_TEST_EQ( *r, 1 );
|
||||
}
|
||||
|
||||
BOOST_TEST_EQ( X::instances, 0 );
|
||||
|
||||
{
|
||||
using R = result<X>;
|
||||
R r( R::in_place_value, 1 );
|
||||
|
||||
BOOST_TEST( r.has_value() );
|
||||
BOOST_TEST( !r.has_error() );
|
||||
|
||||
BOOST_TEST_EQ( r.value().v_, 1 );
|
||||
|
||||
BOOST_TEST_EQ( X::instances, 1 );
|
||||
}
|
||||
|
||||
BOOST_TEST_EQ( X::instances, 0 );
|
||||
|
||||
{
|
||||
using R = result<X>;
|
||||
R r( R::in_place_value, 1, 2 );
|
||||
|
||||
BOOST_TEST( r.has_value() );
|
||||
BOOST_TEST( !r.has_error() );
|
||||
|
||||
BOOST_TEST_EQ( r.value().v_, 1+2 );
|
||||
|
||||
BOOST_TEST_EQ( X::instances, 1 );
|
||||
}
|
||||
|
||||
BOOST_TEST_EQ( X::instances, 0 );
|
||||
|
||||
{
|
||||
using R = result<X>;
|
||||
R r( R::in_place_value, 1, 2, 3 );
|
||||
|
||||
BOOST_TEST( r.has_value() );
|
||||
BOOST_TEST( !r.has_error() );
|
||||
|
||||
BOOST_TEST_EQ( r.value().v_, 1+2+3 );
|
||||
|
||||
BOOST_TEST_EQ( X::instances, 1 );
|
||||
}
|
||||
|
||||
BOOST_TEST_EQ( X::instances, 0 );
|
||||
|
||||
{
|
||||
using R = result<X, X>;
|
||||
R r( R::in_place_value, 1 );
|
||||
|
||||
BOOST_TEST( r.has_value() );
|
||||
BOOST_TEST( !r.has_error() );
|
||||
|
||||
BOOST_TEST_EQ( r->v_, 1 );
|
||||
|
||||
BOOST_TEST_EQ( X::instances, 1 );
|
||||
}
|
||||
|
||||
BOOST_TEST_EQ( X::instances, 0 );
|
||||
|
||||
{
|
||||
using R = result<void>;
|
||||
R r( R::in_place_value );
|
||||
|
||||
BOOST_TEST( r.has_value() );
|
||||
BOOST_TEST( !r.has_error() );
|
||||
}
|
||||
|
||||
{
|
||||
int x1 = 1;
|
||||
|
||||
using R = result<int&>;
|
||||
R r( R::in_place_value, x1 );
|
||||
|
||||
BOOST_TEST( r.has_value() );
|
||||
BOOST_TEST( !r.has_error() );
|
||||
|
||||
BOOST_TEST_EQ( r.value(), 1 );
|
||||
}
|
||||
|
||||
{
|
||||
int x1 = 1;
|
||||
|
||||
using R = result<int&, int>;
|
||||
R r( R::in_place_value, x1 );
|
||||
|
||||
BOOST_TEST( r.has_value() );
|
||||
BOOST_TEST( !r.has_error() );
|
||||
|
||||
BOOST_TEST_EQ( *r, 1 );
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
121
test/result_value_construct6.cpp
Normal file
121
test/result_value_construct6.cpp
Normal file
@@ -0,0 +1,121 @@
|
||||
// Copyright 2017, 2021, 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>
|
||||
#include <boost/core/lightweight_test_trait.hpp>
|
||||
|
||||
using namespace boost::system;
|
||||
|
||||
struct X
|
||||
{
|
||||
static int instances;
|
||||
|
||||
int v_;
|
||||
|
||||
explicit X( int v ): v_( v ) { ++instances; }
|
||||
|
||||
X( X const& ) = delete;
|
||||
X& operator=( X const& ) = delete;
|
||||
|
||||
~X() { --instances; }
|
||||
};
|
||||
|
||||
int X::instances = 0;
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
int x = 0;
|
||||
result<int&> r( x );
|
||||
|
||||
BOOST_TEST( r.has_value() );
|
||||
BOOST_TEST( !r.has_error() );
|
||||
|
||||
BOOST_TEST_EQ( r.value(), 0 );
|
||||
}
|
||||
|
||||
{
|
||||
int x = 0;
|
||||
result<int&> r = x;
|
||||
|
||||
BOOST_TEST( r.has_value() );
|
||||
BOOST_TEST( !r.has_error() );
|
||||
|
||||
BOOST_TEST_EQ( r.value(), 0 );
|
||||
}
|
||||
|
||||
{
|
||||
int x = 1;
|
||||
result<int&, int> r( in_place_value, x );
|
||||
|
||||
BOOST_TEST( r.has_value() );
|
||||
BOOST_TEST( !r.has_error() );
|
||||
|
||||
BOOST_TEST_EQ( *r, 1 );
|
||||
}
|
||||
|
||||
BOOST_TEST_EQ( X::instances, 0 );
|
||||
|
||||
{
|
||||
X x( 1 );
|
||||
result<X&> r( x );
|
||||
|
||||
BOOST_TEST( r.has_value() );
|
||||
BOOST_TEST( !r.has_error() );
|
||||
|
||||
BOOST_TEST_EQ( r.value().v_, 1 );
|
||||
|
||||
BOOST_TEST_EQ( X::instances, 1 );
|
||||
}
|
||||
|
||||
BOOST_TEST_EQ( X::instances, 0 );
|
||||
|
||||
{
|
||||
X x( 1 );
|
||||
result<X&> r = x;
|
||||
|
||||
BOOST_TEST( r.has_value() );
|
||||
BOOST_TEST( !r.has_error() );
|
||||
|
||||
BOOST_TEST_EQ( r.value().v_, 1 );
|
||||
|
||||
BOOST_TEST_EQ( X::instances, 1 );
|
||||
}
|
||||
|
||||
BOOST_TEST_EQ( X::instances, 0 );
|
||||
|
||||
{
|
||||
X x( 1 );
|
||||
result<X&, X> r( in_place_value, x );
|
||||
|
||||
BOOST_TEST( r.has_value() );
|
||||
BOOST_TEST( !r.has_error() );
|
||||
|
||||
BOOST_TEST_EQ( r->v_, 1 );
|
||||
|
||||
BOOST_TEST_EQ( X::instances, 1 );
|
||||
}
|
||||
|
||||
BOOST_TEST_EQ( X::instances, 0 );
|
||||
|
||||
{
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_constructible<result<int&>, int&>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_convertible<int&, result<int&>>));
|
||||
|
||||
BOOST_TEST_TRAIT_FALSE((std::is_constructible<result<int&>, int const&>));
|
||||
BOOST_TEST_TRAIT_FALSE((std::is_convertible<int const&, result<int&>>));
|
||||
|
||||
BOOST_TEST_TRAIT_FALSE((std::is_constructible<result<int&>, int>));
|
||||
BOOST_TEST_TRAIT_FALSE((std::is_convertible<int, result<int&>>));
|
||||
|
||||
BOOST_TEST_TRAIT_FALSE((std::is_constructible<result<int&, int>, int&>));
|
||||
BOOST_TEST_TRAIT_FALSE((std::is_constructible<result<int&, float>, int&>));
|
||||
|
||||
BOOST_TEST_TRAIT_FALSE((std::is_constructible<result<X&>, int>));
|
||||
BOOST_TEST_TRAIT_FALSE((std::is_convertible<int, result<X&>>));
|
||||
}
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
211
test/result_value_construct7.cpp
Normal file
211
test/result_value_construct7.cpp
Normal file
@@ -0,0 +1,211 @@
|
||||
// Copyright 2017, 2021, 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>
|
||||
#include <boost/core/lightweight_test_trait.hpp>
|
||||
|
||||
using namespace boost::system;
|
||||
|
||||
struct X
|
||||
{
|
||||
static int instances;
|
||||
|
||||
int v_;
|
||||
|
||||
explicit X( int v ): v_( v ) { ++instances; }
|
||||
|
||||
X( X const& ) = delete;
|
||||
X& operator=( X const& ) = delete;
|
||||
|
||||
~X() { --instances; }
|
||||
};
|
||||
|
||||
int X::instances = 0;
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
int x = 0;
|
||||
result<int const&> r( x );
|
||||
|
||||
BOOST_TEST( r.has_value() );
|
||||
BOOST_TEST( !r.has_error() );
|
||||
|
||||
BOOST_TEST_EQ( r.value(), 0 );
|
||||
}
|
||||
|
||||
{
|
||||
int const x = 0;
|
||||
result<int const&> r( x );
|
||||
|
||||
BOOST_TEST( r.has_value() );
|
||||
BOOST_TEST( !r.has_error() );
|
||||
|
||||
BOOST_TEST_EQ( r.value(), 0 );
|
||||
}
|
||||
|
||||
{
|
||||
int x = 0;
|
||||
result<int const&> r = x;
|
||||
|
||||
BOOST_TEST( r.has_value() );
|
||||
BOOST_TEST( !r.has_error() );
|
||||
|
||||
BOOST_TEST_EQ( r.value(), 0 );
|
||||
}
|
||||
|
||||
{
|
||||
int const x = 0;
|
||||
result<int const&> r = x;
|
||||
|
||||
BOOST_TEST( r.has_value() );
|
||||
BOOST_TEST( !r.has_error() );
|
||||
|
||||
BOOST_TEST_EQ( r.value(), 0 );
|
||||
}
|
||||
|
||||
{
|
||||
int x = 1;
|
||||
result<int const&, int> r( in_place_value, x );
|
||||
|
||||
BOOST_TEST( r.has_value() );
|
||||
BOOST_TEST( !r.has_error() );
|
||||
|
||||
BOOST_TEST_EQ( *r, 1 );
|
||||
}
|
||||
|
||||
{
|
||||
int const x = 1;
|
||||
result<int const&, int> r( in_place_value, x );
|
||||
|
||||
BOOST_TEST( r.has_value() );
|
||||
BOOST_TEST( !r.has_error() );
|
||||
|
||||
BOOST_TEST_EQ( *r, 1 );
|
||||
}
|
||||
|
||||
BOOST_TEST_EQ( X::instances, 0 );
|
||||
|
||||
{
|
||||
X x( 1 );
|
||||
result<X const&> r( x );
|
||||
|
||||
BOOST_TEST( r.has_value() );
|
||||
BOOST_TEST( !r.has_error() );
|
||||
|
||||
BOOST_TEST_EQ( r.value().v_, 1 );
|
||||
|
||||
BOOST_TEST_EQ( X::instances, 1 );
|
||||
}
|
||||
|
||||
BOOST_TEST_EQ( X::instances, 0 );
|
||||
|
||||
{
|
||||
X const x( 1 );
|
||||
result<X const&> r( x );
|
||||
|
||||
BOOST_TEST( r.has_value() );
|
||||
BOOST_TEST( !r.has_error() );
|
||||
|
||||
BOOST_TEST_EQ( r.value().v_, 1 );
|
||||
|
||||
BOOST_TEST_EQ( X::instances, 1 );
|
||||
}
|
||||
|
||||
BOOST_TEST_EQ( X::instances, 0 );
|
||||
|
||||
{
|
||||
X x( 1 );
|
||||
result<X const&> r = x;
|
||||
|
||||
BOOST_TEST( r.has_value() );
|
||||
BOOST_TEST( !r.has_error() );
|
||||
|
||||
BOOST_TEST_EQ( r.value().v_, 1 );
|
||||
|
||||
BOOST_TEST_EQ( X::instances, 1 );
|
||||
}
|
||||
|
||||
BOOST_TEST_EQ( X::instances, 0 );
|
||||
|
||||
{
|
||||
X const x( 1 );
|
||||
result<X const&> r = x;
|
||||
|
||||
BOOST_TEST( r.has_value() );
|
||||
BOOST_TEST( !r.has_error() );
|
||||
|
||||
BOOST_TEST_EQ( r.value().v_, 1 );
|
||||
|
||||
BOOST_TEST_EQ( X::instances, 1 );
|
||||
}
|
||||
|
||||
BOOST_TEST_EQ( X::instances, 0 );
|
||||
|
||||
{
|
||||
X x( 1 );
|
||||
result<X const&, X> r( in_place_value, x );
|
||||
|
||||
BOOST_TEST( r.has_value() );
|
||||
BOOST_TEST( !r.has_error() );
|
||||
|
||||
BOOST_TEST_EQ( r->v_, 1 );
|
||||
|
||||
BOOST_TEST_EQ( X::instances, 1 );
|
||||
}
|
||||
|
||||
BOOST_TEST_EQ( X::instances, 0 );
|
||||
|
||||
{
|
||||
X const x( 1 );
|
||||
result<X const&, X> r( in_place_value, x );
|
||||
|
||||
BOOST_TEST( r.has_value() );
|
||||
BOOST_TEST( !r.has_error() );
|
||||
|
||||
BOOST_TEST_EQ( r->v_, 1 );
|
||||
|
||||
BOOST_TEST_EQ( X::instances, 1 );
|
||||
}
|
||||
|
||||
BOOST_TEST_EQ( X::instances, 0 );
|
||||
|
||||
{
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_constructible<result<int const&>, int&>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_convertible<int&, result<int const&>>));
|
||||
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_constructible<result<int const&>, int const&>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_convertible<int const&, result<int const&>>));
|
||||
|
||||
BOOST_TEST_TRAIT_FALSE((std::is_constructible<result<int const&>, int>));
|
||||
BOOST_TEST_TRAIT_FALSE((std::is_convertible<int, result<int const&>>));
|
||||
|
||||
BOOST_TEST_TRAIT_FALSE((std::is_constructible<result<double const&>, int&>));
|
||||
BOOST_TEST_TRAIT_FALSE((std::is_convertible<int&, result<double const&>>));
|
||||
|
||||
BOOST_TEST_TRAIT_FALSE((std::is_constructible<result<double const&>, int const&>));
|
||||
BOOST_TEST_TRAIT_FALSE((std::is_convertible<int const&, result<double const&>>));
|
||||
|
||||
BOOST_TEST_TRAIT_FALSE((std::is_constructible<result<double const&>, int>));
|
||||
BOOST_TEST_TRAIT_FALSE((std::is_convertible<int, result<double const&>>));
|
||||
|
||||
BOOST_TEST_TRAIT_FALSE((std::is_constructible<result<int const&, int>, int&>));
|
||||
BOOST_TEST_TRAIT_FALSE((std::is_constructible<result<int const&, float>, int&>));
|
||||
|
||||
BOOST_TEST_TRAIT_FALSE((std::is_constructible<result<int const&, int>, int const&>));
|
||||
BOOST_TEST_TRAIT_FALSE((std::is_constructible<result<int const&, float>, int const&>));
|
||||
|
||||
BOOST_TEST_TRAIT_FALSE((std::is_constructible<result<int const&, int>, int>));
|
||||
BOOST_TEST_TRAIT_FALSE((std::is_constructible<result<int const&, float>, int>));
|
||||
|
||||
BOOST_TEST_TRAIT_FALSE((std::is_constructible<result<X const&>, int>));
|
||||
BOOST_TEST_TRAIT_FALSE((std::is_convertible<int, result<X const&>>));
|
||||
|
||||
BOOST_TEST_TRAIT_FALSE((std::is_constructible<result<X const&>, X const>));
|
||||
BOOST_TEST_TRAIT_FALSE((std::is_convertible<X const, result<X const&>>));
|
||||
}
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
@@ -8,9 +8,6 @@
|
||||
|
||||
// See library home page at http://www.boost.org/libs/system
|
||||
|
||||
// Avoid spurious VC++ warnings
|
||||
# define _CRT_SECURE_NO_WARNINGS
|
||||
|
||||
#include <boost/system/error_code.hpp>
|
||||
#include <boost/config.hpp>
|
||||
#include <boost/config/pragma_message.hpp>
|
||||
@@ -30,6 +27,7 @@ int main()
|
||||
#else
|
||||
|
||||
#include <boost/core/lightweight_test.hpp>
|
||||
#include <boost/core/snprintf.hpp>
|
||||
#include <system_error>
|
||||
#include <cerrno>
|
||||
#include <string>
|
||||
@@ -44,7 +42,8 @@ static void test_generic_category()
|
||||
|
||||
int ev = ENOENT;
|
||||
|
||||
BOOST_TEST_EQ( bt.message( ev ), st.message( ev ) );
|
||||
// Under MSVC, it's "no such file or directory" instead of "No such file or directory"
|
||||
BOOST_TEST_EQ( bt.message( ev ).substr( 1 ), st.message( ev ).substr( 1 ) );
|
||||
|
||||
{
|
||||
boost::system::error_code bc( ev, bt );
|
||||
@@ -82,34 +81,13 @@ static void test_system_category()
|
||||
|
||||
BOOST_TEST_CSTR_EQ( bt.name(), st.name() );
|
||||
|
||||
for( int ev = 1; ev < 6; ++ev )
|
||||
{
|
||||
int ev = 5;
|
||||
BOOST_TEST_EQ( bt.message( ev ), st.message( ev ) );
|
||||
std::string bm = bt.message( ev );
|
||||
std::string sm = st.message( ev );
|
||||
|
||||
{
|
||||
boost::system::error_code bc( ev, bt );
|
||||
|
||||
BOOST_TEST_EQ( bc.value(), ev );
|
||||
BOOST_TEST_EQ( &bc.category(), &bt );
|
||||
|
||||
std::error_code sc( bc );
|
||||
|
||||
BOOST_TEST_EQ( sc.value(), ev );
|
||||
BOOST_TEST_EQ( &sc.category(), &st );
|
||||
}
|
||||
|
||||
{
|
||||
boost::system::error_condition bn = bt.default_error_condition( ev );
|
||||
BOOST_TEST( bt.equivalent( ev, bn ) );
|
||||
|
||||
std::error_condition sn( bn );
|
||||
BOOST_TEST( st.equivalent( ev, sn ) );
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
int ev = 4;
|
||||
BOOST_TEST_EQ( bt.message( ev ), st.message( ev ) );
|
||||
// We strip whitespace and the trailing dot, MSVC not so much
|
||||
BOOST_TEST_EQ( bm, sm.substr( 0, bm.size() ) );
|
||||
|
||||
{
|
||||
boost::system::error_code bc( ev, bt );
|
||||
@@ -147,7 +125,7 @@ public:
|
||||
virtual std::string message( int ev ) const
|
||||
{
|
||||
char buffer[ 256 ];
|
||||
std::sprintf( buffer, "user message %d", ev );
|
||||
boost::core::snprintf( buffer, sizeof( buffer ), "user message %d", ev );
|
||||
|
||||
return buffer;
|
||||
}
|
||||
@@ -287,7 +265,7 @@ public:
|
||||
virtual std::string message( int ev ) const
|
||||
{
|
||||
char buffer[ 256 ];
|
||||
std::sprintf( buffer, "user2 message %d", ev );
|
||||
boost::core::snprintf( buffer, sizeof( buffer ), "user2 message %d", ev );
|
||||
|
||||
return buffer;
|
||||
}
|
||||
|
||||
66
test/std_interop_test10.cpp
Normal file
66
test/std_interop_test10.cpp
Normal file
@@ -0,0 +1,66 @@
|
||||
// Copyright 2021 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/core/lightweight_test.hpp>
|
||||
#include <boost/config/pragma_message.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>
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
boost::system::error_code e1;
|
||||
boost::system::error_code e2( 0, boost::system::system_category() );
|
||||
|
||||
BOOST_TEST_EQ( e1, e2 );
|
||||
|
||||
std::error_code e3( e1 );
|
||||
std::error_code e4( e2 );
|
||||
|
||||
BOOST_TEST_EQ( e3, e4 );
|
||||
}
|
||||
|
||||
{
|
||||
boost::system::error_code e1;
|
||||
|
||||
std::error_code e2( e1 );
|
||||
std::error_code e3( e1.value(), e1.category() );
|
||||
|
||||
BOOST_TEST_EQ( e2, e3 );
|
||||
}
|
||||
|
||||
{
|
||||
boost::system::error_condition e1;
|
||||
boost::system::error_condition e2( 0, boost::system::generic_category() );
|
||||
|
||||
BOOST_TEST_EQ( e1, e2 );
|
||||
|
||||
std::error_condition e3( e1 );
|
||||
std::error_condition e4( e2 );
|
||||
|
||||
BOOST_TEST( e3 == e4 );
|
||||
}
|
||||
|
||||
{
|
||||
boost::system::error_condition e1;
|
||||
|
||||
std::error_condition e2( e1 );
|
||||
std::error_condition e3( e1.value(), e1.category() );
|
||||
|
||||
BOOST_TEST( e2 == e3 );
|
||||
}
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
|
||||
#endif
|
||||
47
test/std_interop_test11.cpp
Normal file
47
test/std_interop_test11.cpp
Normal file
@@ -0,0 +1,47 @@
|
||||
// Copyright 2021 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/core/lightweight_test.hpp>
|
||||
#include <boost/config/pragma_message.hpp>
|
||||
#include <boost/config.hpp>
|
||||
#include <ios>
|
||||
|
||||
#if !defined(BOOST_SYSTEM_HAS_SYSTEM_ERROR)
|
||||
|
||||
BOOST_PRAGMA_MESSAGE( "Skipping test, BOOST_SYSTEM_HAS_SYSTEM_ERROR not defined" )
|
||||
int main() {}
|
||||
|
||||
#elif defined(BOOST_LIBSTDCXX_VERSION) && BOOST_LIBSTDCXX_VERSION < 50000
|
||||
|
||||
BOOST_PRAGMA_MESSAGE( "Skipping test, BOOST_LIBSTDCXX_VERSION < 50000" )
|
||||
int main() {}
|
||||
|
||||
#else
|
||||
|
||||
#include <system_error>
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
boost::system::error_code ec = std::io_errc::stream;
|
||||
|
||||
BOOST_TEST( ec == std::io_errc::stream );
|
||||
BOOST_TEST_NOT( ec != std::io_errc::stream );
|
||||
|
||||
ec.clear();
|
||||
|
||||
BOOST_TEST_NOT( ec == std::io_errc::stream );
|
||||
BOOST_TEST( ec != std::io_errc::stream );
|
||||
|
||||
ec = std::io_errc::stream;
|
||||
|
||||
BOOST_TEST( ec == std::io_errc::stream );
|
||||
BOOST_TEST_NOT( ec != std::io_errc::stream );
|
||||
}
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
|
||||
#endif
|
||||
127
test/std_interop_test12.cpp
Normal file
127
test/std_interop_test12.cpp
Normal file
@@ -0,0 +1,127 @@
|
||||
// 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/system/errc.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>
|
||||
|
||||
enum my_errc
|
||||
{
|
||||
my_enoent = ENOENT
|
||||
};
|
||||
|
||||
class my_category: public boost::system::error_category
|
||||
{
|
||||
public:
|
||||
|
||||
char const* name() const BOOST_NOEXCEPT
|
||||
{
|
||||
return "mycat";
|
||||
}
|
||||
|
||||
boost::system::error_condition default_error_condition( int ev ) const BOOST_NOEXCEPT
|
||||
{
|
||||
switch( ev )
|
||||
{
|
||||
case my_enoent:
|
||||
|
||||
return boost::system::error_condition( ENOENT, boost::system::generic_category() );
|
||||
|
||||
default:
|
||||
|
||||
return boost::system::error_condition( ev, *this );
|
||||
}
|
||||
}
|
||||
|
||||
std::string message( int ev ) const
|
||||
{
|
||||
switch( ev )
|
||||
{
|
||||
case my_enoent:
|
||||
|
||||
return "No such entity";
|
||||
|
||||
default:
|
||||
|
||||
return "Unknown error";
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
#if defined(BOOST_GCC) && BOOST_GCC < 70000
|
||||
|
||||
// g++ 6 and earlier do not allow specializations outside the namespace
|
||||
|
||||
namespace boost
|
||||
{
|
||||
namespace system
|
||||
{
|
||||
|
||||
template<> struct is_error_code_enum<my_errc>: std::true_type {};
|
||||
|
||||
} // namespace system
|
||||
} // namespace boost
|
||||
|
||||
namespace std
|
||||
{
|
||||
|
||||
template<> struct is_error_code_enum<my_errc>: std::true_type {};
|
||||
|
||||
} // namespace std
|
||||
|
||||
#else
|
||||
|
||||
template<> struct boost::system::is_error_code_enum<my_errc>: std::true_type {};
|
||||
template<> struct std::is_error_code_enum<my_errc>: std::true_type {};
|
||||
|
||||
#endif
|
||||
|
||||
boost::system::error_code make_error_code( my_errc e )
|
||||
{
|
||||
// If `cat` is declared constexpr or const, msvc-14.1 and
|
||||
// msvc-14.2 before 19.29 put it in read-only memory,
|
||||
// despite the `ps_` member being mutable. So it crashes.
|
||||
|
||||
static /*BOOST_SYSTEM_CONSTEXPR*/ my_category cat;
|
||||
return boost::system::error_code( e, cat );
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
boost::system::error_code e1 = my_enoent;
|
||||
|
||||
BOOST_TEST( e1 == my_enoent );
|
||||
BOOST_TEST_NOT( e1 != my_enoent );
|
||||
|
||||
BOOST_TEST( e1 == boost::system::errc::no_such_file_or_directory );
|
||||
BOOST_TEST( e1 == std::errc::no_such_file_or_directory );
|
||||
}
|
||||
|
||||
{
|
||||
std::error_code e1 = my_enoent;
|
||||
|
||||
BOOST_TEST( e1 == my_enoent );
|
||||
BOOST_TEST_NOT( e1 != my_enoent );
|
||||
|
||||
BOOST_TEST( e1 == std::errc::no_such_file_or_directory );
|
||||
}
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
|
||||
#endif
|
||||
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
|
||||
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
|
||||
@@ -30,13 +30,20 @@ int main()
|
||||
BOOST_TEST_EQ( e2, e1 );
|
||||
BOOST_TEST_NOT( e2 != e1 );
|
||||
|
||||
BOOST_TEST( e2 == en );
|
||||
#if defined(_LIBCPP_VERSION)
|
||||
|
||||
// Under MS STL and libstdc++, std::error_code() does not compare
|
||||
// equal to std::error_condition(). Go figure.
|
||||
|
||||
BOOST_TEST_EQ( e2, en );
|
||||
BOOST_TEST_NOT( e2 != en );
|
||||
|
||||
boost::system::error_code e3( e2 );
|
||||
|
||||
BOOST_TEST_EQ( e3, en );
|
||||
BOOST_TEST_NOT( e3 != en );
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
{
|
||||
@@ -51,13 +58,17 @@ int main()
|
||||
BOOST_TEST_EQ( e2, e1 );
|
||||
BOOST_TEST_NOT( e2 != e1 );
|
||||
|
||||
BOOST_TEST( e2 == en );
|
||||
#if defined(_LIBCPP_VERSION)
|
||||
|
||||
BOOST_TEST_EQ( e2, en );
|
||||
BOOST_TEST_NOT( e2 != en );
|
||||
|
||||
boost::system::error_code e3( e2 );
|
||||
|
||||
BOOST_TEST_EQ( e3, en );
|
||||
BOOST_TEST_NOT( e3 != en );
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
{
|
||||
@@ -72,7 +83,7 @@ int main()
|
||||
BOOST_TEST_EQ( e2, e1 );
|
||||
BOOST_TEST_NOT( e2 != e1 );
|
||||
|
||||
BOOST_TEST( e2 == en );
|
||||
BOOST_TEST_EQ( e2, en );
|
||||
BOOST_TEST_NOT( e2 != en );
|
||||
|
||||
boost::system::error_code e3( e2 );
|
||||
@@ -93,7 +104,7 @@ int main()
|
||||
BOOST_TEST_EQ( e2, e1 );
|
||||
BOOST_TEST_NOT( e2 != e1 );
|
||||
|
||||
BOOST_TEST( e2 == en );
|
||||
BOOST_TEST_EQ( e2, en );
|
||||
BOOST_TEST_NOT( e2 != en );
|
||||
|
||||
boost::system::error_code e3( e2 );
|
||||
@@ -114,7 +125,7 @@ int main()
|
||||
BOOST_TEST_EQ( e2, e1 );
|
||||
BOOST_TEST_NOT( e2 != e1 );
|
||||
|
||||
BOOST_TEST( e2 == en );
|
||||
BOOST_TEST_EQ( e2, en );
|
||||
BOOST_TEST_NOT( e2 != en );
|
||||
|
||||
boost::system::error_code e3( e2 );
|
||||
|
||||
@@ -8,11 +8,9 @@
|
||||
|
||||
// See library home page at http://www.boost.org/libs/system
|
||||
|
||||
// Avoid spurious VC++ warnings
|
||||
# define _CRT_SECURE_NO_WARNINGS
|
||||
|
||||
#include <boost/system/error_code.hpp>
|
||||
#include <boost/core/lightweight_test.hpp>
|
||||
#include <boost/core/snprintf.hpp>
|
||||
#include <cstring>
|
||||
#include <cstdio>
|
||||
|
||||
@@ -65,7 +63,7 @@ std::string sys_strerror( int ev )
|
||||
{
|
||||
char buffer[ 38 ];
|
||||
|
||||
std::sprintf( buffer, "Unknown error (%d)", ev );
|
||||
boost::core::snprintf( buffer, sizeof( buffer ), "Unknown error (%d)", ev );
|
||||
return buffer;
|
||||
}
|
||||
|
||||
|
||||
@@ -81,27 +81,25 @@ int main( int, char *[] )
|
||||
system_error c6_0( 0, system_category(), "c6_0" );
|
||||
system_error c6_1( 1, system_category(), "c6_1" );
|
||||
|
||||
TEST( c1_0, 0, "The operation completed successfully" );
|
||||
TEST( c1_1, 1, "Incorrect function" );
|
||||
TEST( c1_2u, 2, "The system cannot find the file specified" );
|
||||
TEST( c1_0, 0, "The operation completed successfully [system:0]" );
|
||||
TEST( c1_1, 1, "Incorrect function [system:1]" );
|
||||
TEST( c1_2u, 2, "The system cannot find the file specified [system:2]" );
|
||||
|
||||
TEST( c2_0, 0, "c2_0: The operation completed successfully" );
|
||||
TEST( c2_1, 1, "c2_1: Incorrect function" );
|
||||
TEST( c2_0, 0, "c2_0: The operation completed successfully [system:0]" );
|
||||
TEST( c2_1, 1, "c2_1: Incorrect function [system:1]" );
|
||||
|
||||
TEST( c3_0, 0, "c3_0: The operation completed successfully" );
|
||||
TEST( c3_1, 1, "c3_1: Incorrect function" );
|
||||
TEST( c3_0, 0, "c3_0: The operation completed successfully [system:0]" );
|
||||
TEST( c3_1, 1, "c3_1: Incorrect function [system:1]" );
|
||||
|
||||
TEST( c4_0, 0, "The operation completed successfully" );
|
||||
TEST( c4_1, 1, "Incorrect function" );
|
||||
TEST( c4_2u, 2, "The system cannot find the file specified" );
|
||||
TEST( c4_0, 0, "The operation completed successfully [system:0]" );
|
||||
TEST( c4_1, 1, "Incorrect function [system:1]" );
|
||||
TEST( c4_2u, 2, "The system cannot find the file specified [system:2]" );
|
||||
|
||||
TEST( c5_0, 0, "c5_0: The operation completed successfully" );
|
||||
TEST( c5_1, 1, "c5_1: Incorrect function" );
|
||||
TEST( c5_0, 0, "c5_0: The operation completed successfully [system:0]" );
|
||||
TEST( c5_1, 1, "c5_1: Incorrect function [system:1]" );
|
||||
|
||||
TEST( c6_0, 0, "c6_0: The operation completed successfully" );
|
||||
TEST( c6_1, 1, "c6_1: Incorrect function" );
|
||||
TEST( c6_0, 0, "c6_0: The operation completed successfully [system:0]" );
|
||||
TEST( c6_1, 1, "c6_1: Incorrect function [system:1]" );
|
||||
|
||||
return ::boost::report_errors();
|
||||
}
|
||||
|
||||
|
||||
|
||||
41
test/system_error_test2.cpp
Normal file
41
test/system_error_test2.cpp
Normal file
@@ -0,0 +1,41 @@
|
||||
// Copyright 2021 Peter Dimov
|
||||
// Distributed under the Boost Software License, Version 1.0
|
||||
// https://www.boost.org/LICENSE_1_0.txt
|
||||
|
||||
#include <boost/system/system_error.hpp>
|
||||
#include <boost/core/lightweight_test.hpp>
|
||||
#include <cerrno>
|
||||
|
||||
namespace sys = boost::system;
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
sys::error_code ec( 5, sys::generic_category() );
|
||||
sys::system_error x1( ec );
|
||||
(void)x1;
|
||||
}
|
||||
|
||||
{
|
||||
sys::error_code ec( 5, sys::system_category() );
|
||||
sys::system_error x1( ec );
|
||||
(void)x1;
|
||||
}
|
||||
|
||||
{
|
||||
sys::system_error x1( make_error_code( sys::errc::invalid_argument ) );
|
||||
(void)x1;
|
||||
}
|
||||
|
||||
{
|
||||
sys::system_error x1( 5, sys::generic_category() );
|
||||
(void)x1;
|
||||
}
|
||||
|
||||
{
|
||||
sys::system_error x1( 5, sys::system_category() );
|
||||
(void)x1;
|
||||
}
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
62
test/system_error_test3.cpp
Normal file
62
test/system_error_test3.cpp
Normal file
@@ -0,0 +1,62 @@
|
||||
// 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/system_error.hpp>
|
||||
#include <boost/core/lightweight_test.hpp>
|
||||
#include <cerrno>
|
||||
|
||||
namespace sys = boost::system;
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
sys::error_code ec( 5, sys::generic_category() );
|
||||
sys::system_error x1( ec );
|
||||
|
||||
BOOST_TEST_EQ( std::string( x1.what() ), ec.what() );
|
||||
}
|
||||
|
||||
{
|
||||
sys::error_code ec( 5, sys::generic_category() );
|
||||
sys::system_error x1( ec, "prefix" );
|
||||
|
||||
BOOST_TEST_EQ( std::string( x1.what() ), "prefix: " + ec.what() );
|
||||
}
|
||||
|
||||
{
|
||||
sys::error_code ec( 5, sys::generic_category() );
|
||||
sys::system_error x1( ec, std::string( "prefix2" ) );
|
||||
|
||||
BOOST_TEST_EQ( std::string( x1.what() ), "prefix2: " + ec.what() );
|
||||
}
|
||||
|
||||
{
|
||||
BOOST_STATIC_CONSTEXPR boost::source_location loc = BOOST_CURRENT_LOCATION;
|
||||
|
||||
sys::error_code ec( 5, sys::generic_category(), &loc );
|
||||
sys::system_error x1( ec, "prefix3" );
|
||||
|
||||
BOOST_TEST_EQ( std::string( x1.what() ), "prefix3: " + ec.what() );
|
||||
}
|
||||
|
||||
{
|
||||
sys::system_error x1( 5, sys::system_category() );
|
||||
|
||||
BOOST_TEST_EQ( std::string( x1.what() ), sys::error_code( 5, sys::system_category() ).what() );
|
||||
}
|
||||
|
||||
{
|
||||
sys::system_error x1( 5, sys::system_category(), "prefix" );
|
||||
|
||||
BOOST_TEST_EQ( std::string( x1.what() ), "prefix: " + sys::error_code( 5, sys::system_category() ).what() );
|
||||
}
|
||||
|
||||
{
|
||||
sys::system_error x1( 5, sys::system_category(), std::string( "prefix2" ) );
|
||||
|
||||
BOOST_TEST_EQ( std::string( x1.what() ), "prefix2: " + sys::error_code( 5, sys::system_category() ).what() );
|
||||
}
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
@@ -46,7 +46,7 @@ int main()
|
||||
boost::system::system_error x( bc, "prefix" );
|
||||
|
||||
BOOST_TEST_EQ( x.code(), bc );
|
||||
BOOST_TEST_EQ( std::string( x.what() ), "prefix: " + bc.message() );
|
||||
BOOST_TEST_EQ( std::string( x.what() ), "prefix: " + bc.what() );
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
|
||||
52
test/win32_generic_test.cpp
Normal file
52
test/win32_generic_test.cpp
Normal file
@@ -0,0 +1,52 @@
|
||||
// Copyright 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/config.hpp>
|
||||
#include <boost/config/pragma_message.hpp>
|
||||
|
||||
#if !defined(BOOST_SYSTEM_HAS_SYSTEM_ERROR)
|
||||
|
||||
BOOST_PRAGMA_MESSAGE( "Skipping test, BOOST_SYSTEM_HAS_SYSTEM_ERROR is not defined" )
|
||||
int main() {}
|
||||
|
||||
#elif !defined(BOOST_MSSTL_VERSION) || BOOST_MSSTL_VERSION < 140
|
||||
|
||||
BOOST_PRAGMA_MESSAGE( "Skipping test, BOOST_MSSTL_VERSION is not defined or is less than 140" )
|
||||
int main() {}
|
||||
|
||||
#else
|
||||
|
||||
#include <system_error>
|
||||
#include <iostream>
|
||||
|
||||
int main()
|
||||
{
|
||||
namespace sys = boost::system;
|
||||
|
||||
int n = 0;
|
||||
|
||||
for( int i = 0; i < 65000; ++i )
|
||||
{
|
||||
sys::error_code ec1( i, sys::system_category() );
|
||||
sys::error_condition en1 = ec1.default_error_condition();
|
||||
|
||||
std::error_code ec2( i, std::system_category() );
|
||||
std::error_condition en2 = ec2.default_error_condition();
|
||||
|
||||
if( en1 != en2 )
|
||||
{
|
||||
std::cout << i << ": " << en1 << " (" << en1.message() << ") != cond:" << en2.category().name() << ":" << en2.value() << " (" << en2.message() << ")\n";
|
||||
|
||||
if( en2.category() == std::generic_category() && i != 123 ) // msvc-14.0, msvc-14.1 disagree with us on ERROR_INVALID_NAME
|
||||
{
|
||||
++n;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return n < 256 ? n: 255;
|
||||
}
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user