mirror of
https://github.com/boostorg/system.git
synced 2025-12-25 08:18:05 +01:00
Compare commits
490 Commits
feature/de
...
feature/re
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
982abbe42a | ||
|
|
56ba602d06 | ||
|
|
7ec2584789 | ||
|
|
dec785741b | ||
|
|
c8e1b9fa0b | ||
|
|
4d8f6f85cd | ||
|
|
05cb8f459c | ||
|
|
62878a6d06 | ||
|
|
8bb3ce6277 | ||
|
|
1b74658f57 | ||
|
|
6dc7819c2e | ||
|
|
1061db7dcd | ||
|
|
fa51e42fff | ||
|
|
323c618f99 | ||
|
|
1a3279d087 | ||
|
|
bd46fb21f3 | ||
|
|
14c5f52602 | ||
|
|
7a495bb46d | ||
|
|
db00e1848e | ||
|
|
7a49a5d80d | ||
|
|
a0597f4872 | ||
|
|
485be93281 | ||
|
|
ee0b15efc4 | ||
|
|
09f4eb87e2 | ||
|
|
3e5ce27719 | ||
|
|
40bdcea2e5 | ||
|
|
19bcfebf37 | ||
|
|
6d58d0bb76 | ||
|
|
a664cd1de6 | ||
|
|
e8a089b664 | ||
|
|
75e1a1e28b | ||
|
|
5feb280612 | ||
|
|
fc3ab6db97 | ||
|
|
91929719bd | ||
|
|
8d0fa396b8 | ||
|
|
671d0ad41b | ||
|
|
5d5ecb74a7 | ||
|
|
41ff095c0a | ||
|
|
38d63aaf7c | ||
|
|
d1fb7554c5 | ||
|
|
c63bca6eda | ||
|
|
bef2c5ef6a | ||
|
|
341f960e72 | ||
|
|
4d4f906548 | ||
|
|
8a92683012 | ||
|
|
be5a8ffa80 | ||
|
|
d032ab91fd | ||
|
|
9b82082f76 | ||
|
|
3c293f8740 | ||
|
|
2feb94ac07 | ||
|
|
8f319f30c6 | ||
|
|
d09b2f5f1d | ||
|
|
01d46f597e | ||
|
|
93852d1a7e | ||
|
|
4aeebd2173 | ||
|
|
96fef94580 | ||
|
|
75ab18c9fd | ||
|
|
f9a4655ae7 | ||
|
|
f6fcb1b690 | ||
|
|
27a5096b6c | ||
|
|
9cc66841c4 | ||
|
|
2fc720a1cb | ||
|
|
73de83b8f7 | ||
|
|
310bf1d544 | ||
|
|
f18edb3d24 | ||
|
|
a9659f4318 | ||
|
|
2b14b9a96a | ||
|
|
c7a0ce3349 | ||
|
|
cedf6eb581 | ||
|
|
ab368822a6 | ||
|
|
293174a1d3 | ||
|
|
5c1d0df893 | ||
|
|
3f2f87f734 | ||
|
|
6caa346ba5 | ||
|
|
a5aec941ca | ||
|
|
7f640b92fe | ||
|
|
626263c23f | ||
|
|
53ce7e9f53 | ||
|
|
ff47c6782f | ||
|
|
abbfd46517 | ||
|
|
128fd9341f | ||
|
|
e0b0118406 | ||
|
|
3ded81eed0 | ||
|
|
80e019069c | ||
|
|
e368c2863d | ||
|
|
00fb79f174 | ||
|
|
44582f3c3c | ||
|
|
f08e363c0e | ||
|
|
1474498ccf | ||
|
|
b0304ad0b2 | ||
|
|
9974d92675 | ||
|
|
945b0591dd | ||
|
|
1f1e4e0400 | ||
|
|
1a0b9a46a8 | ||
|
|
f132dca4a9 | ||
|
|
81a9952695 | ||
|
|
b877f65f80 | ||
|
|
aa80e0bdcd | ||
|
|
0b60b13618 | ||
|
|
7dacf5be11 | ||
|
|
c3cd1d5ea9 | ||
|
|
2bea482605 | ||
|
|
48f95f0035 | ||
|
|
16d20175bc | ||
|
|
2aa5d4d97f | ||
|
|
18edbf75d0 | ||
|
|
52220a0351 | ||
|
|
ffa67ab005 | ||
|
|
d8399efcac | ||
|
|
8bc32b7267 | ||
|
|
d11dd4b396 | ||
|
|
ca5bca39ce | ||
|
|
a58115cb50 | ||
|
|
1bc08296de | ||
|
|
25479216b3 | ||
|
|
54d3b253b1 | ||
|
|
194b84e663 | ||
|
|
47a08cb35b | ||
|
|
7ffd63d54c | ||
|
|
92c24da9a1 | ||
|
|
dc73ca428b | ||
|
|
c1fa3619b6 | ||
|
|
0cd351014b | ||
|
|
d38e54d4c3 | ||
|
|
fa3331412d | ||
|
|
b899c49ae8 | ||
|
|
61a0e244da | ||
|
|
eb788615de | ||
|
|
84fd43e14a | ||
|
|
b0ef682e3d | ||
|
|
c360ff1b1c | ||
|
|
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 | ||
|
|
08c12e8ad5 | ||
|
|
7d3cfdd09a | ||
|
|
15f94537a6 | ||
|
|
c0f38e2f3e | ||
|
|
ac28a8cec9 | ||
|
|
4169ef3ce6 | ||
|
|
ce49a7d1be | ||
|
|
1a4eb29719 | ||
|
|
465f6c57da | ||
|
|
cb8db34d7b | ||
|
|
2b6a708070 | ||
|
|
50f84f16dc | ||
|
|
fd21395802 | ||
|
|
cebb011a58 | ||
|
|
3f67d3def5 | ||
|
|
f2b3ae7e2b | ||
|
|
48e56b9874 | ||
|
|
967b7cbc98 | ||
|
|
c8492a705d | ||
|
|
a3187439e3 | ||
|
|
19f9d0c5b4 | ||
|
|
d17f7d7fe6 | ||
|
|
36843a4e2d | ||
|
|
a6c988181e | ||
|
|
10572b7a59 | ||
|
|
fe3d0e6c14 | ||
|
|
ae77563039 | ||
|
|
fd852c675e | ||
|
|
6156076dab | ||
|
|
984f8f1a92 | ||
|
|
b507b2294e | ||
|
|
39ad22d660 | ||
|
|
3b70265ced | ||
|
|
a65b91b3fb | ||
|
|
bed0d59d22 | ||
|
|
5e642b1d43 | ||
|
|
b35b47d8c2 | ||
|
|
f21035f8af | ||
|
|
cd98f4edd7 | ||
|
|
a9b64a888a | ||
|
|
bb4b500cfc | ||
|
|
d44dab91dc | ||
|
|
2b6498ad80 | ||
|
|
22072bfbc9 | ||
|
|
65f644d5de | ||
|
|
f967081d7e | ||
|
|
19e9f08666 | ||
|
|
b41139b28e | ||
|
|
39a19f3c90 | ||
|
|
b4dd5e98c9 | ||
|
|
41e3a7c8af | ||
|
|
aee97e91ce | ||
|
|
98533dedb3 | ||
|
|
fe811d1dd1 | ||
|
|
137ecb4abf | ||
|
|
e5cd7bf852 | ||
|
|
96cd1c0163 | ||
|
|
a9da17f2e2 | ||
|
|
f26dfd3dd7 | ||
|
|
d09c998eb2 | ||
|
|
2374e85dc7 | ||
|
|
9167bf8ee8 | ||
|
|
7f7a9da4d5 | ||
|
|
67ae4d3c47 | ||
|
|
ee028e2f9d | ||
|
|
7657188802 | ||
|
|
210c54b09a | ||
|
|
87bb5616a8 | ||
|
|
6de562c79d | ||
|
|
8efb96350f | ||
|
|
88a7be42b5 | ||
|
|
a3225e78e2 | ||
|
|
3c469fe710 | ||
|
|
c2d044f34e | ||
|
|
9fdfa6c645 | ||
|
|
42a257e17c | ||
|
|
26d0d32c54 | ||
|
|
70b5449e99 | ||
|
|
8043ce0278 | ||
|
|
83a2933afa | ||
|
|
2e707ca921 | ||
|
|
a6c4b6329c | ||
|
|
5b1909eba4 | ||
|
|
9dc13fd82a | ||
|
|
e9cdb10409 | ||
|
|
e625bd0eea | ||
|
|
66656f7044 | ||
|
|
0d8511f571 | ||
|
|
fbc49bbaa0 | ||
|
|
344eb1e1f8 | ||
|
|
20b8e90dff | ||
|
|
a0136e570d | ||
|
|
6586fcb01e | ||
|
|
b74b1e3c8c | ||
|
|
1caaacff57 | ||
|
|
75d5287558 | ||
|
|
25eaf0fdae | ||
|
|
f43293f451 | ||
|
|
f8ab3df822 | ||
|
|
f6fb85d7d3 | ||
|
|
9cd9d8732f | ||
|
|
1b7fd6854d | ||
|
|
610d5f3f78 | ||
|
|
88f7c2bf53 | ||
|
|
723daf5d57 | ||
|
|
3d4c31c213 | ||
|
|
c069ae048f | ||
|
|
28e1b919ac | ||
|
|
b20191f8d7 | ||
|
|
d019c1cdae | ||
|
|
ff77d4c094 | ||
|
|
a21a3050a5 | ||
|
|
08d62ac444 | ||
|
|
45e9dfeba9 | ||
|
|
7d9eb384c6 | ||
|
|
04bfb05b19 | ||
|
|
a650f5d676 | ||
|
|
6ab5fd9dac | ||
|
|
ed14d74323 | ||
|
|
ff9bca96e3 | ||
|
|
8560290b71 | ||
|
|
8b41ff22a6 | ||
|
|
79f9a297cd | ||
|
|
344ea58a77 | ||
|
|
5eae4824ab | ||
|
|
f502e6cda4 | ||
|
|
69bc20fb15 | ||
|
|
fbf7f4a417 | ||
|
|
a688d7834a | ||
|
|
689e09e86f | ||
|
|
b92035d4d2 | ||
|
|
1ba5c9efc4 | ||
|
|
23db4e8d69 | ||
|
|
189cc0c185 | ||
|
|
63a32cea9a | ||
|
|
3e2cb8975f | ||
|
|
4e7c88779b | ||
|
|
3ee8200e75 | ||
|
|
516484a821 |
405
.drone.jsonnet
Normal file
405
.drone.jsonnet
Normal file
@@ -0,0 +1,405 @@
|
||||
# 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',
|
||||
'uname -a',
|
||||
'echo $DRONE_STAGE_MACHINE',
|
||||
] +
|
||||
(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 16.04 GCC 4.8",
|
||||
"cppalliance/droneubuntu1604:1",
|
||||
{ TOOLSET: 'gcc', COMPILER: 'g++-4.8', CXXSTD: '11' },
|
||||
"g++-4.8",
|
||||
),
|
||||
|
||||
linux_pipeline(
|
||||
"Linux 16.04 GCC 4.9",
|
||||
"cppalliance/droneubuntu1604:1",
|
||||
{ TOOLSET: 'gcc', COMPILER: 'g++-4.9', CXXSTD: '11' },
|
||||
"g++-4.9",
|
||||
),
|
||||
|
||||
linux_pipeline(
|
||||
"Linux 16.04 GCC 5*",
|
||||
"cppalliance/droneubuntu1604:1",
|
||||
{ TOOLSET: 'gcc', COMPILER: 'g++', CXXSTD: '11,14' },
|
||||
),
|
||||
|
||||
linux_pipeline(
|
||||
"Linux 18.04 GCC 6",
|
||||
"cppalliance/droneubuntu1804:1",
|
||||
{ TOOLSET: 'gcc', COMPILER: 'g++-6', CXXSTD: '11,14' },
|
||||
"g++-6",
|
||||
),
|
||||
|
||||
linux_pipeline(
|
||||
"Linux 18.04 GCC 7* 32/64",
|
||||
"cppalliance/droneubuntu1804:1",
|
||||
{ TOOLSET: 'gcc', COMPILER: 'g++', CXXSTD: '11,14,17', ADDRMD: '32,64' },
|
||||
),
|
||||
|
||||
linux_pipeline(
|
||||
"Linux 18.04 GCC 8",
|
||||
"cppalliance/droneubuntu1804:1",
|
||||
{ TOOLSET: 'gcc', COMPILER: 'g++-8', CXXSTD: '11,14,17' },
|
||||
"g++-8",
|
||||
),
|
||||
|
||||
linux_pipeline(
|
||||
"Linux 20.04 GCC 9* 32",
|
||||
"cppalliance/droneubuntu2004:1",
|
||||
{ TOOLSET: 'gcc', COMPILER: 'g++', CXXSTD: '11,14,17,2a', ADDRMD: '32' },
|
||||
),
|
||||
|
||||
linux_pipeline(
|
||||
"Linux 20.04 GCC 9* 64",
|
||||
"cppalliance/droneubuntu2004:1",
|
||||
{ TOOLSET: 'gcc', COMPILER: 'g++', CXXSTD: '11,14,17,2a', ADDRMD: '64' },
|
||||
),
|
||||
|
||||
linux_pipeline(
|
||||
"Linux 20.04 GCC 9* ARM64",
|
||||
"cppalliance/droneubuntu2004:multiarch",
|
||||
{ TOOLSET: 'gcc', COMPILER: 'g++', CXXSTD: '11,14,17,2a' },
|
||||
arch="arm64",
|
||||
),
|
||||
|
||||
linux_pipeline(
|
||||
"Linux 20.04 GCC 9* S390x",
|
||||
"cppalliance/droneubuntu2004:multiarch",
|
||||
{ TOOLSET: 'gcc', COMPILER: 'g++', CXXSTD: '11,14,17,2a' },
|
||||
arch="s390x",
|
||||
),
|
||||
|
||||
linux_pipeline(
|
||||
"Linux 20.04 GCC 10 32",
|
||||
"cppalliance/droneubuntu2004:1",
|
||||
{ TOOLSET: 'gcc', COMPILER: 'g++-10', CXXSTD: '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: '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: '11,14,17,2a', ADDRMD: '32' },
|
||||
),
|
||||
|
||||
linux_pipeline(
|
||||
"Linux 22.04 GCC 11* 64",
|
||||
"cppalliance/droneubuntu2204:1",
|
||||
{ TOOLSET: 'gcc', COMPILER: 'g++', CXXSTD: '11,14,17,2a', ADDRMD: '64' },
|
||||
),
|
||||
|
||||
linux_pipeline(
|
||||
"Linux 22.04 GCC 12 32",
|
||||
"cppalliance/droneubuntu2204:1",
|
||||
{ TOOLSET: 'gcc', COMPILER: 'g++-12', CXXSTD: '11,14,17,20,2b', ADDRMD: '32' },
|
||||
"g++-12-multilib",
|
||||
),
|
||||
|
||||
linux_pipeline(
|
||||
"Linux 22.04 GCC 12 64",
|
||||
"cppalliance/droneubuntu2204:1",
|
||||
{ TOOLSET: 'gcc', COMPILER: 'g++-12', CXXSTD: '11,14,17,20,2b', ADDRMD: '64' },
|
||||
"g++-12-multilib",
|
||||
),
|
||||
|
||||
linux_pipeline(
|
||||
"Linux 24.04 GCC 13 32 UBSAN",
|
||||
"cppalliance/droneubuntu2404:1",
|
||||
{ TOOLSET: 'gcc', COMPILER: 'g++-13', CXXSTD: '11,14,17,20,2b', ADDRMD: '32' } + ubsan,
|
||||
"g++-13-multilib",
|
||||
),
|
||||
|
||||
linux_pipeline(
|
||||
"Linux 24.04 GCC 13 64 UBSAN",
|
||||
"cppalliance/droneubuntu2404:1",
|
||||
{ TOOLSET: 'gcc', COMPILER: 'g++-13', CXXSTD: '11,14,17,20,2b', ADDRMD: '64' } + ubsan,
|
||||
"g++-13-multilib",
|
||||
),
|
||||
|
||||
linux_pipeline(
|
||||
"Linux 24.04 GCC 13 32 ASAN",
|
||||
"cppalliance/droneubuntu2404:1",
|
||||
{ TOOLSET: 'gcc', COMPILER: 'g++-13', CXXSTD: '11,14,17,20,2b', ADDRMD: '32' } + asan,
|
||||
"g++-13-multilib",
|
||||
),
|
||||
|
||||
linux_pipeline(
|
||||
"Linux 24.04 GCC 14 UBSAN",
|
||||
"cppalliance/droneubuntu2404:1",
|
||||
{ TOOLSET: 'gcc', COMPILER: 'g++-14', CXXSTD: '11,14,17,20,2b' } + ubsan,
|
||||
"g++-14-multilib",
|
||||
),
|
||||
|
||||
linux_pipeline(
|
||||
"Linux 24.04 GCC 14 ASAN",
|
||||
"cppalliance/droneubuntu2404:1",
|
||||
{ TOOLSET: 'gcc', COMPILER: 'g++-14', CXXSTD: '11,14,17,20,2b' } + asan,
|
||||
"g++-14-multilib",
|
||||
),
|
||||
|
||||
linux_pipeline(
|
||||
"Linux 25.04 GCC 15 UBSAN",
|
||||
"cppalliance/droneubuntu2504:1",
|
||||
{ TOOLSET: 'gcc', COMPILER: 'g++-15', CXXSTD: '11,14,17,20,23,2c' } + ubsan,
|
||||
"g++-15-multilib",
|
||||
),
|
||||
|
||||
linux_pipeline(
|
||||
"Linux 25.04 GCC 15 ASAN",
|
||||
"cppalliance/droneubuntu2504:1",
|
||||
{ TOOLSET: 'gcc', COMPILER: 'g++-15', CXXSTD: '11,14,17,20,23,2c' } + asan,
|
||||
"g++-15-multilib",
|
||||
),
|
||||
|
||||
linux_pipeline(
|
||||
"Linux 16.04 Clang 3.5",
|
||||
"cppalliance/droneubuntu1604:1",
|
||||
{ TOOLSET: 'clang', COMPILER: 'clang++-3.5', CXXSTD: '11' },
|
||||
"clang-3.5",
|
||||
),
|
||||
|
||||
linux_pipeline(
|
||||
"Linux 16.04 Clang 3.6",
|
||||
"cppalliance/droneubuntu1604:1",
|
||||
{ TOOLSET: 'clang', COMPILER: 'clang++-3.6', CXXSTD: '11,14' },
|
||||
"clang-3.6",
|
||||
),
|
||||
|
||||
linux_pipeline(
|
||||
"Linux 16.04 Clang 3.7",
|
||||
"cppalliance/droneubuntu1604:1",
|
||||
{ TOOLSET: 'clang', COMPILER: 'clang++-3.7', CXXSTD: '11,14' },
|
||||
"clang-3.7",
|
||||
),
|
||||
|
||||
linux_pipeline(
|
||||
"Linux 16.04 Clang 3.8",
|
||||
"cppalliance/droneubuntu1604:1",
|
||||
{ TOOLSET: 'clang', COMPILER: 'clang++-3.8', CXXSTD: '11,14' },
|
||||
"clang-3.8",
|
||||
),
|
||||
|
||||
linux_pipeline(
|
||||
"Linux 22.04 Clang 13",
|
||||
"cppalliance/droneubuntu2204:1",
|
||||
{ TOOLSET: 'clang', COMPILER: 'clang++-13', CXXSTD: '11,14,17,20' },
|
||||
"clang-13",
|
||||
),
|
||||
|
||||
linux_pipeline(
|
||||
"Linux 22.04 Clang 14",
|
||||
"cppalliance/droneubuntu2204:1",
|
||||
{ TOOLSET: 'clang', COMPILER: 'clang++-14', CXXSTD: '11,14,17,20' },
|
||||
"clang-14",
|
||||
),
|
||||
|
||||
linux_pipeline(
|
||||
"Linux 22.04 Clang 15",
|
||||
"cppalliance/droneubuntu2204:1",
|
||||
{ TOOLSET: 'clang', COMPILER: 'clang++-15', CXXSTD: '11,14,17,20,2b' },
|
||||
"clang-15",
|
||||
),
|
||||
|
||||
linux_pipeline(
|
||||
"Linux 24.04 Clang 16",
|
||||
"cppalliance/droneubuntu2404:1",
|
||||
{ TOOLSET: 'clang', COMPILER: 'clang++-16', CXXSTD: '11,14,17,20,2b' },
|
||||
"clang-16",
|
||||
),
|
||||
|
||||
linux_pipeline(
|
||||
"Linux 24.04 Clang 17",
|
||||
"cppalliance/droneubuntu2404:1",
|
||||
{ TOOLSET: 'clang', COMPILER: 'clang++-17', CXXSTD: '11,14,17,20,2b' },
|
||||
"clang-17",
|
||||
),
|
||||
|
||||
linux_pipeline(
|
||||
"Linux 24.04 Clang 18 UBSAN",
|
||||
"cppalliance/droneubuntu2404:1",
|
||||
{ TOOLSET: 'clang', COMPILER: 'clang++-18', CXXSTD: '11,14,17,20,2b' } + ubsan,
|
||||
"clang-18",
|
||||
),
|
||||
|
||||
linux_pipeline(
|
||||
"Linux 24.04 Clang 18 ASAN",
|
||||
"cppalliance/droneubuntu2404:1",
|
||||
{ TOOLSET: 'clang', COMPILER: 'clang++-18', CXXSTD: '11,14,17,20,2b' } + asan,
|
||||
"clang-18",
|
||||
),
|
||||
|
||||
linux_pipeline(
|
||||
"Linux 24.04 Clang 19 UBSAN",
|
||||
"cppalliance/droneubuntu2404:1",
|
||||
{ TOOLSET: 'clang', COMPILER: 'clang++-19', CXXSTD: '11,14,17,20,2b' } + ubsan,
|
||||
"clang-19",
|
||||
),
|
||||
|
||||
linux_pipeline(
|
||||
"Linux 24.04 Clang 19 ASAN",
|
||||
"cppalliance/droneubuntu2404:1",
|
||||
{ TOOLSET: 'clang', COMPILER: 'clang++-19', CXXSTD: '11,14,17,20,2b' } + asan,
|
||||
"clang-19",
|
||||
),
|
||||
|
||||
linux_pipeline(
|
||||
"Linux 24.04 Clang 20 UBSAN",
|
||||
"cppalliance/droneubuntu2404:1",
|
||||
{ TOOLSET: 'clang', COMPILER: 'clang++-20', CXXSTD: '11,14,17,20,23,2c' } + ubsan,
|
||||
"clang-20",
|
||||
),
|
||||
|
||||
linux_pipeline(
|
||||
"Linux 24.04 Clang 20 ASAN",
|
||||
"cppalliance/droneubuntu2404:1",
|
||||
{ TOOLSET: 'clang', COMPILER: 'clang++-20', CXXSTD: '11,14,17,20,23,2c' } + asan,
|
||||
"clang-20",
|
||||
),
|
||||
|
||||
macos_pipeline(
|
||||
"MacOS 10.15 Xcode 12.2 UBSAN",
|
||||
{ TOOLSET: 'clang', COMPILER: 'clang++', CXXSTD: '11,14,1z' } + ubsan,
|
||||
),
|
||||
|
||||
macos_pipeline(
|
||||
"MacOS 10.15 Xcode 12.2 ASAN",
|
||||
{ TOOLSET: 'clang', COMPILER: 'clang++', CXXSTD: '11,14,1z' } + asan,
|
||||
),
|
||||
|
||||
macos_pipeline(
|
||||
"MacOS 12.4 Xcode 13.4.1 UBSAN",
|
||||
{ TOOLSET: 'clang', COMPILER: 'clang++', CXXSTD: '11,14,17,20,2b' } + ubsan,
|
||||
xcode_version = "13.4.1", osx_version = "monterey", arch = "arm64",
|
||||
),
|
||||
|
||||
macos_pipeline(
|
||||
"MacOS 12.4 Xcode 13.4.1 ASAN",
|
||||
{ TOOLSET: 'clang', COMPILER: 'clang++', CXXSTD: '11,14,17,20,2b' } + asan,
|
||||
xcode_version = "13.4.1", osx_version = "monterey", arch = "arm64",
|
||||
),
|
||||
|
||||
windows_pipeline(
|
||||
"Windows VS2015 msvc-14.0",
|
||||
"cppalliance/dronevs2015",
|
||||
{ TOOLSET: 'msvc-14.0', CXXSTD: '14,latest', B2_DONT_EMBED_MANIFEST: '1' },
|
||||
),
|
||||
|
||||
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
|
||||
25
.drone/drone.sh
Executable file
25
.drone/drone.sh
Executable file
@@ -0,0 +1,25 @@
|
||||
#!/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
|
||||
export PATH=~/.local/bin:/usr/local/bin:$PATH
|
||||
|
||||
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}
|
||||
659
.github/workflows/ci.yml
vendored
Normal file
659
.github/workflows/ci.yml
vendored
Normal file
@@ -0,0 +1,659 @@
|
||||
name: CI
|
||||
|
||||
on:
|
||||
pull_request:
|
||||
push:
|
||||
branches:
|
||||
- master
|
||||
- develop
|
||||
- feature/**
|
||||
|
||||
env:
|
||||
UBSAN_OPTIONS: print_stacktrace=1
|
||||
|
||||
jobs:
|
||||
posix:
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
include:
|
||||
- toolset: gcc-4.8
|
||||
cxxstd: "11"
|
||||
container: ubuntu:18.04
|
||||
os: ubuntu-latest
|
||||
install: g++-4.8
|
||||
- toolset: gcc-5
|
||||
cxxstd: "11,14,1z"
|
||||
container: ubuntu:18.04
|
||||
os: ubuntu-latest
|
||||
install: g++-5
|
||||
- toolset: gcc-6
|
||||
cxxstd: "11,14,1z"
|
||||
container: ubuntu:18.04
|
||||
os: ubuntu-latest
|
||||
install: g++-6
|
||||
- toolset: gcc-7
|
||||
cxxstd: "11,14,17"
|
||||
container: ubuntu:18.04
|
||||
os: ubuntu-latest
|
||||
- toolset: gcc-8
|
||||
cxxstd: "11,14,17,2a"
|
||||
container: ubuntu:20.04
|
||||
os: ubuntu-latest
|
||||
install: g++-8
|
||||
- toolset: gcc-9
|
||||
cxxstd: "11,14,17,2a"
|
||||
container: ubuntu:20.04
|
||||
os: ubuntu-latest
|
||||
- toolset: gcc-10
|
||||
cxxstd: "11,14,17,2a"
|
||||
container: ubuntu:20.04
|
||||
os: ubuntu-latest
|
||||
install: g++-10
|
||||
- toolset: gcc-11
|
||||
cxxstd: "11,14,17,2a"
|
||||
os: ubuntu-22.04
|
||||
- toolset: gcc-12
|
||||
cxxstd: "11,14,17,20,2b"
|
||||
os: ubuntu-22.04
|
||||
install: g++-12
|
||||
- toolset: gcc-13
|
||||
cxxstd: "11,14,17,20,2b"
|
||||
container: ubuntu:24.04
|
||||
os: ubuntu-latest
|
||||
install: g++-13
|
||||
- toolset: gcc-14
|
||||
cxxstd: "11,14,17,20,2b"
|
||||
container: ubuntu:24.04
|
||||
os: ubuntu-latest
|
||||
install: g++-14
|
||||
- toolset: gcc-15
|
||||
cxxstd: "11,14,17,20,23,2c"
|
||||
container: ubuntu:25.04
|
||||
os: ubuntu-latest
|
||||
install: g++-15
|
||||
- toolset: clang
|
||||
compiler: clang++-3.9
|
||||
cxxstd: "11,14"
|
||||
container: ubuntu:18.04
|
||||
os: ubuntu-latest
|
||||
install: clang-3.9
|
||||
- toolset: clang
|
||||
compiler: clang++-4.0
|
||||
cxxstd: "11,14"
|
||||
container: ubuntu:18.04
|
||||
os: ubuntu-latest
|
||||
install: clang-4.0
|
||||
- toolset: clang
|
||||
compiler: clang++-5.0
|
||||
cxxstd: "11,14,1z"
|
||||
container: ubuntu:18.04
|
||||
os: ubuntu-latest
|
||||
install: clang-5.0
|
||||
- toolset: clang
|
||||
compiler: clang++-6.0
|
||||
cxxstd: "11,14,17"
|
||||
container: ubuntu:20.04
|
||||
os: ubuntu-latest
|
||||
install: clang-6.0
|
||||
- toolset: clang
|
||||
compiler: clang++-7
|
||||
cxxstd: "11,14,17"
|
||||
stdlib: "native,libc++"
|
||||
container: ubuntu:20.04
|
||||
os: ubuntu-latest
|
||||
install: clang-7 libc++-7-dev libc++abi-7-dev
|
||||
- toolset: clang
|
||||
compiler: clang++-8
|
||||
cxxstd: "11,14,17"
|
||||
stdlib: "native,libc++"
|
||||
container: ubuntu:20.04
|
||||
os: ubuntu-latest
|
||||
install: clang-8 libc++-8-dev libc++abi-8-dev
|
||||
- toolset: clang
|
||||
compiler: clang++-9
|
||||
cxxstd: "11,14,17"
|
||||
stdlib: "native,libc++"
|
||||
container: ubuntu:20.04
|
||||
os: ubuntu-latest
|
||||
install: clang-9 libc++-9-dev libc++abi-9-dev
|
||||
- toolset: clang
|
||||
compiler: clang++-10
|
||||
cxxstd: "11,14,17,2a"
|
||||
stdlib: "native,libc++"
|
||||
container: ubuntu:20.04
|
||||
os: ubuntu-latest
|
||||
install: clang-10 libc++-10-dev libc++abi-10-dev
|
||||
- toolset: clang
|
||||
compiler: clang++-11
|
||||
cxxstd: "11,14,17,2a"
|
||||
stdlib: "native,libc++"
|
||||
container: ubuntu:20.04
|
||||
os: ubuntu-latest
|
||||
install: clang-11 libc++-11-dev libc++abi-11-dev
|
||||
- toolset: clang
|
||||
compiler: clang++-12
|
||||
cxxstd: "11,14,17,20"
|
||||
stdlib: "native,libc++"
|
||||
container: ubuntu:20.04
|
||||
os: ubuntu-latest
|
||||
install: clang-12 libc++-12-dev libc++abi-12-dev
|
||||
- toolset: clang
|
||||
compiler: clang++-13
|
||||
cxxstd: "11,14,17,20,2b"
|
||||
stdlib: "native,libc++"
|
||||
container: ubuntu:22.04
|
||||
os: ubuntu-latest
|
||||
install: clang-13 libc++-13-dev libc++abi-13-dev
|
||||
- toolset: clang
|
||||
compiler: clang++-14
|
||||
cxxstd: "11,14,17,20,2b"
|
||||
stdlib: "native,libc++"
|
||||
container: ubuntu:22.04
|
||||
os: ubuntu-latest
|
||||
install: clang-14 libc++-14-dev libc++abi-14-dev
|
||||
- toolset: clang
|
||||
compiler: clang++-15
|
||||
cxxstd: "11,14,17,20,2b"
|
||||
container: ubuntu:22.04
|
||||
stdlib: "native,libc++"
|
||||
os: ubuntu-latest
|
||||
install: clang-15 libc++-15-dev libc++abi-15-dev
|
||||
- toolset: clang
|
||||
compiler: clang++-16
|
||||
cxxstd: "11,14,17,20,2b"
|
||||
stdlib: "native,libc++"
|
||||
container: ubuntu:24.04
|
||||
os: ubuntu-latest
|
||||
install: clang-16 libc++-16-dev libc++abi-16-dev
|
||||
- toolset: clang
|
||||
compiler: clang++-17
|
||||
cxxstd: "11,14,17,20,2b"
|
||||
stdlib: "native,libc++"
|
||||
container: ubuntu:24.04
|
||||
os: ubuntu-latest
|
||||
install: clang-17 libc++-17-dev libc++abi-17-dev
|
||||
- toolset: clang
|
||||
compiler: clang++-18
|
||||
cxxstd: "11,14,17,20,2b"
|
||||
stdlib: "native,libc++"
|
||||
container: ubuntu:24.04
|
||||
os: ubuntu-latest
|
||||
install: clang-18 libc++-18-dev libc++abi-18-dev
|
||||
- toolset: clang
|
||||
compiler: clang++-19
|
||||
cxxstd: "11,14,17,20,2b"
|
||||
stdlib: "native,libc++"
|
||||
container: ubuntu:24.04
|
||||
os: ubuntu-latest
|
||||
install: clang-19 libc++-19-dev libc++abi-19-dev
|
||||
- toolset: clang
|
||||
compiler: clang++-20
|
||||
cxxstd: "11,14,17,20,23,2c"
|
||||
stdlib: "native,libc++"
|
||||
container: ubuntu:24.04
|
||||
os: ubuntu-latest
|
||||
install: clang-20 libc++-20-dev libc++abi-20-dev
|
||||
- toolset: clang
|
||||
compiler: clang++-21
|
||||
cxxstd: "11,14,17,20,23,2c"
|
||||
stdlib: "native,libc++"
|
||||
container: ubuntu:25.10
|
||||
os: ubuntu-latest
|
||||
install: clang-21 libc++-21-dev libc++abi-21-dev
|
||||
- toolset: clang
|
||||
cxxstd: "11,14,17,20,2b"
|
||||
os: macos-14
|
||||
- toolset: clang
|
||||
cxxstd: "11,14,17,20,2b"
|
||||
os: macos-15
|
||||
- toolset: clang
|
||||
cxxstd: "11,14,17,20,23,2c"
|
||||
os: macos-26
|
||||
|
||||
runs-on: ${{matrix.os}}
|
||||
|
||||
container:
|
||||
image: ${{matrix.container}}
|
||||
volumes:
|
||||
- /node20217:/node20217:rw,rshared
|
||||
- ${{ startsWith(matrix.container, 'ubuntu:1') && '/node20217:/__e/node20:ro,rshared' || ' ' }}
|
||||
|
||||
defaults:
|
||||
run:
|
||||
shell: bash
|
||||
|
||||
steps:
|
||||
- name: Setup container environment
|
||||
if: matrix.container
|
||||
run: |
|
||||
apt-get update
|
||||
apt-get -y install sudo python3 git g++ curl xz-utils
|
||||
|
||||
- name: Install nodejs20glibc2.17
|
||||
if: ${{ startsWith( matrix.container, 'ubuntu:1' ) }}
|
||||
run: |
|
||||
curl -LO https://archives.boost.io/misc/node/node-v20.9.0-linux-x64-glibc-217.tar.xz
|
||||
tar -xf node-v20.9.0-linux-x64-glibc-217.tar.xz --strip-components 1 -C /node20217
|
||||
ldd /__e/node20/bin/node
|
||||
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- name: Install packages
|
||||
if: matrix.install
|
||||
run: |
|
||||
sudo apt-get update
|
||||
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
|
||||
python3 tools/boostdep/depinst/depinst.py --git_args "--jobs 3" $LIBRARY
|
||||
./bootstrap.sh
|
||||
./b2 -d0 headers
|
||||
|
||||
- name: Create user-config.jam
|
||||
if: matrix.compiler
|
||||
run: |
|
||||
echo "using ${{matrix.toolset}} : : ${{matrix.compiler}} ;" > ~/user-config.jam
|
||||
|
||||
- name: Run tests
|
||||
run: |
|
||||
cd ../boost-root
|
||||
./b2 -j3 libs/$LIBRARY/test toolset=${{matrix.toolset}} cxxstd=${{matrix.cxxstd}} variant=debug,release ${{ matrix.stdlib && format('stdlib={0}', matrix.stdlib) }}
|
||||
|
||||
windows:
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
include:
|
||||
- toolset: msvc-14.3
|
||||
cxxstd: "14,17,20,latest"
|
||||
addrmd: 32,64
|
||||
os: windows-2022
|
||||
- toolset: clang-win
|
||||
cxxstd: "14,17,20,latest"
|
||||
addrmd: 32,64
|
||||
os: windows-2022
|
||||
- toolset: gcc
|
||||
cxxstd: "11,14,17,2a"
|
||||
addrmd: 64
|
||||
os: windows-2022
|
||||
|
||||
runs-on: ${{matrix.os}}
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- name: Setup Boost
|
||||
shell: cmd
|
||||
run: |
|
||||
echo GITHUB_REPOSITORY: %GITHUB_REPOSITORY%
|
||||
for /f %%i in ("%GITHUB_REPOSITORY%") do set LIBRARY=%%~nxi
|
||||
echo LIBRARY: %LIBRARY%
|
||||
echo LIBRARY=%LIBRARY%>>%GITHUB_ENV%
|
||||
echo GITHUB_BASE_REF: %GITHUB_BASE_REF%
|
||||
echo GITHUB_REF: %GITHUB_REF%
|
||||
if "%GITHUB_BASE_REF%" == "" set GITHUB_BASE_REF=%GITHUB_REF%
|
||||
set BOOST_BRANCH=develop
|
||||
for /f %%i in ("%GITHUB_BASE_REF%") do if "%%~nxi" == "master" set BOOST_BRANCH=master
|
||||
echo BOOST_BRANCH: %BOOST_BRANCH%
|
||||
cd ..
|
||||
git clone -b %BOOST_BRANCH% --depth 1 https://github.com/boostorg/boost.git boost-root
|
||||
cd boost-root
|
||||
xcopy /s /e /q %GITHUB_WORKSPACE% libs\%LIBRARY%\
|
||||
git submodule update --init tools/boostdep
|
||||
python tools/boostdep/depinst/depinst.py --git_args "--jobs 3" %LIBRARY%
|
||||
cmd /c bootstrap
|
||||
b2 -d0 headers
|
||||
|
||||
- name: Run tests
|
||||
shell: cmd
|
||||
run: |
|
||||
cd ../boost-root
|
||||
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-latest
|
||||
- os: macos-latest
|
||||
|
||||
runs-on: ${{matrix.os}}
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- 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-latest
|
||||
- os: macos-latest
|
||||
|
||||
runs-on: ${{matrix.os}}
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- 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-latest
|
||||
- os: macos-latest
|
||||
|
||||
runs-on: ${{matrix.os}}
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- 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-latest
|
||||
|
||||
runs-on: ${{matrix.os}}
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- 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-latest
|
||||
|
||||
runs-on: ${{matrix.os}}
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- 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-latest
|
||||
|
||||
runs-on: ${{matrix.os}}
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- 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
|
||||
327
.travis.yml
327
.travis.yml
@@ -4,8 +4,6 @@
|
||||
|
||||
language: cpp
|
||||
|
||||
sudo: false
|
||||
|
||||
dist: xenial
|
||||
|
||||
branches:
|
||||
@@ -26,7 +24,26 @@ matrix:
|
||||
include:
|
||||
- os: linux
|
||||
compiler: g++
|
||||
env: TOOLSET=gcc COMPILER=g++ CXXSTD=03,11
|
||||
env: TOOLSET=gcc COMPILER=g++ CXXSTD=03,11,14 ADDRMD=32,64
|
||||
addons:
|
||||
apt:
|
||||
packages:
|
||||
- g++-multilib
|
||||
|
||||
- os: linux
|
||||
arch: arm64
|
||||
compiler: g++
|
||||
env: TOOLSET=gcc COMPILER=g++ CXXSTD=03,11,14 ADDRMD=32,64
|
||||
|
||||
- os: linux
|
||||
arch: ppc64le
|
||||
compiler: g++
|
||||
env: TOOLSET=gcc COMPILER=g++ CXXSTD=03,11,14
|
||||
|
||||
- os: linux
|
||||
arch: s390x
|
||||
compiler: g++
|
||||
env: TOOLSET=gcc COMPILER=g++ CXXSTD=03,11,14 ADDRMD=32,64
|
||||
|
||||
- os: linux
|
||||
compiler: g++-4.4
|
||||
@@ -49,108 +66,20 @@ matrix:
|
||||
- ubuntu-toolchain-r-test
|
||||
|
||||
- os: linux
|
||||
compiler: g++-4.7
|
||||
env: TOOLSET=gcc COMPILER=g++-4.7 CXXSTD=03,11
|
||||
addons:
|
||||
apt:
|
||||
packages:
|
||||
- g++-4.7
|
||||
sources:
|
||||
- ubuntu-toolchain-r-test
|
||||
|
||||
- os: linux
|
||||
compiler: g++-4.8
|
||||
env: TOOLSET=gcc COMPILER=g++-4.8 CXXSTD=03,11
|
||||
addons:
|
||||
apt:
|
||||
packages:
|
||||
- g++-4.8
|
||||
sources:
|
||||
- ubuntu-toolchain-r-test
|
||||
- os: linux
|
||||
compiler: g++-4.9
|
||||
env: TOOLSET=gcc COMPILER=g++-4.9 CXXSTD=03,11
|
||||
addons:
|
||||
apt:
|
||||
packages:
|
||||
- g++-4.9
|
||||
sources:
|
||||
- ubuntu-toolchain-r-test
|
||||
|
||||
- os: linux
|
||||
compiler: g++-5
|
||||
env: TOOLSET=gcc COMPILER=g++-5 CXXSTD=03,11,14,1z
|
||||
addons:
|
||||
apt:
|
||||
packages:
|
||||
- g++-5
|
||||
sources:
|
||||
- ubuntu-toolchain-r-test
|
||||
|
||||
- os: linux
|
||||
compiler: g++-6
|
||||
env: TOOLSET=gcc COMPILER=g++-6 CXXSTD=03,11,14,1z
|
||||
addons:
|
||||
apt:
|
||||
packages:
|
||||
- g++-6
|
||||
sources:
|
||||
- ubuntu-toolchain-r-test
|
||||
|
||||
- os: linux
|
||||
compiler: g++-7
|
||||
env: TOOLSET=gcc COMPILER=g++-7 CXXSTD=03,11,14,17
|
||||
addons:
|
||||
apt:
|
||||
packages:
|
||||
- g++-7
|
||||
sources:
|
||||
- ubuntu-toolchain-r-test
|
||||
|
||||
- os: linux
|
||||
compiler: g++-8
|
||||
env: TOOLSET=gcc COMPILER=g++-8 CXXSTD=03,11,14,17,2a
|
||||
addons:
|
||||
apt:
|
||||
packages:
|
||||
- g++-8
|
||||
sources:
|
||||
- ubuntu-toolchain-r-test
|
||||
|
||||
- os: linux
|
||||
compiler: g++-9
|
||||
env: TOOLSET=gcc COMPILER=g++-9 CXXSTD=03,11,14,17,2a
|
||||
addons:
|
||||
apt:
|
||||
packages:
|
||||
- g++-9
|
||||
sources:
|
||||
- ubuntu-toolchain-r-test
|
||||
dist: trusty
|
||||
compiler: g++
|
||||
env: TOOLSET=gcc COMPILER=g++ CXXSTD=03,11
|
||||
|
||||
- os: linux
|
||||
dist: bionic
|
||||
compiler: g++-10
|
||||
env: TOOLSET=gcc COMPILER=g++-10 CXXSTD=03,11,14,17,2a
|
||||
compiler: g++-11
|
||||
env: UBSAN=1 TOOLSET=gcc COMPILER=g++-11 CXXSTD=03,11,14,17,20 UBSAN_OPTIONS=print_stacktrace=1 LINKFLAGS=-fuse-ld=gold
|
||||
addons:
|
||||
apt:
|
||||
packages:
|
||||
- g++-10
|
||||
- g++-11
|
||||
sources:
|
||||
- ubuntu-toolchain-r-test
|
||||
|
||||
- os: linux
|
||||
compiler: g++-9
|
||||
env: UBSAN=1 TOOLSET=gcc COMPILER=g++-9 CXXSTD=03,11,14,17,2a UBSAN_OPTIONS=print_stacktrace=1 LINKFLAGS=-fuse-ld=gold
|
||||
addons:
|
||||
apt:
|
||||
packages:
|
||||
- g++-9
|
||||
sources:
|
||||
- ubuntu-toolchain-r-test
|
||||
|
||||
- os: linux
|
||||
compiler: clang++
|
||||
env: TOOLSET=clang COMPILER=clang++ CXXSTD=03,11
|
||||
- sourceline: "ppa:ubuntu-toolchain-r/test"
|
||||
|
||||
- os: linux
|
||||
dist: trusty
|
||||
@@ -171,189 +100,75 @@ matrix:
|
||||
- clang-3.4
|
||||
|
||||
- os: linux
|
||||
dist: trusty
|
||||
compiler: clang++-3.5
|
||||
env: TOOLSET=clang COMPILER=clang++-3.5 CXXSTD=03,11,14,1z
|
||||
compiler: clang++-12
|
||||
env: UBSAN=1 TOOLSET=clang COMPILER=clang++-12 CXXSTD=03,11,14,17,20 UBSAN_OPTIONS=print_stacktrace=1
|
||||
addons:
|
||||
apt:
|
||||
packages:
|
||||
- clang-3.5
|
||||
- clang-12
|
||||
sources:
|
||||
- ubuntu-toolchain-r-test
|
||||
|
||||
- os: linux
|
||||
compiler: clang++-3.6
|
||||
env: TOOLSET=clang COMPILER=clang++-3.6 CXXSTD=03,11,14,1z
|
||||
addons:
|
||||
apt:
|
||||
packages:
|
||||
- clang-3.6
|
||||
sources:
|
||||
- ubuntu-toolchain-r-test
|
||||
|
||||
- os: linux
|
||||
compiler: clang++-3.7
|
||||
env: TOOLSET=clang COMPILER=clang++-3.7 CXXSTD=03,11,14,1z
|
||||
addons:
|
||||
apt:
|
||||
packages:
|
||||
- clang-3.7
|
||||
sources:
|
||||
- ubuntu-toolchain-r-test
|
||||
|
||||
- os: linux
|
||||
compiler: clang++-3.8
|
||||
env: TOOLSET=clang COMPILER=clang++-3.8 CXXSTD=03,11,14,1z
|
||||
addons:
|
||||
apt:
|
||||
packages:
|
||||
- clang-3.8
|
||||
sources:
|
||||
- ubuntu-toolchain-r-test
|
||||
|
||||
- os: linux
|
||||
compiler: clang++-3.9
|
||||
env: TOOLSET=clang COMPILER=clang++-3.9 CXXSTD=03,11,14,1z
|
||||
addons:
|
||||
apt:
|
||||
packages:
|
||||
- clang-3.9
|
||||
sources:
|
||||
- ubuntu-toolchain-r-test
|
||||
|
||||
- os: linux
|
||||
compiler: clang++-4.0
|
||||
env: TOOLSET=clang COMPILER=clang++-4.0 CXXSTD=03,11,14,1z
|
||||
addons:
|
||||
apt:
|
||||
packages:
|
||||
- clang-4.0
|
||||
sources:
|
||||
- ubuntu-toolchain-r-test
|
||||
|
||||
- os: linux
|
||||
compiler: clang++-5.0
|
||||
env: TOOLSET=clang COMPILER=clang++-5.0 CXXSTD=03,11,14,1z
|
||||
addons:
|
||||
apt:
|
||||
packages:
|
||||
- clang-5.0
|
||||
sources:
|
||||
- ubuntu-toolchain-r-test
|
||||
|
||||
- os: linux
|
||||
compiler: clang++-6.0
|
||||
env: TOOLSET=clang COMPILER=clang++-6.0 CXXSTD=03,11,14,17
|
||||
addons:
|
||||
apt:
|
||||
packages:
|
||||
- clang-6.0
|
||||
sources:
|
||||
- ubuntu-toolchain-r-test
|
||||
|
||||
- os: linux
|
||||
compiler: clang++-7
|
||||
env: TOOLSET=clang COMPILER=clang++-7 CXXSTD=03,11,14,17,2a
|
||||
addons:
|
||||
apt:
|
||||
packages:
|
||||
- clang-7
|
||||
sources:
|
||||
- ubuntu-toolchain-r-test
|
||||
- llvm-toolchain-xenial-7
|
||||
|
||||
- os: linux
|
||||
compiler: clang++-8
|
||||
env: TOOLSET=clang COMPILER=clang++-8 CXXSTD=03,11,14,17,2a
|
||||
addons:
|
||||
apt:
|
||||
packages:
|
||||
- clang-8
|
||||
sources:
|
||||
- ubuntu-toolchain-r-test
|
||||
- llvm-toolchain-xenial-8
|
||||
|
||||
- os: linux
|
||||
compiler: clang++-9
|
||||
env: TOOLSET=clang COMPILER=clang++-9 CXXSTD=03,11,14,17,2a
|
||||
addons:
|
||||
apt:
|
||||
packages:
|
||||
- clang-9
|
||||
sources:
|
||||
- ubuntu-toolchain-r-test
|
||||
- sourceline: 'deb https://apt.llvm.org/xenial/ llvm-toolchain-xenial-9 main'
|
||||
- sourceline: 'deb https://apt.llvm.org/xenial/ llvm-toolchain-xenial-12 main'
|
||||
key_url: 'https://apt.llvm.org/llvm-snapshot.gpg.key'
|
||||
|
||||
- os: linux
|
||||
dist: xenial
|
||||
compiler: clang++-10
|
||||
env: TOOLSET=clang COMPILER=clang++-10 CXXSTD=03,11,14,17,2a
|
||||
addons:
|
||||
apt:
|
||||
packages:
|
||||
- clang-10
|
||||
sources:
|
||||
- ubuntu-toolchain-r-test
|
||||
- sourceline: 'deb https://apt.llvm.org/xenial/ llvm-toolchain-xenial-10 main'
|
||||
key_url: 'https://apt.llvm.org/llvm-snapshot.gpg.key'
|
||||
|
||||
- os: linux
|
||||
dist: xenial
|
||||
compiler: clang++-10
|
||||
env: UBSAN=1 TOOLSET=clang COMPILER=clang++-10 CXXSTD=03,11,14,17,2a UBSAN_OPTIONS=print_stacktrace=1
|
||||
addons:
|
||||
apt:
|
||||
packages:
|
||||
- clang-10
|
||||
sources:
|
||||
- ubuntu-toolchain-r-test
|
||||
- sourceline: 'deb https://apt.llvm.org/xenial/ llvm-toolchain-xenial-10 main'
|
||||
key_url: 'https://apt.llvm.org/llvm-snapshot.gpg.key'
|
||||
|
||||
- os: linux
|
||||
dist: trusty
|
||||
dist: bionic
|
||||
compiler: clang++-libc++
|
||||
env: TOOLSET=clang COMPILER=clang++-libc++ CXXSTD=03,11,14,1z
|
||||
env: UBSAN=1 TOOLSET=clang COMPILER=clang++-libc++ CXXSTD=03,11,14,17,2a UBSAN_OPTIONS=print_stacktrace=1
|
||||
addons:
|
||||
apt:
|
||||
packages:
|
||||
- libc++-dev
|
||||
|
||||
- os: linux
|
||||
dist: trusty
|
||||
compiler: clang++-libc++
|
||||
env: UBSAN=1 TOOLSET=clang COMPILER=clang++-libc++ CXXSTD=03,11,14,1z UBSAN_OPTIONS=print_stacktrace=1
|
||||
addons:
|
||||
apt:
|
||||
packages:
|
||||
- libc++-dev
|
||||
|
||||
- os: osx
|
||||
compiler: clang++
|
||||
env: TOOLSET=clang COMPILER=clang++ CXXSTD=03,11,14,1z
|
||||
|
||||
- os: osx
|
||||
compiler: clang++
|
||||
env: UBSAN=1 TOOLSET=clang COMPILER=clang++ CXXSTD=03,11,14,1z UBSAN_OPTIONS=print_stacktrace=1
|
||||
|
||||
- os: freebsd
|
||||
compiler: clang++
|
||||
env: TOOLSET=clang COMPILER=clang++ CXXSTD=03,11,14,17,2a
|
||||
|
||||
- os: osx
|
||||
compiler: clang++
|
||||
env: TOOLSET=clang COMPILER=clang++ CXXSTD=03,11,14,1z ADDRMD=32,64
|
||||
osx_image: xcode7.3
|
||||
|
||||
- os: osx
|
||||
compiler: clang++
|
||||
env: TOOLSET=clang COMPILER=clang++ CXXSTD=03,11,14,1z ADDRMD=32,64
|
||||
osx_image: xcode8.3
|
||||
|
||||
- os: osx
|
||||
compiler: clang++
|
||||
env: TOOLSET=clang COMPILER=clang++ CXXSTD=03,11,14,1z ADDRMD=32,64
|
||||
osx_image: xcode9.4
|
||||
|
||||
- os: osx
|
||||
compiler: clang++
|
||||
env: TOOLSET=clang COMPILER=clang++ CXXSTD=03,11,14,1z
|
||||
osx_image: xcode10.1
|
||||
|
||||
- os: osx
|
||||
osx_image: xcode11.3
|
||||
compiler: clang++
|
||||
env: TOOLSET=clang COMPILER=clang++ CXXSTD=03,11,14,1z
|
||||
|
||||
- os: osx
|
||||
osx_image: xcode12.2
|
||||
compiler: clang++
|
||||
env: UBSAN=1 TOOLSET=clang COMPILER=clang++ CXXSTD=03,11,14,1z UBSAN_OPTIONS=print_stacktrace=1
|
||||
|
||||
- os: linux
|
||||
env: CMAKE=1
|
||||
script:
|
||||
- mkdir __build__ && cd __build__
|
||||
- cmake -DBOOST_ENABLE_CMAKE=1 -DBoost_VERBOSE=1 -DBOOST_INCLUDE_LIBRARIES=system -DBUILD_TESTING=ON ..
|
||||
- ctest --output-on-failure -R boost_system
|
||||
- cmake -DBOOST_INCLUDE_LIBRARIES=system -DBUILD_TESTING=ON ..
|
||||
- cmake --build . --target tests
|
||||
- ctest --output-on-failure --no-tests=error
|
||||
|
||||
- os: linux
|
||||
env: CMAKE=1 BUILD_SHARED_LIBS=ON
|
||||
script:
|
||||
- mkdir __build__ && cd __build__
|
||||
- cmake -DBOOST_ENABLE_CMAKE=1 -DBoost_VERBOSE=1 -DBUILD_SHARED_LIBS=ON -DBOOST_INCLUDE_LIBRARIES=system -DBUILD_TESTING=ON ..
|
||||
- ctest --output-on-failure -R boost_system
|
||||
- cmake -DBUILD_SHARED_LIBS=ON -DBOOST_INCLUDE_LIBRARIES=system -DBUILD_TESTING=ON ..
|
||||
- cmake --build . --target tests
|
||||
- ctest --output-on-failure --no-tests=error
|
||||
|
||||
- os: linux
|
||||
env: CMAKE_SUBDIR_TEST=1
|
||||
@@ -375,7 +190,7 @@ matrix:
|
||||
script:
|
||||
- pip install --user cmake
|
||||
- mkdir __build__ && cd __build__
|
||||
- cmake -DBOOST_ENABLE_CMAKE=1 -DBoost_VERBOSE=1 -DBOOST_INCLUDE_LIBRARIES="system;core" -DBUILD_TESTING=OFF -DCMAKE_INSTALL_PREFIX=~/.local ..
|
||||
- cmake -DBOOST_INCLUDE_LIBRARIES=system -DCMAKE_INSTALL_PREFIX=~/.local ..
|
||||
- cmake --build . --target install
|
||||
- cd ../libs/system/test/cmake_install_test && mkdir __build__ && cd __build__
|
||||
- cmake -DCMAKE_INSTALL_PREFIX=~/.local ..
|
||||
@@ -396,7 +211,7 @@ install:
|
||||
script:
|
||||
- |-
|
||||
echo "using $TOOLSET : : $COMPILER ;" > ~/user-config.jam
|
||||
- ./b2 -j3 libs/system/test toolset=$TOOLSET cxxstd=$CXXSTD variant=debug,release ${UBSAN:+cxxflags=-fsanitize=undefined cxxflags=-fno-sanitize-recover=undefined linkflags=-fsanitize=undefined define=UBSAN=1 debug-symbols=on} ${LINKFLAGS:+linkflags=$LINKFLAGS}
|
||||
- ./b2 -j3 libs/system/test toolset=$TOOLSET cxxstd=$CXXSTD variant=debug,release ${ADDRMD:+address-model=$ADDRMD} ${UBSAN:+cxxflags=-fsanitize=undefined cxxflags=-fno-sanitize-recover=undefined linkflags=-fsanitize=undefined define=UBSAN=1 debug-symbols=on} ${LINKFLAGS:+linkflags=$LINKFLAGS}
|
||||
|
||||
notifications:
|
||||
email:
|
||||
|
||||
@@ -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
|
||||
# https://www.boost.org/LICENSE_1_0.txt
|
||||
|
||||
cmake_minimum_required(VERSION 3.5...3.16)
|
||||
cmake_minimum_required(VERSION 3.8...3.31)
|
||||
|
||||
project(boost_system VERSION "${BOOST_SUPERPROJECT_VERSION}" LANGUAGES CXX)
|
||||
|
||||
@@ -13,11 +13,26 @@ target_include_directories(boost_system INTERFACE include)
|
||||
|
||||
target_link_libraries(boost_system
|
||||
INTERFACE
|
||||
Boost::assert
|
||||
Boost::compat
|
||||
Boost::config
|
||||
Boost::throw_exception
|
||||
Boost::variant2
|
||||
Boost::winapi
|
||||
)
|
||||
|
||||
if(BUILD_TESTING)
|
||||
target_compile_features(boost_system INTERFACE cxx_std_11)
|
||||
|
||||
if(NOT CMAKE_VERSION VERSION_LESS 3.19 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 AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/test/CMakeLists.txt")
|
||||
|
||||
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).
|
||||
62
appveyor.yml
62
appveyor.yml
@@ -14,40 +14,27 @@ branches:
|
||||
|
||||
environment:
|
||||
matrix:
|
||||
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015
|
||||
TOOLSET: msvc-9.0,msvc-10.0,msvc-11.0
|
||||
ADDRMD: 32
|
||||
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015
|
||||
TOOLSET: msvc-12.0,msvc-14.0
|
||||
ADDRMD: 32,64
|
||||
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017
|
||||
TOOLSET: msvc-14.1
|
||||
CXXSTD: 14,17
|
||||
ADDRMD: 32,64
|
||||
CXXSTD: 14,17,latest
|
||||
ADDRMD: 32
|
||||
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017
|
||||
TOOLSET: clang-win
|
||||
CXXSTD: 14,17
|
||||
TOOLSET: msvc-14.1
|
||||
CXXSTD: 14,17,latest
|
||||
ADDRMD: 64
|
||||
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2019
|
||||
TOOLSET: msvc-14.2
|
||||
CXXSTD: 14,17
|
||||
ADDRMD: 32,64
|
||||
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015
|
||||
ADDPATH: C:\cygwin\bin;
|
||||
TOOLSET: gcc
|
||||
CXXSTD: 03,11,14,1z
|
||||
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015
|
||||
ADDPATH: C:\cygwin64\bin;
|
||||
TOOLSET: gcc
|
||||
CXXSTD: 03,11,14,1z
|
||||
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015
|
||||
ADDPATH: C:\mingw\bin;
|
||||
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2019
|
||||
ADDPATH: C:\mingw-w64\i686-8.1.0-posix-dwarf-rt_v6-rev0\mingw32\bin;
|
||||
TOOLSET: gcc
|
||||
CXXSTD: 03,11,14,1z
|
||||
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015
|
||||
ADDPATH: C:\mingw-w64\x86_64-6.3.0-posix-seh-rt_v5-rev1\mingw64\bin;
|
||||
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2019
|
||||
ADDPATH: C:\mingw-w64\x86_64-8.1.0-posix-seh-rt_v6-rev0\mingw64\bin;
|
||||
TOOLSET: gcc
|
||||
CXXSTD: 03,11,14,1z
|
||||
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015
|
||||
CMAKE_SUBDIR: 1
|
||||
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015
|
||||
CMAKE_INSTALL: 1
|
||||
|
||||
install:
|
||||
- set BOOST_BRANCH=develop
|
||||
@@ -67,4 +54,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
|
||||
- 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
|
||||
|
||||
24
build.jam
Normal file
24
build.jam
Normal file
@@ -0,0 +1,24 @@
|
||||
# Copyright 2023-2024 René Ferdinand Rivera Morell
|
||||
# Copyright 2024 Peter Dimov
|
||||
# Distributed under the Boost Software License, Version 1.0.
|
||||
# https://www.boost.org/LICENSE_1_0.txt
|
||||
|
||||
require-b2 5.2 ;
|
||||
|
||||
constant boost_dependencies :
|
||||
/boost/assert//boost_assert
|
||||
/boost/config//boost_config
|
||||
/boost/throw_exception//boost_throw_exception
|
||||
/boost/variant2//boost_variant2
|
||||
/boost/winapi//boost_winapi
|
||||
;
|
||||
|
||||
project /boost/system ;
|
||||
|
||||
explicit
|
||||
[ alias boost_system : : : : <include>include <library>$(boost_dependencies) ]
|
||||
[ alias all : boost_system test ]
|
||||
;
|
||||
|
||||
call-if : boost-library system
|
||||
;
|
||||
@@ -1,25 +0,0 @@
|
||||
# Boost System Library Build Jamfile
|
||||
|
||||
# (C) Copyright Beman Dawes 2002, 2006
|
||||
|
||||
# Distributed under the Boost Software License, Version 1.0.
|
||||
# (See accompanying file LICENSE_1_0.txt or www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
# See library home page at http://www.boost.org/libs/system
|
||||
|
||||
project boost/system
|
||||
: source-location ../src
|
||||
: usage-requirements # pass these requirement to dependents (i.e. users)
|
||||
<link>shared:<define>BOOST_SYSTEM_DYN_LINK=1
|
||||
<link>static:<define>BOOST_SYSTEM_STATIC_LINK=1
|
||||
;
|
||||
|
||||
SOURCES = error_code ;
|
||||
|
||||
lib boost_system
|
||||
: $(SOURCES).cpp
|
||||
: <link>shared:<define>BOOST_SYSTEM_DYN_LINK=1
|
||||
<link>static:<define>BOOST_SYSTEM_STATIC_LINK=1
|
||||
;
|
||||
|
||||
boost-install boost_system ;
|
||||
@@ -4,19 +4,22 @@ Copyright 2018 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
|
||||
https://www.boost.org/LICENSE_1_0.txt
|
||||
////
|
||||
|
||||
# Boost.System: Extensible Error Reporting
|
||||
Beman Dawes, Christopher Kohlhoff, Peter Dimov
|
||||
:toc: left
|
||||
:toclevels: 3
|
||||
: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,16 +1,107 @@
|
||||
////
|
||||
Copyright 2018 Peter Dimov
|
||||
|
||||
Copyright 2018-2025 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
|
||||
https://www.boost.org/LICENSE_1_0.txt
|
||||
////
|
||||
|
||||
[#changes]
|
||||
# Revision History
|
||||
:idprefix:
|
||||
|
||||
## Changes in Boost 1.91
|
||||
|
||||
* The return type of `operator|(result<T&>, U)` has been changed to non-reference.
|
||||
|
||||
## Changes in Boost 1.89
|
||||
|
||||
* The stub compiled library has been removed; System has been header-only since release 1.69.
|
||||
+
|
||||
This may affect `CMakeLists.txt` files containing `find_package(Boost COMPONENTS system ...)`.
|
||||
The easiest fix is to just remove `system` from the list of components as it's no longer required.
|
||||
If compatibility with Boost releases earlier than 1.69 is to be preserved, one can use
|
||||
`find_package(Boost COMPONENTS ... OPTIONAL_COMPONENTS system)`.
|
||||
|
||||
## Changes in Boost 1.86
|
||||
|
||||
* Support `result<T> & fv`, where `fv` returns `void`.
|
||||
* Support `result<void> &= fv;`, where `fv` returns `void`.
|
||||
|
||||
## Changes in Boost 1.85
|
||||
|
||||
* {cpp}03 is no longer supported; a {cpp}11 compiler is required. (This includes GCC 4.8 or later, and MSVC 14.0 (VS 2015) or later.)
|
||||
* The deprecated header `boost/system/cygwin_error.hpp` has been removed.
|
||||
* The original and obsolete (32 bit) MinGW is no longer supported. MinGW-w64 (both 64 and 32 bit) is still supported.
|
||||
* `operator&` now works for `result<void>` (by way of taking a nullary function.)
|
||||
* Added `operator|=` for `result`.
|
||||
|
||||
## Changes in Boost 1.84
|
||||
|
||||
* Added support for `result<U&, E>`.
|
||||
* Added `operator|` for `result`.
|
||||
* Added `operator&` for `result`.
|
||||
* Added `operator&=` for `result`.
|
||||
|
||||
## 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`, `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>`.
|
||||
|
||||
## Changes in Boost 1.77
|
||||
|
||||
* The conversion operator from `error_category` to `std::error_category`
|
||||
has been improved and no longer requires `<map>` or `<mutex>`.
|
||||
* The comparison operators of `error_category` are now inline friends
|
||||
instead of member functions (a side effect of the previous change.)
|
||||
* `error_condition` now defers calling `generic_category()` to avoid
|
||||
instantiating the object until it's actually needed.
|
||||
* `error_condition::failed` and `error_condition::message` have been
|
||||
undeprecated, and `operator bool()` now once again returns `failed()`.
|
||||
* The system category now doesn't call `generic_category()`, to avoid
|
||||
instantiating the object.
|
||||
* The return value of `default_error_condition` changes in some cases into
|
||||
an `error_condition` from the generic category, instead of from the system
|
||||
category. This happens on POSIX when the input `error_code` is from
|
||||
the system category and does not correspond to any `errc_t` value.
|
||||
* The interoperability of `error_code` and `std::error_code` has been
|
||||
improved substantially. It is now possible to construct
|
||||
`boost::system::error_code` from `std::error_code`, and it's possible
|
||||
to pass `boost::system::error_code` to functions taking `std::error_code&`.
|
||||
* A stream insertion operator for `error_condition` has been added.
|
||||
|
||||
## Changes in Boost 1.76
|
||||
|
||||
* `windows_error.hpp` is no longer deprecated.
|
||||
|
||||
## Changes in Boost 1.75
|
||||
|
||||
* The platform-specific headers `windows_error.hpp`, `linux_error.hpp`,
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
////
|
||||
Copyright 2018 Peter Dimov
|
||||
Copyright 2018-2021 Peter Dimov
|
||||
|
||||
Distributed under the Boost Software License, Version 1.0.
|
||||
|
||||
@@ -14,6 +14,6 @@ http://www.boost.org/LICENSE_1_0.txt
|
||||
This documentation is
|
||||
|
||||
* Copyright 2003-2017 Beman Dawes
|
||||
* Copyright 2018 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`.
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
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._Num==1">{((std::error_code*)d2_)->_Myval} [std:future]</DisplayString>
|
||||
<DisplayString Condition="lc_flags_ == 1 && ((std::error_code*)d2_)->_Mycat->_Addr._Num==3">{((std::error_code*)d2_)->_Myval} [std:generic]</DisplayString>
|
||||
<DisplayString Condition="lc_flags_ == 1 && ((std::error_code*)d2_)->_Mycat->_Addr._Num==5">{((std::error_code*)d2_)->_Myval} [std:iostream]</DisplayString>
|
||||
<DisplayString Condition="lc_flags_ == 1 && ((std::error_code*)d2_)->_Mycat->_Addr._Num==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>
|
||||
14
include/boost/system.hpp
Normal file
14
include/boost/system.hpp
Normal file
@@ -0,0 +1,14 @@
|
||||
#ifndef BOOST_SYSTEM_HPP_INCLUDED
|
||||
#define BOOST_SYSTEM_HPP_INCLUDED
|
||||
|
||||
// Copyright 2021 Peter Dimov
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// https://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
// See library home page at http://www.boost.org/libs/system
|
||||
|
||||
#include <boost/system/error_code.hpp>
|
||||
#include <boost/system/system_error.hpp>
|
||||
#include <boost/system/result.hpp>
|
||||
|
||||
#endif // #ifndef BOOST_SYSTEM_HPP_INCLUDED
|
||||
@@ -1,63 +0,0 @@
|
||||
// boost/system/cygwin_error.hpp -------------------------------------------//
|
||||
|
||||
// Copyright Beman Dawes 2007
|
||||
|
||||
// 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
|
||||
|
||||
#ifndef BOOST_SYSTEM_CYGWIN_ERROR_HPP
|
||||
#define BOOST_SYSTEM_CYGWIN_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.
|
||||
|
||||
# ifdef __CYGWIN__
|
||||
|
||||
#include <boost/system/error_code.hpp>
|
||||
|
||||
namespace boost
|
||||
{
|
||||
namespace system
|
||||
{
|
||||
// To construct an error_code after a API error:
|
||||
//
|
||||
// error_code( errno, system_category() )
|
||||
|
||||
// User code should use the portable "posix" enums for POSIX errors; this
|
||||
// allows such code to be portable to non-POSIX systems. For the non-POSIX
|
||||
// errno values that POSIX-based systems typically provide in addition to
|
||||
// POSIX values, use the system specific enums below.
|
||||
|
||||
namespace cygwin_error
|
||||
{
|
||||
enum cygwin_errno
|
||||
{
|
||||
no_net = ENONET,
|
||||
no_package = ENOPKG,
|
||||
no_share = ENOSHARE
|
||||
};
|
||||
} // namespace cygwin_error
|
||||
|
||||
template<> struct is_error_code_enum<cygwin_error::cygwin_errno>
|
||||
{ static const bool value = true; };
|
||||
|
||||
namespace cygwin_error
|
||||
{
|
||||
inline error_code make_error_code( cygwin_errno e )
|
||||
{ return error_code( e, system_category() ); }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif // __CYGWIN__
|
||||
|
||||
#endif // BOOST_SYSTEM_CYGWIN_ERROR_HPP
|
||||
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,7 +1,7 @@
|
||||
#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)
|
||||
@@ -11,26 +11,16 @@
|
||||
#include <boost/config.hpp>
|
||||
#include <boost/config/workaround.hpp>
|
||||
|
||||
// BOOST_SYSTEM_HAS_SYSTEM_ERROR
|
||||
|
||||
#if !defined(BOOST_NO_CXX11_HDR_SYSTEM_ERROR)
|
||||
# define BOOST_SYSTEM_HAS_SYSTEM_ERROR
|
||||
#endif
|
||||
|
||||
#if BOOST_WORKAROUND(BOOST_GCC, < 40600)
|
||||
// g++ 4.4's <map> is not good enough
|
||||
# undef BOOST_SYSTEM_HAS_SYSTEM_ERROR
|
||||
#endif
|
||||
|
||||
#if defined(BOOST_NO_CXX11_HDR_MUTEX)
|
||||
// Required for thread-safe map manipulation
|
||||
# undef BOOST_SYSTEM_HAS_SYSTEM_ERROR
|
||||
#endif
|
||||
// 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
|
||||
|
||||
// BOOST_SYSTEM_NOEXCEPT
|
||||
// Retained for backward compatibility
|
||||
|
||||
#define BOOST_SYSTEM_NOEXCEPT BOOST_NOEXCEPT
|
||||
#define BOOST_SYSTEM_NOEXCEPT noexcept
|
||||
|
||||
// BOOST_SYSTEM_HAS_CONSTEXPR
|
||||
|
||||
@@ -60,6 +50,34 @@
|
||||
# endif
|
||||
#elif defined(_MSC_VER)
|
||||
# define BOOST_SYSTEM_DEPRECATED(msg) __declspec(deprecated(msg))
|
||||
#elif defined(__sun)
|
||||
# define BOOST_SYSTEM_DEPRECATED(msg) __attribute__((deprecated(msg)))
|
||||
#else
|
||||
# define BOOST_SYSTEM_DEPRECATED(msg)
|
||||
#endif
|
||||
|
||||
// BOOST_SYSTEM_CLANG_6
|
||||
|
||||
// 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
|
||||
|
||||
@@ -5,28 +5,19 @@
|
||||
// Distributed under the Boost Software License, Version 1.0
|
||||
// http://www.boost.org/LICENSE_1_0.txt
|
||||
|
||||
#include <type_traits>
|
||||
|
||||
namespace boost
|
||||
{
|
||||
|
||||
namespace system
|
||||
{
|
||||
|
||||
namespace detail
|
||||
{
|
||||
|
||||
template<bool C, class T = void> struct enable_if
|
||||
{
|
||||
typedef T type;
|
||||
};
|
||||
|
||||
template<class T> struct enable_if<false, T>
|
||||
{
|
||||
};
|
||||
using std::enable_if;
|
||||
|
||||
} // namespace detail
|
||||
|
||||
} // namespace system
|
||||
|
||||
} // namespace boost
|
||||
|
||||
#endif // #ifndef BOOST_SYSTEM_DETAIL_ENABLE_IF_HPP_INCLUDED
|
||||
|
||||
@@ -13,13 +13,12 @@
|
||||
#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>
|
||||
|
||||
#if defined(BOOST_SYSTEM_HAS_SYSTEM_ERROR)
|
||||
# include <system_error>
|
||||
#endif
|
||||
#include <system_error>
|
||||
#include <atomic>
|
||||
|
||||
namespace boost
|
||||
{
|
||||
@@ -38,11 +37,7 @@ namespace detail
|
||||
|
||||
BOOST_SYSTEM_CONSTEXPR bool failed_impl( int ev, error_category const & cat );
|
||||
|
||||
#if defined(BOOST_SYSTEM_HAS_SYSTEM_ERROR)
|
||||
|
||||
std::error_category const & to_std_category( error_category const & cat );
|
||||
|
||||
#endif
|
||||
class std_category;
|
||||
|
||||
} // namespace detail
|
||||
|
||||
@@ -51,6 +46,11 @@ std::error_category const & to_std_category( error_category const & cat );
|
||||
#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:
|
||||
@@ -58,87 +58,74 @@ 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 );
|
||||
|
||||
#if defined(BOOST_SYSTEM_HAS_SYSTEM_ERROR)
|
||||
friend std::error_category const & detail::to_std_category( error_category const & cat );
|
||||
#endif
|
||||
friend class error_code;
|
||||
friend class error_condition;
|
||||
|
||||
#if !defined(BOOST_NO_CXX11_DELETED_FUNCTIONS)
|
||||
public:
|
||||
|
||||
error_category( error_category const & ) = delete;
|
||||
error_category& operator=( error_category const & ) = delete;
|
||||
|
||||
#else
|
||||
private:
|
||||
|
||||
error_category( error_category const & );
|
||||
error_category& operator=( error_category const & );
|
||||
|
||||
#endif
|
||||
|
||||
private:
|
||||
|
||||
boost::ulong_long_type id_;
|
||||
|
||||
protected:
|
||||
static std::size_t const stdcat_size_ = 4 * sizeof( void const* );
|
||||
|
||||
#if !defined(BOOST_NO_CXX11_DEFAULTED_FUNCTIONS) && !defined(BOOST_NO_CXX11_NON_PUBLIC_DEFAULTED_FUNCTIONS)
|
||||
union
|
||||
{
|
||||
mutable unsigned char stdcat_[ stdcat_size_ ];
|
||||
void const* stdcat_align_;
|
||||
};
|
||||
|
||||
mutable std::atomic< unsigned > sc_init_;
|
||||
|
||||
protected:
|
||||
|
||||
~error_category() = default;
|
||||
|
||||
#else
|
||||
|
||||
// We'd like to make the destructor protected, to make code that deletes
|
||||
// an error_category* not compile; unfortunately, doing the below makes
|
||||
// the destructor user-provided and hence breaks use after main, as the
|
||||
// categories may get destroyed before code that uses them
|
||||
|
||||
// ~error_category() {}
|
||||
|
||||
#endif
|
||||
|
||||
BOOST_SYSTEM_CONSTEXPR error_category() BOOST_NOEXCEPT: id_( 0 )
|
||||
constexpr error_category() noexcept: id_( 0 ), stdcat_(), sc_init_()
|
||||
{
|
||||
}
|
||||
|
||||
explicit BOOST_SYSTEM_CONSTEXPR error_category( boost::ulong_long_type id ) BOOST_NOEXCEPT: id_( id )
|
||||
explicit constexpr error_category( boost::ulong_long_type id ) noexcept: id_( id ), stdcat_(), sc_init_()
|
||||
{
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
virtual const char * name() const BOOST_NOEXCEPT = 0;
|
||||
virtual const char * name() const noexcept = 0;
|
||||
|
||||
virtual error_condition default_error_condition( int ev ) const BOOST_NOEXCEPT;
|
||||
virtual bool equivalent( int code, const error_condition & condition ) const BOOST_NOEXCEPT;
|
||||
virtual bool equivalent( const error_code & code, int condition ) const BOOST_NOEXCEPT;
|
||||
virtual error_condition default_error_condition( int ev ) const noexcept;
|
||||
virtual bool equivalent( int code, const error_condition & condition ) const noexcept;
|
||||
virtual bool equivalent( const error_code & code, int condition ) const noexcept;
|
||||
|
||||
virtual std::string message( int ev ) const = 0;
|
||||
virtual char const * message( int ev, char * buffer, std::size_t len ) const BOOST_NOEXCEPT;
|
||||
virtual char const * message( int ev, char * buffer, std::size_t len ) const noexcept;
|
||||
|
||||
virtual bool failed( int ev ) const BOOST_NOEXCEPT
|
||||
virtual bool failed( int ev ) const noexcept
|
||||
{
|
||||
return ev != 0;
|
||||
}
|
||||
|
||||
BOOST_SYSTEM_CONSTEXPR bool operator==( const error_category & rhs ) const BOOST_NOEXCEPT
|
||||
friend BOOST_SYSTEM_CONSTEXPR bool operator==( error_category const & lhs, error_category const & rhs ) noexcept
|
||||
{
|
||||
return rhs.id_ == 0? this == &rhs: id_ == rhs.id_;
|
||||
return rhs.id_ == 0? &lhs == &rhs: lhs.id_ == rhs.id_;
|
||||
}
|
||||
|
||||
BOOST_SYSTEM_CONSTEXPR bool operator!=( const error_category & rhs ) const BOOST_NOEXCEPT
|
||||
friend BOOST_SYSTEM_CONSTEXPR bool operator!=( error_category const & lhs, error_category const & rhs ) noexcept
|
||||
{
|
||||
return !( *this == rhs );
|
||||
return !( lhs == rhs );
|
||||
}
|
||||
|
||||
BOOST_SYSTEM_CONSTEXPR bool operator<( const error_category & rhs ) const BOOST_NOEXCEPT
|
||||
friend BOOST_SYSTEM_CONSTEXPR bool operator<( error_category const & lhs, error_category const & rhs ) noexcept
|
||||
{
|
||||
if( id_ < rhs.id_ )
|
||||
if( lhs.id_ < rhs.id_ )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if( id_ > rhs.id_ )
|
||||
if( lhs.id_ > rhs.id_ )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@@ -148,16 +135,22 @@ public:
|
||||
return false; // equal
|
||||
}
|
||||
|
||||
return std::less<error_category const *>()( this, &rhs );
|
||||
return std::less<error_category const *>()( &lhs, &rhs );
|
||||
}
|
||||
|
||||
#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;
|
||||
|
||||
#endif
|
||||
# else
|
||||
operator std::error_category const & () const BOOST_SYMBOL_VISIBLE;
|
||||
# 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
|
||||
@@ -165,8 +158,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 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 )
|
||||
{
|
||||
|
||||
@@ -13,34 +13,35 @@
|
||||
#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/snprintf.hpp>
|
||||
#include <boost/system/detail/config.hpp>
|
||||
#include <boost/config.hpp>
|
||||
#include <string>
|
||||
#include <cstring>
|
||||
|
||||
namespace boost
|
||||
{
|
||||
|
||||
namespace system
|
||||
{
|
||||
|
||||
// error_category default implementation
|
||||
|
||||
inline error_condition error_category::default_error_condition( int ev ) const BOOST_NOEXCEPT
|
||||
inline error_condition error_category::default_error_condition( int ev ) const noexcept
|
||||
{
|
||||
return error_condition( ev, *this );
|
||||
}
|
||||
|
||||
inline bool error_category::equivalent( int code, const error_condition & condition ) const BOOST_NOEXCEPT
|
||||
inline bool error_category::equivalent( int code, const error_condition & condition ) const noexcept
|
||||
{
|
||||
return default_error_condition( code ) == condition;
|
||||
}
|
||||
|
||||
inline bool error_category::equivalent( const error_code & code, int condition ) const BOOST_NOEXCEPT
|
||||
inline bool error_category::equivalent( const error_code & code, int condition ) const 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
|
||||
inline char const * error_category::message( int ev, char * buffer, std::size_t len ) const noexcept
|
||||
{
|
||||
if( len == 0 )
|
||||
{
|
||||
@@ -57,52 +58,109 @@ inline char const * error_category::message( int ev, char * buffer, std::size_t
|
||||
try
|
||||
#endif
|
||||
{
|
||||
std::string m = this->message( ev );
|
||||
|
||||
# if defined( BOOST_MSVC )
|
||||
# pragma warning( push )
|
||||
# pragma warning( disable: 4996 )
|
||||
# elif defined(__clang__) && defined(__has_warning)
|
||||
# pragma clang diagnostic push
|
||||
# if __has_warning("-Wdeprecated-declarations")
|
||||
# pragma clang diagnostic ignored "-Wdeprecated-declarations"
|
||||
# endif
|
||||
# endif
|
||||
|
||||
std::strncpy( buffer, m.c_str(), len - 1 );
|
||||
buffer[ len-1 ] = 0;
|
||||
|
||||
# if defined( BOOST_MSVC )
|
||||
# pragma warning( pop )
|
||||
# elif defined(__clang__) && defined(__has_warning)
|
||||
# pragma clang diagnostic pop
|
||||
# endif
|
||||
|
||||
detail::snprintf( buffer, len, "%s", this->message( ev ).c_str() );
|
||||
return buffer;
|
||||
}
|
||||
#if !defined(BOOST_NO_EXCEPTIONS)
|
||||
catch( ... )
|
||||
{
|
||||
return "Message text unavailable";
|
||||
detail::snprintf( buffer, len, "No message text available for error %d", ev );
|
||||
return buffer;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
} // 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_impl.hpp>
|
||||
#include <boost/system/detail/mutex.hpp>
|
||||
#include <new>
|
||||
|
||||
#include <boost/system/detail/to_std_category.hpp>
|
||||
|
||||
inline boost::system::error_category::operator std::error_category const & () const
|
||||
namespace boost
|
||||
{
|
||||
return boost::system::detail::to_std_category( *this );
|
||||
namespace system
|
||||
{
|
||||
|
||||
inline void error_category::init_stdcat() const
|
||||
{
|
||||
static_assert( sizeof( stdcat_ ) >= sizeof( boost::system::detail::std_category ), "sizeof(stdcat_) is not enough for std_category" );
|
||||
|
||||
#if defined(BOOST_MSVC) && BOOST_MSVC < 1900
|
||||
// no alignof
|
||||
#else
|
||||
|
||||
static_assert( alignof( decltype(stdcat_align_) ) >= alignof( boost::system::detail::std_category ), "alignof(stdcat_) is not enough for std_category" );
|
||||
|
||||
#endif
|
||||
|
||||
// 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 )
|
||||
{
|
||||
::new( static_cast<void*>( stdcat_ ) ) boost::system::detail::std_category( this, system::detail::id_wrapper<0>() );
|
||||
sc_init_.store( 1, std::memory_order_release );
|
||||
}
|
||||
}
|
||||
|
||||
#endif // #if defined(BOOST_SYSTEM_HAS_SYSTEM_ERROR)
|
||||
#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 // #ifndef BOOST_SYSTEM_DETAIL_ERROR_CATEGORY_IMPL_HPP_INCLUDED
|
||||
|
||||
@@ -3,22 +3,38 @@
|
||||
|
||||
// Copyright Beman Dawes 2006, 2007
|
||||
// Copyright Christoper Kohlhoff 2007
|
||||
// Copyright Peter Dimov 2017, 2018
|
||||
// Copyright Peter Dimov 2017-2021
|
||||
//
|
||||
// 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/is_error_code_enum.hpp>
|
||||
#include <boost/system/detail/error_category.hpp>
|
||||
#include <boost/system/detail/error_condition.hpp>
|
||||
#include <boost/system/detail/system_category.hpp>
|
||||
#include <boost/system/detail/system_category_impl.hpp>
|
||||
#include <boost/system/detail/interop_category.hpp>
|
||||
#include <boost/system/detail/enable_if.hpp>
|
||||
#include <boost/system/is_error_code_enum.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>
|
||||
#include <boost/system/detail/std_category.hpp>
|
||||
#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>
|
||||
#include <system_error>
|
||||
|
||||
#if defined(BOOST_GCC) && BOOST_GCC >= 40600 && BOOST_GCC < 70000
|
||||
# pragma GCC diagnostic push
|
||||
# pragma GCC diagnostic ignored "-Wstrict-aliasing"
|
||||
#endif
|
||||
|
||||
namespace boost
|
||||
{
|
||||
@@ -35,154 +51,578 @@ 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 ) noexcept;
|
||||
std::size_t hash_value( error_code const & ec );
|
||||
|
||||
class error_code
|
||||
{
|
||||
private:
|
||||
|
||||
int val_;
|
||||
bool failed_;
|
||||
const error_category * cat_;
|
||||
friend bool operator==( const error_code & code, const error_condition & condition ) noexcept;
|
||||
friend std::size_t hash_value( error_code const & ec );
|
||||
|
||||
private:
|
||||
|
||||
struct data
|
||||
{
|
||||
int val_;
|
||||
const error_category * cat_;
|
||||
};
|
||||
|
||||
union
|
||||
{
|
||||
data d1_;
|
||||
unsigned char d2_[ sizeof(std::error_code) ];
|
||||
};
|
||||
|
||||
// 0: default constructed, d1_ value initialized
|
||||
// 1: holds std::error_code in d2_
|
||||
// 2: holds error code in d1_, failed == false
|
||||
// 3: holds error code in d1_, failed == true
|
||||
// >3: pointer to source_location, failed_ in lsb
|
||||
boost::uintptr_t lc_flags_;
|
||||
|
||||
private:
|
||||
|
||||
char const* category_name() const 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:
|
||||
val_( 0 ), failed_( false ), cat_( &system_category() )
|
||||
constexpr error_code() noexcept:
|
||||
d1_(), lc_flags_( 0 )
|
||||
{
|
||||
}
|
||||
|
||||
BOOST_SYSTEM_CONSTEXPR error_code( int val, const error_category & cat ) BOOST_NOEXCEPT:
|
||||
val_( val ), failed_( detail::failed_impl( val, cat ) ), cat_( &cat )
|
||||
BOOST_SYSTEM_CONSTEXPR error_code( int val, const error_category & cat ) noexcept:
|
||||
d1_(), lc_flags_( 2 + detail::failed_impl( val, cat ) )
|
||||
{
|
||||
d1_.val_ = val;
|
||||
d1_.cat_ = &cat;
|
||||
}
|
||||
|
||||
error_code( int val, const error_category & cat, source_location const * loc ) noexcept:
|
||||
d1_(), lc_flags_( ( loc? reinterpret_cast<boost::uintptr_t>( loc ): 2 ) | +detail::failed_impl( val, cat ) )
|
||||
{
|
||||
d1_.val_ = val;
|
||||
d1_.cat_ = &cat;
|
||||
}
|
||||
|
||||
template<class ErrorCodeEnum> BOOST_SYSTEM_CONSTEXPR error_code( ErrorCodeEnum e,
|
||||
typename detail::enable_if<is_error_code_enum<ErrorCodeEnum>::value>::type* = 0 ) BOOST_NOEXCEPT
|
||||
typename detail::enable_if<
|
||||
is_error_code_enum<ErrorCodeEnum>::value
|
||||
|| std::is_error_code_enum<ErrorCodeEnum>::value
|
||||
>::type* = 0 ) noexcept: d1_(), lc_flags_( 0 )
|
||||
{
|
||||
*this = make_error_code( e );
|
||||
}
|
||||
|
||||
error_code( error_code const& ec, source_location const * loc ) 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 );
|
||||
}
|
||||
}
|
||||
|
||||
error_code( std::error_code const& ec ) noexcept:
|
||||
d1_(), lc_flags_( 0 )
|
||||
{
|
||||
#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;
|
||||
}
|
||||
}
|
||||
|
||||
// modifiers:
|
||||
|
||||
BOOST_SYSTEM_CONSTEXPR void assign( int val, const error_category & cat ) BOOST_NOEXCEPT
|
||||
BOOST_SYSTEM_CONSTEXPR void assign( int val, const error_category & cat ) noexcept
|
||||
{
|
||||
val_ = val;
|
||||
failed_ = detail::failed_impl( val, cat );
|
||||
cat_ = &cat;
|
||||
*this = error_code( val, cat );
|
||||
}
|
||||
|
||||
void assign( int val, const error_category & cat, source_location const * loc ) noexcept
|
||||
{
|
||||
*this = error_code( val, cat, loc );
|
||||
}
|
||||
|
||||
void assign( error_code const& ec, source_location const * loc ) 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
|
||||
operator=( ErrorCodeEnum val ) noexcept
|
||||
{
|
||||
*this = make_error_code( val );
|
||||
return *this;
|
||||
}
|
||||
|
||||
BOOST_SYSTEM_CONSTEXPR void clear() BOOST_NOEXCEPT
|
||||
BOOST_SYSTEM_CONSTEXPR void clear() noexcept
|
||||
{
|
||||
val_ = 0;
|
||||
failed_ = false;
|
||||
cat_ = &system_category();
|
||||
*this = error_code();
|
||||
}
|
||||
|
||||
// observers:
|
||||
|
||||
BOOST_SYSTEM_CONSTEXPR int value() const BOOST_NOEXCEPT
|
||||
BOOST_SYSTEM_CONSTEXPR int value() const noexcept
|
||||
{
|
||||
return val_;
|
||||
if( lc_flags_ != 1 )
|
||||
{
|
||||
return d1_.val_;
|
||||
}
|
||||
else
|
||||
{
|
||||
std::error_code const& ec = *reinterpret_cast<std::error_code const*>( d2_ );
|
||||
|
||||
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 );
|
||||
}
|
||||
}
|
||||
|
||||
BOOST_SYSTEM_CONSTEXPR const error_category & category() const BOOST_NOEXCEPT
|
||||
BOOST_SYSTEM_CONSTEXPR const error_category & category() const noexcept
|
||||
{
|
||||
return *cat_;
|
||||
if( lc_flags_ == 0 )
|
||||
{
|
||||
return system_category();
|
||||
}
|
||||
else if( lc_flags_ == 1 )
|
||||
{
|
||||
return detail::interop_category();
|
||||
}
|
||||
else
|
||||
{
|
||||
return *d1_.cat_;
|
||||
}
|
||||
}
|
||||
|
||||
error_condition default_error_condition() const BOOST_NOEXCEPT
|
||||
// deprecated?
|
||||
error_condition default_error_condition() const noexcept
|
||||
{
|
||||
return cat_->default_error_condition( value() );
|
||||
return category().default_error_condition( value() );
|
||||
}
|
||||
|
||||
std::string message() const
|
||||
{
|
||||
return cat_->message( value() );
|
||||
if( lc_flags_ == 1 )
|
||||
{
|
||||
std::error_code const& ec = *reinterpret_cast<std::error_code const*>( d2_ );
|
||||
return ec.message();
|
||||
}
|
||||
else 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
|
||||
char const * message( char * buffer, std::size_t len ) const noexcept
|
||||
{
|
||||
return cat_->message( value(), buffer, len );
|
||||
}
|
||||
|
||||
BOOST_SYSTEM_CONSTEXPR bool failed() const BOOST_NOEXCEPT
|
||||
{
|
||||
return failed_;
|
||||
}
|
||||
|
||||
#if !defined(BOOST_NO_CXX11_EXPLICIT_CONVERSION_OPERATORS)
|
||||
|
||||
BOOST_SYSTEM_CONSTEXPR explicit operator bool() const BOOST_NOEXCEPT // true if error
|
||||
{
|
||||
return failed_;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
typedef void (*unspecified_bool_type)();
|
||||
static void unspecified_bool_true() {}
|
||||
|
||||
BOOST_SYSTEM_CONSTEXPR operator unspecified_bool_type() const BOOST_NOEXCEPT // true if error
|
||||
{
|
||||
return failed_? unspecified_bool_true: 0;
|
||||
}
|
||||
|
||||
BOOST_SYSTEM_CONSTEXPR bool operator!() const BOOST_NOEXCEPT // true if no error
|
||||
{
|
||||
return !failed_;
|
||||
}
|
||||
if( lc_flags_ == 1 )
|
||||
{
|
||||
std::error_code const& ec = *reinterpret_cast<std::error_code const*>( d2_ );
|
||||
|
||||
#if !defined(BOOST_NO_EXCEPTIONS)
|
||||
try
|
||||
#endif
|
||||
{
|
||||
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
|
||||
}
|
||||
else 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 noexcept
|
||||
{
|
||||
if( lc_flags_ & 1 )
|
||||
{
|
||||
if( lc_flags_ == 1 )
|
||||
{
|
||||
std::error_code const& ec = *reinterpret_cast<std::error_code const*>( d2_ );
|
||||
return ec.value() != 0;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
BOOST_SYSTEM_CONSTEXPR explicit operator bool() const noexcept // true if error
|
||||
{
|
||||
return failed();
|
||||
}
|
||||
|
||||
bool has_location() const noexcept
|
||||
{
|
||||
return lc_flags_ >= 4;
|
||||
}
|
||||
|
||||
source_location const & location() const noexcept
|
||||
{
|
||||
BOOST_STATIC_CONSTEXPR source_location loc;
|
||||
return lc_flags_ >= 4? *reinterpret_cast<source_location const*>( lc_flags_ &~ static_cast<boost::uintptr_t>( 1 ) ): loc;
|
||||
}
|
||||
|
||||
// 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 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.
|
||||
|
||||
BOOST_SYSTEM_CONSTEXPR inline friend bool operator==( const error_code & lhs, const error_code & rhs ) BOOST_NOEXCEPT
|
||||
BOOST_SYSTEM_CONSTEXPR inline friend bool operator==( const error_code & lhs, const error_code & rhs ) noexcept
|
||||
{
|
||||
return lhs.val_ == rhs.val_ && *lhs.cat_ == *rhs.cat_;
|
||||
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_ );
|
||||
|
||||
return e1 == e2;
|
||||
}
|
||||
else
|
||||
{
|
||||
return lhs.value() == rhs.value() && lhs.category() == rhs.category();
|
||||
}
|
||||
}
|
||||
|
||||
BOOST_SYSTEM_CONSTEXPR inline friend bool operator<( const error_code & lhs, const error_code & rhs ) BOOST_NOEXCEPT
|
||||
BOOST_SYSTEM_CONSTEXPR inline friend bool operator<( const error_code & lhs, const error_code & rhs ) noexcept
|
||||
{
|
||||
return *lhs.cat_ < *rhs.cat_ || ( *lhs.cat_ == *rhs.cat_ && lhs.val_ < rhs.val_ );
|
||||
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_ );
|
||||
|
||||
return e1 < e2;
|
||||
}
|
||||
else
|
||||
{
|
||||
return lhs.category() < rhs.category() || (lhs.category() == rhs.category() && lhs.value() < rhs.value());
|
||||
}
|
||||
}
|
||||
|
||||
#if defined(BOOST_SYSTEM_HAS_SYSTEM_ERROR)
|
||||
|
||||
operator std::error_code () const
|
||||
BOOST_SYSTEM_CONSTEXPR inline friend bool operator!=( const error_code & lhs, const error_code & rhs ) noexcept
|
||||
{
|
||||
return std::error_code( value(), category() );
|
||||
return !( lhs == rhs );
|
||||
}
|
||||
|
||||
inline friend bool operator==( std::error_code const & lhs, error_code const & rhs ) noexcept
|
||||
{
|
||||
return lhs == static_cast< std::error_code >( rhs );
|
||||
}
|
||||
|
||||
inline friend bool operator==( error_code const & lhs, std::error_code const & rhs ) noexcept
|
||||
{
|
||||
return static_cast< std::error_code >( lhs ) == rhs;
|
||||
}
|
||||
|
||||
inline friend bool operator!=( std::error_code const & lhs, error_code const & rhs ) noexcept
|
||||
{
|
||||
return !( lhs == rhs );
|
||||
}
|
||||
|
||||
inline friend bool operator!=( error_code const & lhs, std::error_code const & rhs ) noexcept
|
||||
{
|
||||
return !( lhs == rhs );
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
template<class E, class N = typename detail::enable_if<std::is_error_condition_enum<E>::value>::type>
|
||||
inline friend bool operator==( error_code const & lhs, E rhs ) noexcept
|
||||
{
|
||||
return lhs == make_error_condition( rhs );
|
||||
}
|
||||
|
||||
template<class E, class N = typename detail::enable_if<std::is_error_condition_enum<E>::value>::type>
|
||||
inline friend bool operator==( E lhs, error_code const & rhs ) noexcept
|
||||
{
|
||||
return make_error_condition( lhs ) == rhs;
|
||||
}
|
||||
|
||||
template<class E, class N = typename detail::enable_if<std::is_error_condition_enum<E>::value>::type>
|
||||
inline friend bool operator!=( error_code const & lhs, E rhs ) noexcept
|
||||
{
|
||||
return !( lhs == rhs );
|
||||
}
|
||||
|
||||
template<class E, class N = typename detail::enable_if<std::is_error_condition_enum<E>::value>::type>
|
||||
inline friend bool operator!=( E lhs, error_code const & rhs ) noexcept
|
||||
{
|
||||
return !( lhs == rhs );
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
template<class E, class N1 = void, class N2 = typename detail::enable_if<std::is_error_code_enum<E>::value>::type>
|
||||
BOOST_SYSTEM_CONSTEXPR inline friend bool operator==( error_code const & lhs, E rhs ) 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>
|
||||
BOOST_SYSTEM_CONSTEXPR inline friend bool operator==( E lhs, error_code const & rhs ) 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>
|
||||
BOOST_SYSTEM_CONSTEXPR inline friend bool operator!=( error_code const & lhs, E rhs ) noexcept
|
||||
{
|
||||
return !( lhs == rhs );
|
||||
}
|
||||
|
||||
template<class E, class N1 = void, class N2 = typename detail::enable_if<std::is_error_code_enum<E>::value>::type>
|
||||
BOOST_SYSTEM_CONSTEXPR inline friend bool operator!=( E lhs, error_code const & rhs ) noexcept
|
||||
{
|
||||
return !( lhs == rhs );
|
||||
}
|
||||
|
||||
#if defined(BOOST_SYSTEM_CLANG_6)
|
||||
|
||||
inline friend bool operator==( error_code const & lhs, std::error_condition const & rhs ) noexcept
|
||||
{
|
||||
return static_cast< std::error_code >( lhs ) == rhs;
|
||||
}
|
||||
|
||||
inline friend bool operator==( std::error_condition const & lhs, error_code const & rhs ) noexcept
|
||||
{
|
||||
return lhs == static_cast< std::error_code >( rhs );
|
||||
}
|
||||
|
||||
inline friend bool operator!=( error_code const & lhs, std::error_condition const & rhs ) noexcept
|
||||
{
|
||||
return !( lhs == rhs );
|
||||
}
|
||||
|
||||
inline friend bool operator!=( std::error_condition const & lhs, error_code const & rhs ) noexcept
|
||||
{
|
||||
return !( lhs == rhs );
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
// conversions
|
||||
|
||||
operator std::error_code () const
|
||||
{
|
||||
if( lc_flags_ == 1 )
|
||||
{
|
||||
return *reinterpret_cast<std::error_code const*>( d2_ );
|
||||
}
|
||||
else if( lc_flags_ == 0 )
|
||||
{
|
||||
// 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
|
||||
{
|
||||
return std::error_code( d1_.val_, *d1_.cat_ );
|
||||
}
|
||||
}
|
||||
|
||||
operator std::error_code ()
|
||||
{
|
||||
return const_cast<error_code const&>( *this );
|
||||
}
|
||||
|
||||
template<class T,
|
||||
class E = typename detail::enable_if<detail::is_same<T, std::error_code>::value>::type>
|
||||
operator T& ()
|
||||
{
|
||||
if( lc_flags_ != 1 )
|
||||
{
|
||||
std::error_code e2( *this );
|
||||
::new( d2_ ) std::error_code( e2 );
|
||||
lc_flags_ = 1;
|
||||
}
|
||||
|
||||
return *reinterpret_cast<std::error_code*>( d2_ );
|
||||
}
|
||||
|
||||
#if defined(BOOST_SYSTEM_CLANG_6)
|
||||
|
||||
template<class T,
|
||||
class E = typename std::enable_if<std::is_same<T, std::error_code>::value>::type>
|
||||
operator T const& () = delete;
|
||||
|
||||
#endif
|
||||
|
||||
std::string to_string() const
|
||||
{
|
||||
if( lc_flags_ == 1 )
|
||||
{
|
||||
std::error_code const& e2 = *reinterpret_cast<std::error_code const*>( d2_ );
|
||||
|
||||
std::string r( "std:" );
|
||||
r += e2.category().name();
|
||||
detail::append_int( r, e2.value() );
|
||||
|
||||
return r;
|
||||
}
|
||||
else
|
||||
{
|
||||
std::string r = category_name();
|
||||
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_code const & ec)
|
||||
{
|
||||
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;
|
||||
}
|
||||
};
|
||||
|
||||
BOOST_SYSTEM_CONSTEXPR inline bool operator!=( const error_code & lhs, const error_code & rhs ) BOOST_NOEXCEPT
|
||||
inline bool operator==( const error_code & code, const error_condition & condition ) noexcept
|
||||
{
|
||||
if( code.lc_flags_ == 1 )
|
||||
{
|
||||
return static_cast<std::error_code>( code ) == static_cast<std::error_condition>( condition );
|
||||
}
|
||||
else
|
||||
{
|
||||
return code.category().equivalent( code.value(), condition ) || condition.category().equivalent( code, condition.value() );
|
||||
}
|
||||
}
|
||||
|
||||
inline bool operator==( const error_condition & condition, const error_code & code ) noexcept
|
||||
{
|
||||
return code == condition;
|
||||
}
|
||||
|
||||
inline bool operator!=( const error_code & lhs, const error_condition & rhs ) noexcept
|
||||
{
|
||||
return !( lhs == rhs );
|
||||
}
|
||||
|
||||
template<class Ch, class Tr>
|
||||
inline std::basic_ostream<Ch, Tr>&
|
||||
operator<< (std::basic_ostream<Ch, Tr>& os, error_code const & ec)
|
||||
inline bool operator!=( const error_condition & lhs, const error_code & rhs ) noexcept
|
||||
{
|
||||
os << ec.category().name() << ':' << ec.value();
|
||||
return os;
|
||||
return !( lhs == rhs );
|
||||
}
|
||||
|
||||
inline std::size_t hash_value( error_code const & ec )
|
||||
{
|
||||
if( ec.lc_flags_ == 1 )
|
||||
{
|
||||
std::error_code const& e2 = *reinterpret_cast<std::error_code const*>( ec.d2_ );
|
||||
return std::hash<std::error_code>()( e2 );
|
||||
}
|
||||
|
||||
error_category const & cat = ec.category();
|
||||
|
||||
boost::ulong_long_type id_ = cat.id_;
|
||||
@@ -212,4 +652,8 @@ inline std::size_t hash_value( error_code const & ec )
|
||||
|
||||
} // namespace boost
|
||||
|
||||
#if defined(BOOST_GCC) && BOOST_GCC >= 40600 && BOOST_GCC < 70000
|
||||
# pragma GCC diagnostic pop
|
||||
#endif
|
||||
|
||||
#endif // #ifndef BOOST_SYSTEM_DETAIL_ERROR_CODE_HPP_INCLUDED
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
// Copyright Beman Dawes 2006, 2007
|
||||
// Copyright Christoper Kohlhoff 2007
|
||||
// Copyright Peter Dimov 2017, 2018
|
||||
// Copyright Peter Dimov 2017-2021
|
||||
//
|
||||
// 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)
|
||||
@@ -13,6 +13,9 @@
|
||||
#include <boost/system/detail/error_category.hpp>
|
||||
#include <boost/system/detail/generic_category.hpp>
|
||||
#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>
|
||||
@@ -27,6 +30,17 @@ namespace system
|
||||
|
||||
// error_conditions are portable, error_codes are system or library specific
|
||||
|
||||
namespace detail
|
||||
{
|
||||
|
||||
struct generic_value_tag
|
||||
{
|
||||
int value;
|
||||
BOOST_SYSTEM_CONSTEXPR explicit generic_value_tag( int v ): value( v ) {}
|
||||
};
|
||||
|
||||
} // namespace detail
|
||||
|
||||
class error_condition
|
||||
{
|
||||
private:
|
||||
@@ -34,29 +48,49 @@ private:
|
||||
int val_;
|
||||
error_category const * cat_;
|
||||
|
||||
private:
|
||||
|
||||
boost::ulong_long_type cat_id() const noexcept
|
||||
{
|
||||
return cat_? cat_->id_: detail::generic_category_id;
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
// constructors:
|
||||
|
||||
BOOST_SYSTEM_CONSTEXPR error_condition() BOOST_NOEXCEPT:
|
||||
val_( 0 ), cat_( &generic_category() )
|
||||
BOOST_SYSTEM_CONSTEXPR error_condition() noexcept:
|
||||
val_( 0 ), cat_( 0 )
|
||||
{
|
||||
}
|
||||
|
||||
BOOST_SYSTEM_CONSTEXPR error_condition( int val, const error_category & cat ) BOOST_NOEXCEPT:
|
||||
BOOST_SYSTEM_CONSTEXPR error_condition( int val, const error_category & cat ) noexcept:
|
||||
val_( val ), cat_( &cat )
|
||||
{
|
||||
}
|
||||
|
||||
BOOST_SYSTEM_CONSTEXPR explicit error_condition( boost::system::detail::generic_value_tag vt ) noexcept:
|
||||
val_( vt.value ), cat_( 0 )
|
||||
{
|
||||
}
|
||||
|
||||
template<class ErrorConditionEnum> BOOST_SYSTEM_CONSTEXPR error_condition( ErrorConditionEnum e,
|
||||
typename detail::enable_if<is_error_condition_enum<ErrorConditionEnum>::value>::type* = 0) BOOST_NOEXCEPT
|
||||
typename detail::enable_if<
|
||||
is_error_condition_enum<ErrorConditionEnum>::value && !boost::system::detail::is_same<ErrorConditionEnum, errc::errc_t>::value
|
||||
>::type* = 0) noexcept
|
||||
{
|
||||
*this = make_error_condition( e );
|
||||
}
|
||||
|
||||
template<class ErrorConditionEnum> BOOST_SYSTEM_CONSTEXPR error_condition( ErrorConditionEnum e,
|
||||
typename detail::enable_if<boost::system::detail::is_same<ErrorConditionEnum, errc::errc_t>::value>::type* = 0) noexcept:
|
||||
val_( e ), cat_( 0 )
|
||||
{
|
||||
}
|
||||
|
||||
// modifiers:
|
||||
|
||||
BOOST_SYSTEM_CONSTEXPR void assign( int val, const error_category & cat ) BOOST_NOEXCEPT
|
||||
BOOST_SYSTEM_CONSTEXPR void assign( int val, const error_category & cat ) noexcept
|
||||
{
|
||||
val_ = val;
|
||||
cat_ = &cat;
|
||||
@@ -64,97 +98,226 @@ public:
|
||||
|
||||
template<typename ErrorConditionEnum>
|
||||
BOOST_SYSTEM_CONSTEXPR typename detail::enable_if<is_error_condition_enum<ErrorConditionEnum>::value, error_condition>::type &
|
||||
operator=( ErrorConditionEnum val ) BOOST_NOEXCEPT
|
||||
operator=( ErrorConditionEnum val ) noexcept
|
||||
{
|
||||
*this = make_error_condition( val );
|
||||
*this = error_condition( val );
|
||||
return *this;
|
||||
}
|
||||
|
||||
BOOST_SYSTEM_CONSTEXPR void clear() BOOST_NOEXCEPT
|
||||
BOOST_SYSTEM_CONSTEXPR void clear() noexcept
|
||||
{
|
||||
val_ = 0;
|
||||
cat_ = &generic_category();
|
||||
cat_ = 0;
|
||||
}
|
||||
|
||||
// observers:
|
||||
|
||||
BOOST_SYSTEM_CONSTEXPR int value() const BOOST_NOEXCEPT
|
||||
BOOST_SYSTEM_CONSTEXPR int value() const noexcept
|
||||
{
|
||||
return val_;
|
||||
}
|
||||
|
||||
BOOST_SYSTEM_CONSTEXPR const error_category & category() const BOOST_NOEXCEPT
|
||||
BOOST_SYSTEM_CONSTEXPR const error_category & category() const noexcept
|
||||
{
|
||||
return *cat_;
|
||||
return cat_? *cat_: generic_category();
|
||||
}
|
||||
|
||||
std::string message() const
|
||||
{
|
||||
return cat_->message( value() );
|
||||
if( cat_ )
|
||||
{
|
||||
return cat_->message( value() );
|
||||
}
|
||||
else
|
||||
{
|
||||
return detail::generic_error_category_message( value() );
|
||||
}
|
||||
}
|
||||
|
||||
BOOST_SYSTEM_DEPRECATED("this function is slated for removal") char const * message( char * buffer, std::size_t len ) const BOOST_NOEXCEPT
|
||||
char const * message( char * buffer, std::size_t len ) const noexcept
|
||||
{
|
||||
return cat_->message( value(), buffer, len );
|
||||
if( cat_ )
|
||||
{
|
||||
return cat_->message( value(), buffer, len );
|
||||
}
|
||||
else
|
||||
{
|
||||
return detail::generic_error_category_message( value(), buffer, len );
|
||||
}
|
||||
}
|
||||
|
||||
BOOST_SYSTEM_DEPRECATED("this function is slated for removal") BOOST_SYSTEM_CONSTEXPR bool failed() const BOOST_NOEXCEPT
|
||||
BOOST_SYSTEM_CONSTEXPR bool failed() const noexcept
|
||||
{
|
||||
return detail::failed_impl( val_, *cat_ );
|
||||
if( cat_ )
|
||||
{
|
||||
return detail::failed_impl( val_, *cat_ );
|
||||
}
|
||||
else
|
||||
{
|
||||
return val_ != 0;
|
||||
}
|
||||
}
|
||||
|
||||
#if !defined(BOOST_NO_CXX11_EXPLICIT_CONVERSION_OPERATORS)
|
||||
|
||||
BOOST_SYSTEM_CONSTEXPR explicit operator bool() const BOOST_NOEXCEPT // true if error
|
||||
BOOST_SYSTEM_CONSTEXPR explicit operator bool() const noexcept // true if error
|
||||
{
|
||||
return val_ != 0;
|
||||
return failed();
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
typedef void (*unspecified_bool_type)();
|
||||
static void unspecified_bool_true() {}
|
||||
|
||||
BOOST_SYSTEM_CONSTEXPR operator unspecified_bool_type() const BOOST_NOEXCEPT // true if error
|
||||
{
|
||||
return val_ != 0? unspecified_bool_true: 0;
|
||||
}
|
||||
|
||||
BOOST_SYSTEM_CONSTEXPR bool operator!() const BOOST_NOEXCEPT // true if no error
|
||||
{
|
||||
return val_ == 0;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
// relationals:
|
||||
// the more symmetrical non-member syntax allows enum
|
||||
// conversions work for both rhs and lhs.
|
||||
|
||||
BOOST_SYSTEM_CONSTEXPR inline friend bool operator==( const error_condition & lhs, const error_condition & rhs ) BOOST_NOEXCEPT
|
||||
BOOST_SYSTEM_CONSTEXPR inline friend bool operator==( const error_condition & lhs, const error_condition & rhs ) noexcept
|
||||
{
|
||||
return lhs.val_ == rhs.val_ && *lhs.cat_ == *rhs.cat_;
|
||||
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
|
||||
BOOST_SYSTEM_CONSTEXPR inline friend bool operator<( const error_condition & lhs, const error_condition & rhs ) noexcept
|
||||
{
|
||||
return *lhs.cat_ < *rhs.cat_ || ( *lhs.cat_ == *rhs.cat_ && lhs.val_ < rhs.val_ );
|
||||
error_category const& lcat = lhs.category();
|
||||
error_category const& rcat = rhs.category();
|
||||
return lcat < rcat || ( lcat == rcat && lhs.val_ < rhs.val_ );
|
||||
}
|
||||
|
||||
#if defined(BOOST_SYSTEM_HAS_SYSTEM_ERROR)
|
||||
BOOST_SYSTEM_CONSTEXPR inline friend bool operator!=( const error_condition & lhs, const error_condition & rhs ) noexcept
|
||||
{
|
||||
return !( lhs == rhs );
|
||||
}
|
||||
|
||||
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
|
||||
};
|
||||
}
|
||||
|
||||
BOOST_SYSTEM_CONSTEXPR inline bool operator!=( const error_condition & lhs, const error_condition & rhs ) BOOST_NOEXCEPT
|
||||
{
|
||||
return !( lhs == rhs );
|
||||
}
|
||||
inline friend bool operator==( std::error_code const & lhs, error_condition const & rhs ) noexcept
|
||||
{
|
||||
return lhs == static_cast< std::error_condition >( rhs );
|
||||
}
|
||||
|
||||
inline friend bool operator==( error_condition const & lhs, std::error_code const & rhs ) noexcept
|
||||
{
|
||||
return static_cast< std::error_condition >( lhs ) == rhs;
|
||||
}
|
||||
|
||||
inline friend bool operator!=( std::error_code const & lhs, error_condition const & rhs ) noexcept
|
||||
{
|
||||
return !( lhs == rhs );
|
||||
}
|
||||
|
||||
inline friend bool operator!=( error_condition const & lhs, std::error_code const & rhs ) 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==( error_condition const & lhs, E rhs ) 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 ) 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 ) 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 ) 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 ) 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 ) 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 ) 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 ) noexcept
|
||||
{
|
||||
return !( lhs == rhs );
|
||||
}
|
||||
|
||||
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 << en.to_string();
|
||||
return os;
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace system
|
||||
|
||||
|
||||
@@ -35,18 +35,18 @@ class BOOST_SYMBOL_VISIBLE generic_error_category: public error_category
|
||||
{
|
||||
public:
|
||||
|
||||
BOOST_SYSTEM_CONSTEXPR generic_error_category() BOOST_NOEXCEPT:
|
||||
BOOST_SYSTEM_CONSTEXPR generic_error_category() noexcept:
|
||||
error_category( detail::generic_category_id )
|
||||
{
|
||||
}
|
||||
|
||||
const char * name() const BOOST_NOEXCEPT BOOST_OVERRIDE
|
||||
const char * name() const noexcept BOOST_OVERRIDE
|
||||
{
|
||||
return "generic";
|
||||
}
|
||||
|
||||
std::string message( int ev ) const BOOST_OVERRIDE;
|
||||
char const * message( int ev, char * buffer, std::size_t len ) const BOOST_NOEXCEPT BOOST_OVERRIDE;
|
||||
char const * message( int ev, char * buffer, std::size_t len ) const noexcept BOOST_OVERRIDE;
|
||||
};
|
||||
|
||||
#if ( defined( BOOST_GCC ) && BOOST_GCC >= 40600 ) || defined( BOOST_CLANG )
|
||||
@@ -55,7 +55,7 @@ public:
|
||||
|
||||
// generic_error_category::message
|
||||
|
||||
inline char const * generic_error_category::message( int ev, char * buffer, std::size_t len ) const BOOST_NOEXCEPT
|
||||
inline char const * generic_error_category::message( int ev, char * buffer, std::size_t len ) const noexcept
|
||||
{
|
||||
return generic_error_category_message( ev, buffer, len );
|
||||
}
|
||||
@@ -86,7 +86,7 @@ template<class T> constexpr generic_error_category generic_cat_holder<T>::instan
|
||||
|
||||
} // namespace detail
|
||||
|
||||
constexpr error_category const & generic_category() BOOST_NOEXCEPT
|
||||
constexpr error_category const & generic_category() noexcept
|
||||
{
|
||||
return detail::generic_cat_holder<void>::instance;
|
||||
}
|
||||
@@ -94,10 +94,10 @@ constexpr error_category const & generic_category() BOOST_NOEXCEPT
|
||||
#else // #if defined(BOOST_SYSTEM_HAS_CONSTEXPR)
|
||||
|
||||
#if !defined(__SUNPRO_CC) // trailing __global is not supported
|
||||
inline error_category const & generic_category() BOOST_NOEXCEPT BOOST_SYMBOL_VISIBLE;
|
||||
inline error_category const & generic_category() noexcept BOOST_SYMBOL_VISIBLE;
|
||||
#endif
|
||||
|
||||
inline error_category const & generic_category() BOOST_NOEXCEPT
|
||||
inline error_category const & generic_category() noexcept
|
||||
{
|
||||
static const detail::generic_error_category instance;
|
||||
return instance;
|
||||
|
||||
@@ -27,19 +27,31 @@ namespace detail
|
||||
|
||||
// glibc has two incompatible strerror_r definitions
|
||||
|
||||
inline char const * strerror_r_helper( char const * r, char const * ) BOOST_NOEXCEPT
|
||||
inline char const * strerror_r_helper( char const * r, char const * ) noexcept
|
||||
{
|
||||
return r;
|
||||
}
|
||||
|
||||
inline char const * strerror_r_helper( int r, char const * buffer ) BOOST_NOEXCEPT
|
||||
inline char const * strerror_r_helper( int r, char const * buffer ) noexcept
|
||||
{
|
||||
return r == 0? buffer: "Unknown error";
|
||||
}
|
||||
|
||||
inline char const * generic_error_category_message( int ev, char * buffer, std::size_t len ) BOOST_NOEXCEPT
|
||||
inline char const * generic_error_category_message( int ev, char * buffer, std::size_t len ) noexcept
|
||||
{
|
||||
return strerror_r_helper( strerror_r( ev, buffer, len ), buffer );
|
||||
if( buffer != nullptr )
|
||||
{
|
||||
return strerror_r_helper( strerror_r( ev, buffer, len ), buffer );
|
||||
}
|
||||
else
|
||||
{
|
||||
// strerror_r requires non-null buffer pointer
|
||||
|
||||
char tmp[ 1 ] = {};
|
||||
char const* r = strerror_r_helper( strerror_r( ev, tmp, 0 ), buffer );
|
||||
|
||||
return r == tmp? nullptr: r;
|
||||
}
|
||||
}
|
||||
|
||||
inline std::string generic_error_category_message( int ev )
|
||||
@@ -68,7 +80,7 @@ inline std::string generic_error_category_message( int ev )
|
||||
return m? m: "Unknown error";
|
||||
}
|
||||
|
||||
inline char const * generic_error_category_message( int ev, char * buffer, std::size_t len ) BOOST_NOEXCEPT
|
||||
inline char const * generic_error_category_message( int ev, char * buffer, std::size_t len ) noexcept
|
||||
{
|
||||
if( len == 0 )
|
||||
{
|
||||
|
||||
107
include/boost/system/detail/interop_category.hpp
Normal file
107
include/boost/system/detail/interop_category.hpp
Normal file
@@ -0,0 +1,107 @@
|
||||
#ifndef BOOST_SYSTEM_DETAIL_INTEROP_CATEGORY_HPP_INCLUDED
|
||||
#define BOOST_SYSTEM_DETAIL_INTEROP_CATEGORY_HPP_INCLUDED
|
||||
|
||||
// Copyright Beman Dawes 2006, 2007
|
||||
// Copyright Christoper Kohlhoff 2007
|
||||
// Copyright Peter Dimov 2017, 2018, 2021
|
||||
//
|
||||
// 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/error_category.hpp>
|
||||
#include <boost/system/detail/snprintf.hpp>
|
||||
#include <boost/system/detail/config.hpp>
|
||||
#include <boost/config.hpp>
|
||||
|
||||
namespace boost
|
||||
{
|
||||
|
||||
namespace system
|
||||
{
|
||||
|
||||
namespace detail
|
||||
{
|
||||
|
||||
// interop_error_category, used for std::error_code
|
||||
|
||||
#if ( defined( BOOST_GCC ) && BOOST_GCC >= 40600 ) || defined( BOOST_CLANG )
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wnon-virtual-dtor"
|
||||
#endif
|
||||
|
||||
class BOOST_SYMBOL_VISIBLE interop_error_category: public error_category
|
||||
{
|
||||
public:
|
||||
|
||||
BOOST_SYSTEM_CONSTEXPR interop_error_category() noexcept:
|
||||
error_category( detail::interop_category_id )
|
||||
{
|
||||
}
|
||||
|
||||
const char * name() const noexcept BOOST_OVERRIDE
|
||||
{
|
||||
return "std:unknown";
|
||||
}
|
||||
|
||||
std::string message( int ev ) const BOOST_OVERRIDE;
|
||||
char const * message( int ev, char * buffer, std::size_t len ) const noexcept BOOST_OVERRIDE;
|
||||
};
|
||||
|
||||
#if ( defined( BOOST_GCC ) && BOOST_GCC >= 40600 ) || defined( BOOST_CLANG )
|
||||
#pragma GCC diagnostic pop
|
||||
#endif
|
||||
|
||||
inline char const * interop_error_category::message( int ev, char * buffer, std::size_t len ) const noexcept
|
||||
{
|
||||
detail::snprintf( buffer, len, "Unknown interop error %d", ev );
|
||||
return buffer;
|
||||
}
|
||||
|
||||
inline std::string interop_error_category::message( int ev ) const
|
||||
{
|
||||
char buffer[ 48 ];
|
||||
return message( ev, buffer, sizeof( buffer ) );
|
||||
}
|
||||
|
||||
// interop_category()
|
||||
|
||||
#if defined(BOOST_SYSTEM_HAS_CONSTEXPR)
|
||||
|
||||
template<class T> struct BOOST_SYMBOL_VISIBLE interop_cat_holder
|
||||
{
|
||||
static constexpr interop_error_category instance{};
|
||||
};
|
||||
|
||||
// Before C++17 it was mandatory to redeclare all static constexpr
|
||||
#if defined(BOOST_NO_CXX17_INLINE_VARIABLES)
|
||||
template<class T> constexpr interop_error_category interop_cat_holder<T>::instance;
|
||||
#endif
|
||||
|
||||
constexpr error_category const & interop_category() noexcept
|
||||
{
|
||||
return interop_cat_holder<void>::instance;
|
||||
}
|
||||
|
||||
#else // #if defined(BOOST_SYSTEM_HAS_CONSTEXPR)
|
||||
|
||||
#if !defined(__SUNPRO_CC) // trailing __global is not supported
|
||||
inline error_category const & interop_category() noexcept BOOST_SYMBOL_VISIBLE;
|
||||
#endif
|
||||
|
||||
inline error_category const & interop_category() noexcept
|
||||
{
|
||||
static const detail::interop_error_category instance;
|
||||
return instance;
|
||||
}
|
||||
|
||||
#endif // #if defined(BOOST_SYSTEM_HAS_CONSTEXPR)
|
||||
|
||||
} // namespace detail
|
||||
|
||||
} // namespace system
|
||||
|
||||
} // namespace boost
|
||||
|
||||
#endif // #ifndef BOOST_SYSTEM_DETAIL_INTEROP_CATEGORY_HPP_INCLUDED
|
||||
@@ -1,125 +0,0 @@
|
||||
#ifndef BOOST_SYSTEM_DETAIL_IS_GENERIC_VALUE_HPP_INCLUDED
|
||||
#define BOOST_SYSTEM_DETAIL_IS_GENERIC_VALUE_HPP_INCLUDED
|
||||
|
||||
// Copyright 2018 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/errc.hpp>
|
||||
|
||||
namespace boost
|
||||
{
|
||||
|
||||
namespace system
|
||||
{
|
||||
|
||||
namespace detail
|
||||
{
|
||||
|
||||
inline bool is_generic_value( int ev ) BOOST_NOEXCEPT
|
||||
{
|
||||
using namespace errc;
|
||||
|
||||
static int const gen[] =
|
||||
{
|
||||
success,
|
||||
address_family_not_supported,
|
||||
address_in_use,
|
||||
address_not_available,
|
||||
already_connected,
|
||||
argument_list_too_long,
|
||||
argument_out_of_domain,
|
||||
bad_address,
|
||||
bad_file_descriptor,
|
||||
bad_message,
|
||||
broken_pipe,
|
||||
connection_aborted,
|
||||
connection_already_in_progress,
|
||||
connection_refused,
|
||||
connection_reset,
|
||||
cross_device_link,
|
||||
destination_address_required,
|
||||
device_or_resource_busy,
|
||||
directory_not_empty,
|
||||
executable_format_error,
|
||||
file_exists,
|
||||
file_too_large,
|
||||
filename_too_long,
|
||||
function_not_supported,
|
||||
host_unreachable,
|
||||
identifier_removed,
|
||||
illegal_byte_sequence,
|
||||
inappropriate_io_control_operation,
|
||||
interrupted,
|
||||
invalid_argument,
|
||||
invalid_seek,
|
||||
io_error,
|
||||
is_a_directory,
|
||||
message_size,
|
||||
network_down,
|
||||
network_reset,
|
||||
network_unreachable,
|
||||
no_buffer_space,
|
||||
no_child_process,
|
||||
no_link,
|
||||
no_lock_available,
|
||||
no_message_available,
|
||||
no_message,
|
||||
no_protocol_option,
|
||||
no_space_on_device,
|
||||
no_stream_resources,
|
||||
no_such_device_or_address,
|
||||
no_such_device,
|
||||
no_such_file_or_directory,
|
||||
no_such_process,
|
||||
not_a_directory,
|
||||
not_a_socket,
|
||||
not_a_stream,
|
||||
not_connected,
|
||||
not_enough_memory,
|
||||
not_supported,
|
||||
operation_canceled,
|
||||
operation_in_progress,
|
||||
operation_not_permitted,
|
||||
operation_not_supported,
|
||||
operation_would_block,
|
||||
owner_dead,
|
||||
permission_denied,
|
||||
protocol_error,
|
||||
protocol_not_supported,
|
||||
read_only_file_system,
|
||||
resource_deadlock_would_occur,
|
||||
resource_unavailable_try_again,
|
||||
result_out_of_range,
|
||||
state_not_recoverable,
|
||||
stream_timeout,
|
||||
text_file_busy,
|
||||
timed_out,
|
||||
too_many_files_open_in_system,
|
||||
too_many_files_open,
|
||||
too_many_links,
|
||||
too_many_symbolic_link_levels,
|
||||
value_too_large,
|
||||
wrong_protocol_type
|
||||
};
|
||||
|
||||
int const n = sizeof( gen ) / sizeof( gen[0] );
|
||||
|
||||
for( int i = 0; i < n; ++i )
|
||||
{
|
||||
if( ev == gen[ i ] ) return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
} // namespace detail
|
||||
|
||||
} // namespace system
|
||||
|
||||
} // namespace boost
|
||||
|
||||
#endif // #ifndef BOOST_SYSTEM_DETAIL_IS_GENERIC_VALUE_HPP_INCLUDED
|
||||
23
include/boost/system/detail/is_same.hpp
Normal file
23
include/boost/system/detail/is_same.hpp
Normal file
@@ -0,0 +1,23 @@
|
||||
#ifndef BOOST_SYSTEM_DETAIL_IS_SAME_HPP_INCLUDED
|
||||
#define BOOST_SYSTEM_DETAIL_IS_SAME_HPP_INCLUDED
|
||||
|
||||
// Copyright 2021 Peter Dimov
|
||||
// Distributed under the Boost Software License, Version 1.0
|
||||
// http://www.boost.org/LICENSE_1_0.txt
|
||||
|
||||
#include <type_traits>
|
||||
|
||||
namespace boost
|
||||
{
|
||||
namespace system
|
||||
{
|
||||
namespace detail
|
||||
{
|
||||
|
||||
using std::is_same;
|
||||
|
||||
} // namespace detail
|
||||
} // namespace system
|
||||
} // namespace boost
|
||||
|
||||
#endif // #ifndef BOOST_SYSTEM_DETAIL_IS_SAME_HPP_INCLUDED
|
||||
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
|
||||
28
include/boost/system/detail/snprintf.hpp
Normal file
28
include/boost/system/detail/snprintf.hpp
Normal file
@@ -0,0 +1,28 @@
|
||||
#ifndef BOOST_SYSTEM_DETAIL_SNPRINTF_HPP_INCLUDED
|
||||
#define BOOST_SYSTEM_DETAIL_SNPRINTF_HPP_INCLUDED
|
||||
|
||||
// Copyright 2018, 2020, 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 <cstdio>
|
||||
|
||||
//
|
||||
|
||||
namespace boost
|
||||
{
|
||||
namespace system
|
||||
{
|
||||
namespace detail
|
||||
{
|
||||
|
||||
using std::snprintf;
|
||||
|
||||
} // namespace detail
|
||||
} // namespace system
|
||||
} // namespace boost
|
||||
|
||||
#endif // #ifndef BOOST_SYSTEM_DETAIL_SNPRINTF_HPP_INCLUDED
|
||||
84
include/boost/system/detail/std_category.hpp
Normal file
84
include/boost/system/detail/std_category.hpp
Normal file
@@ -0,0 +1,84 @@
|
||||
#ifndef BOOST_SYSTEM_DETAIL_STD_CATEGORY_HPP_INCLUDED
|
||||
#define BOOST_SYSTEM_DETAIL_STD_CATEGORY_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/error_category.hpp>
|
||||
#include <boost/config.hpp>
|
||||
#include <system_error>
|
||||
|
||||
//
|
||||
|
||||
namespace boost
|
||||
{
|
||||
|
||||
namespace system
|
||||
{
|
||||
|
||||
namespace detail
|
||||
{
|
||||
|
||||
template<unsigned Id> struct id_wrapper {};
|
||||
|
||||
class BOOST_SYMBOL_VISIBLE std_category: public std::error_category
|
||||
{
|
||||
private:
|
||||
|
||||
boost::system::error_category const * pc_;
|
||||
|
||||
public:
|
||||
|
||||
boost::system::error_category const & original_category() const noexcept
|
||||
{
|
||||
return *pc_;
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
template<unsigned Id>
|
||||
explicit std_category( boost::system::error_category const * pc, id_wrapper<Id> ): pc_( pc )
|
||||
{
|
||||
#if defined(_MSC_VER) && defined(_CPPLIB_VER) && _MSC_VER >= 1900 && _MSC_VER < 2000
|
||||
|
||||
// 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
|
||||
|
||||
static_assert( Id == 0, "This constructor should only be called with Id == 0 under MS STL 14.0+" );
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
const char * name() const noexcept BOOST_OVERRIDE
|
||||
{
|
||||
return pc_->name();
|
||||
}
|
||||
|
||||
std::string message( int ev ) const BOOST_OVERRIDE
|
||||
{
|
||||
return pc_->message( ev );
|
||||
}
|
||||
|
||||
std::error_condition default_error_condition( int ev ) const noexcept BOOST_OVERRIDE
|
||||
{
|
||||
return pc_->default_error_condition( ev );
|
||||
}
|
||||
|
||||
inline bool equivalent( int code, const std::error_condition & condition ) const noexcept BOOST_OVERRIDE;
|
||||
inline bool equivalent( const std::error_code & code, int condition ) const noexcept BOOST_OVERRIDE;
|
||||
};
|
||||
|
||||
} // namespace detail
|
||||
|
||||
} // namespace system
|
||||
|
||||
} // namespace boost
|
||||
|
||||
#endif // #ifndef BOOST_SYSTEM_DETAIL_STD_CATEGORY_HPP_INCLUDED
|
||||
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 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 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
|
||||
@@ -34,20 +34,20 @@ class BOOST_SYMBOL_VISIBLE system_error_category: public error_category
|
||||
{
|
||||
public:
|
||||
|
||||
BOOST_SYSTEM_CONSTEXPR system_error_category() BOOST_NOEXCEPT:
|
||||
BOOST_SYSTEM_CONSTEXPR system_error_category() noexcept:
|
||||
error_category( detail::system_category_id )
|
||||
{
|
||||
}
|
||||
|
||||
const char * name() const BOOST_NOEXCEPT BOOST_OVERRIDE
|
||||
const char * name() const noexcept BOOST_OVERRIDE
|
||||
{
|
||||
return "system";
|
||||
}
|
||||
|
||||
error_condition default_error_condition( int ev ) const BOOST_NOEXCEPT BOOST_OVERRIDE;
|
||||
error_condition default_error_condition( int ev ) const noexcept BOOST_OVERRIDE;
|
||||
|
||||
std::string message( int ev ) const BOOST_OVERRIDE;
|
||||
char const * message( int ev, char * buffer, std::size_t len ) const BOOST_NOEXCEPT BOOST_OVERRIDE;
|
||||
char const * message( int ev, char * buffer, std::size_t len ) const noexcept BOOST_OVERRIDE;
|
||||
};
|
||||
|
||||
#if ( defined( BOOST_GCC ) && BOOST_GCC >= 40600 ) || defined( BOOST_CLANG )
|
||||
@@ -75,7 +75,7 @@ template<class T> constexpr system_error_category system_cat_holder<T>::instance
|
||||
|
||||
} // namespace detail
|
||||
|
||||
constexpr error_category const & system_category() BOOST_NOEXCEPT
|
||||
constexpr error_category const & system_category() noexcept
|
||||
{
|
||||
return detail::system_cat_holder<void>::instance;
|
||||
}
|
||||
@@ -83,10 +83,10 @@ constexpr error_category const & system_category() BOOST_NOEXCEPT
|
||||
#else // #if defined(BOOST_SYSTEM_HAS_CONSTEXPR)
|
||||
|
||||
#if !defined(__SUNPRO_CC) // trailing __global is not supported
|
||||
inline error_category const & system_category() BOOST_NOEXCEPT BOOST_SYMBOL_VISIBLE;
|
||||
inline error_category const & system_category() noexcept BOOST_SYMBOL_VISIBLE;
|
||||
#endif
|
||||
|
||||
inline error_category const & system_category() BOOST_NOEXCEPT
|
||||
inline error_category const & system_category() noexcept
|
||||
{
|
||||
static const detail::system_error_category instance;
|
||||
return instance;
|
||||
|
||||
@@ -25,7 +25,7 @@ namespace system
|
||||
namespace detail
|
||||
{
|
||||
|
||||
inline int system_category_condition_win32( int ev ) BOOST_NOEXCEPT
|
||||
inline int system_category_condition_win32( int ev ) noexcept
|
||||
{
|
||||
// When using the Windows Runtime, most system errors are reported as HRESULTs.
|
||||
// We want to map the common Win32 errors to their equivalent error condition,
|
||||
@@ -58,7 +58,10 @@ 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;
|
||||
case ERROR_BUSY_: return device_or_resource_busy;
|
||||
case ERROR_BUSY_DRIVE_: return device_or_resource_busy;
|
||||
@@ -73,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;
|
||||
@@ -80,7 +84,8 @@ inline int system_category_condition_win32( int ev ) BOOST_NOEXCEPT
|
||||
case ERROR_INVALID_DRIVE_: return no_such_device;
|
||||
case ERROR_INVALID_FUNCTION_: return function_not_supported;
|
||||
case ERROR_INVALID_HANDLE_: return invalid_argument;
|
||||
case ERROR_INVALID_NAME_: return invalid_argument;
|
||||
case ERROR_INVALID_NAME_: return no_such_file_or_directory;
|
||||
case ERROR_INVALID_PARAMETER_: return invalid_argument;
|
||||
case ERROR_LOCK_VIOLATION_: return no_lock_available;
|
||||
case ERROR_LOCKED_: return no_lock_available;
|
||||
case ERROR_NEGATIVE_SEEK_: return invalid_argument;
|
||||
@@ -94,13 +99,19 @@ inline int system_category_condition_win32( int ev ) BOOST_NOEXCEPT
|
||||
case ERROR_OUTOFMEMORY_: return not_enough_memory;
|
||||
case ERROR_PATH_NOT_FOUND_: return no_such_file_or_directory;
|
||||
case ERROR_READ_FAULT_: return io_error;
|
||||
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,10 +11,9 @@
|
||||
// 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/detail/generic_category.hpp>
|
||||
#include <boost/system/api_config.hpp>
|
||||
#include <boost/config.hpp>
|
||||
|
||||
#if !defined(BOOST_POSIX_API) && !defined(BOOST_WINDOWS_API)
|
||||
# error BOOST_POSIX_API or BOOST_WINDOWS_API must be defined
|
||||
@@ -24,10 +23,9 @@
|
||||
|
||||
#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
|
||||
inline boost::system::error_condition boost::system::detail::system_error_category::default_error_condition( int ev ) const noexcept
|
||||
{
|
||||
int e2 = system_category_condition_win32( ev );
|
||||
|
||||
@@ -37,47 +35,27 @@ inline boost::system::error_condition boost::system::detail::system_error_catego
|
||||
}
|
||||
else
|
||||
{
|
||||
return error_condition( e2, generic_category() );
|
||||
return error_condition( boost::system::detail::generic_value_tag( e2 ) );
|
||||
}
|
||||
}
|
||||
|
||||
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>
|
||||
#include <boost/system/detail/is_generic_value.hpp>
|
||||
|
||||
inline boost::system::error_condition boost::system::detail::system_error_category::default_error_condition( int ev ) const BOOST_NOEXCEPT
|
||||
inline boost::system::error_condition boost::system::detail::system_error_category::default_error_condition( int ev ) const noexcept
|
||||
{
|
||||
if( is_generic_value( ev ) )
|
||||
{
|
||||
return error_condition( ev, generic_category() );
|
||||
}
|
||||
else
|
||||
{
|
||||
return error_condition( ev, *this );
|
||||
}
|
||||
}
|
||||
|
||||
inline std::string boost::system::detail::system_error_category::message( int ev ) const
|
||||
{
|
||||
return generic_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 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 system_error_category_message( ev );
|
||||
}
|
||||
|
||||
inline char const * boost::system::detail::system_error_category::message( int ev, char * buffer, std::size_t len ) const noexcept
|
||||
{
|
||||
return system_error_category_message( ev, buffer, len );
|
||||
}
|
||||
|
||||
#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 ) 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 ) 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
|
||||
@@ -10,6 +10,7 @@
|
||||
//
|
||||
// See library home page at http://www.boost.org/libs/system
|
||||
|
||||
#include <boost/system/detail/snprintf.hpp>
|
||||
#include <boost/winapi/error_handling.hpp>
|
||||
#include <boost/winapi/character_code_conversion.hpp>
|
||||
#include <boost/winapi/local_memory.hpp>
|
||||
@@ -27,35 +28,12 @@ namespace system
|
||||
namespace detail
|
||||
{
|
||||
|
||||
#if ( defined(_MSC_VER) && _MSC_VER < 1900 ) || ( defined(__MINGW32__) && !defined(__MINGW64_VERSION_MAJOR) )
|
||||
|
||||
inline char const * unknown_message_win32( int ev, char * buffer, std::size_t len )
|
||||
{
|
||||
# if defined( BOOST_MSVC )
|
||||
# pragma warning( push )
|
||||
# pragma warning( disable: 4996 )
|
||||
# endif
|
||||
|
||||
_snprintf( buffer, len - 1, "Unknown error (%d)", ev );
|
||||
|
||||
buffer[ len - 1 ] = 0;
|
||||
return buffer;
|
||||
|
||||
# if defined( BOOST_MSVC )
|
||||
# pragma warning( pop )
|
||||
# endif
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
inline char const * unknown_message_win32( int ev, char * buffer, std::size_t len )
|
||||
{
|
||||
std::snprintf( buffer, len, "Unknown error (%d)", ev );
|
||||
detail::snprintf( buffer, len, "Unknown error (%d)", ev );
|
||||
return buffer;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
inline boost::winapi::UINT_ message_cp_win32()
|
||||
{
|
||||
#if defined(BOOST_SYSTEM_USE_UTF8)
|
||||
@@ -69,7 +47,7 @@ inline boost::winapi::UINT_ message_cp_win32()
|
||||
#endif
|
||||
}
|
||||
|
||||
inline char const * system_category_message_win32( int ev, char * buffer, std::size_t len ) BOOST_NOEXCEPT
|
||||
inline char const * system_category_message_win32( int ev, char * buffer, std::size_t len ) noexcept
|
||||
{
|
||||
if( len == 0 )
|
||||
{
|
||||
@@ -95,7 +73,7 @@ inline char const * system_category_message_win32( int ev, char * buffer, std::s
|
||||
DWORD_ retval = boost::winapi::FormatMessageA(
|
||||
FORMAT_MESSAGE_FROM_SYSTEM_ | FORMAT_MESSAGE_IGNORE_INSERTS_,
|
||||
NULL,
|
||||
ev,
|
||||
static_cast<DWORD_>(ev),
|
||||
MAKELANGID_( LANG_NEUTRAL_, SUBLANG_DEFAULT_ ), // Default language
|
||||
buffer,
|
||||
static_cast<DWORD_>( len ),
|
||||
@@ -116,7 +94,7 @@ inline char const * system_category_message_win32( int ev, char * buffer, std::s
|
||||
DWORD_ retval = boost::winapi::FormatMessageW(
|
||||
FORMAT_MESSAGE_ALLOCATE_BUFFER_ | FORMAT_MESSAGE_FROM_SYSTEM_ | FORMAT_MESSAGE_IGNORE_INSERTS_,
|
||||
NULL,
|
||||
ev,
|
||||
static_cast<DWORD_>(ev),
|
||||
MAKELANGID_( LANG_NEUTRAL_, SUBLANG_DEFAULT_ ), // Default language
|
||||
(LPWSTR_) &lpMsgBuf,
|
||||
0,
|
||||
@@ -174,7 +152,7 @@ inline std::string system_category_message_win32( int ev )
|
||||
DWORD_ retval = boost::winapi::FormatMessageW(
|
||||
FORMAT_MESSAGE_ALLOCATE_BUFFER_ | FORMAT_MESSAGE_FROM_SYSTEM_ | FORMAT_MESSAGE_IGNORE_INSERTS_,
|
||||
NULL,
|
||||
ev,
|
||||
static_cast<DWORD_>(ev),
|
||||
MAKELANGID_( LANG_NEUTRAL_, SUBLANG_DEFAULT_ ), // Default language
|
||||
(LPWSTR_) &lpMsgBuf,
|
||||
0,
|
||||
@@ -198,7 +176,7 @@ inline std::string system_category_message_win32( int ev )
|
||||
return unknown_message_win32( ev );
|
||||
}
|
||||
|
||||
std::string buffer( r, char() );
|
||||
std::string buffer( static_cast<std::size_t>(r), char() );
|
||||
|
||||
r = boost::winapi::WideCharToMultiByte( code_page, 0, lpMsgBuf, -1, &buffer[0], r, NULL, NULL );
|
||||
|
||||
@@ -209,12 +187,12 @@ inline std::string system_category_message_win32( int ev )
|
||||
|
||||
--r; // exclude null terminator
|
||||
|
||||
while( r > 0 && ( buffer[ r-1 ] == '\n' || buffer[ r-1 ] == '\r' ) )
|
||||
while( r > 0 && ( buffer[ static_cast<std::size_t>(r)-1 ] == '\n' || buffer[ static_cast<std::size_t>(r)-1 ] == '\r' ) )
|
||||
{
|
||||
--r;
|
||||
}
|
||||
|
||||
if( r > 0 && buffer[ r-1 ] == '.' )
|
||||
if( r > 0 && buffer[ static_cast<std::size_t>(r)-1 ] == '.' )
|
||||
{
|
||||
--r;
|
||||
}
|
||||
|
||||
@@ -1,191 +0,0 @@
|
||||
#ifndef BOOST_SYSTEM_DETAIL_TO_STD_CATEGORY_HPP_INCLUDED
|
||||
#define BOOST_SYSTEM_DETAIL_TO_STD_CATEGORY_HPP_INCLUDED
|
||||
|
||||
// Support for interoperability between Boost.System and <system_error>
|
||||
//
|
||||
// Copyright 2018 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/error_category.hpp>
|
||||
#include <boost/system/detail/error_condition.hpp>
|
||||
#include <boost/system/detail/error_code.hpp>
|
||||
#include <boost/system/detail/generic_category.hpp>
|
||||
#include <system_error>
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
|
||||
//
|
||||
|
||||
namespace boost
|
||||
{
|
||||
|
||||
namespace system
|
||||
{
|
||||
|
||||
namespace detail
|
||||
{
|
||||
|
||||
class BOOST_SYMBOL_VISIBLE std_category: public std::error_category
|
||||
{
|
||||
private:
|
||||
|
||||
boost::system::error_category const * pc_;
|
||||
|
||||
public:
|
||||
|
||||
explicit std_category( boost::system::error_category const * pc, unsigned 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
|
||||
|
||||
_Addr = id;
|
||||
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
const char * name() const BOOST_NOEXCEPT BOOST_OVERRIDE
|
||||
{
|
||||
return pc_->name();
|
||||
}
|
||||
|
||||
std::string message( int ev ) const BOOST_OVERRIDE
|
||||
{
|
||||
return pc_->message( ev );
|
||||
}
|
||||
|
||||
std::error_condition default_error_condition( int ev ) const BOOST_NOEXCEPT BOOST_OVERRIDE
|
||||
{
|
||||
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;
|
||||
};
|
||||
|
||||
#if !defined(__SUNPRO_CC) // trailing __global is not supported
|
||||
inline std::error_category const & to_std_category( boost::system::error_category const & cat ) BOOST_SYMBOL_VISIBLE;
|
||||
#endif
|
||||
|
||||
struct cat_ptr_less
|
||||
{
|
||||
bool operator()( boost::system::error_category const * p1, boost::system::error_category const * p2 ) const BOOST_NOEXCEPT
|
||||
{
|
||||
return *p1 < *p2;
|
||||
}
|
||||
};
|
||||
|
||||
inline std::error_category const & to_std_category( boost::system::error_category const & cat )
|
||||
{
|
||||
if( cat.id_ == boost::system::detail::system_category_id )
|
||||
{
|
||||
static const std_category system_instance( &cat, 0x1F4D7 );
|
||||
return system_instance;
|
||||
}
|
||||
else if( cat.id_ == boost::system::detail::generic_category_id )
|
||||
{
|
||||
static const std_category generic_instance( &cat, 0x1F4D3 );
|
||||
return generic_instance;
|
||||
}
|
||||
else
|
||||
{
|
||||
typedef std::map< boost::system::error_category const *, std::unique_ptr<std_category>, cat_ptr_less > map_type;
|
||||
|
||||
static map_type map_;
|
||||
static std::mutex map_mx_;
|
||||
|
||||
std::lock_guard<std::mutex> guard( map_mx_ );
|
||||
|
||||
map_type::iterator i = map_.find( &cat );
|
||||
|
||||
if( i == map_.end() )
|
||||
{
|
||||
std::unique_ptr<std_category> p( new std_category( &cat, 0 ) );
|
||||
|
||||
std::pair<map_type::iterator, bool> r = map_.insert( map_type::value_type( &cat, std::move( p ) ) );
|
||||
|
||||
i = r.first;
|
||||
}
|
||||
|
||||
return *i->second;
|
||||
}
|
||||
}
|
||||
|
||||
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_TO_STD_CATEGORY_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
|
||||
@@ -30,13 +31,19 @@ namespace errc
|
||||
{
|
||||
|
||||
// explicit conversion:
|
||||
BOOST_SYSTEM_CONSTEXPR inline error_code make_error_code( errc_t e ) BOOST_NOEXCEPT
|
||||
BOOST_SYSTEM_CONSTEXPR inline error_code make_error_code( errc_t e ) noexcept
|
||||
{
|
||||
return error_code( e, generic_category() );
|
||||
}
|
||||
|
||||
// explicit conversion:
|
||||
inline error_code make_error_code( errc_t e, boost::source_location const * loc ) noexcept
|
||||
{
|
||||
return error_code( e, generic_category(), loc );
|
||||
}
|
||||
|
||||
// implicit conversion:
|
||||
BOOST_SYSTEM_CONSTEXPR inline error_condition make_error_condition( errc_t e ) BOOST_NOEXCEPT
|
||||
BOOST_SYSTEM_CONSTEXPR inline error_condition make_error_condition( errc_t e ) noexcept
|
||||
{
|
||||
return error_condition( e, generic_category() );
|
||||
}
|
||||
|
||||
@@ -17,38 +17,5 @@
|
||||
#include <boost/system/generic_category.hpp>
|
||||
#include <boost/system/system_category.hpp>
|
||||
#include <boost/system/detail/throws.hpp>
|
||||
#include <boost/config.hpp>
|
||||
|
||||
namespace boost
|
||||
{
|
||||
|
||||
namespace system
|
||||
{
|
||||
|
||||
// non-member functions of error_code and error_condition
|
||||
|
||||
inline bool operator==( const error_code & code, const error_condition & condition ) BOOST_NOEXCEPT
|
||||
{
|
||||
return code.category().equivalent( code.value(), condition ) || condition.category().equivalent( code, condition.value() );
|
||||
}
|
||||
|
||||
inline bool operator!=( const error_code & lhs, const error_condition & rhs ) BOOST_NOEXCEPT
|
||||
{
|
||||
return !( lhs == rhs );
|
||||
}
|
||||
|
||||
inline bool operator==( const error_condition & condition, const error_code & code ) BOOST_NOEXCEPT
|
||||
{
|
||||
return code.category().equivalent( code.value(), condition ) || condition.category().equivalent( code, condition.value() );
|
||||
}
|
||||
|
||||
inline bool operator!=( const error_condition & lhs, const error_code & rhs ) BOOST_NOEXCEPT
|
||||
{
|
||||
return !( lhs == rhs );
|
||||
}
|
||||
|
||||
} // namespace system
|
||||
|
||||
} // namespace boost
|
||||
|
||||
#endif // BOOST_SYSTEM_ERROR_CODE_HPP_INCLUDED
|
||||
|
||||
@@ -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.
|
||||
|
||||
|
||||
1409
include/boost/system/result.hpp
Normal file
1409
include/boost/system/result.hpp
Normal file
File diff suppressed because it is too large
Load Diff
@@ -1,84 +1,55 @@
|
||||
// Boost system_error.hpp --------------------------------------------------//
|
||||
|
||||
// Copyright Beman Dawes 2006
|
||||
|
||||
// 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)
|
||||
|
||||
#ifndef BOOST_SYSTEM_SYSTEM_ERROR_HPP
|
||||
#define BOOST_SYSTEM_SYSTEM_ERROR_HPP
|
||||
|
||||
#include <boost/system/error_code.hpp>
|
||||
// Copyright Beman Dawes 2006
|
||||
// Copyright Peter Dimov 2021
|
||||
// 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 <string>
|
||||
#include <stdexcept>
|
||||
#include <cassert>
|
||||
|
||||
namespace boost
|
||||
{
|
||||
namespace system
|
||||
{
|
||||
// class system_error ------------------------------------------------------------//
|
||||
namespace system
|
||||
{
|
||||
|
||||
class BOOST_SYMBOL_VISIBLE system_error : public std::runtime_error
|
||||
// BOOST_SYMBOL_VISIBLE is needed by GCC to ensure system_error thrown from a shared
|
||||
// library can be caught. See svn.boost.org/trac/boost/ticket/3697
|
||||
class BOOST_SYMBOL_VISIBLE system_error: public std::runtime_error
|
||||
{
|
||||
private:
|
||||
|
||||
error_code code_;
|
||||
|
||||
public:
|
||||
|
||||
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( prefix + ": " + ec.what() ), 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( error_code( ev, ecat ).what() ), 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( std::string( prefix ) + ": " + error_code( ev, ecat ).what() ), code_( ev, ecat ) {}
|
||||
|
||||
error_code code() const noexcept
|
||||
{
|
||||
public:
|
||||
explicit system_error( error_code ec )
|
||||
: std::runtime_error(""), m_error_code(ec) {}
|
||||
|
||||
system_error( error_code ec, const std::string & what_arg )
|
||||
: std::runtime_error(what_arg), m_error_code(ec) {}
|
||||
|
||||
system_error( error_code ec, const char* what_arg )
|
||||
: std::runtime_error(what_arg), m_error_code(ec) {}
|
||||
|
||||
system_error( int ev, const error_category & ecat )
|
||||
: std::runtime_error(""), m_error_code(ev,ecat) {}
|
||||
|
||||
system_error( int ev, const error_category & ecat,
|
||||
const std::string & what_arg )
|
||||
: std::runtime_error(what_arg), m_error_code(ev,ecat) {}
|
||||
|
||||
system_error( int ev, const error_category & ecat,
|
||||
const char * what_arg )
|
||||
: std::runtime_error(what_arg), m_error_code(ev,ecat) {}
|
||||
|
||||
virtual ~system_error() BOOST_NOEXCEPT_OR_NOTHROW {}
|
||||
|
||||
error_code code() const BOOST_NOEXCEPT { return m_error_code; }
|
||||
const char * what() const BOOST_NOEXCEPT_OR_NOTHROW BOOST_OVERRIDE;
|
||||
|
||||
private:
|
||||
error_code m_error_code;
|
||||
mutable std::string m_what;
|
||||
};
|
||||
|
||||
// implementation ------------------------------------------------------//
|
||||
|
||||
inline const char * system_error::what() const BOOST_NOEXCEPT_OR_NOTHROW
|
||||
// see http://www.boost.org/more/error_handling.html for lazy build rationale
|
||||
{
|
||||
if ( m_what.empty() )
|
||||
{
|
||||
#ifndef BOOST_NO_EXCEPTIONS
|
||||
try
|
||||
#endif
|
||||
{
|
||||
m_what = this->std::runtime_error::what();
|
||||
if ( !m_what.empty() ) m_what += ": ";
|
||||
m_what += m_error_code.message();
|
||||
}
|
||||
#ifndef BOOST_NO_EXCEPTIONS
|
||||
catch (...) { return std::runtime_error::what(); }
|
||||
#endif
|
||||
}
|
||||
return m_what.c_str();
|
||||
return code_;
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace system
|
||||
} // namespace system
|
||||
} // namespace boost
|
||||
|
||||
#endif // BOOST_SYSTEM_SYSTEM_ERROR_HPP
|
||||
|
||||
|
||||
|
||||
@@ -10,13 +10,6 @@
|
||||
#ifndef BOOST_SYSTEM_WINDOWS_ERROR_HPP
|
||||
#define BOOST_SYSTEM_WINDOWS_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.
|
||||
|
||||
@@ -25,16 +18,6 @@
|
||||
#ifdef BOOST_WINDOWS_API
|
||||
|
||||
#include <boost/system/error_code.hpp>
|
||||
|
||||
//// Neither MinGW or Cygwin versions of winerror.h work if used alone, so on
|
||||
//// either of those platforms include the full windows.h
|
||||
//
|
||||
//#if defined(__MINGW32__) || defined(__CYGWIN__)
|
||||
//#include <windows.h>
|
||||
//#else
|
||||
//#include <winerror.h>
|
||||
//#endif
|
||||
|
||||
#include <boost/winapi/error_codes.hpp>
|
||||
|
||||
namespace boost
|
||||
@@ -89,7 +72,8 @@ namespace boost
|
||||
wrong_disk = boost::winapi::ERROR_WRONG_DISK_,
|
||||
sharing_buffer_exceeded = boost::winapi::ERROR_SHARING_BUFFER_EXCEEDED_,
|
||||
handle_eof = boost::winapi::ERROR_HANDLE_EOF_,
|
||||
handle_disk_full= boost::winapi::ERROR_HANDLE_DISK_FULL_,
|
||||
handle_disk_full = boost::winapi::ERROR_HANDLE_DISK_FULL_,
|
||||
not_supported = boost::winapi::ERROR_NOT_SUPPORTED_,
|
||||
rem_not_list = boost::winapi::ERROR_REM_NOT_LIST_,
|
||||
dup_name = boost::winapi::ERROR_DUP_NAME_,
|
||||
bad_net_path = boost::winapi::ERROR_BAD_NETPATH_,
|
||||
@@ -101,7 +85,7 @@ namespace boost
|
||||
broken_pipe = boost::winapi::ERROR_BROKEN_PIPE_,
|
||||
open_failed = boost::winapi::ERROR_OPEN_FAILED_,
|
||||
buffer_overflow = boost::winapi::ERROR_BUFFER_OVERFLOW_,
|
||||
disk_full= boost::winapi::ERROR_DISK_FULL_,
|
||||
disk_full = boost::winapi::ERROR_DISK_FULL_,
|
||||
// ...
|
||||
lock_failed = boost::winapi::ERROR_LOCK_FAILED_,
|
||||
busy = boost::winapi::ERROR_BUSY_,
|
||||
|
||||
@@ -8,8 +8,8 @@ Automatic redirection failed, please go to
|
||||
</body>
|
||||
</html>
|
||||
<!--
|
||||
<EFBFBD> Copyright Beman Dawes, 2001
|
||||
© Copyright Beman Dawes, 2001
|
||||
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
|
||||
https://www.boost.org/LICENSE_1_0.txt
|
||||
-->
|
||||
|
||||
@@ -4,8 +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": "11"
|
||||
}
|
||||
|
||||
@@ -1,31 +0,0 @@
|
||||
// error_code stub implementation, for compatibility only
|
||||
|
||||
// Copyright Beman Dawes 2002, 2006
|
||||
// Copyright Peter Dimov 2018
|
||||
|
||||
// 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
|
||||
|
||||
//----------------------------------------------------------------------------//
|
||||
|
||||
// define BOOST_SYSTEM_SOURCE so that <boost/system/config.hpp> knows
|
||||
// the library is being built (possibly exporting rather than importing code)
|
||||
#define BOOST_SYSTEM_SOURCE
|
||||
|
||||
#include <boost/system/config.hpp>
|
||||
|
||||
namespace boost
|
||||
{
|
||||
|
||||
namespace system
|
||||
{
|
||||
|
||||
BOOST_SYSTEM_DECL void dummy_exported_function()
|
||||
{
|
||||
}
|
||||
|
||||
} // namespace system
|
||||
|
||||
} // namespace boost
|
||||
@@ -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()
|
||||
|
||||
@@ -69,3 +70,111 @@ lib(boost_system_std_single_instance_lib2 STD_SINGLE_INSTANCE_DYN_LINK std_singl
|
||||
|
||||
system_run(std_single_instance_test.cpp std_single_instance_1.cpp std_single_instance_2.cpp)
|
||||
boost_test(SOURCES std_single_instance_test.cpp NAME std_single_instance_test_lib LINK_LIBRARIES boost_system_std_single_instance_lib1 boost_system_std_single_instance_lib2)
|
||||
|
||||
boost_test(TYPE run SOURCES is_error_code_enum_test.cpp)
|
||||
boost_test(TYPE run SOURCES is_error_condition_enum_test.cpp)
|
||||
boost_test(TYPE run SOURCES errc_test.cpp)
|
||||
boost_test(TYPE run SOURCES errc_test2.cpp)
|
||||
boost_test(TYPE run SOURCES error_category_test2.cpp)
|
||||
boost_test(TYPE run SOURCES error_condition_test.cpp)
|
||||
boost_test(TYPE run SOURCES error_condition_test2.cpp)
|
||||
boost_test(TYPE run SOURCES generic_category_test2.cpp)
|
||||
boost_test(TYPE run SOURCES generic_category_test3.cpp)
|
||||
boost_test(TYPE run SOURCES system_category_test2.cpp)
|
||||
boost_test(TYPE run SOURCES system_category_test3.cpp)
|
||||
|
||||
boost_test(TYPE run SOURCES windows_error_test.cpp)
|
||||
boost_test(TYPE run SOURCES linux_error_test.cpp)
|
||||
|
||||
boost_test(TYPE link SOURCES errc_test3.cpp)
|
||||
|
||||
boost_test(TYPE run SOURCES snprintf_test.cpp)
|
||||
|
||||
boost_test(TYPE run SOURCES std_interop_test2.cpp)
|
||||
boost_test(TYPE run SOURCES std_interop_test3.cpp)
|
||||
boost_test(TYPE run SOURCES std_interop_test4.cpp)
|
||||
boost_test(TYPE run SOURCES std_interop_test5.cpp)
|
||||
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
|
||||
|
||||
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)
|
||||
boost_test(TYPE run SOURCES result_or_value.cpp)
|
||||
boost_test(TYPE run SOURCES result_or_fn0v.cpp)
|
||||
boost_test(TYPE run SOURCES result_or_fn0r.cpp)
|
||||
boost_test(TYPE run SOURCES result_and_fn1v.cpp)
|
||||
boost_test(TYPE run SOURCES result_and_fn1r.cpp)
|
||||
boost_test(TYPE run SOURCES result_and_eq_fn1v.cpp)
|
||||
boost_test(TYPE run SOURCES result_and_eq_fn1r.cpp)
|
||||
boost_test(TYPE run SOURCES result_in_place_use.cpp)
|
||||
boost_test(TYPE run SOURCES result_or_eq_value.cpp)
|
||||
boost_test(TYPE run SOURCES result_or_eq_fn0v.cpp)
|
||||
boost_test(TYPE run SOURCES result_or_eq_fn0r.cpp)
|
||||
|
||||
boost_test(TYPE run SOURCES result_and_mfn1v.cpp)
|
||||
boost_test(TYPE run SOURCES result_and_mfn1r.cpp)
|
||||
|
||||
134
test/Jamfile.v2
134
test/Jamfile.v2
@@ -1,7 +1,7 @@
|
||||
# Boost System Library test Jamfile
|
||||
|
||||
# Copyright Beman Dawes 2003, 2006
|
||||
# Copyright 2017-2019 Peter Dimov
|
||||
# Copyright 2017-2021 Peter Dimov
|
||||
|
||||
# Distributed under the Boost Software License, Version 1.0.
|
||||
# See accompanying file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt
|
||||
@@ -10,6 +10,23 @@
|
||||
|
||||
import testing ;
|
||||
|
||||
project
|
||||
: default-build
|
||||
|
||||
<warnings>extra
|
||||
|
||||
: requirements
|
||||
|
||||
<library>/boost/system//boost_system
|
||||
<library>/boost/core//boost_core
|
||||
|
||||
<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 + )
|
||||
{
|
||||
local result ;
|
||||
@@ -19,6 +36,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) ;
|
||||
}
|
||||
@@ -47,7 +65,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 ;
|
||||
|
||||
@@ -56,13 +78,15 @@ system-run generic_category_test.cpp ;
|
||||
system-run system_category_test.cpp ;
|
||||
system-run after_main_test.cpp ;
|
||||
system-run failed_test.cpp ;
|
||||
system-run failed_constexpr_test.cpp ;
|
||||
run failed_constexpr_test.cpp : : :
|
||||
# GCC w/ UBSAN doesn't consider `cat_ != 0` a constant expression
|
||||
<toolset>gcc,<undefined-sanitizer>norecover:<build>no ;
|
||||
|
||||
# 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 ;
|
||||
@@ -87,5 +111,103 @@ run system_category_test2.cpp ;
|
||||
run system_category_test3.cpp ;
|
||||
|
||||
run windows_error_test.cpp ;
|
||||
run cygwin_error_test.cpp ;
|
||||
run linux_error_test.cpp ;
|
||||
|
||||
link errc_test3.cpp ;
|
||||
|
||||
run snprintf_test.cpp ;
|
||||
|
||||
run std_interop_test2.cpp ;
|
||||
run std_interop_test3.cpp ;
|
||||
run std_interop_test4.cpp ;
|
||||
run std_interop_test5.cpp
|
||||
: : :
|
||||
# crash on xenial, but the real g++ 4.8 on both centos 7 and trusty works
|
||||
<toolset>gcc-4.8:<build>no
|
||||
<toolset>gcc-4.9:<build>no
|
||||
;
|
||||
|
||||
run std_interop_test6.cpp ;
|
||||
run std_interop_test7.cpp ;
|
||||
run std_interop_test8.cpp ;
|
||||
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
|
||||
|
||||
run result_default_construct.cpp ;
|
||||
run result_value_construct.cpp ;
|
||||
run result_error_construct.cpp ;
|
||||
run result_copy_construct.cpp ;
|
||||
run result_move_construct.cpp ;
|
||||
run result_copy_assign.cpp ;
|
||||
run result_move_assign.cpp ;
|
||||
run result_value_access.cpp ;
|
||||
run result_error_access.cpp ;
|
||||
run result_swap.cpp : : : <toolset>gcc-10:<cxxflags>"-Wno-maybe-uninitialized" ;
|
||||
run result_eq.cpp ;
|
||||
run result_range_for.cpp ;
|
||||
run result_value_construct2.cpp ;
|
||||
run result_error_construct2.cpp ;
|
||||
run result_errc_construct.cpp ;
|
||||
run result_convert_construct.cpp ;
|
||||
run result_typedefs.cpp ;
|
||||
run result_value_construct3.cpp ;
|
||||
run result_error_construct3.cpp ;
|
||||
run result_emplace.cpp ;
|
||||
run result_error_construct4.cpp ;
|
||||
run result_value_construct4.cpp ;
|
||||
run result_value_construct5.cpp ;
|
||||
run result_error_move.cpp ;
|
||||
run result_value_construct6.cpp ;
|
||||
run result_value_construct7.cpp ;
|
||||
run result_error_construct5.cpp ;
|
||||
run result_or_value.cpp ;
|
||||
run result_or_fn0v.cpp ;
|
||||
run result_or_fn0r.cpp ;
|
||||
run result_and_fn1v.cpp ;
|
||||
run result_and_fn1r.cpp ;
|
||||
run result_and_eq_fn1v.cpp ;
|
||||
run result_and_eq_fn1r.cpp ;
|
||||
run result_in_place_use.cpp ;
|
||||
run result_or_eq_value.cpp ;
|
||||
run result_or_eq_fn0v.cpp ;
|
||||
run result_or_eq_fn0r.cpp ;
|
||||
|
||||
run result_and_mfn1v.cpp ;
|
||||
run result_and_mfn1r.cpp ;
|
||||
|
||||
@@ -5,8 +5,13 @@
|
||||
#include <boost/system/error_code.hpp>
|
||||
#include <boost/core/lightweight_test.hpp>
|
||||
#include <boost/core/quick_exit.hpp>
|
||||
#include <boost/config.hpp>
|
||||
#include <cerrno>
|
||||
|
||||
#if defined(BOOST_MSVC)
|
||||
# pragma warning(disable: 4722) // Z::~Z never returns
|
||||
#endif
|
||||
|
||||
using namespace boost::system;
|
||||
|
||||
struct Z
|
||||
@@ -27,4 +32,6 @@ static error_code e2( ENOENT, generic_category() );
|
||||
|
||||
int main()
|
||||
{
|
||||
(void)e1;
|
||||
(void)e2;
|
||||
}
|
||||
|
||||
@@ -7,12 +7,11 @@ cmake_minimum_required(VERSION 3.5...3.16)
|
||||
project(cmake_install_test LANGUAGES CXX)
|
||||
|
||||
find_package(boost_system REQUIRED)
|
||||
find_package(boost_core REQUIRED)
|
||||
|
||||
add_executable(quick ../quick.cpp)
|
||||
target_link_libraries(quick Boost::system Boost::core)
|
||||
add_executable(main main.cpp)
|
||||
target_link_libraries(main Boost::system)
|
||||
|
||||
enable_testing()
|
||||
add_test(quick quick)
|
||||
add_test(main main)
|
||||
|
||||
add_custom_target(check COMMAND ${CMAKE_CTEST_COMMAND} --output-on-failure -C $<CONFIG>)
|
||||
add_custom_target(check VERBATIM COMMAND ${CMAKE_CTEST_COMMAND} --output-on-failure -C $<CONFIG>)
|
||||
|
||||
44
test/cmake_install_test/main.cpp
Normal file
44
test/cmake_install_test/main.cpp
Normal file
@@ -0,0 +1,44 @@
|
||||
// Copyright 2017, 2021 Peter Dimov.
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// https://www.boost.org/LICENSE_1_0.txt
|
||||
|
||||
// See library home page at http://www.boost.org/libs/system
|
||||
|
||||
#include <boost/system.hpp>
|
||||
#include <cassert>
|
||||
#include <cerrno>
|
||||
|
||||
#define BOOST_TEST(expr) assert(expr)
|
||||
#define BOOST_TEST_EQ(x1, x2) assert((x1)==(x2))
|
||||
|
||||
int main()
|
||||
{
|
||||
boost::system::error_category const & bt = boost::system::generic_category();
|
||||
|
||||
int ev = ENOENT;
|
||||
|
||||
boost::system::error_code bc( ev, bt );
|
||||
|
||||
BOOST_TEST_EQ( bc.value(), ev );
|
||||
BOOST_TEST_EQ( &bc.category(), &bt );
|
||||
|
||||
boost::system::error_condition bn = bt.default_error_condition( ev );
|
||||
|
||||
BOOST_TEST_EQ( bn.value(), ev );
|
||||
BOOST_TEST_EQ( &bn.category(), &bt );
|
||||
|
||||
BOOST_TEST( bt.equivalent( ev, bn ) );
|
||||
|
||||
BOOST_TEST( bc == bn );
|
||||
|
||||
boost::system::error_code bc2 = make_error_code( boost::system::errc::no_such_file_or_directory );
|
||||
|
||||
BOOST_TEST_EQ( bc2, bc );
|
||||
BOOST_TEST_EQ( bc2.value(), ev );
|
||||
BOOST_TEST_EQ( &bc.category(), &bt );
|
||||
|
||||
boost::system::system_error x( bc, "prefix" );
|
||||
|
||||
BOOST_TEST_EQ( x.code(), bc );
|
||||
BOOST_TEST_EQ( std::string( x.what() ), "prefix: " + bc.what() );
|
||||
}
|
||||
@@ -1,16 +1,21 @@
|
||||
# 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)
|
||||
|
||||
add_subdirectory(../.. boostorg/system)
|
||||
add_subdirectory(../../../assert boostorg/assert)
|
||||
add_subdirectory(../../../compat boostorg/compat)
|
||||
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 +24,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 VERBATIM COMMAND ${CMAKE_CTEST_COMMAND} --output-on-failure --no-tests=error -C $<CONFIG>)
|
||||
|
||||
@@ -50,16 +50,6 @@ int main()
|
||||
std::cout << "BOOST_NO_ANSI_APIS is defined" << std::endl;
|
||||
#else
|
||||
std::cout << "BOOST_NO_ANSI_APIS is not defined" << std::endl;
|
||||
#endif
|
||||
#ifdef BOOST_NO_CXX11_NOEXCEPT
|
||||
std::cout << "BOOST_NO_CXX11_NOEXCEPT is defined" << std::endl;
|
||||
#else
|
||||
std::cout << "BOOST_NO_CXX11_NOEXCEPT is not defined" << std::endl;
|
||||
#endif
|
||||
#ifdef BOOST_NO_CXX11_EXPLICIT_CONVERSION_OPERATORS
|
||||
std::cout << "BOOST_NO_CXX11_EXPLICIT_CONVERSION_OPERATORS is defined" << std::endl;
|
||||
#else
|
||||
std::cout << "BOOST_NO_CXX11_EXPLICIT_CONVERSION_OPERATORS is not defined" << std::endl;
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
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
|
||||
@@ -1,29 +0,0 @@
|
||||
// Copyright 2020 Peter Dimov
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// https://www.boost.org/LICENSE_1_0.txt
|
||||
|
||||
#include <boost/system/cygwin_error.hpp>
|
||||
#include <boost/config/pragma_message.hpp>
|
||||
|
||||
#if !defined(__CYGWIN__)
|
||||
|
||||
BOOST_PRAGMA_MESSAGE( "Skipping test, __CYGWIN__ is not defined" )
|
||||
int main() {}
|
||||
|
||||
#else
|
||||
|
||||
#include <boost/core/lightweight_test.hpp>
|
||||
|
||||
int main()
|
||||
{
|
||||
namespace sys = boost::system;
|
||||
|
||||
sys::error_code ec = sys::cygwin_error::no_package;
|
||||
|
||||
BOOST_TEST_EQ( ec, sys::cygwin_error::no_package );
|
||||
BOOST_TEST_EQ( ec, sys::error_code( ENOPKG, sys::system_category() ) );
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
|
||||
#endif
|
||||
126
test/ec_hash_value_test.cpp
Normal file
126
test/ec_hash_value_test.cpp
Normal file
@@ -0,0 +1,126 @@
|
||||
// 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>
|
||||
#include <system_error>
|
||||
|
||||
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 ) );
|
||||
}
|
||||
|
||||
// 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 ) );
|
||||
}
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
112
test/ec_location_test.cpp
Normal file
112
test/ec_location_test.cpp
Normal file
@@ -0,0 +1,112 @@
|
||||
// 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>
|
||||
|
||||
int main()
|
||||
{
|
||||
int const val = ENOENT;
|
||||
boost::system::error_category const & cat = boost::system::generic_category();
|
||||
|
||||
{
|
||||
boost::system::error_code ec( val, cat );
|
||||
|
||||
BOOST_TEST_EQ( ec.value(), val );
|
||||
BOOST_TEST_EQ( &ec.category(), &cat );
|
||||
|
||||
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;
|
||||
|
||||
boost::system::error_code ec( val, cat, &loc );
|
||||
|
||||
BOOST_TEST_EQ( ec.value(), val );
|
||||
BOOST_TEST_EQ( &ec.category(), &cat );
|
||||
|
||||
BOOST_TEST( ec.failed() );
|
||||
|
||||
BOOST_TEST( ec.has_location() );
|
||||
BOOST_TEST_EQ( ec.location().line(), 27 );
|
||||
}
|
||||
|
||||
{
|
||||
boost::system::error_code ec;
|
||||
|
||||
BOOST_TEST_EQ( ec.value(), 0 );
|
||||
BOOST_TEST_EQ( &ec.category(), &boost::system::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 = boost::system::error_code( val, cat, &loc );
|
||||
|
||||
BOOST_TEST_EQ( ec.value(), val );
|
||||
BOOST_TEST_EQ( &ec.category(), &cat );
|
||||
|
||||
BOOST_TEST( ec.failed() );
|
||||
|
||||
BOOST_TEST( ec.has_location() );
|
||||
BOOST_TEST_EQ( ec.location().line(), 51 );
|
||||
}
|
||||
|
||||
{
|
||||
boost::system::error_code ec;
|
||||
|
||||
BOOST_TEST_EQ( ec.value(), 0 );
|
||||
BOOST_TEST_EQ( &ec.category(), &boost::system::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( val, cat, &loc );
|
||||
|
||||
BOOST_TEST_EQ( ec.value(), val );
|
||||
BOOST_TEST_EQ( &ec.category(), &cat );
|
||||
|
||||
BOOST_TEST( ec.failed() );
|
||||
|
||||
BOOST_TEST( ec.has_location() );
|
||||
BOOST_TEST_EQ( ec.location().line(), 75 );
|
||||
}
|
||||
|
||||
{
|
||||
std::error_code e2( val, std::generic_category() );
|
||||
|
||||
boost::system::error_code ec( e2 );
|
||||
|
||||
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( val, cat, &loc );
|
||||
|
||||
BOOST_TEST_EQ( ec.value(), val );
|
||||
BOOST_TEST_EQ( &ec.category(), &cat );
|
||||
|
||||
BOOST_TEST( ec.failed() );
|
||||
|
||||
BOOST_TEST( ec.has_location() );
|
||||
BOOST_TEST_EQ( ec.location().line(), 98 );
|
||||
}
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
279
test/ec_location_test2.cpp
Normal file
279
test/ec_location_test2.cpp
Normal file
@@ -0,0 +1,279 @@
|
||||
// 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() );
|
||||
}
|
||||
|
||||
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() );
|
||||
}
|
||||
|
||||
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(), 73 );
|
||||
}
|
||||
|
||||
{
|
||||
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(), 123 );
|
||||
}
|
||||
|
||||
{
|
||||
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(), 171 );
|
||||
}
|
||||
|
||||
{
|
||||
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 );
|
||||
}
|
||||
|
||||
{
|
||||
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 );
|
||||
}
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
86
test/ec_location_test3.cpp
Normal file
86
test/ec_location_test3.cpp
Normal file
@@ -0,0 +1,86 @@
|
||||
// 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() );
|
||||
}
|
||||
|
||||
{
|
||||
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() );
|
||||
}
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
89
test/ec_location_test4.cpp
Normal file
89
test/ec_location_test4.cpp
Normal file
@@ -0,0 +1,89 @@
|
||||
// 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() );
|
||||
}
|
||||
|
||||
{
|
||||
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() );
|
||||
}
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
87
test/ec_what_test.cpp
Normal file
87
test/ec_what_test.cpp
Normal file
@@ -0,0 +1,87 @@
|
||||
// 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() + "]" );
|
||||
}
|
||||
|
||||
{
|
||||
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]" );
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
34
test/errc_test3.cpp
Normal file
34
test/errc_test3.cpp
Normal file
@@ -0,0 +1,34 @@
|
||||
// Copyright 2021 Peter Dimov.
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// http://www.boost.org/LICENSE_1_0.txt
|
||||
|
||||
#include <boost/system/errc.hpp>
|
||||
|
||||
int main()
|
||||
{
|
||||
make_error_code( boost::system::errc::success ).value();
|
||||
make_error_code( boost::system::errc::success ).category();
|
||||
make_error_code( boost::system::errc::success ).default_error_condition();
|
||||
make_error_code( boost::system::errc::success ).message();
|
||||
make_error_code( boost::system::errc::success ).failed();
|
||||
make_error_code( boost::system::errc::success ).clear();
|
||||
|
||||
make_error_condition( boost::system::errc::success ).value();
|
||||
make_error_condition( boost::system::errc::success ).category();
|
||||
make_error_condition( boost::system::errc::success ).message();
|
||||
make_error_condition( boost::system::errc::success ).failed();
|
||||
make_error_condition( boost::system::errc::success ).clear();
|
||||
|
||||
make_error_code( boost::system::errc::no_such_file_or_directory ).value();
|
||||
make_error_code( boost::system::errc::no_such_file_or_directory ).category();
|
||||
make_error_code( boost::system::errc::no_such_file_or_directory ).default_error_condition();
|
||||
make_error_code( boost::system::errc::no_such_file_or_directory ).message();
|
||||
make_error_code( boost::system::errc::no_such_file_or_directory ).failed();
|
||||
make_error_code( boost::system::errc::no_such_file_or_directory ).clear();
|
||||
|
||||
make_error_condition( boost::system::errc::no_such_file_or_directory ).value();
|
||||
make_error_condition( boost::system::errc::no_such_file_or_directory ).category();
|
||||
make_error_condition( boost::system::errc::no_such_file_or_directory ).message();
|
||||
make_error_condition( boost::system::errc::no_such_file_or_directory ).failed();
|
||||
make_error_condition( boost::system::errc::no_such_file_or_directory ).clear();
|
||||
}
|
||||
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>
|
||||
|
||||
//
|
||||
@@ -23,7 +21,7 @@ class user_category: public sys::error_category
|
||||
{
|
||||
public:
|
||||
|
||||
virtual const char * name() const BOOST_NOEXCEPT
|
||||
virtual const char * name() const noexcept
|
||||
{
|
||||
return "user";
|
||||
}
|
||||
@@ -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>
|
||||
|
||||
//
|
||||
@@ -23,7 +21,7 @@ class user_category: public sys::error_category
|
||||
{
|
||||
public:
|
||||
|
||||
virtual const char * name() const BOOST_NOEXCEPT
|
||||
virtual const char * name() const noexcept
|
||||
{
|
||||
return "user";
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -108,6 +108,7 @@ int main( int, char ** )
|
||||
|
||||
std::cout << "Conversion use cases...\n";
|
||||
error_condition x1( errc::file_exists );
|
||||
(void)x1;
|
||||
//error_code x2( errc::file_exists ); // should fail to compile
|
||||
make_error_code(errc::file_exists);
|
||||
make_error_condition(errc::file_exists);
|
||||
|
||||
224
test/error_code_test2.cpp
Normal file
224
test/error_code_test2.cpp
Normal file
@@ -0,0 +1,224 @@
|
||||
// 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[ 4096 ], buffer2[ 4096 ];
|
||||
|
||||
{
|
||||
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(), buffer2, sizeof( buffer2 ) ) );
|
||||
BOOST_TEST_CSTR_EQ( ec.message( buffer, sizeof( buffer ) ), ec.message().c_str() );
|
||||
|
||||
{
|
||||
char const* msg = ec.message( nullptr, 0 );
|
||||
|
||||
if( msg != nullptr )
|
||||
{
|
||||
BOOST_TEST_CSTR_EQ( msg, ec.message().c_str() );
|
||||
}
|
||||
}
|
||||
|
||||
BOOST_TEST( !ec.failed() );
|
||||
BOOST_TEST( !ec );
|
||||
|
||||
BOOST_TEST_EQ( ec.to_string(), std::string( "system:0" ) );
|
||||
}
|
||||
|
||||
{
|
||||
sys::error_code ec;
|
||||
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(), buffer2, sizeof( buffer2 ) ) );
|
||||
BOOST_TEST_CSTR_EQ( ec2.message( buffer, sizeof( buffer ) ), ec2.message().c_str() );
|
||||
|
||||
{
|
||||
char const* msg = ec2.message( nullptr, 0 );
|
||||
|
||||
if( msg != nullptr )
|
||||
{
|
||||
BOOST_TEST_CSTR_EQ( msg, ec2.message().c_str() );
|
||||
}
|
||||
}
|
||||
|
||||
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 ec;
|
||||
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(), buffer2, sizeof( buffer2 ) ) );
|
||||
BOOST_TEST_CSTR_EQ( ec2.message( buffer, sizeof( buffer ) ), ec2.message().c_str() );
|
||||
|
||||
{
|
||||
char const* msg = ec2.message( nullptr, 0 );
|
||||
|
||||
if( msg != nullptr )
|
||||
{
|
||||
BOOST_TEST_CSTR_EQ( msg, ec2.message().c_str() );
|
||||
}
|
||||
}
|
||||
|
||||
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(), buffer2, sizeof( buffer2 ) ) );
|
||||
BOOST_TEST_CSTR_EQ( ec2.message( buffer, sizeof( buffer ) ), ec2.message().c_str() );
|
||||
|
||||
{
|
||||
char const* msg = ec2.message( nullptr, 0 );
|
||||
|
||||
if( msg != nullptr )
|
||||
{
|
||||
BOOST_TEST_CSTR_EQ( msg, ec2.message().c_str() );
|
||||
}
|
||||
}
|
||||
|
||||
BOOST_TEST( ec2.failed() );
|
||||
BOOST_TEST( ec2 );
|
||||
BOOST_TEST_NOT( !ec2 );
|
||||
|
||||
sys::error_code ec;
|
||||
|
||||
BOOST_TEST_NE( ec, ec2 );
|
||||
BOOST_TEST_NOT( ec == ec2 );
|
||||
|
||||
BOOST_TEST_EQ( ec2.to_string(), std::string( "generic:5" ) );
|
||||
}
|
||||
|
||||
{
|
||||
sys::error_code ec2( -4, sys::generic_category() );
|
||||
|
||||
BOOST_TEST_EQ( ec2.value(), -4 );
|
||||
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(), buffer2, sizeof( buffer2 ) ) );
|
||||
BOOST_TEST_CSTR_EQ( ec2.message( buffer, sizeof( buffer ) ), ec2.message().c_str() );
|
||||
|
||||
{
|
||||
char const* msg = ec2.message( nullptr, 0 );
|
||||
|
||||
if( msg != nullptr )
|
||||
{
|
||||
BOOST_TEST_CSTR_EQ( msg, ec2.message().c_str() );
|
||||
}
|
||||
}
|
||||
|
||||
BOOST_TEST( ec2.failed() );
|
||||
BOOST_TEST( ec2 );
|
||||
BOOST_TEST_NOT( !ec2 );
|
||||
|
||||
sys::error_code ec;
|
||||
|
||||
BOOST_TEST_NE( ec, ec2 );
|
||||
BOOST_TEST_NOT( ec == ec2 );
|
||||
|
||||
BOOST_TEST_EQ( ec2.to_string(), std::string( "generic:-4" ) );
|
||||
}
|
||||
|
||||
{
|
||||
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(), buffer2, sizeof( buffer2 ) ) );
|
||||
BOOST_TEST_CSTR_EQ( ec2.message( buffer, sizeof( buffer ) ), ec2.message().c_str() );
|
||||
|
||||
{
|
||||
char const* msg = ec2.message( nullptr, 0 );
|
||||
|
||||
if( msg != nullptr )
|
||||
{
|
||||
BOOST_TEST_CSTR_EQ( msg, ec2.message().c_str() );
|
||||
}
|
||||
}
|
||||
|
||||
BOOST_TEST( ec2.failed() );
|
||||
BOOST_TEST( ec2 );
|
||||
BOOST_TEST_NOT( !ec2 );
|
||||
|
||||
sys::error_code ec;
|
||||
|
||||
BOOST_TEST_NE( ec, ec2 );
|
||||
BOOST_TEST_NOT( ec == ec2 );
|
||||
|
||||
BOOST_TEST_EQ( ec2.to_string(), std::string( "system:5" ) );
|
||||
}
|
||||
|
||||
{
|
||||
sys::error_code ec2( -4, sys::system_category() );
|
||||
|
||||
BOOST_TEST_EQ( ec2.value(), -4 );
|
||||
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(), buffer2, sizeof( buffer2 ) ) );
|
||||
BOOST_TEST_CSTR_EQ( ec2.message( buffer, sizeof( buffer ) ), ec2.message().c_str() );
|
||||
|
||||
{
|
||||
char const* msg = ec2.message( nullptr, 0 );
|
||||
|
||||
if( msg != nullptr )
|
||||
{
|
||||
BOOST_TEST_CSTR_EQ( msg, ec2.message().c_str() );
|
||||
}
|
||||
}
|
||||
|
||||
BOOST_TEST( ec2.failed() );
|
||||
BOOST_TEST( ec2 );
|
||||
BOOST_TEST_NOT( !ec2 );
|
||||
|
||||
sys::error_code ec;
|
||||
|
||||
BOOST_TEST_NE( ec, ec2 );
|
||||
BOOST_TEST_NOT( ec == ec2 );
|
||||
|
||||
BOOST_TEST_EQ( ec2.to_string(), std::string( "system:-4" ) );
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
224
test/error_condition_test3.cpp
Normal file
224
test/error_condition_test3.cpp
Normal file
@@ -0,0 +1,224 @@
|
||||
// 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[ 4096 ], buffer2[ 4096 ];
|
||||
|
||||
{
|
||||
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(), buffer2, sizeof( buffer2 ) ) );
|
||||
BOOST_TEST_CSTR_EQ( en.message( buffer, sizeof( buffer ) ), en.message().c_str() );
|
||||
|
||||
{
|
||||
char const* msg = en.message( nullptr, 0 );
|
||||
|
||||
if( msg != nullptr )
|
||||
{
|
||||
BOOST_TEST_CSTR_EQ( msg, en.message().c_str() );
|
||||
}
|
||||
}
|
||||
|
||||
BOOST_TEST( !en.failed() );
|
||||
BOOST_TEST( !en );
|
||||
|
||||
BOOST_TEST_EQ( en.to_string(), std::string( "cond:generic:0" ) );
|
||||
}
|
||||
|
||||
{
|
||||
sys::error_condition en;
|
||||
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(), buffer2, sizeof( buffer2 ) ) );
|
||||
BOOST_TEST_CSTR_EQ( en2.message( buffer, sizeof( buffer ) ), en2.message().c_str() );
|
||||
|
||||
{
|
||||
char const* msg = en2.message( nullptr, 0 );
|
||||
|
||||
if( msg != nullptr )
|
||||
{
|
||||
BOOST_TEST_CSTR_EQ( msg, en2.message().c_str() );
|
||||
}
|
||||
}
|
||||
|
||||
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 en;
|
||||
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(), buffer2, sizeof( buffer2 ) ) );
|
||||
BOOST_TEST_CSTR_EQ( en2.message( buffer, sizeof( buffer ) ), en2.message().c_str() );
|
||||
|
||||
{
|
||||
char const* msg = en2.message( nullptr, 0 );
|
||||
|
||||
if( msg != nullptr )
|
||||
{
|
||||
BOOST_TEST_CSTR_EQ( msg, en2.message().c_str() );
|
||||
}
|
||||
}
|
||||
|
||||
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(), buffer2, sizeof( buffer2 ) ) );
|
||||
BOOST_TEST_CSTR_EQ( en2.message( buffer, sizeof( buffer ) ), en2.message().c_str() );
|
||||
|
||||
{
|
||||
char const* msg = en2.message( nullptr, 0 );
|
||||
|
||||
if( msg != nullptr )
|
||||
{
|
||||
BOOST_TEST_CSTR_EQ( msg, en2.message().c_str() );
|
||||
}
|
||||
}
|
||||
|
||||
BOOST_TEST( en2.failed() );
|
||||
BOOST_TEST( en2 );
|
||||
BOOST_TEST_NOT( !en2 );
|
||||
|
||||
sys::error_condition en;
|
||||
|
||||
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( -4, sys::generic_category() );
|
||||
|
||||
BOOST_TEST_EQ( en2.value(), -4 );
|
||||
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(), buffer2, sizeof( buffer2 ) ) );
|
||||
BOOST_TEST_CSTR_EQ( en2.message( buffer, sizeof( buffer ) ), en2.message().c_str() );
|
||||
|
||||
{
|
||||
char const* msg = en2.message( nullptr, 0 );
|
||||
|
||||
if( msg != nullptr )
|
||||
{
|
||||
BOOST_TEST_CSTR_EQ( msg, en2.message().c_str() );
|
||||
}
|
||||
}
|
||||
|
||||
BOOST_TEST( en2.failed() );
|
||||
BOOST_TEST( en2 );
|
||||
BOOST_TEST_NOT( !en2 );
|
||||
|
||||
sys::error_condition en;
|
||||
|
||||
BOOST_TEST_NE( en, en2 );
|
||||
BOOST_TEST_NOT( en == en2 );
|
||||
|
||||
BOOST_TEST_EQ( en2.to_string(), std::string( "cond:generic:-4" ) );
|
||||
}
|
||||
|
||||
{
|
||||
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(), buffer2, sizeof( buffer2 ) ) );
|
||||
BOOST_TEST_CSTR_EQ( en2.message( buffer, sizeof( buffer ) ), en2.message().c_str() );
|
||||
|
||||
{
|
||||
char const* msg = en2.message( nullptr, 0 );
|
||||
|
||||
if( msg != nullptr )
|
||||
{
|
||||
BOOST_TEST_CSTR_EQ( msg, en2.message().c_str() );
|
||||
}
|
||||
}
|
||||
|
||||
BOOST_TEST( en2.failed() );
|
||||
BOOST_TEST( en2 );
|
||||
BOOST_TEST_NOT( !en2 );
|
||||
|
||||
sys::error_condition en;
|
||||
|
||||
BOOST_TEST_NE( en, en2 );
|
||||
BOOST_TEST_NOT( en == en2 );
|
||||
|
||||
BOOST_TEST_EQ( en2.to_string(), std::string( "cond:system:5" ) );
|
||||
}
|
||||
|
||||
{
|
||||
sys::error_condition en2( -4, sys::system_category() );
|
||||
|
||||
BOOST_TEST_EQ( en2.value(), -4 );
|
||||
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(), buffer2, sizeof( buffer2 ) ) );
|
||||
BOOST_TEST_CSTR_EQ( en2.message( buffer, sizeof( buffer ) ), en2.message().c_str() );
|
||||
|
||||
{
|
||||
char const* msg = en2.message( nullptr, 0 );
|
||||
|
||||
if( msg != nullptr )
|
||||
{
|
||||
BOOST_TEST_CSTR_EQ( msg, en2.message().c_str() );
|
||||
}
|
||||
}
|
||||
|
||||
BOOST_TEST( en2.failed() );
|
||||
BOOST_TEST( en2 );
|
||||
BOOST_TEST_NOT( !en2 );
|
||||
|
||||
sys::error_condition en;
|
||||
|
||||
BOOST_TEST_NE( en, en2 );
|
||||
BOOST_TEST_NOT( en == en2 );
|
||||
|
||||
BOOST_TEST_EQ( en2.to_string(), std::string( "cond:system:-4" ) );
|
||||
}
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
@@ -33,6 +33,12 @@ BOOST_STATIC_ASSERT( !ec3.failed() );
|
||||
BOOST_STATIC_ASSERT( ec3? false: true );
|
||||
BOOST_STATIC_ASSERT( !ec3 );
|
||||
|
||||
#if defined(__GNUC__) && __GNUC__ == 7 && __cplusplus == 201703L
|
||||
|
||||
// 'cat_' is not a constant expression
|
||||
|
||||
#else
|
||||
|
||||
constexpr error_condition en1( 1, system_category() );
|
||||
|
||||
BOOST_STATIC_ASSERT( en1.failed() );
|
||||
@@ -51,6 +57,8 @@ BOOST_STATIC_ASSERT( !en3.failed() );
|
||||
BOOST_STATIC_ASSERT( en3? false: true );
|
||||
BOOST_STATIC_ASSERT( !en3 );
|
||||
|
||||
#endif
|
||||
|
||||
int main()
|
||||
{
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
@@ -15,11 +13,11 @@ struct http_category_impl: public error_category
|
||||
{
|
||||
// clang++ 3.8 and below: initialization of const object
|
||||
// requires a user-provided default constructor
|
||||
BOOST_SYSTEM_CONSTEXPR http_category_impl() BOOST_NOEXCEPT
|
||||
BOOST_SYSTEM_CONSTEXPR http_category_impl() noexcept
|
||||
{
|
||||
}
|
||||
|
||||
char const * name() const BOOST_NOEXCEPT
|
||||
char const * name() const noexcept
|
||||
{
|
||||
return "http";
|
||||
}
|
||||
@@ -28,11 +26,11 @@ 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;
|
||||
}
|
||||
|
||||
bool failed( int ev ) const BOOST_NOEXCEPT
|
||||
bool failed( int ev ) const noexcept
|
||||
{
|
||||
return !( ev >= 200 && ev < 300 );
|
||||
}
|
||||
@@ -120,30 +118,18 @@ template<class Ec> void test()
|
||||
ec.assign( 0, generic_category() );
|
||||
TEST_NOT_FAILED( ec );
|
||||
}
|
||||
}
|
||||
|
||||
template<class Ec> void test2()
|
||||
{
|
||||
Ec ec( 0, http_category() );
|
||||
TEST_FAILED( ec );
|
||||
{
|
||||
Ec ec( 0, http_category() );
|
||||
TEST_FAILED( ec );
|
||||
|
||||
ec.assign( 200, http_category() );
|
||||
TEST_NOT_FAILED( ec );
|
||||
ec.assign( 200, http_category() );
|
||||
TEST_NOT_FAILED( ec );
|
||||
|
||||
ec = Ec( 404, http_category() );
|
||||
TEST_FAILED( ec );
|
||||
}
|
||||
ec = Ec( 404, http_category() );
|
||||
TEST_FAILED( ec );
|
||||
}
|
||||
|
||||
template<class Ec> void test3()
|
||||
{
|
||||
Ec ec( 0, http_category() );
|
||||
BOOST_TEST( ec.failed() );
|
||||
|
||||
ec.assign( 200, http_category() );
|
||||
BOOST_TEST( !ec.failed() );
|
||||
|
||||
ec = Ec( 404, http_category() );
|
||||
BOOST_TEST( ec.failed() );
|
||||
}
|
||||
|
||||
int main()
|
||||
@@ -159,9 +145,7 @@ int main()
|
||||
BOOST_TEST( http_category().failed( 404 ) );
|
||||
|
||||
test<error_code>();
|
||||
test2<error_code>();
|
||||
test<error_condition>();
|
||||
test3<error_condition>();
|
||||
|
||||
{
|
||||
error_condition ec( errc::success );
|
||||
|
||||
@@ -16,8 +16,10 @@
|
||||
#include <boost/detail/lightweight_test.hpp>
|
||||
#include <boost/system/error_code.hpp>
|
||||
|
||||
int main( int, char*[] )
|
||||
int main()
|
||||
{
|
||||
boost::system::error_code ec( 0, boost::system::system_category() );
|
||||
return ::boost::report_errors();
|
||||
boost::system::error_code ec( 0, boost::system::system_category() );
|
||||
(void)ec;
|
||||
|
||||
return ::boost::report_errors();
|
||||
}
|
||||
|
||||
@@ -1,15 +1,10 @@
|
||||
|
||||
// Copyright 2017 Peter Dimov.
|
||||
//
|
||||
// Copyright 2017, 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
|
||||
// https://www.boost.org/LICENSE_1_0.txt
|
||||
|
||||
// See library home page at http://www.boost.org/libs/system
|
||||
|
||||
#include <boost/system/system_error.hpp>
|
||||
#include <boost/system/error_code.hpp>
|
||||
#include <boost/system.hpp>
|
||||
#include <boost/core/lightweight_test.hpp>
|
||||
#include <cerrno>
|
||||
|
||||
@@ -33,10 +28,16 @@ int main()
|
||||
|
||||
BOOST_TEST( bc == bn );
|
||||
|
||||
boost::system::error_code bc2 = make_error_code( boost::system::errc::no_such_file_or_directory );
|
||||
|
||||
BOOST_TEST_EQ( bc2, bc );
|
||||
BOOST_TEST_EQ( bc2.value(), ev );
|
||||
BOOST_TEST_EQ( &bc.category(), &bt );
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
149
test/result_and_eq_fn1r.cpp
Normal file
149
test/result_and_eq_fn1r.cpp
Normal file
@@ -0,0 +1,149 @@
|
||||
// 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
|
||||
{
|
||||
int v_;
|
||||
};
|
||||
|
||||
struct Y
|
||||
{
|
||||
int v_;
|
||||
|
||||
explicit Y( int v ): v_( v ) {}
|
||||
Y( X x ): v_( x.v_) {}
|
||||
|
||||
Y( Y const& ) = delete;
|
||||
Y& operator=( Y const& ) = delete;
|
||||
|
||||
Y( Y&& r ): v_( r.v_ )
|
||||
{
|
||||
r.v_ = 0;
|
||||
}
|
||||
|
||||
Y& operator=( Y&& r )
|
||||
{
|
||||
if( &r != this )
|
||||
{
|
||||
v_ = r.v_;
|
||||
r.v_ = 0;
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
};
|
||||
|
||||
struct E
|
||||
{
|
||||
};
|
||||
|
||||
struct E2
|
||||
{
|
||||
E2() {}
|
||||
E2( E ) {}
|
||||
};
|
||||
|
||||
result<int, E> fi( int x )
|
||||
{
|
||||
return 2 * x + 1;
|
||||
}
|
||||
|
||||
result<int, E2> fi2( int )
|
||||
{
|
||||
return E2();
|
||||
}
|
||||
|
||||
result<X, E> fy( Y y )
|
||||
{
|
||||
return X{ 2 * y.v_ + 1 };
|
||||
}
|
||||
|
||||
result<Y, E2> fy2( Y )
|
||||
{
|
||||
return E2();
|
||||
}
|
||||
|
||||
result<int&, E> fri( int& )
|
||||
{
|
||||
static int x = 2;
|
||||
return x;
|
||||
}
|
||||
|
||||
result<int&, E2> fri2( int& )
|
||||
{
|
||||
return E2();
|
||||
}
|
||||
|
||||
result<void, E2> fv()
|
||||
{
|
||||
return {};
|
||||
}
|
||||
|
||||
result<void, E2> fv2()
|
||||
{
|
||||
return E2();
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
result<int, E2> r( 1 );
|
||||
|
||||
r &= fi;
|
||||
BOOST_TEST( r.has_value() ) && BOOST_TEST_EQ( *r, 3 );
|
||||
|
||||
r &= fi2;
|
||||
BOOST_TEST( r.has_error() );
|
||||
|
||||
r &= fi;
|
||||
BOOST_TEST( r.has_error() );
|
||||
}
|
||||
|
||||
{
|
||||
result<Y, E2> r( in_place_value, 1 );
|
||||
|
||||
r &= fy;
|
||||
BOOST_TEST( r.has_value() ) && BOOST_TEST_EQ( r->v_, 3 );
|
||||
|
||||
r &= fy2;
|
||||
BOOST_TEST( r.has_error() );
|
||||
|
||||
r &= fy;
|
||||
BOOST_TEST( r.has_error() );
|
||||
}
|
||||
|
||||
{
|
||||
int x1 = 1;
|
||||
result<int&, E2> r( x1 );
|
||||
|
||||
r &= fri;
|
||||
BOOST_TEST( r.has_value() ) && BOOST_TEST_EQ( &*r, &*fri( x1 ) );
|
||||
|
||||
r &= fri2;
|
||||
BOOST_TEST( r.has_error() );
|
||||
|
||||
r &= fri;
|
||||
BOOST_TEST( r.has_error() );
|
||||
}
|
||||
|
||||
{
|
||||
result<void, E2> r;
|
||||
|
||||
r &= fv;
|
||||
BOOST_TEST( r.has_value() );
|
||||
|
||||
r &= fv2;
|
||||
BOOST_TEST( r.has_error() );
|
||||
|
||||
r &= fv;
|
||||
BOOST_TEST( r.has_error() );
|
||||
}
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
141
test/result_and_eq_fn1v.cpp
Normal file
141
test/result_and_eq_fn1v.cpp
Normal file
@@ -0,0 +1,141 @@
|
||||
// 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
|
||||
{
|
||||
int v_;
|
||||
};
|
||||
|
||||
struct Y
|
||||
{
|
||||
int v_;
|
||||
|
||||
explicit Y( int v ): v_( v ) {}
|
||||
Y( X x ): v_( x.v_) {}
|
||||
|
||||
Y( Y const& ) = delete;
|
||||
Y& operator=( Y const& ) = delete;
|
||||
|
||||
Y( Y&& r ): v_( r.v_ )
|
||||
{
|
||||
r.v_ = 0;
|
||||
}
|
||||
|
||||
Y& operator=( Y&& r )
|
||||
{
|
||||
if( &r != this )
|
||||
{
|
||||
v_ = r.v_;
|
||||
r.v_ = 0;
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
};
|
||||
|
||||
struct E
|
||||
{
|
||||
};
|
||||
|
||||
int f( int x )
|
||||
{
|
||||
return x * 2 + 1;
|
||||
}
|
||||
|
||||
X g( Y y )
|
||||
{
|
||||
return X{ y.v_ * 2 + 1 };
|
||||
}
|
||||
|
||||
int& h( int& )
|
||||
{
|
||||
static int x = 2;
|
||||
return x;
|
||||
}
|
||||
|
||||
static int fv_called;
|
||||
|
||||
void fv()
|
||||
{
|
||||
++fv_called;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
result<int> r( 1 );
|
||||
|
||||
r &= f;
|
||||
|
||||
BOOST_TEST( r.has_value() ) && BOOST_TEST_EQ( *r, 3 );
|
||||
}
|
||||
|
||||
{
|
||||
result<int, E> r( in_place_error );
|
||||
|
||||
r &= f;
|
||||
|
||||
BOOST_TEST( r.has_error() );
|
||||
}
|
||||
|
||||
{
|
||||
result<Y> r( in_place_value, 1 );
|
||||
|
||||
r &= g;
|
||||
|
||||
BOOST_TEST( r.has_value() ) && BOOST_TEST_EQ( r->v_, 3 );
|
||||
}
|
||||
|
||||
{
|
||||
result<Y, E> r( in_place_error );
|
||||
|
||||
r &= g;
|
||||
|
||||
BOOST_TEST( r.has_error() );
|
||||
}
|
||||
|
||||
{
|
||||
int x1 = 1;
|
||||
result<int&> r( x1 );
|
||||
|
||||
r &= h;
|
||||
|
||||
BOOST_TEST( r.has_value() ) && BOOST_TEST_EQ( &*r, &h( x1 ) );
|
||||
}
|
||||
|
||||
{
|
||||
result<int&, E> r( in_place_error );
|
||||
|
||||
r &= h;
|
||||
|
||||
BOOST_TEST( r.has_error() );
|
||||
}
|
||||
|
||||
{
|
||||
result<void> r;
|
||||
fv_called = 0;
|
||||
|
||||
r &= fv;
|
||||
|
||||
BOOST_TEST( r.has_value() );
|
||||
BOOST_TEST_EQ( fv_called, 1 );
|
||||
}
|
||||
|
||||
{
|
||||
result<void, E> r( in_place_error );
|
||||
fv_called = 0;
|
||||
|
||||
r &= fv;
|
||||
|
||||
BOOST_TEST( r.has_error() );
|
||||
BOOST_TEST_EQ( fv_called, 0 );
|
||||
}
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
503
test/result_and_fn1r.cpp
Normal file
503
test/result_and_fn1r.cpp
Normal file
@@ -0,0 +1,503 @@
|
||||
// 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
|
||||
{
|
||||
int v_;
|
||||
};
|
||||
|
||||
struct Y
|
||||
{
|
||||
int v_;
|
||||
|
||||
explicit Y( int v ): v_( v ) {}
|
||||
Y( X x ): v_( x.v_) {}
|
||||
|
||||
Y( Y const& ) = delete;
|
||||
Y& operator=( Y const& ) = delete;
|
||||
|
||||
Y( Y&& r ): v_( r.v_ )
|
||||
{
|
||||
r.v_ = 0;
|
||||
}
|
||||
|
||||
Y& operator=( Y&& ) = delete;
|
||||
};
|
||||
|
||||
struct E
|
||||
{
|
||||
};
|
||||
|
||||
struct E2
|
||||
{
|
||||
E2() {}
|
||||
E2( E ) {}
|
||||
};
|
||||
|
||||
result<int, E2> fi( int x )
|
||||
{
|
||||
return 2 * x + 1;
|
||||
}
|
||||
|
||||
result<int, E2> fi2( int )
|
||||
{
|
||||
return E2();
|
||||
}
|
||||
|
||||
result<void, E2> fi3( int )
|
||||
{
|
||||
return {};
|
||||
}
|
||||
|
||||
result<X, E2> fy( Y y )
|
||||
{
|
||||
return X{ 2 * y.v_ + 1 };
|
||||
}
|
||||
|
||||
result<X, E2> fy2( Y )
|
||||
{
|
||||
return E2();
|
||||
}
|
||||
|
||||
result<void, E2> fy3( Y )
|
||||
{
|
||||
return {};
|
||||
}
|
||||
|
||||
result<int, E2> fri( int& x )
|
||||
{
|
||||
return x * 2 + 1;
|
||||
}
|
||||
|
||||
result<int&, E2> fri2( int& )
|
||||
{
|
||||
return E2();
|
||||
}
|
||||
|
||||
result<void, E2> fri3( int& )
|
||||
{
|
||||
return {};
|
||||
}
|
||||
|
||||
result<int, E2> fk()
|
||||
{
|
||||
return 7;
|
||||
}
|
||||
|
||||
result<int, E2> fk2()
|
||||
{
|
||||
return E2();
|
||||
}
|
||||
|
||||
result<void, E2> fk3()
|
||||
{
|
||||
return {};
|
||||
}
|
||||
|
||||
result<void, E2> fk4()
|
||||
{
|
||||
return E2();
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
result<int, E> r( 1 );
|
||||
|
||||
{
|
||||
result<int, E2> r2 = r & fi;
|
||||
BOOST_TEST( r2.has_value() ) && BOOST_TEST_EQ( *r2, 3 );
|
||||
}
|
||||
|
||||
{
|
||||
result<int, E2> r2 = r & fi2;
|
||||
BOOST_TEST( r2.has_error() );
|
||||
}
|
||||
|
||||
{
|
||||
result<void, E2> r2 = r & fi3;
|
||||
BOOST_TEST( r2.has_value() );
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
result<int, E> const r( 1 );
|
||||
|
||||
{
|
||||
result<int, E2> r2 = r & fi;
|
||||
BOOST_TEST( r2.has_value() ) && BOOST_TEST_EQ( *r2, 3 );
|
||||
}
|
||||
|
||||
{
|
||||
result<int, E2> r2 = r & fi2;
|
||||
BOOST_TEST( r2.has_error() );
|
||||
}
|
||||
|
||||
{
|
||||
result<void, E2> r2 = r & fi3;
|
||||
BOOST_TEST( r2.has_value() );
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
result<int, E2> r2 = result<int, E>( 1 ) & fi;
|
||||
BOOST_TEST( r2.has_value() ) && BOOST_TEST_EQ( *r2, 3 );
|
||||
}
|
||||
|
||||
{
|
||||
result<int, E2> r2 = result<int, E>( 1 ) & fi2;
|
||||
BOOST_TEST( r2.has_error() );
|
||||
}
|
||||
|
||||
{
|
||||
result<void, E2> r2 = result<int, E>( 1 ) & fi3;
|
||||
BOOST_TEST( r2.has_value() );
|
||||
}
|
||||
|
||||
{
|
||||
result<int, E> r( in_place_error );
|
||||
|
||||
{
|
||||
result<int, E2> r2 = r & fi;
|
||||
BOOST_TEST( r2.has_error() );
|
||||
}
|
||||
|
||||
{
|
||||
result<int, E2> r2 = r & fi2;
|
||||
BOOST_TEST( r2.has_error() );
|
||||
}
|
||||
|
||||
{
|
||||
result<void, E2> r2 = r & fi3;
|
||||
BOOST_TEST( r2.has_error() );
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
result<int, E> const r( in_place_error );
|
||||
|
||||
{
|
||||
result<int, E2> r2 = r & fi;
|
||||
BOOST_TEST( r2.has_error() );
|
||||
}
|
||||
|
||||
{
|
||||
result<int, E2> r2 = r & fi2;
|
||||
BOOST_TEST( r2.has_error() );
|
||||
}
|
||||
|
||||
{
|
||||
result<void, E2> r2 = r & fi3;
|
||||
BOOST_TEST( r2.has_error() );
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
result<int, E2> r2 = result<int, E>( in_place_error ) & fi;
|
||||
BOOST_TEST( r2.has_error() );
|
||||
}
|
||||
|
||||
{
|
||||
result<int, E2> r2 = result<int, E>( in_place_error ) & fi2;
|
||||
BOOST_TEST( r2.has_error() );
|
||||
}
|
||||
|
||||
{
|
||||
result<void, E2> r2 = result<int, E>( in_place_error ) & fi3;
|
||||
BOOST_TEST( r2.has_error() );
|
||||
}
|
||||
|
||||
{
|
||||
result<X, E2> r2 = result<Y, E>( in_place_value, 1 ) & fy;
|
||||
|
||||
BOOST_TEST( r2.has_value() ) && BOOST_TEST_EQ( r2->v_, 3 );
|
||||
}
|
||||
|
||||
{
|
||||
result<X, E2> r2 = result<Y, E>( in_place_value, 1 ) & fy2;
|
||||
|
||||
BOOST_TEST( r2.has_error() );
|
||||
}
|
||||
|
||||
{
|
||||
result<void, E2> r2 = result<Y, E>( in_place_value, 1 ) & fy3;
|
||||
|
||||
BOOST_TEST( r2.has_value() );
|
||||
}
|
||||
|
||||
{
|
||||
result<X, E2> r2 = result<Y, E>( in_place_error ) & fy;
|
||||
|
||||
BOOST_TEST( r2.has_error() );
|
||||
}
|
||||
|
||||
{
|
||||
result<X, E2> r2 = result<Y, E>( in_place_error ) & fy2;
|
||||
|
||||
BOOST_TEST( r2.has_error() );
|
||||
}
|
||||
|
||||
{
|
||||
result<void, E2> r2 = result<Y, E>( in_place_error ) & fy3;
|
||||
|
||||
BOOST_TEST( r2.has_error() );
|
||||
}
|
||||
|
||||
{
|
||||
int x1 = 1;
|
||||
result<int&, E> r( x1 );
|
||||
|
||||
{
|
||||
result<int, E2> r2 = r & fri;
|
||||
BOOST_TEST( r2.has_value() ) && BOOST_TEST_EQ( *r2, 3 );
|
||||
}
|
||||
|
||||
{
|
||||
result<int&, E2> r2 = r & fri2;
|
||||
BOOST_TEST( r2.has_error() );
|
||||
}
|
||||
|
||||
{
|
||||
result<void, E2> r2 = r & fri3;
|
||||
BOOST_TEST( r2.has_value() );
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
int x1 = 1;
|
||||
result<int&, E> const r( x1 );
|
||||
|
||||
{
|
||||
result<int, E2> r2 = r & fri;
|
||||
BOOST_TEST( r2.has_value() ) && BOOST_TEST_EQ( *r2, 3 );
|
||||
}
|
||||
|
||||
{
|
||||
result<int&, E2> r2 = r & fri2;
|
||||
BOOST_TEST( r2.has_error() );
|
||||
}
|
||||
|
||||
{
|
||||
result<void, E2> r2 = r & fri3;
|
||||
BOOST_TEST( r2.has_value() );
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
int x1 = 1;
|
||||
|
||||
result<int, E2> r2 = result<int&, E>( x1 ) & fri;
|
||||
BOOST_TEST( r2.has_value() ) && BOOST_TEST_EQ( *r2, 3 );
|
||||
}
|
||||
|
||||
{
|
||||
int x1 = 1;
|
||||
|
||||
result<int&, E2> r2 = result<int&, E>( x1 ) & fri2;
|
||||
BOOST_TEST( r2.has_error() );
|
||||
}
|
||||
|
||||
{
|
||||
int x1 = 1;
|
||||
|
||||
result<void, E2> r2 = result<int&, E>( x1 ) & fri3;
|
||||
BOOST_TEST( r2.has_value() );
|
||||
}
|
||||
|
||||
{
|
||||
result<int&, E> r( in_place_error );
|
||||
|
||||
{
|
||||
result<int, E2> r2 = r & fri;
|
||||
BOOST_TEST( r2.has_error() );
|
||||
}
|
||||
|
||||
{
|
||||
result<int&, E2> r2 = r & fri2;
|
||||
BOOST_TEST( r2.has_error() );
|
||||
}
|
||||
|
||||
{
|
||||
result<void, E2> r2 = r & fri3;
|
||||
BOOST_TEST( r2.has_error() );
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
result<int&, E> const r( in_place_error );
|
||||
|
||||
{
|
||||
result<int, E2> r2 = r & fri;
|
||||
BOOST_TEST( r2.has_error() );
|
||||
}
|
||||
|
||||
{
|
||||
result<int&, E2> r2 = r & fri2;
|
||||
BOOST_TEST( r2.has_error() );
|
||||
}
|
||||
|
||||
{
|
||||
result<void, E2> r2 = r & fri3;
|
||||
BOOST_TEST( r2.has_error() );
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
result<int, E2> r2 = result<int&, E>( in_place_error ) & fri;
|
||||
BOOST_TEST( r2.has_error() );
|
||||
}
|
||||
|
||||
{
|
||||
result<int&, E2> r2 = result<int&, E>( in_place_error ) & fri2;
|
||||
BOOST_TEST( r2.has_error() );
|
||||
}
|
||||
|
||||
{
|
||||
result<void, E2> r2 = result<int&, E>( in_place_error ) & fri3;
|
||||
BOOST_TEST( r2.has_error() );
|
||||
}
|
||||
|
||||
{
|
||||
result<void, E> r;
|
||||
|
||||
{
|
||||
result<int, E2> r2 = r & fk;
|
||||
BOOST_TEST( r2.has_value() ) && BOOST_TEST_EQ( *r2, 7 );
|
||||
}
|
||||
|
||||
{
|
||||
result<int, E2> r2 = r & fk2;
|
||||
BOOST_TEST( r2.has_error() );
|
||||
}
|
||||
|
||||
{
|
||||
result<void, E2> r2 = r & fk3;
|
||||
BOOST_TEST( r2.has_value() );
|
||||
}
|
||||
|
||||
{
|
||||
result<void, E2> r2 = r & fk4;
|
||||
BOOST_TEST( r2.has_error() );
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
result<void, E> const r;
|
||||
|
||||
{
|
||||
result<int, E2> r2 = r & fk;
|
||||
BOOST_TEST( r2.has_value() ) && BOOST_TEST_EQ( *r2, 7 );
|
||||
}
|
||||
|
||||
{
|
||||
result<int, E2> r2 = r & fk2;
|
||||
BOOST_TEST( r2.has_error() );
|
||||
}
|
||||
|
||||
{
|
||||
result<void, E2> r2 = r & fk3;
|
||||
BOOST_TEST( r2.has_value() );
|
||||
}
|
||||
|
||||
{
|
||||
result<void, E2> r2 = r & fk4;
|
||||
BOOST_TEST( r2.has_error() );
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
result<int, E2> r2 = result<void, E>() & fk;
|
||||
BOOST_TEST( r2.has_value() ) && BOOST_TEST_EQ( *r2, 7 );
|
||||
}
|
||||
|
||||
{
|
||||
result<int, E2> r2 = result<void, E>() & fk2;
|
||||
BOOST_TEST( r2.has_error() );
|
||||
}
|
||||
|
||||
{
|
||||
result<void, E2> r2 = result<void, E>() & fk3;
|
||||
BOOST_TEST( r2.has_value() );
|
||||
}
|
||||
|
||||
{
|
||||
result<void, E2> r2 = result<void, E>() & fk4;
|
||||
BOOST_TEST( r2.has_error() );
|
||||
}
|
||||
|
||||
{
|
||||
result<void, E> r( in_place_error );
|
||||
|
||||
{
|
||||
result<int, E2> r2 = r & fk;
|
||||
BOOST_TEST( r2.has_error() );
|
||||
}
|
||||
|
||||
{
|
||||
result<int, E2> r2 = r & fk2;
|
||||
BOOST_TEST( r2.has_error() );
|
||||
}
|
||||
|
||||
{
|
||||
result<void, E2> r2 = r & fk3;
|
||||
BOOST_TEST( r2.has_error() );
|
||||
}
|
||||
|
||||
{
|
||||
result<void, E2> r2 = r & fk4;
|
||||
BOOST_TEST( r2.has_error() );
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
result<void, E> const r( in_place_error );
|
||||
|
||||
{
|
||||
result<int, E2> r2 = r & fk;
|
||||
BOOST_TEST( r2.has_error() );
|
||||
}
|
||||
|
||||
{
|
||||
result<int, E2> r2 = r & fk2;
|
||||
BOOST_TEST( r2.has_error() );
|
||||
}
|
||||
|
||||
{
|
||||
result<void, E2> r2 = r & fk3;
|
||||
BOOST_TEST( r2.has_error() );
|
||||
}
|
||||
|
||||
{
|
||||
result<void, E2> r2 = r & fk4;
|
||||
BOOST_TEST( r2.has_error() );
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
result<int, E2> r2 = result<void, E>( in_place_error ) & fk;
|
||||
BOOST_TEST( r2.has_error() );
|
||||
}
|
||||
|
||||
{
|
||||
result<int, E2> r2 = result<void, E>( in_place_error ) & fk2;
|
||||
BOOST_TEST( r2.has_error() );
|
||||
}
|
||||
|
||||
{
|
||||
result<void, E2> r2 = result<void, E>( in_place_error ) & fk3;
|
||||
BOOST_TEST( r2.has_error() );
|
||||
}
|
||||
|
||||
{
|
||||
result<void, E2> r2 = result<void, E>( in_place_error ) & fk4;
|
||||
BOOST_TEST( r2.has_error() );
|
||||
}
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
331
test/result_and_fn1v.cpp
Normal file
331
test/result_and_fn1v.cpp
Normal file
@@ -0,0 +1,331 @@
|
||||
// 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
|
||||
{
|
||||
int v_;
|
||||
};
|
||||
|
||||
struct Y
|
||||
{
|
||||
int v_;
|
||||
|
||||
explicit Y( int v ): v_( v ) {}
|
||||
Y( X x ): v_( x.v_) {}
|
||||
|
||||
Y( Y const& ) = delete;
|
||||
Y& operator=( Y const& ) = delete;
|
||||
|
||||
Y( Y&& r ): v_( r.v_ )
|
||||
{
|
||||
r.v_ = 0;
|
||||
}
|
||||
|
||||
Y& operator=( Y&& ) = delete;
|
||||
};
|
||||
|
||||
struct E
|
||||
{
|
||||
};
|
||||
|
||||
int f( int x )
|
||||
{
|
||||
return x * 2 + 1;
|
||||
}
|
||||
|
||||
X g( Y y )
|
||||
{
|
||||
return X{ y.v_ * 2 + 1 };
|
||||
}
|
||||
|
||||
int& h( int& )
|
||||
{
|
||||
static int x = 2;
|
||||
return x;
|
||||
}
|
||||
|
||||
int k()
|
||||
{
|
||||
return 7;
|
||||
}
|
||||
|
||||
static int fv1_called_with;
|
||||
|
||||
void fv1( int x )
|
||||
{
|
||||
fv1_called_with = x;
|
||||
}
|
||||
|
||||
static int fv2_called;
|
||||
|
||||
void fv2()
|
||||
{
|
||||
++fv2_called;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
result<int> r( 1 );
|
||||
result<int> r2 = r & f;
|
||||
|
||||
BOOST_TEST( r2.has_value() ) && BOOST_TEST_EQ( *r2, 3 );
|
||||
}
|
||||
|
||||
{
|
||||
result<int> const r( 1 );
|
||||
result<int> r2 = r & f;
|
||||
|
||||
BOOST_TEST( r2.has_value() ) && BOOST_TEST_EQ( *r2, 3 );
|
||||
}
|
||||
|
||||
{
|
||||
result<int> r2 = result<int>( 1 ) & f;
|
||||
|
||||
BOOST_TEST( r2.has_value() ) && BOOST_TEST_EQ( *r2, 3 );
|
||||
}
|
||||
|
||||
{
|
||||
result<int, E> r( in_place_error );
|
||||
result<int, E> r2 = r & f;
|
||||
|
||||
BOOST_TEST( r2.has_error() );
|
||||
}
|
||||
|
||||
{
|
||||
result<int, E> const r( in_place_error );
|
||||
result<int, E> r2 = r & f;
|
||||
|
||||
BOOST_TEST( r2.has_error() );
|
||||
}
|
||||
|
||||
{
|
||||
result<int, E> r2 = result<int, E>( in_place_error ) & f;
|
||||
|
||||
BOOST_TEST( r2.has_error() );
|
||||
}
|
||||
|
||||
{
|
||||
result<X> r2 = result<Y>( in_place_value, 1 ) & g;
|
||||
|
||||
BOOST_TEST( r2.has_value() ) && BOOST_TEST_EQ( r2->v_, 3 );
|
||||
}
|
||||
|
||||
{
|
||||
result<X, E> r2 = result<Y, E>( in_place_error ) & g;
|
||||
|
||||
BOOST_TEST( r2.has_error() );
|
||||
}
|
||||
|
||||
{
|
||||
int x1 = 1;
|
||||
|
||||
result<int&> r( x1 );
|
||||
|
||||
result<int&> r2 = r & h;
|
||||
|
||||
BOOST_TEST( r2.has_value() ) && BOOST_TEST_EQ( &*r2, &h( x1 ) );
|
||||
}
|
||||
|
||||
{
|
||||
int x1 = 1;
|
||||
|
||||
result<int&> const r( x1 );
|
||||
|
||||
result<int&> r2 = r & h;
|
||||
|
||||
BOOST_TEST( r2.has_value() ) && BOOST_TEST_EQ( &*r2, &h( x1 ) );
|
||||
}
|
||||
|
||||
{
|
||||
int x1 = 1;
|
||||
|
||||
result<int&> r2 = result<int&>( x1 ) & h;
|
||||
|
||||
BOOST_TEST( r2.has_value() ) && BOOST_TEST_EQ( &*r2, &h( x1 ) );
|
||||
}
|
||||
|
||||
{
|
||||
result<int&, E> r( in_place_error );
|
||||
|
||||
result<int&, E> r2 = r & h;
|
||||
|
||||
BOOST_TEST( r2.has_error() );
|
||||
}
|
||||
|
||||
{
|
||||
result<int&, E> const r( in_place_error );
|
||||
|
||||
result<int&, E> r2 = r & h;
|
||||
|
||||
BOOST_TEST( r2.has_error() );
|
||||
}
|
||||
|
||||
{
|
||||
result<int&, E> r2 = result<int&, E>( in_place_error ) & h;
|
||||
|
||||
BOOST_TEST( r2.has_error() );
|
||||
}
|
||||
|
||||
{
|
||||
result<void> r;
|
||||
result<int> r2 = r & k;
|
||||
|
||||
BOOST_TEST( r2.has_value() ) && BOOST_TEST_EQ( *r2, 7 );
|
||||
}
|
||||
|
||||
{
|
||||
result<void> const r;
|
||||
result<int> r2 = r & k;
|
||||
|
||||
BOOST_TEST( r2.has_value() ) && BOOST_TEST_EQ( *r2, 7 );
|
||||
}
|
||||
|
||||
{
|
||||
result<int> r2 = result<void>() & k;
|
||||
|
||||
BOOST_TEST( r2.has_value() ) && BOOST_TEST_EQ( *r2, 7 );
|
||||
}
|
||||
|
||||
{
|
||||
result<void, E> r( in_place_error );
|
||||
result<int, E> r2 = r & k;
|
||||
|
||||
BOOST_TEST( r2.has_error() );
|
||||
}
|
||||
|
||||
{
|
||||
result<void, E> const r( in_place_error );
|
||||
result<int, E> r2 = r & k;
|
||||
|
||||
BOOST_TEST( r2.has_error() );
|
||||
}
|
||||
|
||||
{
|
||||
result<int, E> r2 = result<void, E>( in_place_error ) & k;
|
||||
|
||||
BOOST_TEST( r2.has_error() );
|
||||
}
|
||||
|
||||
{
|
||||
fv1_called_with = 0;
|
||||
|
||||
result<int> r( 1 );
|
||||
result<void> r2 = r & fv1;
|
||||
|
||||
BOOST_TEST( r2.has_value() );
|
||||
BOOST_TEST_EQ( fv1_called_with, 1 );
|
||||
}
|
||||
|
||||
{
|
||||
result<int> const r( 1 );
|
||||
result<void> r2 = r & fv1;
|
||||
|
||||
BOOST_TEST( r2.has_value() );
|
||||
BOOST_TEST_EQ( fv1_called_with, 1 );
|
||||
}
|
||||
|
||||
{
|
||||
fv1_called_with = 0;
|
||||
|
||||
result<void> r2 = result<int>( 1 ) & fv1;
|
||||
|
||||
BOOST_TEST( r2.has_value() );
|
||||
BOOST_TEST_EQ( fv1_called_with, 1 );
|
||||
}
|
||||
|
||||
{
|
||||
fv1_called_with = 0;
|
||||
|
||||
result<int, E> r( in_place_error );
|
||||
result<void, E> r2 = r & fv1;
|
||||
|
||||
BOOST_TEST( r2.has_error() );
|
||||
BOOST_TEST_EQ( fv1_called_with, 0 );
|
||||
}
|
||||
|
||||
{
|
||||
fv1_called_with = 0;
|
||||
|
||||
result<int, E> const r( in_place_error );
|
||||
result<void, E> r2 = r & fv1;
|
||||
|
||||
BOOST_TEST( r2.has_error() );
|
||||
BOOST_TEST_EQ( fv1_called_with, 0 );
|
||||
}
|
||||
|
||||
{
|
||||
fv1_called_with = 0;
|
||||
|
||||
result<void, E> r2 = result<int, E>( in_place_error ) & fv1;
|
||||
|
||||
BOOST_TEST( r2.has_error() );
|
||||
BOOST_TEST_EQ( fv1_called_with, 0 );
|
||||
}
|
||||
|
||||
{
|
||||
result<void> r;
|
||||
fv2_called = 0;
|
||||
|
||||
result<void> r2 = r & fv2;
|
||||
|
||||
BOOST_TEST( r2.has_value() );
|
||||
BOOST_TEST_EQ( fv2_called, 1 );
|
||||
}
|
||||
|
||||
{
|
||||
result<void> const r;
|
||||
fv2_called = 0;
|
||||
|
||||
result<void> r2 = r & fv2;
|
||||
|
||||
BOOST_TEST( r2.has_value() );
|
||||
BOOST_TEST_EQ( fv2_called, 1 );
|
||||
}
|
||||
|
||||
{
|
||||
fv2_called = 0;
|
||||
|
||||
result<void> r2 = result<void>() & fv2;
|
||||
|
||||
BOOST_TEST( r2.has_value() );
|
||||
BOOST_TEST_EQ( fv2_called, 1 );
|
||||
}
|
||||
|
||||
{
|
||||
result<void, E> r( in_place_error );
|
||||
fv2_called = 0;
|
||||
|
||||
result<void, E> r2 = r & fv2;
|
||||
|
||||
BOOST_TEST( r2.has_error() );
|
||||
BOOST_TEST_EQ( fv2_called, 0 );
|
||||
}
|
||||
|
||||
{
|
||||
result<void, E> const r( in_place_error );
|
||||
fv2_called = 0;
|
||||
|
||||
result<void, E> r2 = r & fv2;
|
||||
|
||||
BOOST_TEST( r2.has_error() );
|
||||
BOOST_TEST_EQ( fv2_called, 0 );
|
||||
}
|
||||
|
||||
{
|
||||
fv2_called = 0;
|
||||
|
||||
result<void, E> r2 = result<void, E>( in_place_error ) & fv2;
|
||||
|
||||
BOOST_TEST( r2.has_error() );
|
||||
BOOST_TEST_EQ( fv2_called, 0 );
|
||||
}
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
230
test/result_and_mfn1r.cpp
Normal file
230
test/result_and_mfn1r.cpp
Normal file
@@ -0,0 +1,230 @@
|
||||
// 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 E
|
||||
{
|
||||
};
|
||||
|
||||
struct E2
|
||||
{
|
||||
E2() {}
|
||||
E2( E ) {}
|
||||
};
|
||||
|
||||
struct X
|
||||
{
|
||||
int v_ = 0;
|
||||
mutable int g_called_ = 0;
|
||||
|
||||
X( int v ): v_( v ) {}
|
||||
|
||||
result<int, E2> f() const { return v_; }
|
||||
result<int, E2> f2() const { return E2(); }
|
||||
|
||||
result<int&, E2> g() { return v_; }
|
||||
result<int const&, E2> g2() const { return v_; }
|
||||
|
||||
result<void, E2> h() const { return {}; }
|
||||
result<void, E2> h2() const { return E2(); }
|
||||
};
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
result<X, E> r( 1 );
|
||||
|
||||
{
|
||||
result<int, E2> r2 = r & &X::f;
|
||||
BOOST_TEST( r2.has_value() ) && BOOST_TEST_EQ( *r2, 1 );
|
||||
}
|
||||
|
||||
{
|
||||
result<int, E2> r2 = r & &X::f2;
|
||||
BOOST_TEST( r2.has_error() );
|
||||
}
|
||||
|
||||
{
|
||||
result<int&, E2> r2 = r & &X::g;
|
||||
BOOST_TEST( r2.has_value() ) && BOOST_TEST_EQ( &*r2, &r->v_ );
|
||||
}
|
||||
|
||||
{
|
||||
result<int const&, E2> r2 = r & &X::g2;
|
||||
BOOST_TEST( r2.has_value() ) && BOOST_TEST_EQ( &*r2, &r->v_ );
|
||||
}
|
||||
|
||||
{
|
||||
result<void, E2> r2 = r & &X::h;
|
||||
BOOST_TEST( r2.has_value() );
|
||||
}
|
||||
|
||||
{
|
||||
result<void, E2> r2 = r & &X::h2;
|
||||
BOOST_TEST( r2.has_error() );
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
result<X, E> const r( 1 );
|
||||
|
||||
{
|
||||
result<int, E2> r2 = r & &X::f;
|
||||
BOOST_TEST( r2.has_value() ) && BOOST_TEST_EQ( *r2, 1 );
|
||||
}
|
||||
|
||||
{
|
||||
result<int, E2> r2 = r & &X::f2;
|
||||
BOOST_TEST( r2.has_error() );
|
||||
}
|
||||
|
||||
{
|
||||
result<int const&, E2> r2 = r & &X::g2;
|
||||
BOOST_TEST( r2.has_value() ) && BOOST_TEST_EQ( &*r2, &r->v_ );
|
||||
}
|
||||
|
||||
{
|
||||
result<void, E2> r2 = r & &X::h;
|
||||
BOOST_TEST( r2.has_value() );
|
||||
}
|
||||
|
||||
{
|
||||
result<void, E2> r2 = r & &X::h2;
|
||||
BOOST_TEST( r2.has_error() );
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
{
|
||||
result<int, E2> r2 = result<X, E>( 1 ) & &X::f;
|
||||
BOOST_TEST( r2.has_value() ) && BOOST_TEST_EQ( *r2, 1 );
|
||||
}
|
||||
|
||||
{
|
||||
result<int, E2> r2 = result<X, E>( 1 ) & &X::f2;
|
||||
BOOST_TEST( r2.has_error() );
|
||||
}
|
||||
|
||||
{
|
||||
result<int&, E2> r2 = result<X, E>( 1 ) & &X::g;
|
||||
BOOST_TEST( r2.has_value() );
|
||||
}
|
||||
|
||||
{
|
||||
result<int const&, E2> r2 = result<X, E>( 1 ) & &X::g2;
|
||||
BOOST_TEST( r2.has_value() );
|
||||
}
|
||||
|
||||
{
|
||||
result<void, E2> r2 = result<X, E>( 1 ) & &X::h;
|
||||
BOOST_TEST( r2.has_value() );
|
||||
}
|
||||
|
||||
{
|
||||
result<void, E2> r2 = result<X, E>( 1 ) & &X::h2;
|
||||
BOOST_TEST( r2.has_error() );
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
result<X, E> r( in_place_error );
|
||||
|
||||
{
|
||||
result<int, E2> r2 = r & &X::f;
|
||||
BOOST_TEST( r2.has_error() );
|
||||
}
|
||||
|
||||
{
|
||||
result<int, E2> r2 = r & &X::f2;
|
||||
BOOST_TEST( r2.has_error() );
|
||||
}
|
||||
|
||||
{
|
||||
result<int&, E2> r2 = r & &X::g;
|
||||
BOOST_TEST( r2.has_error() );
|
||||
}
|
||||
|
||||
{
|
||||
result<int const&, E2> r2 = r & &X::g2;
|
||||
BOOST_TEST( r2.has_error() );
|
||||
}
|
||||
|
||||
{
|
||||
result<void, E2> r2 = r & &X::h;
|
||||
BOOST_TEST( r2.has_error() );
|
||||
}
|
||||
|
||||
{
|
||||
result<void, E2> r2 = r & &X::h2;
|
||||
BOOST_TEST( r2.has_error() );
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
result<X, E> const r( in_place_error );
|
||||
|
||||
{
|
||||
result<int, E2> r2 = r & &X::f;
|
||||
BOOST_TEST( r2.has_error() );
|
||||
}
|
||||
|
||||
{
|
||||
result<int, E2> r2 = r & &X::f2;
|
||||
BOOST_TEST( r2.has_error() );
|
||||
}
|
||||
|
||||
{
|
||||
result<int const&, E2> r2 = r & &X::g2;
|
||||
BOOST_TEST( r2.has_error() );
|
||||
}
|
||||
|
||||
{
|
||||
result<void, E2> r2 = r & &X::h;
|
||||
BOOST_TEST( r2.has_error() );
|
||||
}
|
||||
|
||||
{
|
||||
result<void, E2> r2 = r & &X::h2;
|
||||
BOOST_TEST( r2.has_error() );
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
{
|
||||
result<int, E2> r2 = result<X, E>( in_place_error ) & &X::f;
|
||||
BOOST_TEST( r2.has_error() );
|
||||
}
|
||||
|
||||
{
|
||||
result<int, E2> r2 = result<X, E>( in_place_error ) & &X::f2;
|
||||
BOOST_TEST( r2.has_error() );
|
||||
}
|
||||
|
||||
{
|
||||
result<int&, E2> r2 = result<X, E>( in_place_error ) & &X::g;
|
||||
BOOST_TEST( r2.has_error() );
|
||||
}
|
||||
|
||||
{
|
||||
result<int const&, E2> r2 = result<X, E>( in_place_error ) & &X::g2;
|
||||
BOOST_TEST( r2.has_error() );
|
||||
}
|
||||
|
||||
{
|
||||
result<void, E2> r2 = result<X, E>( in_place_error ) & &X::h;
|
||||
BOOST_TEST( r2.has_error() );
|
||||
}
|
||||
|
||||
{
|
||||
result<void, E2> r2 = result<X, E>( in_place_error ) & &X::h2;
|
||||
BOOST_TEST( r2.has_error() );
|
||||
}
|
||||
}
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
254
test/result_and_mfn1v.cpp
Normal file
254
test/result_and_mfn1v.cpp
Normal file
@@ -0,0 +1,254 @@
|
||||
// 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
|
||||
{
|
||||
int v_ = 0;
|
||||
mutable int g_called_ = 0;
|
||||
|
||||
X( int v ): v_( v ) {}
|
||||
|
||||
int f() const { return v_; }
|
||||
|
||||
void g() const { ++g_called_; }
|
||||
|
||||
int& h() { return v_; }
|
||||
int const& h2() const { return v_; }
|
||||
};
|
||||
|
||||
struct E
|
||||
{
|
||||
};
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
result<X> r( 1 );
|
||||
result<int> r2 = r & &X::f;
|
||||
|
||||
BOOST_TEST( r2.has_value() ) && BOOST_TEST_EQ( *r2, 1 );
|
||||
}
|
||||
|
||||
{
|
||||
result<X> const r( 1 );
|
||||
result<int> r2 = r & &X::f;
|
||||
|
||||
BOOST_TEST( r2.has_value() ) && BOOST_TEST_EQ( *r2, 1 );
|
||||
}
|
||||
|
||||
{
|
||||
result<int> r2 = result<X>( 1 ) & &X::f;
|
||||
|
||||
BOOST_TEST( r2.has_value() ) && BOOST_TEST_EQ( *r2, 1 );
|
||||
}
|
||||
|
||||
{
|
||||
result<X, E> r( in_place_error );
|
||||
result<int, E> r2 = r & &X::f;
|
||||
|
||||
BOOST_TEST( r2.has_error() );
|
||||
}
|
||||
|
||||
{
|
||||
result<X, E> const r( in_place_error );
|
||||
result<int, E> r2 = r & &X::f;
|
||||
|
||||
BOOST_TEST( r2.has_error() );
|
||||
}
|
||||
|
||||
{
|
||||
result<int, E> r2 = result<X, E>( in_place_error ) & &X::f;
|
||||
|
||||
BOOST_TEST( r2.has_error() );
|
||||
}
|
||||
|
||||
{
|
||||
result<X> r( 1 );
|
||||
result<int&> r2 = r & &X::v_;
|
||||
|
||||
BOOST_TEST( r2.has_value() ) && BOOST_TEST_EQ( &*r2, &r->v_ );
|
||||
}
|
||||
|
||||
{
|
||||
result<X> const r( 1 );
|
||||
result<int const&> r2 = r & &X::v_;
|
||||
|
||||
BOOST_TEST( r2.has_value() ) && BOOST_TEST_EQ( &*r2, &r->v_ );
|
||||
}
|
||||
|
||||
{
|
||||
result<int> r2 = result<X>( 1 ) & &X::v_;
|
||||
|
||||
BOOST_TEST( r2.has_value() ) && BOOST_TEST_EQ( *r2, 1 );
|
||||
}
|
||||
|
||||
{
|
||||
result<X, E> r( in_place_error );
|
||||
result<int&, E> r2 = r & &X::v_;
|
||||
|
||||
BOOST_TEST( r2.has_error() );
|
||||
}
|
||||
|
||||
{
|
||||
result<X, E> const r( in_place_error );
|
||||
result<int const&, E> r2 = r & &X::v_;
|
||||
|
||||
BOOST_TEST( r2.has_error() );
|
||||
}
|
||||
|
||||
{
|
||||
result<int, E> r2 = result<X, E>( in_place_error ) & &X::v_;
|
||||
|
||||
BOOST_TEST( r2.has_error() );
|
||||
}
|
||||
|
||||
{
|
||||
X x( 1 );
|
||||
|
||||
result<X&> r( x );
|
||||
result<int&> r2 = r & &X::v_;
|
||||
|
||||
BOOST_TEST( r2.has_value() ) && BOOST_TEST_EQ( &*r2, &x.v_ );
|
||||
}
|
||||
|
||||
{
|
||||
X const x( 1 );
|
||||
|
||||
result<X const&> r( x );
|
||||
result<int const&> r2 = r & &X::v_;
|
||||
|
||||
BOOST_TEST( r2.has_value() ) && BOOST_TEST_EQ( &*r2, &x.v_ );
|
||||
}
|
||||
|
||||
{
|
||||
X x( 1 );
|
||||
|
||||
result<int&> r2 = result<X&>( x ) & &X::v_;
|
||||
|
||||
BOOST_TEST( r2.has_value() ) && BOOST_TEST_EQ( &*r2, &x.v_ );
|
||||
}
|
||||
|
||||
{
|
||||
X const x( 1 );
|
||||
|
||||
result<int const&> r2 = result<X const&>( x ) & &X::v_;
|
||||
|
||||
BOOST_TEST( r2.has_value() ) && BOOST_TEST_EQ( &*r2, &x.v_ );
|
||||
}
|
||||
|
||||
{
|
||||
result<X&, E> r( in_place_error );
|
||||
result<int&, E> r2 = r & &X::v_;
|
||||
|
||||
BOOST_TEST( r2.has_error() );
|
||||
}
|
||||
|
||||
{
|
||||
result<X const&, E> const r( in_place_error );
|
||||
result<int const&, E> r2 = r & &X::v_;
|
||||
|
||||
BOOST_TEST( r2.has_error() );
|
||||
}
|
||||
|
||||
{
|
||||
result<int&, E> r2 = result<X&, E>( in_place_error ) & &X::v_;
|
||||
|
||||
BOOST_TEST( r2.has_error() );
|
||||
}
|
||||
|
||||
{
|
||||
result<int const&, E> r2 = result<X const&, E>( in_place_error ) & &X::v_;
|
||||
|
||||
BOOST_TEST( r2.has_error() );
|
||||
}
|
||||
|
||||
{
|
||||
result<X> r( 1 );
|
||||
result<void> r2 = r & &X::g;
|
||||
|
||||
BOOST_TEST( r2.has_value() );
|
||||
BOOST_TEST_EQ( r->g_called_, 1 );
|
||||
}
|
||||
|
||||
{
|
||||
result<X> const r( 1 );
|
||||
result<void> r2 = r & &X::g;
|
||||
|
||||
BOOST_TEST( r2.has_value() );
|
||||
BOOST_TEST_EQ( r->g_called_, 1 );
|
||||
}
|
||||
|
||||
{
|
||||
result<void> r2 = result<X>( 1 ) & &X::g;
|
||||
|
||||
BOOST_TEST( r2.has_value() );
|
||||
}
|
||||
|
||||
{
|
||||
result<X, E> r( in_place_error );
|
||||
result<void, E> r2 = r & &X::g;
|
||||
|
||||
BOOST_TEST( r2.has_error() );
|
||||
}
|
||||
|
||||
{
|
||||
result<X, E> const r( in_place_error );
|
||||
result<void, E> r2 = r & &X::g;
|
||||
|
||||
BOOST_TEST( r2.has_error() );
|
||||
}
|
||||
|
||||
{
|
||||
result<void, E> r2 = result<X, E>( in_place_error ) & &X::g;
|
||||
|
||||
BOOST_TEST( r2.has_error() );
|
||||
}
|
||||
|
||||
{
|
||||
result<X> r( 1 );
|
||||
result<int&> r2 = r & &X::h;
|
||||
|
||||
BOOST_TEST( r2.has_value() ) && BOOST_TEST_EQ( *r2, 1 );
|
||||
}
|
||||
|
||||
{
|
||||
result<X> const r( 1 );
|
||||
result<int const&> r2 = r & &X::h2;
|
||||
|
||||
BOOST_TEST( r2.has_value() ) && BOOST_TEST_EQ( *r2, 1 );
|
||||
}
|
||||
|
||||
{
|
||||
result<int> r2 = result<X>( 1 ) & &X::h2;
|
||||
|
||||
BOOST_TEST( r2.has_value() ) && BOOST_TEST_EQ( *r2, 1 );
|
||||
}
|
||||
|
||||
{
|
||||
result<X, E> r( in_place_error );
|
||||
result<int&, E> r2 = r & &X::h;
|
||||
|
||||
BOOST_TEST( r2.has_error() );
|
||||
}
|
||||
|
||||
{
|
||||
result<X, E> const r( in_place_error );
|
||||
result<int const&, E> r2 = r & &X::h2;
|
||||
|
||||
BOOST_TEST( r2.has_error() );
|
||||
}
|
||||
|
||||
{
|
||||
result<int, E> r2 = result<X, E>( in_place_error ) & &X::h2;
|
||||
|
||||
BOOST_TEST( r2.has_error() );
|
||||
}
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
306
test/result_convert_construct.cpp
Normal file
306
test/result_convert_construct.cpp
Normal file
@@ -0,0 +1,306 @@
|
||||
// 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 );
|
||||
|
||||
//
|
||||
|
||||
{
|
||||
result<void, int> r;
|
||||
result<void, X> r2 = r;
|
||||
|
||||
BOOST_TEST( r2 );
|
||||
BOOST_TEST_EQ( X::instances, 0 );
|
||||
}
|
||||
|
||||
BOOST_TEST_EQ( X::instances, 0 );
|
||||
|
||||
{
|
||||
result<void, int> const r;
|
||||
result<void, X> r2 = r;
|
||||
|
||||
BOOST_TEST( r2 );
|
||||
BOOST_TEST_EQ( X::instances, 0 );
|
||||
}
|
||||
|
||||
BOOST_TEST_EQ( X::instances, 0 );
|
||||
|
||||
{
|
||||
result<void, X> r2 = result<void, int>();
|
||||
|
||||
BOOST_TEST( r2 );
|
||||
BOOST_TEST_EQ( X::instances, 0 );
|
||||
}
|
||||
|
||||
BOOST_TEST_EQ( X::instances, 0 );
|
||||
|
||||
{
|
||||
result<void, int> r( 5 );
|
||||
result<void, 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<void, int> const r( 6 );
|
||||
result<void, X> r2 = r;
|
||||
|
||||
BOOST_TEST( !r2 );
|
||||
BOOST_TEST_EQ( r2.error(), X(6) );
|
||||
BOOST_TEST_EQ( X::instances, 1 );
|
||||
}
|
||||
|
||||
{
|
||||
result<void, X> r2 = result<void, 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_FALSE((std::is_constructible<result<void, void*>, result<void, int>>));
|
||||
BOOST_TEST_TRAIT_FALSE((std::is_convertible<result<void, int>, result<void, 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();
|
||||
}
|
||||
832
test/result_copy_assign.cpp
Normal file
832
test/result_copy_assign.cpp
Normal file
@@ -0,0 +1,832 @@
|
||||
// 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 <iosfwd>
|
||||
#include <cerrno>
|
||||
|
||||
using namespace boost::system;
|
||||
|
||||
struct X
|
||||
{
|
||||
static int instances;
|
||||
|
||||
int v_;
|
||||
|
||||
explicit X( int v = 0 ): v_( v ) { ++instances; }
|
||||
|
||||
X( X const& r ): v_( r.v_ ) { ++instances; }
|
||||
|
||||
X& operator=( X const& ) = default;
|
||||
|
||||
~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;
|
||||
|
||||
struct Y
|
||||
{
|
||||
static int instances;
|
||||
|
||||
int v_;
|
||||
|
||||
explicit Y( int v = 0 ): v_( v ) { ++instances; }
|
||||
|
||||
Y( Y const& r ) noexcept: v_( r.v_ ) { ++instances; }
|
||||
|
||||
Y& operator=( Y const& ) = default;
|
||||
|
||||
~Y() { --instances; }
|
||||
};
|
||||
|
||||
bool operator==( Y const & y1, Y const & y2 )
|
||||
{
|
||||
return y1.v_ == y2.v_;
|
||||
}
|
||||
|
||||
std::ostream& operator<<( std::ostream& os, Y const & y )
|
||||
{
|
||||
os << "Y:" << y.v_;
|
||||
return os;
|
||||
}
|
||||
|
||||
int Y::instances = 0;
|
||||
|
||||
int main()
|
||||
{
|
||||
// default-initialized lhs
|
||||
|
||||
{
|
||||
result<int> r;
|
||||
result<int> r2;
|
||||
|
||||
r2 = r;
|
||||
|
||||
BOOST_TEST_EQ( r, r2 );
|
||||
}
|
||||
|
||||
{
|
||||
result<int> r;
|
||||
result<int> r2( 1 );
|
||||
|
||||
r2 = r;
|
||||
|
||||
BOOST_TEST_EQ( r, r2 );
|
||||
}
|
||||
|
||||
{
|
||||
result<int> r;
|
||||
result<int> r2( ENOENT, generic_category() );
|
||||
|
||||
r2 = r;
|
||||
|
||||
BOOST_TEST_EQ( r, r2 );
|
||||
}
|
||||
|
||||
{
|
||||
result<int> const r;
|
||||
result<int> r2;
|
||||
|
||||
r2 = r;
|
||||
|
||||
BOOST_TEST_EQ( r, r2 );
|
||||
}
|
||||
|
||||
{
|
||||
result<int> const r;
|
||||
result<int> r2( 1 );
|
||||
|
||||
r2 = r;
|
||||
|
||||
BOOST_TEST_EQ( r, r2 );
|
||||
}
|
||||
|
||||
{
|
||||
result<int> const r;
|
||||
result<int> r2( ENOENT, generic_category() );
|
||||
|
||||
r2 = r;
|
||||
|
||||
BOOST_TEST_EQ( r, r2 );
|
||||
}
|
||||
|
||||
BOOST_TEST_EQ( X::instances, 0 );
|
||||
|
||||
{
|
||||
result<X> r;
|
||||
result<X> r2;
|
||||
|
||||
BOOST_TEST_EQ( X::instances, 2 );
|
||||
|
||||
r2 = r;
|
||||
|
||||
BOOST_TEST_EQ( X::instances, 2 );
|
||||
|
||||
BOOST_TEST_EQ( r, r2 );
|
||||
}
|
||||
|
||||
BOOST_TEST_EQ( X::instances, 0 );
|
||||
|
||||
{
|
||||
result<X> r;
|
||||
result<X> r2( 1 );
|
||||
|
||||
BOOST_TEST_EQ( X::instances, 2 );
|
||||
|
||||
r2 = r;
|
||||
|
||||
BOOST_TEST_EQ( X::instances, 2 );
|
||||
|
||||
BOOST_TEST_EQ( r, r2 );
|
||||
}
|
||||
|
||||
BOOST_TEST_EQ( X::instances, 0 );
|
||||
|
||||
{
|
||||
result<X> r;
|
||||
result<X> r2( ENOENT, generic_category() );
|
||||
|
||||
BOOST_TEST_EQ( X::instances, 1 );
|
||||
|
||||
r2 = r;
|
||||
|
||||
BOOST_TEST_EQ( X::instances, 2 );
|
||||
|
||||
BOOST_TEST_EQ( r, r2 );
|
||||
}
|
||||
|
||||
BOOST_TEST_EQ( X::instances, 0 );
|
||||
|
||||
{
|
||||
result<X> const r;
|
||||
result<X> r2;
|
||||
|
||||
BOOST_TEST_EQ( X::instances, 2 );
|
||||
|
||||
r2 = r;
|
||||
|
||||
BOOST_TEST_EQ( X::instances, 2 );
|
||||
|
||||
BOOST_TEST_EQ( r, r2 );
|
||||
}
|
||||
|
||||
BOOST_TEST_EQ( X::instances, 0 );
|
||||
|
||||
{
|
||||
result<X> const r;
|
||||
result<X> r2( 1 );
|
||||
|
||||
BOOST_TEST_EQ( X::instances, 2 );
|
||||
|
||||
r2 = r;
|
||||
|
||||
BOOST_TEST_EQ( X::instances, 2 );
|
||||
|
||||
BOOST_TEST_EQ( r, r2 );
|
||||
}
|
||||
|
||||
BOOST_TEST_EQ( X::instances, 0 );
|
||||
|
||||
{
|
||||
result<X> const r;
|
||||
result<X> r2( ENOENT, generic_category() );
|
||||
|
||||
BOOST_TEST_EQ( X::instances, 1 );
|
||||
|
||||
r2 = r;
|
||||
|
||||
BOOST_TEST_EQ( X::instances, 2 );
|
||||
|
||||
BOOST_TEST_EQ( r, r2 );
|
||||
}
|
||||
|
||||
BOOST_TEST_EQ( X::instances, 0 );
|
||||
|
||||
// value lhs
|
||||
|
||||
{
|
||||
result<int> r( 0 );
|
||||
result<int> r2;
|
||||
|
||||
r2 = r;
|
||||
|
||||
BOOST_TEST_EQ( r, r2 );
|
||||
}
|
||||
|
||||
{
|
||||
result<int> r( 0 );
|
||||
result<int> r2( 1 );
|
||||
|
||||
r2 = r;
|
||||
|
||||
BOOST_TEST_EQ( r, r2 );
|
||||
}
|
||||
|
||||
{
|
||||
result<int> r( 0 );
|
||||
result<int> r2( ENOENT, generic_category() );
|
||||
|
||||
r2 = r;
|
||||
|
||||
BOOST_TEST_EQ( r, r2 );
|
||||
}
|
||||
|
||||
{
|
||||
result<int> const r( 0 );
|
||||
result<int> r2;
|
||||
|
||||
r2 = r;
|
||||
|
||||
BOOST_TEST_EQ( r, r2 );
|
||||
}
|
||||
|
||||
{
|
||||
result<int> const r( 0 );
|
||||
result<int> r2( 1 );
|
||||
|
||||
r2 = r;
|
||||
|
||||
BOOST_TEST_EQ( r, r2 );
|
||||
}
|
||||
|
||||
{
|
||||
result<int> const r( 0 );
|
||||
result<int> r2( ENOENT, generic_category() );
|
||||
|
||||
r2 = r;
|
||||
|
||||
BOOST_TEST_EQ( r, r2 );
|
||||
}
|
||||
|
||||
BOOST_TEST_EQ( X::instances, 0 );
|
||||
|
||||
{
|
||||
result<X> r( 1 );
|
||||
result<X> r2;
|
||||
|
||||
BOOST_TEST_EQ( X::instances, 2 );
|
||||
|
||||
r2 = r;
|
||||
|
||||
BOOST_TEST_EQ( X::instances, 2 );
|
||||
|
||||
BOOST_TEST_EQ( r, r2 );
|
||||
}
|
||||
|
||||
BOOST_TEST_EQ( X::instances, 0 );
|
||||
|
||||
{
|
||||
result<X> r( 1 );
|
||||
result<X> r2( 2 );
|
||||
|
||||
BOOST_TEST_EQ( X::instances, 2 );
|
||||
|
||||
r2 = r;
|
||||
|
||||
BOOST_TEST_EQ( X::instances, 2 );
|
||||
|
||||
BOOST_TEST_EQ( r, r2 );
|
||||
}
|
||||
|
||||
BOOST_TEST_EQ( X::instances, 0 );
|
||||
|
||||
{
|
||||
result<X> r( 1 );
|
||||
result<X> r2( ENOENT, generic_category() );
|
||||
|
||||
BOOST_TEST_EQ( X::instances, 1 );
|
||||
|
||||
r2 = r;
|
||||
|
||||
BOOST_TEST_EQ( X::instances, 2 );
|
||||
|
||||
BOOST_TEST_EQ( r, r2 );
|
||||
}
|
||||
|
||||
BOOST_TEST_EQ( X::instances, 0 );
|
||||
|
||||
{
|
||||
result<X> const r( 1 );
|
||||
result<X> r2;
|
||||
|
||||
BOOST_TEST_EQ( X::instances, 2 );
|
||||
|
||||
r2 = r;
|
||||
|
||||
BOOST_TEST_EQ( X::instances, 2 );
|
||||
|
||||
BOOST_TEST_EQ( r, r2 );
|
||||
}
|
||||
|
||||
BOOST_TEST_EQ( X::instances, 0 );
|
||||
|
||||
{
|
||||
result<X> const r( 1 );
|
||||
result<X> r2( 2 );
|
||||
|
||||
BOOST_TEST_EQ( X::instances, 2 );
|
||||
|
||||
r2 = r;
|
||||
|
||||
BOOST_TEST_EQ( X::instances, 2 );
|
||||
|
||||
BOOST_TEST_EQ( r, r2 );
|
||||
}
|
||||
|
||||
BOOST_TEST_EQ( X::instances, 0 );
|
||||
|
||||
{
|
||||
result<X> const r( 1 );
|
||||
result<X> r2( ENOENT, generic_category() );
|
||||
|
||||
BOOST_TEST_EQ( X::instances, 1 );
|
||||
|
||||
r2 = r;
|
||||
|
||||
BOOST_TEST_EQ( X::instances, 2 );
|
||||
|
||||
BOOST_TEST_EQ( r, r2 );
|
||||
}
|
||||
|
||||
BOOST_TEST_EQ( X::instances, 0 );
|
||||
|
||||
// error lhs
|
||||
|
||||
{
|
||||
auto ec = make_error_code( errc::invalid_argument );
|
||||
|
||||
result<int> r( ec );
|
||||
result<int> r2;
|
||||
|
||||
r2 = r;
|
||||
|
||||
BOOST_TEST_EQ( r, r2 );
|
||||
}
|
||||
|
||||
{
|
||||
auto ec = make_error_code( errc::invalid_argument );
|
||||
|
||||
result<int> r( ec );
|
||||
result<int> r2( 1 );
|
||||
|
||||
r2 = r;
|
||||
|
||||
BOOST_TEST_EQ( r, r2 );
|
||||
}
|
||||
|
||||
{
|
||||
auto ec = make_error_code( errc::invalid_argument );
|
||||
|
||||
result<int> r( ec );
|
||||
result<int> r2( ENOENT, generic_category() );
|
||||
|
||||
r2 = r;
|
||||
|
||||
BOOST_TEST_EQ( r, r2 );
|
||||
}
|
||||
|
||||
{
|
||||
auto ec = make_error_code( errc::invalid_argument );
|
||||
|
||||
result<int> const r( ec );
|
||||
result<int> r2;
|
||||
|
||||
r2 = r;
|
||||
|
||||
BOOST_TEST_EQ( r, r2 );
|
||||
}
|
||||
|
||||
{
|
||||
auto ec = make_error_code( errc::invalid_argument );
|
||||
|
||||
result<int> const r( ec );
|
||||
result<int> r2( 1 );
|
||||
|
||||
r2 = r;
|
||||
|
||||
BOOST_TEST_EQ( r, r2 );
|
||||
}
|
||||
|
||||
{
|
||||
auto ec = make_error_code( errc::invalid_argument );
|
||||
|
||||
result<int> const r( ec );
|
||||
result<int> r2( ENOENT, generic_category() );
|
||||
|
||||
r2 = r;
|
||||
|
||||
BOOST_TEST_EQ( r, r2 );
|
||||
}
|
||||
|
||||
BOOST_TEST_EQ( X::instances, 0 );
|
||||
|
||||
{
|
||||
auto ec = make_error_code( errc::invalid_argument );
|
||||
|
||||
result<X> r( ec );
|
||||
result<X> r2;
|
||||
|
||||
BOOST_TEST_EQ( X::instances, 1 );
|
||||
|
||||
r2 = r;
|
||||
|
||||
BOOST_TEST_EQ( X::instances, 0 );
|
||||
|
||||
BOOST_TEST_EQ( r, r2 );
|
||||
}
|
||||
|
||||
BOOST_TEST_EQ( X::instances, 0 );
|
||||
|
||||
{
|
||||
auto ec = make_error_code( errc::invalid_argument );
|
||||
|
||||
result<X> r( ec );
|
||||
result<X> r2( 1 );
|
||||
|
||||
BOOST_TEST_EQ( X::instances, 1 );
|
||||
|
||||
r2 = r;
|
||||
|
||||
BOOST_TEST_EQ( X::instances, 0 );
|
||||
|
||||
BOOST_TEST_EQ( r, r2 );
|
||||
}
|
||||
|
||||
BOOST_TEST_EQ( X::instances, 0 );
|
||||
|
||||
{
|
||||
auto ec = make_error_code( errc::invalid_argument );
|
||||
|
||||
result<X> r( ec );
|
||||
result<X> r2( ENOENT, generic_category() );
|
||||
|
||||
BOOST_TEST_EQ( X::instances, 0 );
|
||||
|
||||
r2 = r;
|
||||
|
||||
BOOST_TEST_EQ( X::instances, 0 );
|
||||
|
||||
BOOST_TEST_EQ( r, r2 );
|
||||
}
|
||||
|
||||
BOOST_TEST_EQ( X::instances, 0 );
|
||||
|
||||
{
|
||||
auto ec = make_error_code( errc::invalid_argument );
|
||||
|
||||
result<X> const r( ec );
|
||||
result<X> r2;
|
||||
|
||||
BOOST_TEST_EQ( X::instances, 1 );
|
||||
|
||||
r2 = r;
|
||||
|
||||
BOOST_TEST_EQ( X::instances, 0 );
|
||||
|
||||
BOOST_TEST_EQ( r, r2 );
|
||||
}
|
||||
|
||||
BOOST_TEST_EQ( X::instances, 0 );
|
||||
|
||||
{
|
||||
auto ec = make_error_code( errc::invalid_argument );
|
||||
|
||||
result<X> const r( ec );
|
||||
result<X> r2( 1 );
|
||||
|
||||
BOOST_TEST_EQ( X::instances, 1 );
|
||||
|
||||
r2 = r;
|
||||
|
||||
BOOST_TEST_EQ( X::instances, 0 );
|
||||
|
||||
BOOST_TEST_EQ( r, r2 );
|
||||
}
|
||||
|
||||
BOOST_TEST_EQ( X::instances, 0 );
|
||||
|
||||
{
|
||||
auto ec = make_error_code( errc::invalid_argument );
|
||||
|
||||
result<X> const r( ec );
|
||||
result<X> r2( ENOENT, generic_category() );
|
||||
|
||||
BOOST_TEST_EQ( X::instances, 0 );
|
||||
|
||||
r2 = r;
|
||||
|
||||
BOOST_TEST_EQ( X::instances, 0 );
|
||||
|
||||
BOOST_TEST_EQ( r, r2 );
|
||||
}
|
||||
|
||||
BOOST_TEST_EQ( X::instances, 0 );
|
||||
|
||||
//
|
||||
|
||||
BOOST_TEST_EQ( Y::instances, 0 );
|
||||
|
||||
{
|
||||
result<std::string, Y> r( 1 );
|
||||
result<std::string, Y> r2( 2 );
|
||||
|
||||
BOOST_TEST_EQ( Y::instances, 2 );
|
||||
|
||||
r2 = r;
|
||||
|
||||
BOOST_TEST_EQ( Y::instances, 2 );
|
||||
|
||||
BOOST_TEST_EQ( r, r2 );
|
||||
}
|
||||
|
||||
BOOST_TEST_EQ( Y::instances, 0 );
|
||||
|
||||
{
|
||||
result<std::string, Y> r( 1 );
|
||||
result<std::string, Y> r2( "str" );
|
||||
|
||||
BOOST_TEST_EQ( Y::instances, 1 );
|
||||
|
||||
r2 = r;
|
||||
|
||||
BOOST_TEST_EQ( Y::instances, 2 );
|
||||
|
||||
BOOST_TEST_EQ( r, r2 );
|
||||
}
|
||||
|
||||
BOOST_TEST_EQ( Y::instances, 0 );
|
||||
|
||||
{
|
||||
result<std::string, Y> const r( 1 );
|
||||
result<std::string, Y> r2( 2 );
|
||||
|
||||
BOOST_TEST_EQ( Y::instances, 2 );
|
||||
|
||||
r2 = r;
|
||||
|
||||
BOOST_TEST_EQ( Y::instances, 2 );
|
||||
|
||||
BOOST_TEST_EQ( r, r2 );
|
||||
}
|
||||
|
||||
BOOST_TEST_EQ( Y::instances, 0 );
|
||||
|
||||
{
|
||||
result<std::string, Y> const r( 1 );
|
||||
result<std::string, Y> r2( "str" );
|
||||
|
||||
BOOST_TEST_EQ( Y::instances, 1 );
|
||||
|
||||
r2 = r;
|
||||
|
||||
BOOST_TEST_EQ( Y::instances, 2 );
|
||||
|
||||
BOOST_TEST_EQ( r, r2 );
|
||||
}
|
||||
|
||||
BOOST_TEST_EQ( Y::instances, 0 );
|
||||
|
||||
// void
|
||||
|
||||
{
|
||||
result<void> r;
|
||||
result<void> r2;
|
||||
|
||||
r2 = r;
|
||||
|
||||
BOOST_TEST_EQ( r, r2 );
|
||||
}
|
||||
|
||||
{
|
||||
result<void> r;
|
||||
result<void> r2( ENOENT, generic_category() );
|
||||
|
||||
r2 = r;
|
||||
|
||||
BOOST_TEST_EQ( r, r2 );
|
||||
}
|
||||
|
||||
{
|
||||
result<void> const r;
|
||||
result<void> r2;
|
||||
|
||||
r2 = r;
|
||||
|
||||
BOOST_TEST_EQ( r, r2 );
|
||||
}
|
||||
|
||||
{
|
||||
result<void> const r;
|
||||
result<void> r2( ENOENT, generic_category() );
|
||||
|
||||
r2 = r;
|
||||
|
||||
BOOST_TEST_EQ( r, r2 );
|
||||
}
|
||||
|
||||
{
|
||||
auto ec = make_error_code( errc::invalid_argument );
|
||||
|
||||
result<void> r( ec );
|
||||
result<void> r2;
|
||||
|
||||
r2 = r;
|
||||
|
||||
BOOST_TEST_EQ( r, r2 );
|
||||
}
|
||||
|
||||
{
|
||||
auto ec = make_error_code( errc::invalid_argument );
|
||||
|
||||
result<void> r( ec );
|
||||
result<void> r2( ENOENT, generic_category() );
|
||||
|
||||
r2 = r;
|
||||
|
||||
BOOST_TEST_EQ( r, r2 );
|
||||
}
|
||||
|
||||
{
|
||||
auto ec = make_error_code( errc::invalid_argument );
|
||||
|
||||
result<void> const r( ec );
|
||||
result<void> r2;
|
||||
|
||||
r2 = r;
|
||||
|
||||
BOOST_TEST_EQ( r, r2 );
|
||||
}
|
||||
|
||||
{
|
||||
auto ec = make_error_code( errc::invalid_argument );
|
||||
|
||||
result<void> const r( ec );
|
||||
result<void> r2( ENOENT, generic_category() );
|
||||
|
||||
r2 = r;
|
||||
|
||||
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();
|
||||
}
|
||||
299
test/result_copy_construct.cpp
Normal file
299
test/result_copy_construct.cpp
Normal file
@@ -0,0 +1,299 @@
|
||||
// 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>
|
||||
|
||||
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; }
|
||||
};
|
||||
|
||||
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;
|
||||
result<int> r2( r );
|
||||
|
||||
BOOST_TEST_EQ( r, r2 );
|
||||
}
|
||||
|
||||
{
|
||||
result<int> const r;
|
||||
result<int> r2( r );
|
||||
|
||||
BOOST_TEST_EQ( r, r2 );
|
||||
}
|
||||
|
||||
BOOST_TEST_EQ( X::instances, 0 );
|
||||
|
||||
{
|
||||
result<X> r;
|
||||
result<X> r2( r );
|
||||
|
||||
BOOST_TEST_EQ( r, r2 );
|
||||
BOOST_TEST_EQ( X::instances, 2 );
|
||||
}
|
||||
|
||||
BOOST_TEST_EQ( X::instances, 0 );
|
||||
|
||||
{
|
||||
result<int> r( 1 );
|
||||
result<int> r2( r );
|
||||
|
||||
BOOST_TEST_EQ( r, r2 );
|
||||
}
|
||||
|
||||
{
|
||||
result<int> const r( 1 );
|
||||
result<int> r2( r );
|
||||
|
||||
BOOST_TEST_EQ( r, r2 );
|
||||
}
|
||||
|
||||
BOOST_TEST_EQ( X::instances, 0 );
|
||||
|
||||
{
|
||||
result<X> r( 1 );
|
||||
result<X> r2( r );
|
||||
|
||||
BOOST_TEST_EQ( r, r2 );
|
||||
BOOST_TEST_EQ( X::instances, 2 );
|
||||
}
|
||||
|
||||
BOOST_TEST_EQ( X::instances, 0 );
|
||||
|
||||
{
|
||||
result<X> const r( 1 );
|
||||
result<X> r2( r );
|
||||
|
||||
BOOST_TEST_EQ( r, r2 );
|
||||
BOOST_TEST_EQ( X::instances, 2 );
|
||||
}
|
||||
|
||||
BOOST_TEST_EQ( X::instances, 0 );
|
||||
|
||||
{
|
||||
auto ec = make_error_code( errc::invalid_argument );
|
||||
|
||||
result<int> r( ec );
|
||||
result<int> r2( r );
|
||||
|
||||
BOOST_TEST_EQ( r, r2 );
|
||||
}
|
||||
|
||||
{
|
||||
auto ec = make_error_code( errc::invalid_argument );
|
||||
|
||||
result<int> const r( ec );
|
||||
result<int> r2( r );
|
||||
|
||||
BOOST_TEST_EQ( r, r2 );
|
||||
}
|
||||
|
||||
BOOST_TEST_EQ( X::instances, 0 );
|
||||
|
||||
{
|
||||
result<std::string, X> r( 1 );
|
||||
result<std::string, X> r2( r );
|
||||
|
||||
BOOST_TEST_EQ( r, r2 );
|
||||
BOOST_TEST_EQ( X::instances, 2 );
|
||||
}
|
||||
|
||||
BOOST_TEST_EQ( X::instances, 0 );
|
||||
|
||||
{
|
||||
result<std::string, X> const r( 1 );
|
||||
result<std::string, X> r2( r );
|
||||
|
||||
BOOST_TEST_EQ( r, r2 );
|
||||
BOOST_TEST_EQ( X::instances, 2 );
|
||||
}
|
||||
|
||||
BOOST_TEST_EQ( X::instances, 0 );
|
||||
|
||||
//
|
||||
|
||||
{
|
||||
result<void> r;
|
||||
result<void> r2( r );
|
||||
|
||||
BOOST_TEST_EQ( r, r2 );
|
||||
}
|
||||
|
||||
{
|
||||
result<void> const r;
|
||||
result<void> r2( r );
|
||||
|
||||
BOOST_TEST_EQ( r, r2 );
|
||||
}
|
||||
|
||||
{
|
||||
auto ec = make_error_code( errc::invalid_argument );
|
||||
|
||||
result<void> r( ec );
|
||||
result<void> r2( r );
|
||||
|
||||
BOOST_TEST_EQ( r, r2 );
|
||||
}
|
||||
|
||||
{
|
||||
auto ec = make_error_code( errc::invalid_argument );
|
||||
|
||||
result<void> const r( ec );
|
||||
result<void> r2( r );
|
||||
|
||||
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();
|
||||
}
|
||||
107
test/result_default_construct.cpp
Normal file
107
test/result_default_construct.cpp
Normal file
@@ -0,0 +1,107 @@
|
||||
// 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>
|
||||
|
||||
using namespace boost::system;
|
||||
|
||||
struct X
|
||||
{
|
||||
};
|
||||
|
||||
struct Y
|
||||
{
|
||||
Y( int );
|
||||
};
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
result<int> r;
|
||||
|
||||
BOOST_TEST( r.has_value() );
|
||||
BOOST_TEST( !r.has_error() );
|
||||
|
||||
BOOST_TEST_EQ( r.value(), 0 );
|
||||
}
|
||||
|
||||
{
|
||||
result<int> r{};
|
||||
|
||||
BOOST_TEST( r.has_value() );
|
||||
BOOST_TEST( !r.has_error() );
|
||||
|
||||
BOOST_TEST_EQ( r.value(), 0 );
|
||||
}
|
||||
|
||||
{
|
||||
result<int> r = {};
|
||||
|
||||
BOOST_TEST( r.has_value() );
|
||||
BOOST_TEST( !r.has_error() );
|
||||
|
||||
BOOST_TEST_EQ( r.value(), 0 );
|
||||
}
|
||||
|
||||
{
|
||||
result<X> r;
|
||||
|
||||
BOOST_TEST( r.has_value() );
|
||||
BOOST_TEST( !r.has_error() );
|
||||
}
|
||||
|
||||
{
|
||||
result<X> r{};
|
||||
|
||||
BOOST_TEST( r.has_value() );
|
||||
BOOST_TEST( !r.has_error() );
|
||||
}
|
||||
|
||||
{
|
||||
result<X> r = {};
|
||||
|
||||
BOOST_TEST( r.has_value() );
|
||||
BOOST_TEST( !r.has_error() );
|
||||
}
|
||||
|
||||
{
|
||||
result<void> r;
|
||||
|
||||
BOOST_TEST( r.has_value() );
|
||||
BOOST_TEST( !r.has_error() );
|
||||
}
|
||||
|
||||
{
|
||||
result<void> r{};
|
||||
|
||||
BOOST_TEST( r.has_value() );
|
||||
BOOST_TEST( !r.has_error() );
|
||||
}
|
||||
|
||||
{
|
||||
result<void> r = {};
|
||||
|
||||
BOOST_TEST( r.has_value() );
|
||||
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();
|
||||
}
|
||||
231
test/result_eq.cpp
Normal file
231
test/result_eq.cpp
Normal file
@@ -0,0 +1,231 @@
|
||||
// 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 <iosfwd>
|
||||
#include <cerrno>
|
||||
|
||||
using namespace boost::system;
|
||||
|
||||
struct X
|
||||
{
|
||||
static int instances;
|
||||
|
||||
int v_;
|
||||
|
||||
explicit X( int v ): v_( v ) { ++instances; }
|
||||
|
||||
X( X const& r ) = delete;
|
||||
X( X&& r ): v_( r.v_ ) { r.v_ = 0; ++instances; }
|
||||
|
||||
X& operator=( X const& ) = delete;
|
||||
|
||||
X& operator=( X&& r )
|
||||
{
|
||||
v_ = r.v_;
|
||||
r.v_ = 0;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
~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;
|
||||
|
||||
struct Y
|
||||
{
|
||||
static int instances;
|
||||
|
||||
int v_;
|
||||
|
||||
explicit Y( int v = 0 ): v_( v ) { ++instances; }
|
||||
|
||||
Y( Y const& r ) noexcept: v_( r.v_ ) { ++instances; }
|
||||
Y( Y&& r ) noexcept: v_( r.v_ ) { r.v_ = 0; ++instances; }
|
||||
|
||||
Y& operator=( Y const& ) = default;
|
||||
|
||||
Y& operator=( Y&& r )
|
||||
{
|
||||
v_ = r.v_;
|
||||
r.v_ = 0;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
~Y() { --instances; }
|
||||
};
|
||||
|
||||
bool operator==( Y const & y1, Y const & y2 )
|
||||
{
|
||||
return y1.v_ == y2.v_;
|
||||
}
|
||||
|
||||
std::ostream& operator<<( std::ostream& os, Y const & y )
|
||||
{
|
||||
os << "Y:" << y.v_;
|
||||
return os;
|
||||
}
|
||||
|
||||
int Y::instances = 0;
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
result<int> r1( 1 );
|
||||
result<int> r2( 2 );
|
||||
|
||||
BOOST_TEST_EQ( r1, r1 );
|
||||
BOOST_TEST_NE( r1, r2 );
|
||||
}
|
||||
|
||||
{
|
||||
result<int> r1( 1, generic_category() );
|
||||
result<int> r2( 2, generic_category() );
|
||||
|
||||
BOOST_TEST_EQ( r1, r1 );
|
||||
BOOST_TEST_NE( r1, r2 );
|
||||
}
|
||||
|
||||
{
|
||||
result<int> r1( 1 );
|
||||
result<int> r2( 2, generic_category() );
|
||||
|
||||
BOOST_TEST_EQ( r1, r1 );
|
||||
BOOST_TEST_NE( r1, r2 );
|
||||
}
|
||||
|
||||
{
|
||||
result<X, Y> r1( in_place_value, 1 );
|
||||
result<X, Y> r2( in_place_value, 2 );
|
||||
|
||||
BOOST_TEST_EQ( r1, r1 );
|
||||
BOOST_TEST_NE( 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 );
|
||||
}
|
||||
|
||||
{
|
||||
result<X, Y> r1( in_place_value, 1 );
|
||||
result<X, Y> r2( in_place_error, 2 );
|
||||
|
||||
BOOST_TEST_EQ( r1, r1 );
|
||||
BOOST_TEST_NE( r1, r2 );
|
||||
}
|
||||
|
||||
{
|
||||
result<void> r1;
|
||||
result<void> r2;
|
||||
|
||||
BOOST_TEST_EQ( r1, r1 );
|
||||
BOOST_TEST_EQ( r1, r2 );
|
||||
}
|
||||
|
||||
{
|
||||
result<void> r1( 1, generic_category() );
|
||||
result<void> r2( 2, generic_category() );
|
||||
|
||||
BOOST_TEST_EQ( r1, r1 );
|
||||
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();
|
||||
}
|
||||
280
test/result_error_access.cpp
Normal file
280
test/result_error_access.cpp
Normal file
@@ -0,0 +1,280 @@
|
||||
// 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>
|
||||
|
||||
using namespace boost::system;
|
||||
|
||||
struct X
|
||||
{
|
||||
int v_;
|
||||
|
||||
explicit X( int v = 0 ): v_( v ) {}
|
||||
|
||||
X( X const& ) = default;
|
||||
X& operator=( X const& ) = delete;
|
||||
};
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
result<int> r;
|
||||
|
||||
BOOST_TEST( r.has_value() );
|
||||
BOOST_TEST( !r.has_error() );
|
||||
|
||||
BOOST_TEST_EQ( r.error(), error_code() );
|
||||
}
|
||||
|
||||
{
|
||||
result<int> const r;
|
||||
|
||||
BOOST_TEST( r.has_value() );
|
||||
BOOST_TEST( !r.has_error() );
|
||||
|
||||
BOOST_TEST_EQ( r.error(), error_code() );
|
||||
}
|
||||
|
||||
{
|
||||
BOOST_TEST( result<int>().has_value() );
|
||||
BOOST_TEST( !result<int>().has_error() );
|
||||
|
||||
BOOST_TEST_EQ( result<int>().error(), error_code() );
|
||||
}
|
||||
|
||||
{
|
||||
result<int> r( 1 );
|
||||
|
||||
BOOST_TEST( r.has_value() );
|
||||
BOOST_TEST( !r.has_error() );
|
||||
|
||||
BOOST_TEST_EQ( r.error(), error_code() );
|
||||
}
|
||||
|
||||
{
|
||||
result<int> const r( 1 );
|
||||
|
||||
BOOST_TEST( r.has_value() );
|
||||
BOOST_TEST( !r.has_error() );
|
||||
|
||||
BOOST_TEST_EQ( r.error(), error_code() );
|
||||
}
|
||||
|
||||
{
|
||||
BOOST_TEST( result<int>( 1 ).has_value() );
|
||||
BOOST_TEST( !result<int>( 1 ).has_error() );
|
||||
|
||||
BOOST_TEST_EQ( result<int>( 1 ).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 );
|
||||
}
|
||||
|
||||
{
|
||||
result<std::string, X> r( 1 );
|
||||
|
||||
BOOST_TEST( !r.has_value() );
|
||||
BOOST_TEST( r.has_error() );
|
||||
|
||||
BOOST_TEST_EQ( r.error().v_, 1 );
|
||||
}
|
||||
|
||||
{
|
||||
result<std::string, X> const r( 1 );
|
||||
|
||||
BOOST_TEST( !r.has_value() );
|
||||
BOOST_TEST( r.has_error() );
|
||||
|
||||
BOOST_TEST_EQ( 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( r.error().v_, 0 );
|
||||
}
|
||||
|
||||
{
|
||||
result<std::string, X> const r( "s" );
|
||||
|
||||
BOOST_TEST( r.has_value() );
|
||||
BOOST_TEST( !r.has_error() );
|
||||
|
||||
BOOST_TEST_EQ( 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> r;
|
||||
|
||||
BOOST_TEST( r.has_value() );
|
||||
BOOST_TEST( !r.has_error() );
|
||||
|
||||
BOOST_TEST_EQ( r.error(), error_code() );
|
||||
}
|
||||
|
||||
{
|
||||
result<void> const r;
|
||||
|
||||
BOOST_TEST( r.has_value() );
|
||||
BOOST_TEST( !r.has_error() );
|
||||
|
||||
BOOST_TEST_EQ( r.error(), error_code() );
|
||||
}
|
||||
|
||||
{
|
||||
BOOST_TEST( result<void>().has_value() );
|
||||
BOOST_TEST( !result<void>().has_error() );
|
||||
|
||||
BOOST_TEST_EQ( result<void>().error(), error_code() );
|
||||
}
|
||||
|
||||
{
|
||||
auto ec = make_error_code( errc::invalid_argument );
|
||||
|
||||
result<void> 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<void> 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<void>( ec ).has_value() );
|
||||
BOOST_TEST( result<void>( ec ).has_error() );
|
||||
|
||||
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();
|
||||
}
|
||||
191
test/result_error_construct.cpp
Normal file
191
test/result_error_construct.cpp
Normal file
@@ -0,0 +1,191 @@
|
||||
// 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>>));
|
||||
|
||||
// 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>>));
|
||||
}
|
||||
|
||||
{
|
||||
auto ec = make_error_code( errc::invalid_argument );
|
||||
|
||||
result<void> 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<void> r = ec;
|
||||
|
||||
BOOST_TEST( !r.has_value() );
|
||||
BOOST_TEST( r.has_error() );
|
||||
|
||||
BOOST_TEST_EQ( r.error(), ec );
|
||||
}
|
||||
|
||||
{
|
||||
result<void> r( 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();
|
||||
}
|
||||
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();
|
||||
}
|
||||
45
test/result_error_construct4.cpp
Normal file
45
test/result_error_construct4.cpp
Normal file
@@ -0,0 +1,45 @@
|
||||
// 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 );
|
||||
}
|
||||
|
||||
{
|
||||
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 );
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
22
test/result_in_place_use.cpp
Normal file
22
test/result_in_place_use.cpp
Normal file
@@ -0,0 +1,22 @@
|
||||
// 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>
|
||||
|
||||
template<class T, class U> void test( T const& t, U const& u )
|
||||
{
|
||||
BOOST_TEST_NE( static_cast<void const*>( &t ), static_cast<void const*>( &u ) );
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
using namespace boost::system;
|
||||
|
||||
test( result<int>::in_place_value, result<int>::in_place_error );
|
||||
test( result<void>::in_place_value, result<void>::in_place_error );
|
||||
test( result<int&>::in_place_value, result<int&>::in_place_error );
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
711
test/result_move_assign.cpp
Normal file
711
test/result_move_assign.cpp
Normal file
@@ -0,0 +1,711 @@
|
||||
// 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 <iosfwd>
|
||||
#include <cerrno>
|
||||
|
||||
using namespace boost::system;
|
||||
|
||||
struct X
|
||||
{
|
||||
static int instances;
|
||||
|
||||
int v_;
|
||||
|
||||
explicit X( int v = 0 ): v_( v ) { ++instances; }
|
||||
|
||||
X( X const& r ) = delete;
|
||||
X( X&& r ): v_( r.v_ ) { r.v_ = 0; ++instances; }
|
||||
|
||||
X& operator=( X const& ) = delete;
|
||||
|
||||
X& operator=( X&& r )
|
||||
{
|
||||
v_ = r.v_;
|
||||
r.v_ = 0;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
~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;
|
||||
|
||||
struct Y
|
||||
{
|
||||
static int instances;
|
||||
|
||||
int v_;
|
||||
|
||||
explicit Y( int v = 0 ): v_( v ) { ++instances; }
|
||||
|
||||
Y( Y const& r ) noexcept: v_( r.v_ ) { ++instances; }
|
||||
Y( Y&& r ) noexcept: v_( r.v_ ) { r.v_ = 0; ++instances; }
|
||||
|
||||
Y& operator=( Y const& ) = default;
|
||||
|
||||
Y& operator=( Y&& r )
|
||||
{
|
||||
v_ = r.v_;
|
||||
r.v_ = 0;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
~Y() { --instances; }
|
||||
};
|
||||
|
||||
bool operator==( Y const & y1, Y const & y2 )
|
||||
{
|
||||
return y1.v_ == y2.v_;
|
||||
}
|
||||
|
||||
std::ostream& operator<<( std::ostream& os, Y const & y )
|
||||
{
|
||||
os << "Y:" << y.v_;
|
||||
return os;
|
||||
}
|
||||
|
||||
int Y::instances = 0;
|
||||
|
||||
int main()
|
||||
{
|
||||
// default-initialized lhs
|
||||
|
||||
{
|
||||
result<int> r;
|
||||
result<int> r2;
|
||||
|
||||
r2 = std::move( r );
|
||||
|
||||
BOOST_TEST( r2.has_value() );
|
||||
BOOST_TEST( !r2.has_error() );
|
||||
|
||||
BOOST_TEST_EQ( r2.value(), 0 );
|
||||
}
|
||||
|
||||
{
|
||||
result<int> r2;
|
||||
|
||||
r2 = result<int>();
|
||||
|
||||
BOOST_TEST( r2.has_value() );
|
||||
BOOST_TEST( !r2.has_error() );
|
||||
|
||||
BOOST_TEST_EQ( r2.value(), 0 );
|
||||
}
|
||||
|
||||
{
|
||||
result<int> r;
|
||||
result<int> r2( 1 );
|
||||
|
||||
r2 = std::move( r );
|
||||
|
||||
BOOST_TEST( r2.has_value() );
|
||||
BOOST_TEST( !r2.has_error() );
|
||||
|
||||
BOOST_TEST_EQ( r2.value(), 0 );
|
||||
}
|
||||
|
||||
{
|
||||
result<int> r2( 1 );
|
||||
|
||||
r2 = result<int>();
|
||||
|
||||
BOOST_TEST( r2.has_value() );
|
||||
BOOST_TEST( !r2.has_error() );
|
||||
|
||||
BOOST_TEST_EQ( r2.value(), 0 );
|
||||
}
|
||||
|
||||
{
|
||||
result<int> r;
|
||||
result<int> r2( ENOENT, generic_category() );
|
||||
|
||||
r2 = std::move( r );
|
||||
|
||||
BOOST_TEST( r2.has_value() );
|
||||
BOOST_TEST( !r2.has_error() );
|
||||
|
||||
BOOST_TEST_EQ( r2.value(), 0 );
|
||||
}
|
||||
|
||||
{
|
||||
result<int> r2( ENOENT, generic_category() );
|
||||
|
||||
r2 = result<int>();
|
||||
|
||||
BOOST_TEST( r2.has_value() );
|
||||
BOOST_TEST( !r2.has_error() );
|
||||
|
||||
BOOST_TEST_EQ( r2.value(), 0 );
|
||||
}
|
||||
|
||||
BOOST_TEST_EQ( X::instances, 0 );
|
||||
|
||||
{
|
||||
result<X> r;
|
||||
result<X> r2;
|
||||
|
||||
BOOST_TEST_EQ( X::instances, 2 );
|
||||
|
||||
r2 = std::move( r );
|
||||
|
||||
BOOST_TEST_EQ( X::instances, 2 );
|
||||
|
||||
BOOST_TEST( r2.has_value() );
|
||||
BOOST_TEST( !r2.has_error() );
|
||||
|
||||
BOOST_TEST_EQ( r2.value(), X() );
|
||||
}
|
||||
|
||||
BOOST_TEST_EQ( X::instances, 0 );
|
||||
|
||||
{
|
||||
result<X> r;
|
||||
result<X> r2( 1 );
|
||||
|
||||
BOOST_TEST_EQ( X::instances, 2 );
|
||||
|
||||
r2 = std::move( r );
|
||||
|
||||
BOOST_TEST_EQ( X::instances, 2 );
|
||||
|
||||
BOOST_TEST( r2.has_value() );
|
||||
BOOST_TEST( !r2.has_error() );
|
||||
|
||||
BOOST_TEST_EQ( r2.value(), X() );
|
||||
}
|
||||
|
||||
BOOST_TEST_EQ( X::instances, 0 );
|
||||
|
||||
{
|
||||
result<X> r;
|
||||
result<X> r2( ENOENT, generic_category() );
|
||||
|
||||
BOOST_TEST_EQ( X::instances, 1 );
|
||||
|
||||
r2 = std::move( r );
|
||||
|
||||
BOOST_TEST_EQ( X::instances, 2 );
|
||||
|
||||
BOOST_TEST( r2.has_value() );
|
||||
BOOST_TEST( !r2.has_error() );
|
||||
|
||||
BOOST_TEST_EQ( r2.value(), X() );
|
||||
}
|
||||
|
||||
BOOST_TEST_EQ( X::instances, 0 );
|
||||
|
||||
// value lhs
|
||||
|
||||
{
|
||||
result<int> r( 1 );
|
||||
result<int> r2;
|
||||
|
||||
r2 = std::move( r );
|
||||
|
||||
BOOST_TEST( r2.has_value() );
|
||||
BOOST_TEST( !r2.has_error() );
|
||||
|
||||
BOOST_TEST_EQ( r2.value(), 1 );
|
||||
|
||||
BOOST_TEST_EQ( r, r2 );
|
||||
}
|
||||
|
||||
{
|
||||
result<int> r( 1 );
|
||||
result<int> r2( 2 );
|
||||
|
||||
r2 = std::move( r );
|
||||
|
||||
BOOST_TEST( r2.has_value() );
|
||||
BOOST_TEST( !r2.has_error() );
|
||||
|
||||
BOOST_TEST_EQ( r2.value(), 1 );
|
||||
|
||||
BOOST_TEST_EQ( r, r2 );
|
||||
}
|
||||
|
||||
{
|
||||
result<int> r( 1 );
|
||||
result<int> r2( ENOENT, generic_category() );
|
||||
|
||||
r2 = std::move( r );
|
||||
|
||||
BOOST_TEST( r2.has_value() );
|
||||
BOOST_TEST( !r2.has_error() );
|
||||
|
||||
BOOST_TEST_EQ( r2.value(), 1 );
|
||||
|
||||
BOOST_TEST_EQ( r, r2 );
|
||||
}
|
||||
|
||||
BOOST_TEST_EQ( X::instances, 0 );
|
||||
|
||||
{
|
||||
result<X> r( 1 );
|
||||
result<X> r2;
|
||||
|
||||
BOOST_TEST_EQ( X::instances, 2 );
|
||||
|
||||
r2 = std::move( r );
|
||||
|
||||
BOOST_TEST_EQ( X::instances, 2 );
|
||||
|
||||
BOOST_TEST( r2.has_value() );
|
||||
BOOST_TEST( !r2.has_error() );
|
||||
|
||||
BOOST_TEST_EQ( r2.value().v_, 1 );
|
||||
|
||||
BOOST_TEST_EQ( r.value().v_, 0 );
|
||||
}
|
||||
|
||||
BOOST_TEST_EQ( X::instances, 0 );
|
||||
|
||||
{
|
||||
result<X> r( 1 );
|
||||
result<X> r2( 2 );
|
||||
|
||||
BOOST_TEST_EQ( X::instances, 2 );
|
||||
|
||||
r2 = std::move( r );
|
||||
|
||||
BOOST_TEST_EQ( X::instances, 2 );
|
||||
|
||||
BOOST_TEST( r2.has_value() );
|
||||
BOOST_TEST( !r2.has_error() );
|
||||
|
||||
BOOST_TEST_EQ( r2.value().v_, 1 );
|
||||
|
||||
BOOST_TEST_EQ( r.value().v_, 0 );
|
||||
}
|
||||
|
||||
BOOST_TEST_EQ( X::instances, 0 );
|
||||
|
||||
{
|
||||
result<X> r( 1 );
|
||||
result<X> r2( ENOENT, generic_category() );
|
||||
|
||||
BOOST_TEST_EQ( X::instances, 1 );
|
||||
|
||||
r2 = std::move( r );
|
||||
|
||||
BOOST_TEST_EQ( X::instances, 2 );
|
||||
|
||||
BOOST_TEST( r2.has_value() );
|
||||
BOOST_TEST( !r2.has_error() );
|
||||
|
||||
BOOST_TEST_EQ( r2.value().v_, 1 );
|
||||
|
||||
BOOST_TEST_EQ( r.value().v_, 0 );
|
||||
}
|
||||
|
||||
BOOST_TEST_EQ( X::instances, 0 );
|
||||
|
||||
// error lhs
|
||||
|
||||
{
|
||||
auto ec = make_error_code( errc::invalid_argument );
|
||||
|
||||
result<int> r( ec );
|
||||
result<int> r2;
|
||||
|
||||
r2 = std::move( r );
|
||||
|
||||
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;
|
||||
|
||||
r2 = result<int>( ec );
|
||||
|
||||
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> r( ec );
|
||||
result<int> r2( 1 );
|
||||
|
||||
r2 = std::move( r );
|
||||
|
||||
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( 1 );
|
||||
|
||||
r2 = result<int>( ec );
|
||||
|
||||
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> r( ec );
|
||||
result<int> r2( ENOENT, generic_category() );
|
||||
|
||||
r2 = std::move( r );
|
||||
|
||||
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 );
|
||||
}
|
||||
|
||||
BOOST_TEST_EQ( X::instances, 0 );
|
||||
|
||||
{
|
||||
auto ec = make_error_code( errc::invalid_argument );
|
||||
|
||||
result<X> r( ec );
|
||||
result<X> r2;
|
||||
|
||||
BOOST_TEST_EQ( X::instances, 1 );
|
||||
|
||||
r2 = std::move( r );
|
||||
|
||||
BOOST_TEST_EQ( X::instances, 0 );
|
||||
|
||||
BOOST_TEST( !r2.has_value() );
|
||||
BOOST_TEST( r2.has_error() );
|
||||
|
||||
BOOST_TEST_EQ( r2.error(), ec );
|
||||
}
|
||||
|
||||
BOOST_TEST_EQ( X::instances, 0 );
|
||||
|
||||
{
|
||||
auto ec = make_error_code( errc::invalid_argument );
|
||||
|
||||
result<X> r( ec );
|
||||
result<X> r2( 1 );
|
||||
|
||||
BOOST_TEST_EQ( X::instances, 1 );
|
||||
|
||||
r2 = std::move( r );
|
||||
|
||||
BOOST_TEST_EQ( X::instances, 0 );
|
||||
|
||||
BOOST_TEST( !r2.has_value() );
|
||||
BOOST_TEST( r2.has_error() );
|
||||
|
||||
BOOST_TEST_EQ( r2.error(), ec );
|
||||
}
|
||||
|
||||
BOOST_TEST_EQ( X::instances, 0 );
|
||||
|
||||
{
|
||||
auto ec = make_error_code( errc::invalid_argument );
|
||||
|
||||
result<X> r( ec );
|
||||
result<X> r2( ENOENT, generic_category() );
|
||||
|
||||
BOOST_TEST_EQ( X::instances, 0 );
|
||||
|
||||
r2 = std::move( r );
|
||||
|
||||
BOOST_TEST_EQ( X::instances, 0 );
|
||||
|
||||
BOOST_TEST( !r2.has_value() );
|
||||
BOOST_TEST( r2.has_error() );
|
||||
|
||||
BOOST_TEST_EQ( r2.error(), ec );
|
||||
}
|
||||
|
||||
BOOST_TEST_EQ( X::instances, 0 );
|
||||
|
||||
//
|
||||
|
||||
BOOST_TEST_EQ( Y::instances, 0 );
|
||||
|
||||
{
|
||||
result<std::string, Y> r( 1 );
|
||||
result<std::string, Y> r2( 2 );
|
||||
|
||||
BOOST_TEST_EQ( Y::instances, 2 );
|
||||
|
||||
r2 = std::move( r );
|
||||
|
||||
BOOST_TEST_EQ( Y::instances, 2 );
|
||||
|
||||
BOOST_TEST( !r2.has_value() );
|
||||
BOOST_TEST( r2.has_error() );
|
||||
|
||||
BOOST_TEST_EQ( r2.error().v_, 1 );
|
||||
|
||||
BOOST_TEST_EQ( r.error().v_, 0 );
|
||||
}
|
||||
|
||||
BOOST_TEST_EQ( Y::instances, 0 );
|
||||
|
||||
{
|
||||
result<std::string, Y> r( 1 );
|
||||
result<std::string, Y> r2( "str" );
|
||||
|
||||
BOOST_TEST_EQ( Y::instances, 1 );
|
||||
|
||||
r2 = std::move( r );
|
||||
|
||||
BOOST_TEST_EQ( Y::instances, 2 );
|
||||
|
||||
BOOST_TEST( !r2.has_value() );
|
||||
BOOST_TEST( r2.has_error() );
|
||||
|
||||
BOOST_TEST_EQ( r2.error().v_, 1 );
|
||||
|
||||
BOOST_TEST_EQ( r.error().v_, 0 );
|
||||
}
|
||||
|
||||
BOOST_TEST_EQ( Y::instances, 0 );
|
||||
|
||||
//
|
||||
|
||||
{
|
||||
result<void> r;
|
||||
result<void> r2;
|
||||
|
||||
r2 = std::move( r );
|
||||
|
||||
BOOST_TEST( r2.has_value() );
|
||||
BOOST_TEST( !r2.has_error() );
|
||||
}
|
||||
|
||||
{
|
||||
result<void> r2;
|
||||
|
||||
r2 = result<void>();
|
||||
|
||||
BOOST_TEST( r2.has_value() );
|
||||
BOOST_TEST( !r2.has_error() );
|
||||
}
|
||||
|
||||
{
|
||||
result<void> r;
|
||||
result<void> r2( ENOENT, generic_category() );
|
||||
|
||||
r2 = std::move( r );
|
||||
|
||||
BOOST_TEST( r2.has_value() );
|
||||
BOOST_TEST( !r2.has_error() );
|
||||
}
|
||||
|
||||
{
|
||||
result<void> r2( ENOENT, generic_category() );
|
||||
|
||||
r2 = result<void>();
|
||||
|
||||
BOOST_TEST( r2.has_value() );
|
||||
BOOST_TEST( !r2.has_error() );
|
||||
}
|
||||
|
||||
{
|
||||
auto ec = make_error_code( errc::invalid_argument );
|
||||
|
||||
result<void> r( ec );
|
||||
result<void> r2;
|
||||
|
||||
r2 = std::move( r );
|
||||
|
||||
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<void> r2;
|
||||
|
||||
r2 = result<void>( ec );
|
||||
|
||||
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<void> r( ec );
|
||||
result<void> r2( ENOENT, generic_category() );
|
||||
|
||||
r2 = std::move( r );
|
||||
|
||||
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<void> r2( ENOENT, generic_category() );
|
||||
|
||||
r2 = result<void>( ec );
|
||||
|
||||
BOOST_TEST( !r2.has_value() );
|
||||
BOOST_TEST( r2.has_error() );
|
||||
|
||||
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();
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user