Compare commits

...

107 Commits

Author SHA1 Message Date
Peter Dimov
8bc32b7267 Update documentation 2023-10-31 04:20:33 +02:00
Peter Dimov
d11dd4b396 Add operator&=( result&, unary-returning-result ) 2023-10-31 03:08:02 +02:00
Peter Dimov
ca5bca39ce Add operator&=( result&, unary-returning-value ) 2023-10-31 02:44:45 +02:00
Peter Dimov
a58115cb50 Reorder operator& code for better codegen 2023-10-31 01:51:38 +02:00
Peter Dimov
1bc08296de Update documentation 2023-10-30 21:03:39 +02:00
Peter Dimov
25479216b3 Fix test file names 2023-10-30 00:52:38 +02:00
Peter Dimov
54d3b253b1 Add operator&( result, unary-returning-result ) 2023-10-29 20:57:29 +02:00
Peter Dimov
194b84e663 Add operator&( result, unary-returning-value ) 2023-10-29 19:37:43 +02:00
Peter Dimov
47a08cb35b Update documentation 2023-10-29 19:14:13 +02:00
Peter Dimov
7ffd63d54c Fix rvalue result<void> cases 2023-10-29 19:13:11 +02:00
Peter Dimov
92c24da9a1 Document operator| 2023-10-29 03:10:27 +02:00
Peter Dimov
dc73ca428b Add operator|( result, nullary-returning-result ) 2023-10-29 03:20:08 +03:00
Peter Dimov
c1fa3619b6 Add operator|( result, nullary-returning-value ) 2023-10-29 02:32:19 +03:00
Peter Dimov
0cd351014b Remove C++14-ism 2023-10-29 01:41:50 +03:00
Peter Dimov
d38e54d4c3 Add operator|( result, value ) 2023-10-29 01:30:01 +03:00
Peter Dimov
fa3331412d Update ci.yml 2023-10-28 20:53:44 +03:00
Peter Dimov
b899c49ae8 Update .drone.jsonnet 2023-10-21 04:17:30 +03:00
Peter Dimov
61a0e244da Add some more test cases exercising result initialization from {} 2023-10-20 21:49:20 +03:00
Peter Dimov
eb788615de Update ci.yml 2023-10-20 03:04:29 +03:00
Peter Dimov
84fd43e14a Update C++03 deprecation message 2023-10-19 18:15:05 +03:00
Peter Dimov
b0ef682e3d Update documentation 2023-09-14 02:20:46 +03:00
Peter Dimov
c360ff1b1c Add a converting constructor to result<void> 2023-09-12 04:48:45 +03:00
Peter Dimov
951b3fe7b4 Add result<U&, E> specialization. Fixes #72. 2023-09-12 03:34:24 +03:00
Peter Dimov
a57c568324 Do not use <shared_mutex> when BOOST_USE_WINAPI_VERSION is 0x5xx (Windows XP). Fixes #113. 2023-09-04 16:28:34 +03:00
Peter Dimov
4843453528 Update ci.yml 2023-09-04 13:04:34 +03:00
Peter Dimov
2e7e46a802 Update C++03 deprecation message 2023-06-03 02:31:27 +03:00
Peter Dimov
32dbf1b992 Disable use of <shared_mutex> under the XP toolsets (v140_xp and v141_xp). Fixes #110. 2023-04-30 18:44:56 +03:00
Peter Dimov
707b24bfa1 Update reference 2023-03-18 05:30:43 +02:00
Peter Dimov
bb1caae0d5 Update test/result_error_move.cpp 2023-03-18 05:25:44 +02:00
Klemens
c5c49894e6 Made result::error movable.
Closes #108.
2023-03-17 12:53:14 +08:00
Peter Dimov
ee80491cab Add C++03 deprecation notice 2023-03-06 07:49:33 +02:00
Peter Dimov
a83319fde1 Update ci.yml 2023-03-06 06:22:31 +02:00
Peter Dimov
4b90524729 Disable the constexpr constructors on GCC 4.7 2023-03-01 05:18:23 +02:00
Peter Dimov
6ac5f23999 Make error_category constructors unconditionally constexpr 2023-03-01 03:36:07 +02:00
Peter Dimov
f332a52597 Disable C4800 under msvc-14.0 2023-01-22 04:54:46 +02:00
Peter Dimov
c92d50abbd Do not consider types with explicit operator bool (such as result itself) constructible from bool for the purposes of result construction. Refs #104. 2023-01-22 02:07:28 +02:00
Peter Dimov
805b260a7a Add test/result_value_construct5.cpp. Refs #104. 2023-01-22 01:58:29 +02:00
Peter Dimov
f32ffcba48 Update result_value_construct4.cpp 2023-01-22 01:25:30 +02:00
Peter Dimov
8ce2a9f835 Disable result converting constructor when T is convertible from the rhs result<T2, E2>. Refs #104. 2023-01-22 01:22:02 +02:00
Peter Dimov
6a58b03eab Add test/result_value_construct4.cpp. Refs #104. 2023-01-22 01:15:08 +02:00
Peter Dimov
f0b27c5826 Enable implicit construction when the alternative is explicitly constructible from the argument. Fixes #103. 2023-01-21 20:09:53 +02:00
Peter Dimov
456b3c2dad Add test/result_error_construct4.cpp. Refs #103. 2023-01-21 19:45:32 +02:00
Peter Dimov
eb3f3a8e41 Use boost::core::snprintf in std_interop_test16 as well 2023-01-20 04:39:08 +02:00
Peter Dimov
e6986a51d5 Merge branch 'develop' into feature/issue-102 2023-01-20 04:38:15 +02:00
Peter Dimov
fb648760b5 Change uses of std::sprintf in tests to boost::core::snprintf, to avoid deprecation warnings 2023-01-20 02:29:38 +02:00
Peter Dimov
71ee26c188 Move the stdcat mutex into init_stdcat() as a local static to fix msvc-12.0 2023-01-20 01:22:42 +02:00
Peter Dimov
8449c62162 Update detail/mutex.hpp to use std::shared_mutex under the MS STL 2023-01-19 18:05:21 +02:00
Peter Dimov
4bca94ffc4 Merge branch 'develop' into feature/issue-102 2023-01-19 16:35:05 +02:00
Peter Dimov
3e6af15652 Add system/detail/mutex.hpp, use it in error_category_impl.hpp 2023-01-19 12:04:06 +02:00
Peter Dimov
86ff47ff63 Update std_interop_test16.cpp to not use asio/error.hpp. 2023-01-19 11:13:40 +02:00
Peter Dimov
06ddfdb4a6 Add std_interop_test16.cpp. Refs #102. 2023-01-19 05:46:11 +02:00
Peter Dimov
bb60a27b18 Update appveyor.yml 2023-01-12 20:38:54 +02:00
Peter Dimov
e478ba1a2b Update appveyor.yml 2023-01-12 15:18:11 +02:00
Peter Dimov
50100b0e81 Update CMakeLists.txt 2023-01-12 10:37:55 +02:00
Peter Dimov
bb502f5d67 Merge branch 'develop' into feature/pr-90 2023-01-12 10:36:56 +02:00
Peter Dimov
fa2349eee7 Add CMake tests to Appveyor 2023-01-12 05:45:30 +02:00
Peter Dimov
3d9acaf082 Update CMakeLists.txt 2023-01-12 05:41:30 +02:00
Peter Dimov
c6795eb9d0 Merge branch 'natvis' of https://github.com/vinniefalco/boost-system into feature/pr-90 2023-01-12 05:39:37 +02:00
Peter Dimov
57c295bbf7 Work around Clang 3.5 failures in result_value_access 2023-01-10 05:46:57 +02:00
Peter Dimov
36e3b2c6ae Work around Clang 3.5..3.8 failure in constexpr_test2 2023-01-10 05:14:36 +02:00
Peter Dimov
583cd8dba2 Update .drone.jsonnet 2023-01-10 04:36:37 +02:00
Peter Dimov
0c2de4cb2a Update .drone.jsonnet 2023-01-10 04:19:25 +02:00
Peter Dimov
3d595a6e79 Update ci.yml 2023-01-10 04:06:30 +02:00
Peter Dimov
b3faedfe3e Extend Clang 6 workaround to Clang 7 under Android. Fixes #100. 2023-01-10 03:09:20 +02:00
Peter Dimov
32bf67f748 error_code wrapping std::error_code should never compare equal to error_code not wrapping std (because of hash_value.) Fixes #101. 2023-01-07 19:56:34 +02:00
Peter Dimov
5d15aa1267 Add ec_hash_value_test 2023-01-07 19:42:59 +02:00
Peter Dimov
36e1236a0f Remove _Addr assignment from the constructor of std_category. Fixes #98. 2022-12-10 22:17:51 +02:00
Peter Dimov
2c20b6e7e5 Work around ERROR_INVALID_NAME failure on msvc-14.0, msvc-14.1 2022-12-10 19:45:14 +02:00
Peter Dimov
103f3b4f00 Print original error code in win32_generic_test 2022-12-10 18:47:54 +02:00
Peter Dimov
14f779e234 Update Win32 translation table. Closes #97. 2022-12-10 18:38:19 +02:00
Peter Dimov
bfccd4b4d9 Add win32_generic_test. Refs #97. 2022-12-10 18:24:34 +02:00
Peter Dimov
7ae6b317f3 Only disable C4351 on msvc-12.0 and earlier (refs #96) 2022-10-26 15:52:18 +03:00
Peter Dimov
9a6d79b841 Update revision history 2022-10-18 04:17:17 +03:00
Peter Dimov
ece71199a9 Document result<>::emplace 2022-10-18 04:15:40 +03:00
Peter Dimov
1e4c050d6c Add result<>::emplace (refs #85) 2022-10-18 00:46:59 +03:00
Peter Dimov
21115121bb Update ci.yml 2022-10-15 04:17:12 +03:00
Peter Dimov
956fa92a53 Update revision history 2022-09-27 20:32:03 +03:00
Peter Dimov
ee318f937f Document result<>::value_type, error_type, in_place_value, in_place_error. Closes #93. 2022-09-27 20:23:28 +03:00
Peter Dimov
19f99264de Document BOOST_SYSTEM_DISABLE_THREADS 2022-09-27 20:20:36 +03:00
Peter Dimov
3261bae6de Update .drone.jsonnet 2022-09-27 18:58:14 +03:00
Peter Dimov
20ce51858b Add in_place_value, in_place_error to result<>. Refs #93. 2022-09-27 18:18:16 +03:00
Peter Dimov
52d7429473 Add value_type, error_type typedefs to result. Refs #93. 2022-09-26 21:20:40 +03:00
Peter Dimov
53c00841fc Add support for BOOST_SYSTEM_DISABLE_THREADS (refs #92) 2022-09-08 18:32:26 +03:00
Peter Dimov
19e27a73e9 Disable failing test for msvc-12.0 2022-08-25 17:38:59 +03:00
Peter Dimov
19020ce925 Disable std_interop_test15 on g++ 4.8/4.9 2022-08-24 23:37:03 +03:00
Peter Dimov
3faf415026 Resolve ambiguities when comparing error_condition with std enums (refs #91) 2022-08-24 22:56:15 +03:00
Peter Dimov
a2df4d09da Update error_code_test3.cpp 2022-08-24 21:41:38 +03:00
Peter Dimov
455c6a6332 Add std_interop_test15.cpp 2022-08-24 21:40:20 +03:00
Peter Dimov
efb7634666 Move code/condition comparisons back outside class error_code; fixes #91 2022-08-24 21:10:05 +03:00
Peter Dimov
2bba3fd5e2 Add error_code_test3.cpp 2022-08-24 20:54:20 +03:00
Peter Dimov
8c740705e6 Add missing include 2022-08-21 19:42:10 +03:00
Peter Dimov
4708d95e80 Merge branch 'constexpr-default-ctor' of https://github.com/vinniefalco/boost-system into feature/pr-89 2022-08-21 19:13:48 +03:00
Peter Dimov
867f6d06d0 Add constexpr_test2.cpp 2022-08-21 19:13:12 +03:00
Vinnie Falco
ac1ed1ecc1 error_code default ctor is constexpr in c++11 2022-08-21 08:17:54 -07:00
Vinnie Falco
fe48c3058d add boost_system.natvis and interface source files 2022-08-19 11:40:36 -07:00
Peter Dimov
cc7c2f7ee4 Return v_.index() == 1 from has_error() to avoid -Wmaybe-uninitialized in error() 2022-08-02 22:44:34 +03:00
Peter Dimov
f2e1db8021 Constrain explicit value and error constructors to not accept zero arguments. Fixes #86. 2022-07-26 21:49:13 +03:00
Peter Dimov
ede243c42f Add (negative) tests for default constructability (refs #86) 2022-07-26 21:35:33 +03:00
Peter Dimov
1558aaa789 Update ci.yml 2022-07-26 20:41:24 +03:00
Peter Dimov
96b876d91a Add README.md 2022-06-19 02:19:58 +03:00
Peter Dimov
eb9ae4ac69 Update revision history 2022-06-19 01:30:17 +03:00
Peter Dimov
8fd487d496 Update documentation 2022-06-19 01:28:36 +03:00
Peter Dimov
5223c94aa9 Disable throws_assign_fail.cpp for GCC/release, because gcc-12 fails it at compile time 2022-06-18 23:07:41 +03:00
Peter Dimov
a5ee3f291c Update ci.yml 2022-06-18 21:47:57 +03:00
Peter Dimov
4200b00973 Add converting constructor to result (refs #82) 2022-06-18 18:12:06 +03:00
Peter Dimov
533dfe1688 Update revision history 2022-05-05 21:17:09 +03:00
Peter Dimov
7dec756a6f Update documentation 2022-05-05 21:15:03 +03:00
65 changed files with 6793 additions and 181 deletions

View File

@@ -173,48 +173,135 @@ local windows_pipeline(name, image, environment, arch = "amd64") =
),
linux_pipeline(
"Linux 20.04 GCC 9 ARM64 32/64",
"Linux 20.04 GCC 9* ARM64",
"cppalliance/droneubuntu2004:multiarch",
{ TOOLSET: 'gcc', COMPILER: 'g++', CXXSTD: '03,11,14,17,2a', ADDRMD: '32,64' },
{ TOOLSET: 'gcc', COMPILER: 'g++', CXXSTD: '03,11,14,17,2a' },
arch="arm64",
),
linux_pipeline(
"Linux 20.04 GCC 10 32 ASAN",
"Linux 20.04 GCC 9* S390x",
"cppalliance/droneubuntu2004:multiarch",
{ TOOLSET: 'gcc', COMPILER: 'g++', CXXSTD: '03,11,14,17,2a' },
arch="s390x",
),
linux_pipeline(
"Linux 20.04 GCC 10 32",
"cppalliance/droneubuntu2004:1",
{ TOOLSET: 'gcc', COMPILER: 'g++-10', CXXSTD: '03,11,14,17,20', ADDRMD: '32' } + asan,
{ TOOLSET: 'gcc', COMPILER: 'g++-10', CXXSTD: '03,11,14,17,20', ADDRMD: '32' },
"g++-10-multilib",
),
linux_pipeline(
"Linux 20.04 GCC 10 64 ASAN",
"Linux 20.04 GCC 10 64",
"cppalliance/droneubuntu2004:1",
{ TOOLSET: 'gcc', COMPILER: 'g++-10', CXXSTD: '03,11,14,17,20', ADDRMD: '64' } + asan,
{ TOOLSET: 'gcc', COMPILER: 'g++-10', CXXSTD: '03,11,14,17,20', ADDRMD: '64' },
"g++-10-multilib",
),
linux_pipeline(
"Linux 20.04 Clang 13",
"cppalliance/droneubuntu2004:1",
"Linux 22.04 GCC 11* 32",
"cppalliance/droneubuntu2204:1",
{ TOOLSET: 'gcc', COMPILER: 'g++', CXXSTD: '03,11,14,17,2a', ADDRMD: '32' },
),
linux_pipeline(
"Linux 22.04 GCC 11* 64",
"cppalliance/droneubuntu2204:1",
{ TOOLSET: 'gcc', COMPILER: 'g++', CXXSTD: '03,11,14,17,2a', ADDRMD: '64' },
),
linux_pipeline(
"Linux 22.04 GCC 12 32 ASAN",
"cppalliance/droneubuntu2204:1",
{ TOOLSET: 'gcc', COMPILER: 'g++-12', CXXSTD: '03,11,14,17,20,2b', ADDRMD: '32' } + asan,
"g++-12-multilib",
),
linux_pipeline(
"Linux 22.04 GCC 12 64 ASAN",
"cppalliance/droneubuntu2204:1",
{ TOOLSET: 'gcc', COMPILER: 'g++-12', CXXSTD: '03,11,14,17,20,2b', ADDRMD: '64' } + asan,
"g++-12-multilib",
),
linux_pipeline(
"Linux 23.04 GCC 13 32",
"cppalliance/droneubuntu2304:1",
{ TOOLSET: 'gcc', COMPILER: 'g++-13', CXXSTD: '03,11,14,17,20,2b', ADDRMD: '32' },
"g++-13-multilib",
),
linux_pipeline(
"Linux 23.04 GCC 13 64",
"cppalliance/droneubuntu2304:1",
{ TOOLSET: 'gcc', COMPILER: 'g++-13', CXXSTD: '03,11,14,17,20,2b', ADDRMD: '64' },
"g++-13-multilib",
),
linux_pipeline(
"Linux 16.04 Clang 3.5",
"cppalliance/droneubuntu1604:1",
{ TOOLSET: 'clang', COMPILER: 'clang++-3.5', CXXSTD: '03,11' },
"clang-3.5",
),
linux_pipeline(
"Linux 16.04 Clang 3.6",
"cppalliance/droneubuntu1604:1",
{ TOOLSET: 'clang', COMPILER: 'clang++-3.6', CXXSTD: '03,11,14' },
"clang-3.6",
),
linux_pipeline(
"Linux 16.04 Clang 3.7",
"cppalliance/droneubuntu1604:1",
{ TOOLSET: 'clang', COMPILER: 'clang++-3.7', CXXSTD: '03,11,14' },
"clang-3.7",
),
linux_pipeline(
"Linux 16.04 Clang 3.8",
"cppalliance/droneubuntu1604:1",
{ TOOLSET: 'clang', COMPILER: 'clang++-3.8', CXXSTD: '03,11,14' },
"clang-3.8",
),
linux_pipeline(
"Linux 22.04 Clang 13",
"cppalliance/droneubuntu2204:1",
{ TOOLSET: 'clang', COMPILER: 'clang++-13', CXXSTD: '03,11,14,17,20' },
"clang-13",
["deb http://apt.llvm.org/focal/ llvm-toolchain-focal-13 main"],
),
linux_pipeline(
"Linux 20.04 Clang 14 UBSAN",
"cppalliance/droneubuntu2004:1",
"Linux 22.04 Clang 14 UBSAN",
"cppalliance/droneubuntu2204:1",
{ TOOLSET: 'clang', COMPILER: 'clang++-14', CXXSTD: '03,11,14,17,20' } + ubsan,
"clang-14",
["deb http://apt.llvm.org/focal/ llvm-toolchain-focal-14 main"],
),
linux_pipeline(
"Linux 20.04 Clang 14 ASAN",
"cppalliance/droneubuntu2004:1",
"Linux 22.04 Clang 14 ASAN",
"cppalliance/droneubuntu2204:1",
{ TOOLSET: 'clang', COMPILER: 'clang++-14', CXXSTD: '03,11,14,17,20' } + asan,
"clang-14",
["deb http://apt.llvm.org/focal/ llvm-toolchain-focal-14 main"],
),
linux_pipeline(
"Linux 22.04 Clang 15",
"cppalliance/droneubuntu2204:1",
{ TOOLSET: 'clang', COMPILER: 'clang++-15', CXXSTD: '03,11,14,17,20,2b' },
"clang-15",
["deb http://apt.llvm.org/jammy/ llvm-toolchain-jammy-15 main"],
),
linux_pipeline(
"Linux 23.04 Clang 16",
"cppalliance/droneubuntu2304:1",
{ TOOLSET: 'clang', COMPILER: 'clang++-16', CXXSTD: '11,14,17,20,2b' },
"clang-16",
),
macos_pipeline(
@@ -227,6 +314,18 @@ local windows_pipeline(name, image, environment, arch = "amd64") =
{ TOOLSET: 'clang', COMPILER: 'clang++', CXXSTD: '03,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",

View File

@@ -5,6 +5,7 @@
# https://www.boost.org/LICENSE_1_0.txt
set -ex
export PATH=~/.local/bin:/usr/local/bin:$PATH
DRONE_BUILD_DIR=$(pwd)

View File

@@ -19,22 +19,26 @@ jobs:
include:
- toolset: gcc-4.8
cxxstd: "03,11"
os: ubuntu-18.04
os: ubuntu-latest
container: ubuntu:18.04
install: g++-4.8
- toolset: gcc-5
cxxstd: "03,11,14,1z"
os: ubuntu-18.04
os: ubuntu-latest
container: ubuntu:18.04
install: g++-5
- toolset: gcc-6
cxxstd: "03,11,14,1z"
os: ubuntu-18.04
os: ubuntu-latest
container: ubuntu:18.04
install: g++-6
- toolset: gcc-7
cxxstd: "03,11,14,17"
os: ubuntu-18.04
os: ubuntu-latest
container: ubuntu:18.04
- toolset: gcc-8
cxxstd: "03,11,14,17,2a"
os: ubuntu-18.04
os: ubuntu-20.04
install: g++-8
- toolset: gcc-9
cxxstd: "03,11,14,17,2a"
@@ -47,30 +51,42 @@ jobs:
cxxstd: "03,11,14,17,2a"
os: ubuntu-20.04
install: g++-11
- toolset: gcc-12
cxxstd: "03,11,14,17,20,2b"
os: ubuntu-22.04
install: g++-12
- toolset: gcc-13
cxxstd: "03,11,14,17,20,2b"
os: ubuntu-latest
container: ubuntu:23.04
install: g++-13
- toolset: clang
compiler: clang++-3.9
cxxstd: "03,11,14"
os: ubuntu-18.04
os: ubuntu-latest
container: ubuntu:18.04
install: clang-3.9
- toolset: clang
compiler: clang++-4.0
cxxstd: "03,11,14"
os: ubuntu-18.04
os: ubuntu-latest
container: ubuntu:18.04
install: clang-4.0
- toolset: clang
compiler: clang++-5.0
cxxstd: "03,11,14,1z"
os: ubuntu-18.04
os: ubuntu-latest
container: ubuntu:18.04
install: clang-5.0
- toolset: clang
compiler: clang++-6.0
cxxstd: "03,11,14,17"
os: ubuntu-18.04
os: ubuntu-20.04
install: clang-6.0
- toolset: clang
compiler: clang++-7
cxxstd: "03,11,14,17"
os: ubuntu-18.04
os: ubuntu-20.04
install: clang-7
- toolset: clang
compiler: clang++-8
@@ -92,20 +108,63 @@ jobs:
os: ubuntu-20.04
- toolset: clang
compiler: clang++-12
cxxstd: "03,11,14,17,2a"
cxxstd: "03,11,14,17,20"
os: ubuntu-20.04
- toolset: clang
compiler: clang++-13
cxxstd: "03,11,14,17,20,2b"
container: ubuntu:22.04
os: ubuntu-latest
install: clang-13
- toolset: clang
compiler: clang++-14
cxxstd: "03,11,14,17,20,2b"
container: ubuntu:22.04
os: ubuntu-latest
install: clang-14
- toolset: clang
compiler: clang++-15
cxxstd: "03,11,14,17,20,2b"
container: ubuntu:22.04
os: ubuntu-latest
install: clang-15
- toolset: clang
compiler: clang++-16
cxxstd: "03,11,14,17,20,2b"
os: ubuntu-latest
container: ubuntu:23.04
install: clang-16
- toolset: clang
cxxstd: "03,11,14,17,2a"
os: macos-10.15
os: macos-11
- toolset: clang
cxxstd: "03,11,14,17,20,2b"
os: macos-12
- toolset: clang
cxxstd: "03,11,14,17,20,2b"
os: macos-13
runs-on: ${{matrix.os}}
container: ${{matrix.container}}
defaults:
run:
shell: bash
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: Setup container environment
if: matrix.container
run: |
apt-get update
apt-get -y install sudo python3 git g++
- name: Install packages
if: matrix.install
run: sudo apt install ${{matrix.install}}
run: |
sudo apt-get update
sudo apt-get -y install ${{matrix.install}}
- name: Setup Boost
run: |
@@ -125,7 +184,7 @@ jobs:
cd boost-root
cp -r $GITHUB_WORKSPACE/* libs/$LIBRARY
git submodule update --init tools/boostdep
python tools/boostdep/depinst/depinst.py --git_args "--jobs 3" $LIBRARY
python3 tools/boostdep/depinst/depinst.py --git_args "--jobs 3" $LIBRARY
./bootstrap.sh
./b2 -d0 headers
@@ -157,7 +216,7 @@ jobs:
addrmd: 32,64
os: windows-2022
- toolset: clang-win
cxxstd: "14,17,latest"
cxxstd: "14,17,20,latest"
addrmd: 32,64
os: windows-2022
- toolset: gcc
@@ -168,7 +227,7 @@ jobs:
runs-on: ${{matrix.os}}
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: Setup Boost
shell: cmd
@@ -203,18 +262,20 @@ jobs:
fail-fast: false
matrix:
include:
- os: ubuntu-18.04
- os: ubuntu-20.04
- os: macos-10.15
- os: ubuntu-22.04
- os: macos-11
- os: macos-12
- os: macos-13
runs-on: ${{matrix.os}}
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: Install packages
if: matrix.install
run: sudo apt install ${{matrix.install}}
run: sudo apt-get -y install ${{matrix.install}}
- name: Setup Boost
run: |
@@ -249,18 +310,20 @@ jobs:
fail-fast: false
matrix:
include:
- os: ubuntu-18.04
- os: ubuntu-20.04
- os: macos-10.15
- os: ubuntu-22.04
- os: macos-11
- os: macos-12
- os: macos-13
runs-on: ${{matrix.os}}
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: Install packages
if: matrix.install
run: sudo apt install ${{matrix.install}}
run: sudo apt-get -y install ${{matrix.install}}
- name: Setup Boost
run: |
@@ -305,18 +368,20 @@ jobs:
fail-fast: false
matrix:
include:
- os: ubuntu-18.04
- os: ubuntu-20.04
- os: macos-10.15
- os: ubuntu-22.04
- os: macos-11
- os: macos-12
- os: macos-13
runs-on: ${{matrix.os}}
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: Install packages
if: matrix.install
run: sudo apt install ${{matrix.install}}
run: sudo apt-get -y install ${{matrix.install}}
- name: Setup Boost
run: |
@@ -353,3 +418,183 @@ jobs:
run: |
cd ../boost-root/__build__
ctest --output-on-failure --no-tests=error
windows-cmake-subdir:
strategy:
fail-fast: false
matrix:
include:
- os: windows-2019
- os: windows-2022
runs-on: ${{matrix.os}}
steps:
- uses: actions/checkout@v3
- name: Setup Boost
shell: cmd
run: |
echo GITHUB_REPOSITORY: %GITHUB_REPOSITORY%
for /f %%i in ("%GITHUB_REPOSITORY%") do set LIBRARY=%%~nxi
echo LIBRARY: %LIBRARY%
echo LIBRARY=%LIBRARY%>>%GITHUB_ENV%
echo GITHUB_BASE_REF: %GITHUB_BASE_REF%
echo GITHUB_REF: %GITHUB_REF%
if "%GITHUB_BASE_REF%" == "" set GITHUB_BASE_REF=%GITHUB_REF%
set BOOST_BRANCH=develop
for /f %%i in ("%GITHUB_BASE_REF%") do if "%%~nxi" == "master" set BOOST_BRANCH=master
echo BOOST_BRANCH: %BOOST_BRANCH%
cd ..
git clone -b %BOOST_BRANCH% --depth 1 https://github.com/boostorg/boost.git boost-root
cd boost-root
xcopy /s /e /q %GITHUB_WORKSPACE% libs\%LIBRARY%\
git submodule update --init tools/boostdep
python tools/boostdep/depinst/depinst.py --git_args "--jobs 3" %LIBRARY%
- name: Use library with add_subdirectory (Debug)
shell: cmd
run: |
cd ../boost-root/libs/%LIBRARY%/test/cmake_subdir_test
mkdir __build__ && cd __build__
cmake ..
cmake --build . --config Debug
ctest --output-on-failure --no-tests=error -C Debug
- name: Use library with add_subdirectory (Release)
shell: cmd
run: |
cd ../boost-root/libs/%LIBRARY%/test/cmake_subdir_test/__build__
cmake --build . --config Release
ctest --output-on-failure --no-tests=error -C Release
windows-cmake-install:
strategy:
fail-fast: false
matrix:
include:
- os: windows-2019
- os: windows-2022
runs-on: ${{matrix.os}}
steps:
- uses: actions/checkout@v3
- name: Setup Boost
shell: cmd
run: |
echo GITHUB_REPOSITORY: %GITHUB_REPOSITORY%
for /f %%i in ("%GITHUB_REPOSITORY%") do set LIBRARY=%%~nxi
echo LIBRARY: %LIBRARY%
echo LIBRARY=%LIBRARY%>>%GITHUB_ENV%
echo GITHUB_BASE_REF: %GITHUB_BASE_REF%
echo GITHUB_REF: %GITHUB_REF%
if "%GITHUB_BASE_REF%" == "" set GITHUB_BASE_REF=%GITHUB_REF%
set BOOST_BRANCH=develop
for /f %%i in ("%GITHUB_BASE_REF%") do if "%%~nxi" == "master" set BOOST_BRANCH=master
echo BOOST_BRANCH: %BOOST_BRANCH%
cd ..
git clone -b %BOOST_BRANCH% --depth 1 https://github.com/boostorg/boost.git boost-root
cd boost-root
xcopy /s /e /q %GITHUB_WORKSPACE% libs\%LIBRARY%\
git submodule update --init tools/boostdep
python tools/boostdep/depinst/depinst.py --git_args "--jobs 3" %LIBRARY%
- name: Configure
shell: cmd
run: |
cd ../boost-root
mkdir __build__ && cd __build__
cmake -DBOOST_INCLUDE_LIBRARIES=%LIBRARY% -DCMAKE_INSTALL_PREFIX=C:/cmake-prefix ..
- name: Install (Debug)
shell: cmd
run: |
cd ../boost-root/__build__
cmake --build . --target install --config Debug
- name: Install (Release)
shell: cmd
run: |
cd ../boost-root/__build__
cmake --build . --target install --config Release
- name: Use the installed library (Debug)
shell: cmd
run: |
cd ../boost-root/libs/%LIBRARY%/test/cmake_install_test && mkdir __build__ && cd __build__
cmake -DCMAKE_INSTALL_PREFIX=C:/cmake-prefix ..
cmake --build . --config Debug
ctest --output-on-failure --no-tests=error -C Debug
- name: Use the installed library (Release)
shell: cmd
run: |
cd ../boost-root/libs/%LIBRARY%/test/cmake_install_test/__build__
cmake --build . --config Release
ctest --output-on-failure --no-tests=error -C Release
windows-cmake-test:
strategy:
fail-fast: false
matrix:
include:
- os: windows-2019
- os: windows-2022
runs-on: ${{matrix.os}}
steps:
- uses: actions/checkout@v3
- name: Setup Boost
shell: cmd
run: |
echo GITHUB_REPOSITORY: %GITHUB_REPOSITORY%
for /f %%i in ("%GITHUB_REPOSITORY%") do set LIBRARY=%%~nxi
echo LIBRARY: %LIBRARY%
echo LIBRARY=%LIBRARY%>>%GITHUB_ENV%
echo GITHUB_BASE_REF: %GITHUB_BASE_REF%
echo GITHUB_REF: %GITHUB_REF%
if "%GITHUB_BASE_REF%" == "" set GITHUB_BASE_REF=%GITHUB_REF%
set BOOST_BRANCH=develop
for /f %%i in ("%GITHUB_BASE_REF%") do if "%%~nxi" == "master" set BOOST_BRANCH=master
echo BOOST_BRANCH: %BOOST_BRANCH%
cd ..
git clone -b %BOOST_BRANCH% --depth 1 https://github.com/boostorg/boost.git boost-root
cd boost-root
xcopy /s /e /q %GITHUB_WORKSPACE% libs\%LIBRARY%\
git submodule update --init tools/boostdep
python tools/boostdep/depinst/depinst.py --git_args "--jobs 3" %LIBRARY%
- name: Configure
shell: cmd
run: |
cd ../boost-root
mkdir __build__ && cd __build__
cmake -DBOOST_INCLUDE_LIBRARIES=%LIBRARY% -DBUILD_TESTING=ON ..
- name: Build tests (Debug)
shell: cmd
run: |
cd ../boost-root/__build__
cmake --build . --target tests --config Debug
- name: Run tests (Debug)
shell: cmd
run: |
cd ../boost-root/__build__
ctest --output-on-failure --no-tests=error -C Debug
- name: Build tests (Release)
shell: cmd
run: |
cd ../boost-root/__build__
cmake --build . --target tests --config Release
- name: Run tests (Release)
shell: cmd
run: |
cd ../boost-root/__build__
ctest --output-on-failure --no-tests=error -C Release

View File

@@ -2,7 +2,7 @@
# Distributed under the Boost Software License, Version 1.0.
# See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt
cmake_minimum_required(VERSION 3.5...3.16)
cmake_minimum_required(VERSION 3.5...3.20)
project(boost_system VERSION "${BOOST_SUPERPROJECT_VERSION}" LANGUAGES CXX)
@@ -20,6 +20,15 @@ target_link_libraries(boost_system
Boost::winapi
)
if(CMAKE_VERSION VERSION_GREATER 3.18 AND CMAKE_GENERATOR MATCHES "Visual Studio")
file(GLOB_RECURSE boost_system_IDEFILES CONFIGURE_DEPENDS include/*.hpp)
source_group(TREE ${PROJECT_SOURCE_DIR}/include FILES ${boost_system_IDEFILES} PREFIX "Header Files")
list(APPEND boost_system_IDEFILES extra/boost_system.natvis)
target_sources(boost_system PRIVATE ${boost_system_IDEFILES})
endif()
if(BUILD_TESTING)
add_subdirectory(test)

25
README.md Normal file
View 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).

View File

@@ -40,6 +40,12 @@ environment:
ADDPATH: C:\mingw-w64\x86_64-6.3.0-posix-seh-rt_v5-rev1\mingw64\bin;
TOOLSET: gcc
CXXSTD: 03,11,14,1z
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015
CMAKE: 1
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017
CMAKE_SUBDIR: 1
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2019
CMAKE_INSTALL: 1
install:
- set BOOST_BRANCH=develop
@@ -59,4 +65,27 @@ test_script:
- PATH=%ADDPATH%%PATH%
- if not "%CXXSTD%" == "" set CXXSTD=cxxstd=%CXXSTD%
- if not "%ADDRMD%" == "" set ADDRMD=address-model=%ADDRMD%
- b2 -j3 libs/system/test toolset=%TOOLSET% %CXXSTD% %ADDRMD% variant=debug,release embed-manifest-via=linker
- if "%CMAKE%%CMAKE_SUBDIR%%CMAKE_INSTALL%" == "" b2 -j3 libs/system/test toolset=%TOOLSET% %CXXSTD% %ADDRMD% variant=debug,release embed-manifest-via=linker
- if not "%CMAKE%" == "" mkdir __build__ && cd __build__
- if not "%CMAKE%" == "" cmake -DBUILD_TESTING=ON -DBOOST_INCLUDE_LIBRARIES=system -DBoost_VERBOSE=ON ..
- if not "%CMAKE%" == "" cmake --build . --target tests -j 3 --config Debug & ctest --output-on-failure --no-tests=error -j 3 -C Debug
- if not "%CMAKE%" == "" cmake --build . --target tests -j 3 --config Release & ctest --output-on-failure --no-tests=error -j 3 -C Release
- if not "%CMAKE%" == "" cmake --build . --target tests -j 3 --config MinSizeRel & ctest --output-on-failure --no-tests=error -j 3 -C MinSizeRel
- if not "%CMAKE%" == "" cmake --build . --target tests -j 3 --config RelWithDebInfo & ctest --output-on-failure --no-tests=error -j 3 -C RelWithDebInfo
- if not "%CMAKE_SUBDIR%" == "" cd libs/system/test/cmake_subdir_test && mkdir __build__ && cd __build__
- if not "%CMAKE_SUBDIR%" == "" cmake ..
- if not "%CMAKE_SUBDIR%" == "" cmake --build . --config Debug && cmake --build . --target check --config Debug
- if not "%CMAKE_SUBDIR%" == "" cmake --build . --config Release && cmake --build . --target check --config Release
- if not "%CMAKE_SUBDIR%" == "" cmake --build . --config MinSizeRel && cmake --build . --target check --config MinSizeRel
- if not "%CMAKE_SUBDIR%" == "" cmake --build . --config RelWithDebInfo && cmake --build . --target check --config RelWithDebInfo
- if not "%CMAKE_INSTALL%" == "" mkdir __build__ && cd __build__
- if not "%CMAKE_INSTALL%" == "" cmake -DBOOST_INCLUDE_LIBRARIES=system -DCMAKE_INSTALL_PREFIX=C:/cmake-prefix ..
- if not "%CMAKE_INSTALL%" == "" cmake --build . --target install --config Debug
- if not "%CMAKE_INSTALL%" == "" cmake --build . --target install --config Release
- if not "%CMAKE_INSTALL%" == "" cd ../libs/system/test/cmake_install_test && mkdir __build__ && cd __build__
- if not "%CMAKE_INSTALL%" == "" cmake -DCMAKE_INSTALL_PREFIX=C:/cmake-prefix ..
- if not "%CMAKE_INSTALL%" == "" cmake --build . --config Debug && cmake --build . --target check --config Debug
- if not "%CMAKE_INSTALL%" == "" cmake --build . --config Release && cmake --build . --target check --config Release

View File

@@ -8,12 +8,30 @@ https://www.boost.org/LICENSE_1_0.txt
# Revision History
:idprefix:
## 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

View File

@@ -29,6 +29,11 @@ When `BOOST_SYSTEM_USE_UTF8` is defined, on Windows the library returns
UTF-8 messages using code page `CP_UTF8` instead of the default `CP_ACP`.
This macro has no effect on POSIX.
When `BOOST_SYSTEM_DISABLE_THREADS` is defined, the library assumes that
the current platform doesn't support multiple threads and disables the use
of the standard header `<mutex>`, eliminating the mutex locks. The single
threaded `libstdc++` is one such platform.
## Deprecated Names
In the process of adding Boost.System to the {cpp}11 standard library, the
@@ -610,9 +615,8 @@ public:
template<class ErrorCodeEnum>
constexpr error_code( ErrorCodeEnum e ) noexcept;
template<class ErrorCodeEnum>
error_code( ErrorCodeEnum e, boost::source_location const * loc )
noexcept;
error_code( error_code const& ec,
boost::source_location const * loc ) noexcept;
error_code( std::error_code const& ec ) noexcept;
@@ -626,9 +630,8 @@ public:
template<class ErrorCodeEnum>
constexpr error_code & operator=( ErrorCodeEnum e ) noexcept;
template<class ErrorCodeEnum>
void assign( ErrorCodeEnum e,
boost::source_location const * loc ) noexcept;
void assign( error_code const& ec,
boost::source_location const * loc ) noexcept;
constexpr void clear() noexcept;
@@ -757,17 +760,17 @@ Ensures: :: `*this == make_error_code( e )`.
Remarks: :: This constructor is only enabled when `is_error_code_enum<ErrorCodeEnum>::value` is `true`.
```
template<class ErrorCodeEnum>
error_code( ErrorCodeEnum e, boost::source_location const * loc ) noexcept;
error_code( error_code const& ec,
boost::source_location const * loc ) noexcept;
```
[none]
* {blank}
+
Requires: :: `loc` points to a valid `boost::source_location` object with static storage duration.
Ensures: :: `*this == make_error_code( e )`.
Remarks: :: This constructor is only enabled when `is_error_code_enum<ErrorCodeEnum>::value` is `true`.
When `make_error_code( e )` is not a default-constructed `error_code` and doesn't wrap a
`std::error_code`, `has_location()` is `true` and `&location()` is `loc`.
Requires: :: `loc` points to a valid `boost::source_location` object with static storage duration, or is `nullptr`.
Ensures: :: `*this == ec`.
Remarks: :: When `ec` is a default-constructed `error_code` or wraps a `std::error_code`,
or when `loc` is `nullptr`, `*this` stores no location (`has_location()` is `false`).
Otherwise, `*this` stores `loc` (`has_location()` is `true` and `&location()` is `loc`.)
```
error_code( std::error_code const & ec ) noexcept;
@@ -808,16 +811,13 @@ Ensures: :: `*this == make_error_code( e )`.
Remarks: :: This operator is only enabled when `is_error_code_enum<ErrorCodeEnum>::value` is `true`.
```
template<class ErrorCodeEnum>
void assign( ErrorCodeEnum e,
boost::source_location const * loc ) noexcept;
void assign( error_code const& ec,
boost::source_location const * loc ) noexcept;
```
[none]
* {blank}
+
Requires: :: `loc` points to a valid `boost::source_location` object with static storage duration.
Effects: :: `*this = error_code( e, loc )`.
Remarks: :: This function is only enabled when `is_error_code_enum<ErrorCodeEnum>::value` is `true`.
Effects: :: `*this = error_code( ec, loc )`.
```
constexpr void clear() noexcept;
@@ -1517,6 +1517,38 @@ constexpr in_place_error_t in_place_error{};
template<class T, class E = error_code> class result;
template<class E> class result<void, E>;
template<class U, class E> class result<U&, E>;
// operator|
template<class T, class E, class U> T operator|( result<T, E> const& r, U&& u );
template<class T, class E, class U> T operator|( result<T, E>&& r, U&& u );
template<class T, class E, class F> T operator|( result<T, E> const& r, F&& f );
template<class T, class E, class F> T operator|( result<T, E>&& r, F&& f );
template<class T, class E, class F, class R = ...> R operator|( result<T, E> const& r, F&& f );
template<class T, class E, class F, class R = ...> R operator|( result<T, E>&& r, F&& f );
template<class E, class F, class R = ...> R operator|( result<void, E> const& r, F&& f );
template<class E, class F, class R = ...> R operator|( result<void, E>&& r, F&& f );
// operator&
template<class T, class E, class F, class U = ...>
result<U, E> operator&( result<T, E> const& r, F&& f );
template<class T, class E, class F, class U = ...>
result<U, E> operator&( result<T, E>&& r, F&& f );
template<class T, class E, class F, class R = ...> R operator&( result<T, E> const& r, F&& f );
template<class T, class E, class F, class R = ...> R operator&( result<T, E>&& r, F&& f );
// operator&=
template<class T, class E, class F, class U = ...>
result<T, E>& operator&=( result<T, E>& r, F&& f );
template<class T, class E, class F, class R = ...>
result<T, E>& operator&=( result<T, E>& r, F&& f );
} // namespace system
} // namespace boost
@@ -1600,6 +1632,12 @@ template<class T, class E = error_code> class result
{
public:
using value_type = T;
using error_type = E;
static constexpr in_place_value_t in_place_value{};
static constexpr in_place_error_t in_place_error{};
// constructors
constexpr result();
@@ -1613,6 +1651,12 @@ public:
template<class... A>
constexpr result( in_place_error_t, A&&... a );
template<class T2, class E2>
constexpr result( result<T2, E2> const& r2 );
template<class T2, class E2>
constexpr result( result<T2, E2>&& r2 );
// queries
constexpr bool has_value() const noexcept;
@@ -1645,7 +1689,13 @@ public:
// error access
constexpr E error() const;
constexpr E error() const &;
constexpr E error() &&;
// emplace
template<class... A>
constexpr T& emplace( A&&... a );
// swap
@@ -1695,7 +1745,7 @@ Effects: ::
ensures that `*this` holds the error `E( std::forward<A>(a)... )`.
- Otherwise, this constructor does not participate in overload resolution.
Remarks: ::
This constructor is only enabled when `sizeof...(T) > 0`.
This constructor is only enabled when `sizeof...(A) > 0`.
```
template<class... A>
@@ -1721,6 +1771,30 @@ Ensures: ::
Remarks: ::
This constructor is only enabled when `std::is_constructible<E, A...>::value` is `true`.
```
template<class T2, class E2>
constexpr result( result<T2, E2> const& r2 );
```
[none]
* {blank}
+
Ensures: ::
If `r2.has_value()` is `true`, `*this` holds the value `T( *r2 )`, otherwise `*this` holds the error `E( r2.error() )`.
Remarks: ::
This constructor is only enabled when `std::is_convertible<T2, T>::value && std::is_convertible<E2, E>::value` is `true`.
```
template<class T2, class E2>
constexpr result( result<T2, E2>&& r2 );
```
[none]
* {blank}
+
Ensures: ::
If `r2.has_value()` is `true`, `*this` holds the value `T( std::move( *r2 ) )`, otherwise `*this` holds the error `E( r2.error() )`.
Remarks: ::
This constructor is only enabled when `std::is_convertible<T2, T>::value && std::is_convertible<E2, E>::value` is `true`.
#### Queries
```
@@ -1810,7 +1884,8 @@ Returns: ::
#### Error Access
```
constexpr E error() const;
constexpr E error() const &;
constexpr E error() &&;
```
[none]
* {blank}
@@ -1818,6 +1893,20 @@ constexpr E error() const;
Effects: ::
If `*this` holds an error, returns it. Otherwise, returns `E()`.
#### emplace
```
template<class... A>
constexpr T& emplace( A&&... a );
```
[none]
* {blank}
+
Ensures: ::
`*this` holds the value `T( std::forward<A>(a)... )`.
Returns: ::
A reference to the contained value.
#### swap
```
@@ -1886,6 +1975,12 @@ template<class E> class result<void, E>
{
public:
using value_type = void;
using error_type = E;
static constexpr in_place_value_t in_place_value{};
static constexpr in_place_error_t in_place_error{};
// constructors
constexpr result() noexcept;
@@ -1898,6 +1993,9 @@ public:
template<class... A>
constexpr result( in_place_error_t, A&&... a );
template<class E2>
constexpr result( result<void, E2> const& r2 );
// queries
constexpr bool has_value() const noexcept;
@@ -1918,7 +2016,12 @@ public:
// error access
constexpr E error() const;
constexpr E error() const &;
constexpr E error() &&;
// emplace
constexpr void emplace();
// swap
@@ -1964,7 +2067,7 @@ Effects: ::
ensures that `*this` holds the error `E( std::forward<A>(a)... )`.
- Otherwise, this constructor does not participate in overload resolution.
Remarks: ::
This constructor is only enabled when `sizeof...(T) > 0`.
This constructor is only enabled when `sizeof...(A) > 0`.
```
template<class... A>
@@ -1988,6 +2091,18 @@ Ensures: ::
Remarks: ::
This constructor is only enabled when `std::is_constructible<E, A...>::value` is `true`.
```
template<class E2>
constexpr result( result<void, E2> const& r2 );
```
[none]
* {blank}
+
Ensures: ::
If `r2.has_value()` is `true`, `*this` holds an unspecified value, otherwise `*this` holds the error `E( r2.error() )`.
Remarks: ::
This constructor is only enabled when `std::is_convertible<E2, E>::value` is `true`.
#### Queries
```
@@ -2055,7 +2170,8 @@ Effects: ::
#### Error Access
```
constexpr E error() const;
constexpr E error() const &;
constexpr E error() &&;
```
[none]
* {blank}
@@ -2063,6 +2179,17 @@ constexpr E error() const;
Effects: ::
If `*this` holds an error, returns it. Otherwise, returns `E()`.
#### emplace
```
constexpr void emplace();
```
[none]
* {blank}
+
Ensures: ::
`*this` holds an unspecified value.
#### swap
```
@@ -2121,6 +2248,533 @@ Effects: ::
Returns: ::
`os`.
### result<U&, E>
```
namespace boost {
namespace system {
template<class U, class E> class result<U&, E>
{
public:
using value_type = U&;
using error_type = E;
static constexpr in_place_value_t in_place_value{};
static constexpr in_place_error_t in_place_error{};
// constructors
template<class A>
constexpr result( A&& a ) noexcept;
template<class... A>
constexpr result( A&&... a );
template<class A>
constexpr result( in_place_value_t, A&& a ) noexcept;
template<class... A>
constexpr result( in_place_error_t, A&&... a );
template<class U2, class E2>
constexpr result( result<U2&, E2> const& r2 );
// queries
constexpr bool has_value() const noexcept;
constexpr bool has_error() const noexcept;
constexpr explicit operator bool() const noexcept;
// checked value access
constexpr U& value( boost::source_location const & loc =
BOOST_CURRENT_LOCATION ) const;
// unchecked value access
constexpr U* operator->() const noexcept;
constexpr U& operator*() const noexcept;
// error access
constexpr E error() const &;
constexpr E error() &&;
// emplace
template<class A>
constexpr U& emplace( A&& a ) noexcept;
// swap
constexpr void swap( result& r );
friend constexpr void swap( result & r1, result & r2 );
// equality
friend constexpr bool operator==( result const & r1, result const & r2 );
friend constexpr bool operator!=( result const & r1, result const & r2 );
};
} // namespace system
} // namespace boost
```
#### Constructors
```
template<class A>
constexpr result( A&& a ) noexcept;
```
[none]
* {blank}
+
Ensures: ::
`*this` holds the reference `static_cast<U&>( std::forward<A>(a) )`.
Remarks: ::
This constructor is only enabled when `A` is `B&` and `std::is_convertible<B*, U*>::value` is `true`.
```
template<class... A>
constexpr result( A&&... a );
```
[none]
* {blank}
+
Effects: ::
- If `std::is_constructible<E, A...>::value && !std::is_constructible<U&, A...>::value`,
ensures that `*this` holds the error `E( std::forward<A>(a)... )`.
- Otherwise, this constructor does not participate in overload resolution.
Remarks: ::
This constructor is only enabled when `sizeof...(A) > 0`.
```
template<class A>
constexpr result( in_place_value_t, A&& a ) noexcept;
```
[none]
* {blank}
+
Ensures: ::
`*this` holds the reference `static_cast<U&>( std::forward<A>(a) )`.
Remarks: ::
This constructor is only enabled when `A` is `B&` and `std::is_convertible<B*, U*>::value` is `true`.
```
template<class... A>
constexpr result( in_place_error_t, A&&... a );
```
[none]
* {blank}
+
Ensures: ::
`*this` holds the error `E( std::forward<A>(a)... )`.
Remarks: ::
This constructor is only enabled when `std::is_constructible<E, A...>::value` is `true`.
```
template<class U2, class E2>
constexpr result( result<U2&, E2> const& r2 );
```
[none]
* {blank}
+
Ensures: ::
If `r2.has_value()` is `true`, `*this` holds the reference `static_cast<U&>( *r2 )`, otherwise `*this` holds the error `E( r2.error() )`.
Remarks: ::
This constructor is only enabled when `std::is_convertible<U2*, U*>::value && std::is_convertible<E2, E>::value` is `true`.
#### Queries
```
constexpr bool has_value() const noexcept;
```
[none]
* {blank}
+
Returns: ::
`true` when `*this` holds a value, `false` otherwise.
```
constexpr bool has_error() const noexcept;
```
[none]
* {blank}
+
Returns: ::
`!has_value()`.
```
constexpr explicit operator bool() const noexcept;
```
[none]
* {blank}
+
Returns: ::
`has_value()`.
#### Checked Value Access
```
constexpr U& value(
boost::source_location const & loc = BOOST_CURRENT_LOCATION ) const;
```
[none]
* {blank}
+
Effects: ::
If `*this` holds a reference, returns it. Otherwise,
calls `throw_exception_from_error`, passing it a reference to
the held error, and `loc`.
#### Unchecked Value Access
```
constexpr U* operator->() const noexcept;
```
[none]
* {blank}
+
Returns: ::
If `*this` holds a reference, a pointer to its referent. Otherwise, `nullptr`.
```
constexpr U& operator*() const noexcept;
```
[none]
* {blank}
+
Requires: :: `*this` holds a reference.
Returns: ::
`*operator\->()`.
#### Error Access
```
constexpr E error() const &;
constexpr E error() &&;
```
[none]
* {blank}
+
Effects: ::
If `*this` holds an error, returns it. Otherwise, returns `E()`.
#### emplace
```
template<class A>
constexpr U& emplace( A&& a ) noexcept;
```
[none]
* {blank}
+
Ensures: ::
`*this` holds the reference `static_cast<U&>( std::forward<A>(a)... )`.
Returns: ::
The contained reference.
Remarks: ::
This function is only enabled when `A` is `B&` and `std::is_convertible<B*, U*>::value` is `true`.
#### swap
```
constexpr void swap( result& r );
```
[none]
* {blank}
+
Effects: ::
Exchanges the contents of `*this` and `r`.
```
friend constexpr void swap( result & r1, result & r2 );
```
[none]
* {blank}
+
Effects: ::
Exchanges the contents of `r1` and `r2`.
#### Equality
```
friend constexpr bool operator==( result const & r1, result const & r2 );
```
[none]
* {blank}
+
Effects: ::
- If `r1` holds a reference `t1` and `r2` holds a reference `t2`, returns `t1 == t2`.
- If `r1` holds an error `e1` and `r2` holds an error `e2`, returns `e1 == e2`.
- Otherwise, returns `false`.
```
friend constexpr bool operator!=( result const & r1, result const & r2 );
```
[none]
* {blank}
+
Returns: ::
`!( r1 == r2 )`.
### Chaining
#### operator|
```
template<class T, class E, class U> T operator|( result<T, E> const& r, U&& u );
template<class T, class E, class U> T operator|( result<T, E>&& r, U&& u );
```
[none]
* {blank}
+
Returns the value in `r`, or if `r` contains an error, a default value `u`.
+
Effects: ::
- If `r.has_value()` is `true`, returns `*r`.
- Otherwise, returns `u`.
Remarks: ::
Only enabled when `U` is convertible to `T`.
Example: ::
+
```
result<int> get_server_port(); // can fail
int get_port()
{
return get_server_port() | 443;
}
```
```
template<class T, class E, class F> T operator|( result<T, E> const& r, F&& f );
template<class T, class E, class F> T operator|( result<T, E>&& r, F&& f );
```
[none]
* {blank}
+
Returns the value in `r`, or if `r` contains an error, a default value obtained
by invoking the function `f`.
+
Effects: ::
- If `r.has_value()` is `true`, returns `*r`.
- Otherwise, returns `f()`.
Remarks: ::
Only enabled when `f()` is convertible to `T`.
Example: ::
+
```
result<int> get_server_port(); // can fail
int get_default_port();
int get_port()
{
return get_server_port() | get_default_port;
}
```
+
Note that the right hand side is `get_default_port` and not `get_default_port()`.
This is important; spelled this way, the function `get_default_port` is called
only when `get_server_port_impl()` fails. If it were
+
```
return get_server_port() | get_default_port();
```
+
the function would have been called unconditionally.
+
Another, equivalent, way is to use a lambda
+
```
return get_server_port() | []{ return get_default_port(); };
```
+
which isn't necessary here, but would be needed for more complex expressions.
```
template<class T, class E, class F, class R = ...> R operator|( result<T, E> const& r, F&& f );
template<class T, class E, class F, class R = ...> R operator|( result<T, E>&& r, F&& f );
template<class E, class F, class R = ...> R operator|( result<void, E> const& r, F&& f );
template<class E, class F, class R = ...> R operator|( result<void, E>&& r, F&& f );
```
[none]
* {blank}
+
Returns the value in `r`, or if `r` contains an error, another `result` obtained
by invoking the function `f`.
+
Let `R` be the type of `f()`.
+
Effects: ::
- If `r.has_value()` is `true`, returns `*r`.
- Otherwise, returns `f()`.
Remarks: ::
Only enabled when `R` is an instance of `result` and `T` is convertible to `R::value_type`.
Example: ::
+
```
result<int> get_server_port(); // can fail
result<int> get_default_port(); // can fail
int get_port()
{
return get_server_port() | get_default_port | 443;
}
```
#### operator&
```
template<class T, class E, class F, class U = ...>
result<U, E> operator&( result<T, E> const& r, F&& f );
template<class T, class E, class F, class U = ...>
result<U, E> operator&( result<T, E>&& r, F&& f );
```
[none]
* {blank}
+
Returns the error in `r`, or if `r` contains a value, transforms the value by calling `f` on it.
+
Let `U` be the type of `f(*r)`.
+
Effects: ::
- If `r.has_value()` is `true`, returns `f(*r)`.
- Otherwise, returns `r.error()`.
Remarks: ::
Only enabled when `U` is not an instance of `result`.
Example: ::
+
```
struct currency_type
{
char code_[ 4 ] = {};
};
result<double> get_exchange_rate( currency_type from, currency_type to );
result<double> convert( double amount, currency_type from, currency_type to )
{
return get_exchange_rate( from, to ) & [&](double rate){ return rate * amount; };
}
```
```
template<class T, class E, class F, class R = ...> R operator&( result<T, E> const& r, F&& f );
template<class T, class E, class F, class R = ...> R operator&( result<T, E>&& r, F&& f );
```
[none]
* {blank}
+
Returns the error in `r`, or if `r` contains a value, another `result` obtained
by invoking the function `f` on the value in `r`.
+
Let `R` be the type of `f(*r)`.
+
Effects: ::
- If `r.has_value()` is `true`, returns `f(*r)`.
- Otherwise, returns `r.error()`.
Remarks: ::
Only enabled when `R` is an instance of `result` and `E` is convertible to `R::error_type`.
Example: ::
+
```
struct JsonValue
{
result<JsonValue const&> at( std::size_t i ) const noexcept;
result<JsonValue const&> at( std::string_view key ) const noexcept;
template<class T> result<T> to_number() const noexcept;
};
namespace helpers
{
inline auto at( std::size_t i ) {
return [=](JsonValue const& jv){ return jv.at( i ); }; }
inline auto at( std::string_view key ) {
return [=](JsonValue const& jv){ return jv.at( key ); }; }
template<class T> inline auto to_number() {
return [](JsonValue const& jv){ return jv.to_number<T>(); }; }
} // namespace helpers
int get_port( JsonValue const& config, int def )
{
using namespace helpers;
return config.at( "servers" ) & at( 0 ) & at( "port" ) & to_number<int>() | def;
}
```
#### operator&=
```
template<class T, class E, class F, class U = ...>
result<T, E>& operator&=( result<T, E>& r, F&& f );
```
[none]
* {blank}
+
If `r` contains a value, replaces it with the result of invoking the function `f` on the value in `r`.
+
Let `U` be the type of `f(*r)`.
+
Effects: :: If `r.has_value()` is `true`, assigns `f(*std::move(r))` to `r`.
Returns: :: `r`.
Remarks: ::
Only enabled when `U` is not an instance of `result` and is convertible to `T`.
```
template<class T, class E, class F, class R = ...>
result<T, E>& operator&=( result<T, E>& r, F&& f );
```
[none]
* {blank}
+
If `r` contains a value, replaces `r` with the result of invoking the function `f` on the value in `r`.
+
Let `R` be the type of `f(*r)`.
+
Effects: :: If `r.has_value()` is `true`, assigns `f(*std::move(r))` to `r`.
Returns: :: `r`.
Remarks: ::
Only enabled when `R` is an instance of `result` and is convertible to `result<T, E>`.
Example: ::
+
```
struct JsonValue
{
result<JsonValue const&> at( std::string_view key ) const noexcept;
};
namespace helpers
{
inline auto at( std::string_view key ) {
return [=](JsonValue const& jv){ return jv.at( key ); }; }
} // namespace helpers
result<JsonValue const&> at_path( JsonValue const& jv,
std::initializer_list<std::string_view> path )
{
result<JsonValue const&> r( jv );
using namespace helpers;
for( auto key: path )
{
r &= at( key );
}
return r;
}
```
## <boost/system.hpp>
This convenience header includes all the headers previously described.

53
extra/boost_system.natvis Normal file
View 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 &amp;&amp; ((std::error_code*)d2_)->_Mycat->_Addr==1">{((std::error_code*)d2_)->_Myval} [std:future]</DisplayString>
<DisplayString Condition="lc_flags_ == 1 &amp;&amp; ((std::error_code*)d2_)->_Mycat->_Addr==3">{((std::error_code*)d2_)->_Myval} [std:generic]</DisplayString>
<DisplayString Condition="lc_flags_ == 1 &amp;&amp; ((std::error_code*)d2_)->_Mycat->_Addr==5">{((std::error_code*)d2_)->_Myval} [std:iostream]</DisplayString>
<DisplayString Condition="lc_flags_ == 1 &amp;&amp; ((std::error_code*)d2_)->_Mycat->_Addr==7">{((std::error_code*)d2_)->_Myval} [std:system]</DisplayString>
<DisplayString Condition="lc_flags_ == 1">{((std::error_code*)d2_)->_Myval} std@{((uintptr_t)((std::error_code*)d2_)->_Mycat),x}</DisplayString>
<DisplayString Condition="d1_.cat_->id_ == 0xb2ab117a257edfd0 &amp;&amp;
(lc_flags_ == 2 || (lc_flags_ &gt; 3 &amp;&amp; ( lc_flags_ % 2 == 0 )))">{d1_.val_} [generic] ✓</DisplayString>
<DisplayString Condition="d1_.cat_->id_ == 0xb2ab117a257edfd1 &amp;&amp;
(lc_flags_ == 2 || (lc_flags_ &gt; 3 &amp;&amp; ( lc_flags_ % 2 == 0 )))">{d1_.val_} [system] ✓</DisplayString>
<DisplayString Condition="d1_.cat_->id_ == 0xb2ab117a257edfd2 &amp;&amp;
(lc_flags_ == 2 || (lc_flags_ &gt; 3 &amp;&amp; ( lc_flags_ % 2 == 0 )))">{d1_.val_} [interop] ✓</DisplayString>
<DisplayString Condition="d1_.cat_->id_ != 0 &amp;&amp;
(lc_flags_ == 2 || (lc_flags_ &gt; 3 &amp;&amp; ( lc_flags_ % 2 == 0 )))">{d1_.val_} [{d1_.cat_->id_,x}] ✓</DisplayString>
<DisplayString Condition=
"lc_flags_ == 2 || (lc_flags_ &gt; 3 &amp;&amp; ( lc_flags_ % 2 == 0 ))">{d1_.val_} @{((uintptr_t)d1_.cat_),x} ✓</DisplayString>
<DisplayString Condition="d1_.cat_->id_ == 0xb2ab117a257edfd0 &amp;&amp;
(lc_flags_ &gt;= 3 &amp;&amp; ( lc_flags_ % 2 == 1 ))">{d1_.val_} [generic]</DisplayString>
<DisplayString Condition="d1_.cat_->id_ == 0xb2ab117a257edfd1 &amp;&amp;
(lc_flags_ &gt;= 3 &amp;&amp; ( lc_flags_ % 2 == 1 ))">{d1_.val_} [system]</DisplayString>
<DisplayString Condition="d1_.cat_->id_ == 0xb2ab117a257edfd2 &amp;&amp;
(lc_flags_ &gt;= 3 &amp;&amp; ( lc_flags_ % 2 == 1 ))">{d1_.val_} [interop]</DisplayString>
<DisplayString Condition="d1_.cat_->id_ != 0 &amp;&amp;
(lc_flags_ &gt;= 3 &amp;&amp; ( lc_flags_ % 2 == 1 ))">{d1_.val_} [{d1_.cat_->id_,x}]</DisplayString>
<DisplayString Condition=
"lc_flags_ &gt;= 3 &amp;&amp; ( 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_ &gt; 3">*((boost::source_location*)(lc_flags_ &amp; ~1))</Item>
</Expand>
</Type>
<Type Name="boost::system::result&lt;*,*&gt;">
<DisplayString>{v_}</DisplayString>
</Type>
</AutoVisualizer>

View File

@@ -8,12 +8,19 @@
//
// See http://www.boost.org/libs/system for documentation.
#include <boost/system/detail/requires_cxx11.hpp>
#include <boost/config.hpp>
#include <boost/config/workaround.hpp>
// BOOST_SYSTEM_HAS_SYSTEM_ERROR
//
// The macro BOOST_SYSTEM_DISABLE_THREADS can be defined on configurations
// that provide <system_error> and <atomic>, but not <mutex>, such as the
// single-threaded libstdc++.
//
// https://github.com/boostorg/system/issues/92
#if !defined(BOOST_NO_CXX11_HDR_SYSTEM_ERROR) && !defined(BOOST_NO_CXX11_HDR_ATOMIC) && !defined(BOOST_NO_CXX11_HDR_MUTEX)
#if !defined(BOOST_NO_CXX11_HDR_SYSTEM_ERROR) && !defined(BOOST_NO_CXX11_HDR_ATOMIC) && ( !defined(BOOST_NO_CXX11_HDR_MUTEX) || defined(BOOST_SYSTEM_DISABLE_THREADS) )
# define BOOST_SYSTEM_HAS_SYSTEM_ERROR
#endif
@@ -58,7 +65,9 @@
// BOOST_SYSTEM_CLANG_6
#if defined(__clang__) && (__clang_major__ < 7 || (defined(__APPLE__) && __clang_major__ < 11))
// Android NDK r18b has Clang 7.0.2 that still needs the workaround
// https://github.com/boostorg/system/issues/100
#if defined(__clang__) && (__clang_major__ < 7 || (defined(__APPLE__) && __clang_major__ < 11) || (defined(__ANDROID__) && __clang_major__ == 7))
# define BOOST_SYSTEM_CLANG_6
#endif

View File

@@ -13,6 +13,7 @@
#include <boost/system/detail/config.hpp>
#include <boost/cstdint.hpp>
#include <boost/config.hpp>
#include <boost/config/workaround.hpp>
#include <string>
#include <functional>
#include <cstddef>
@@ -48,7 +49,7 @@ class std_category;
#pragma GCC diagnostic ignored "-Wnon-virtual-dtor"
#endif
#if defined(BOOST_MSVC)
#if defined(BOOST_MSVC) && BOOST_MSVC < 1900
#pragma warning(push)
#pragma warning(disable: 4351) // new behavior: elements of array will be default initialized
#endif
@@ -116,11 +117,18 @@ protected:
#endif
BOOST_SYSTEM_CONSTEXPR error_category() BOOST_NOEXCEPT: id_( 0 ), stdcat_(), sc_init_()
#if !BOOST_WORKAROUND(BOOST_GCC, < 40800)
BOOST_CONSTEXPR
#endif
error_category() BOOST_NOEXCEPT: id_( 0 ), stdcat_(), sc_init_()
{
}
explicit BOOST_SYSTEM_CONSTEXPR error_category( boost::ulong_long_type id ) BOOST_NOEXCEPT: id_( id ), stdcat_(), sc_init_()
explicit
#if !BOOST_WORKAROUND(BOOST_GCC, < 40800)
BOOST_CONSTEXPR
#endif
error_category( boost::ulong_long_type id ) BOOST_NOEXCEPT: id_( id ), stdcat_(), sc_init_()
{
}
@@ -183,7 +191,7 @@ public:
#endif
};
#if defined(BOOST_MSVC)
#if defined(BOOST_MSVC) && BOOST_MSVC < 1900
#pragma warning(pop)
#endif

View File

@@ -98,7 +98,7 @@ inline char const * error_category::message( int ev, char * buffer, std::size_t
#if defined(BOOST_SYSTEM_HAS_SYSTEM_ERROR)
#include <boost/system/detail/std_category_impl.hpp>
#include <mutex>
#include <boost/system/detail/mutex.hpp>
#include <new>
namespace boost
@@ -106,18 +106,6 @@ namespace boost
namespace system
{
namespace detail
{
template<class = void> struct stdcat_mx_holder
{
static std::mutex mx_;
};
template<class T> std::mutex stdcat_mx_holder<T>::mx_;
} // namespace detail
inline void error_category::init_stdcat() const
{
static_assert( sizeof( stdcat_ ) >= sizeof( boost::system::detail::std_category ), "sizeof(stdcat_) is not enough for std_category" );
@@ -130,11 +118,17 @@ inline void error_category::init_stdcat() const
#endif
std::lock_guard<std::mutex> lk( boost::system::detail::stdcat_mx_holder<>::mx_ );
// detail::mutex has a constexpr default constructor,
// and therefore guarantees static initialization, on
// everything except VS 2013 (msvc-12.0)
static system::detail::mutex mx_;
system::detail::lock_guard<system::detail::mutex> lk( mx_ );
if( sc_init_.load( std::memory_order_acquire ) == 0 )
{
::new( static_cast<void*>( stdcat_ ) ) boost::system::detail::std_category( this, 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 );
}
}
@@ -151,7 +145,7 @@ inline BOOST_NOINLINE error_category::operator std::error_category const & () co
// This condition must be the same as the one in error_condition.hpp
#if defined(BOOST_SYSTEM_AVOID_STD_GENERIC_CATEGORY)
static const boost::system::detail::std_category generic_instance( this, 0x1F4D3 );
static const boost::system::detail::std_category generic_instance( this, system::detail::id_wrapper<0x1F4D3>() );
return generic_instance;
#else
@@ -166,7 +160,7 @@ inline BOOST_NOINLINE error_category::operator std::error_category const & () co
// This condition must be the same as the one in error_code.hpp
#if defined(BOOST_SYSTEM_AVOID_STD_SYSTEM_CATEGORY)
static const boost::system::detail::std_category system_instance( this, 0x1F4D7 );
static const boost::system::detail::std_category system_instance( this, system::detail::id_wrapper<0x1F4D7>() );
return system_instance;
#else

View File

@@ -29,6 +29,7 @@
#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>
@@ -57,12 +58,14 @@ namespace system
// and error_code containing a pointer to an object of a type derived
// from error_category.
bool operator==( const error_code & code, const error_condition & condition ) BOOST_NOEXCEPT;
std::size_t hash_value( error_code const & ec );
class error_code
{
private:
friend bool operator==( const error_code & code, const error_condition & condition ) BOOST_NOEXCEPT;
friend std::size_t hash_value( error_code const & ec );
private:
@@ -114,7 +117,10 @@ public:
// constructors:
BOOST_SYSTEM_CONSTEXPR error_code() BOOST_NOEXCEPT:
#if !BOOST_WORKAROUND(BOOST_GCC, < 40800)
BOOST_CONSTEXPR
#endif
error_code() BOOST_NOEXCEPT:
d1_(), lc_flags_( 0 )
{
}
@@ -397,7 +403,12 @@ public:
{
#if defined(BOOST_SYSTEM_HAS_SYSTEM_ERROR)
if( lhs.lc_flags_ == 1 && rhs.lc_flags_ == 1 )
bool s1 = lhs.lc_flags_ == 1;
bool s2 = rhs.lc_flags_ == 1;
if( s1 != s2 ) return false;
if( s1 && s2 )
{
std::error_code const& e1 = *reinterpret_cast<std::error_code const*>( lhs.d2_ );
std::error_code const& e2 = *reinterpret_cast<std::error_code const*>( rhs.d2_ );
@@ -415,7 +426,13 @@ public:
{
#if defined(BOOST_SYSTEM_HAS_SYSTEM_ERROR)
if( lhs.lc_flags_ == 1 && rhs.lc_flags_ == 1 )
bool s1 = lhs.lc_flags_ == 1;
bool s2 = rhs.lc_flags_ == 1;
if( s1 < s2 ) return true;
if( s2 < s1 ) return false;
if( s1 && s2 )
{
std::error_code const& e1 = *reinterpret_cast<std::error_code const*>( lhs.d2_ );
std::error_code const& e2 = *reinterpret_cast<std::error_code const*>( rhs.d2_ );
@@ -434,48 +451,6 @@ public:
return !( lhs == rhs );
}
inline friend bool operator==( const error_code & code, const error_condition & condition ) BOOST_NOEXCEPT
{
#if defined(BOOST_SYSTEM_HAS_SYSTEM_ERROR)
if( code.lc_flags_ == 1 )
{
return static_cast<std::error_code>( code ) == static_cast<std::error_condition>( condition );
}
else
#endif
{
return code.category().equivalent( code.value(), condition ) || condition.category().equivalent( code, condition.value() );
}
}
inline friend bool operator==( const error_condition & condition, const error_code & code ) BOOST_NOEXCEPT
{
#if defined(BOOST_SYSTEM_HAS_SYSTEM_ERROR)
if( code.lc_flags_ == 1 )
{
return static_cast<std::error_code>( code ) == static_cast<std::error_condition>( condition );
}
else
#endif
{
return code.category().equivalent( code.value(), condition ) || condition.category().equivalent( code, condition.value() );
}
}
inline friend bool operator!=( const error_code & lhs, const error_condition & rhs ) BOOST_NOEXCEPT
{
return !( lhs == rhs );
}
inline friend bool operator!=( const error_condition & lhs, const error_code & rhs ) BOOST_NOEXCEPT
{
return !( lhs == rhs );
}
#if defined(BOOST_SYSTEM_HAS_SYSTEM_ERROR)
inline friend bool operator==( std::error_code const & lhs, error_code const & rhs ) BOOST_NOEXCEPT
@@ -678,6 +653,37 @@ public:
}
};
inline bool operator==( const error_code & code, const error_condition & condition ) BOOST_NOEXCEPT
{
#if defined(BOOST_SYSTEM_HAS_SYSTEM_ERROR)
if( code.lc_flags_ == 1 )
{
return static_cast<std::error_code>( code ) == static_cast<std::error_condition>( condition );
}
else
#endif
{
return code.category().equivalent( code.value(), condition ) || condition.category().equivalent( code, condition.value() );
}
}
inline bool operator==( const error_condition & condition, const error_code & code ) BOOST_NOEXCEPT
{
return code == condition;
}
inline bool operator!=( const error_code & lhs, const error_condition & rhs ) BOOST_NOEXCEPT
{
return !( lhs == rhs );
}
inline bool operator!=( const error_condition & lhs, const error_code & rhs ) BOOST_NOEXCEPT
{
return !( lhs == rhs );
}
inline std::size_t hash_value( error_code const & ec )
{
#if defined(BOOST_SYSTEM_HAS_SYSTEM_ERROR)

View File

@@ -261,6 +261,58 @@ public:
return !( lhs == rhs );
}
//
template<class E, class N = typename detail::enable_if<std::is_error_condition_enum<E>::value>::type>
BOOST_SYSTEM_CONSTEXPR inline friend bool operator==( error_condition const & lhs, E rhs ) BOOST_NOEXCEPT
{
return lhs == make_error_condition( rhs );
}
template<class E, class N = typename detail::enable_if<std::is_error_condition_enum<E>::value>::type>
BOOST_SYSTEM_CONSTEXPR inline friend bool operator==( E lhs, error_condition const & rhs ) BOOST_NOEXCEPT
{
return make_error_condition( lhs ) == rhs;
}
template<class E, class N = typename detail::enable_if<std::is_error_condition_enum<E>::value>::type>
BOOST_SYSTEM_CONSTEXPR inline friend bool operator!=( error_condition const & lhs, E rhs ) BOOST_NOEXCEPT
{
return !( lhs == rhs );
}
template<class E, class N = typename detail::enable_if<std::is_error_condition_enum<E>::value>::type>
BOOST_SYSTEM_CONSTEXPR inline friend bool operator!=( E lhs, error_condition const & rhs ) BOOST_NOEXCEPT
{
return !( lhs == rhs );
}
//
template<class E, class N1 = void, class N2 = typename detail::enable_if<std::is_error_code_enum<E>::value>::type>
inline friend bool operator==( error_condition const & lhs, E rhs ) BOOST_NOEXCEPT
{
return lhs == make_error_code( rhs );
}
template<class E, class N1 = void, class N2 = typename detail::enable_if<std::is_error_code_enum<E>::value>::type>
inline friend bool operator==( E lhs, error_condition const & rhs ) BOOST_NOEXCEPT
{
return make_error_code( lhs ) == rhs;
}
template<class E, class N1 = void, class N2 = typename detail::enable_if<std::is_error_code_enum<E>::value>::type>
inline friend bool operator!=( error_condition const & lhs, E rhs ) BOOST_NOEXCEPT
{
return !( lhs == rhs );
}
template<class E, class N1 = void, class N2 = typename detail::enable_if<std::is_error_code_enum<E>::value>::type>
inline friend bool operator!=( E lhs, error_condition const & rhs ) BOOST_NOEXCEPT
{
return !( lhs == rhs );
}
#endif
std::string to_string() const

View 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

View File

@@ -0,0 +1,21 @@
#ifndef BOOST_SYSTEM_DETAIL_REQUIRES_CXX11_HPP_INCLUDED
#define BOOST_SYSTEM_DETAIL_REQUIRES_CXX11_HPP_INCLUDED
// Copyright 2023 Peter Dimov
// Distributed under the Boost Software License, Version 1.0.
// https://www.boost.org/LICENSE_1_0.txt
#include <boost/config.hpp>
#include <boost/config/pragma_message.hpp>
#if defined(BOOST_NO_CXX11_CONSTEXPR) || \
defined(BOOST_NO_CXX11_NOEXCEPT) || \
defined(BOOST_NO_CXX11_EXPLICIT_CONVERSION_OPERATORS) || \
defined(BOOST_NO_CXX11_DEFAULTED_FUNCTIONS) || \
defined(BOOST_NO_CXX11_HDR_SYSTEM_ERROR)
BOOST_PRAGMA_MESSAGE("C++03 support was deprecated in Boost.System 1.82 and will be removed in Boost.System 1.85.")
#endif
#endif // #ifndef BOOST_SYSTEM_DETAIL_REQUIRES_CXX11_HPP_INCLUDED

View File

@@ -11,6 +11,7 @@
// 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>
//
@@ -24,6 +25,8 @@ namespace system
namespace detail
{
template<unsigned Id> struct id_wrapper {};
class BOOST_SYMBOL_VISIBLE std_category: public std::error_category
{
private:
@@ -39,20 +42,22 @@ public:
public:
explicit std_category( boost::system::error_category const * pc, unsigned id ): pc_( pc )
template<unsigned Id>
explicit std_category( boost::system::error_category const * pc, id_wrapper<Id> ): pc_( pc )
{
if( id != 0 )
{
#if defined(_MSC_VER) && defined(_CPPLIB_VER) && _MSC_VER >= 1900 && _MSC_VER < 2000
// Poking into the protected _Addr member of std::error_category
// is not a particularly good programming practice, but what can
// you do
// We used to assign to the protected _Addr member of std::error_category
// here when Id != 0, but this should never happen now because this code
// path is no longer used
_Addr = id;
#if !defined(BOOST_NO_CXX11_STATIC_ASSERT)
static_assert( Id == 0, "This constructor should only be called with Id == 0 under MS STL 14.0+" );
#endif
#endif
}
}
const char * name() const BOOST_NOEXCEPT BOOST_OVERRIDE

View File

@@ -59,6 +59,7 @@ inline int system_category_condition_win32( int ev ) BOOST_NOEXCEPT
case ERROR_ACCESS_DENIED_: return permission_denied;
case ERROR_ALREADY_EXISTS_: return file_exists;
case ERROR_BAD_NETPATH_: return no_such_file_or_directory;
case ERROR_BAD_NET_NAME_: return no_such_file_or_directory;
case ERROR_BAD_UNIT_: return no_such_device;
case ERROR_BROKEN_PIPE_: return broken_pipe;
case ERROR_BUFFER_OVERFLOW_: return filename_too_long;
@@ -75,6 +76,7 @@ inline int system_category_condition_win32( int ev ) BOOST_NOEXCEPT
case ERROR_DIR_NOT_EMPTY_: return directory_not_empty;
case ERROR_DIRECTORY_: return invalid_argument; // WinError.h: "The directory name is invalid"
case ERROR_DISK_FULL_: return no_space_on_device;
case ERROR_FILENAME_EXCED_RANGE_: return filename_too_long;
case ERROR_FILE_EXISTS_: return file_exists;
case ERROR_FILE_NOT_FOUND_: return no_such_file_or_directory;
case ERROR_HANDLE_DISK_FULL_: return no_space_on_device;
@@ -100,12 +102,16 @@ inline int system_category_condition_win32( int ev ) BOOST_NOEXCEPT
case ERROR_REPARSE_TAG_INVALID_: return invalid_argument;
case ERROR_RETRY_: return resource_unavailable_try_again;
case ERROR_SEEK_: return io_error;
case ERROR_SEM_TIMEOUT_: return timed_out;
case ERROR_SHARING_VIOLATION_: return permission_denied;
case ERROR_NOT_SUPPORTED_: return not_supported; // WinError.h: "The request is not supported."
case ERROR_TIMEOUT_: return timed_out;
case ERROR_TOO_MANY_OPEN_FILES_: return too_many_files_open;
case ERROR_WRITE_FAULT_: return io_error;
case ERROR_WRITE_PROTECT_: return permission_denied;
case 258: return timed_out; // WAIT_TIMEOUT
case WSAEACCES_: return permission_denied;
case WSAEADDRINUSE_: return address_in_use;
case WSAEADDRNOTAVAIL_: return address_not_available;

View File

@@ -85,6 +85,10 @@ template<class T> using remove_cvref = typename std::remove_cv< typename std::re
template<class... T> using is_errc_t = std::is_same<mp11::mp_list<remove_cvref<T>...>, mp11::mp_list<errc::errc_t>>;
template<class T, class... A> struct is_constructible: std::is_constructible<T, A...> {};
template<class A> struct is_constructible<bool, A>: std::is_convertible<A, bool> {};
template<class A> struct is_constructible<bool const, A>: std::is_convertible<A, bool> {};
} // namespace detail
// result
@@ -95,6 +99,14 @@ private:
variant2::variant<T, E> v_;
public:
using value_type = T;
using error_type = E;
static constexpr in_place_value_t in_place_value{};
static constexpr in_place_error_t in_place_error{};
public:
// constructors
@@ -114,7 +126,7 @@ public:
template<class A = T, typename std::enable_if<
std::is_convertible<A, T>::value &&
!(detail::is_errc_t<A>::value && std::is_arithmetic<T>::value) &&
!std::is_constructible<E, A>::value, int>::type = 0>
!std::is_convertible<A, E>::value, int>::type = 0>
constexpr result( A&& a )
noexcept( std::is_nothrow_constructible<T, A>::value )
: v_( in_place_value, std::forward<A>(a) )
@@ -124,7 +136,7 @@ public:
// implicit, error
template<class A = E, class = void, typename std::enable_if<
std::is_convertible<A, E>::value &&
!std::is_constructible<T, A>::value, int>::type = 0>
!std::is_convertible<A, T>::value, int>::type = 0>
constexpr result( A&& a )
noexcept( std::is_nothrow_constructible<E, A>::value )
: v_( in_place_error, std::forward<A>(a) )
@@ -133,9 +145,10 @@ public:
// explicit, value
template<class... A, class En = typename std::enable_if<
std::is_constructible<T, A...>::value &&
detail::is_constructible<T, A...>::value &&
!(detail::is_errc_t<A...>::value && std::is_arithmetic<T>::value) &&
!std::is_constructible<E, A...>::value
!detail::is_constructible<E, A...>::value &&
sizeof...(A) >= 1
>::type>
explicit constexpr result( A&&... a )
noexcept( std::is_nothrow_constructible<T, A...>::value )
@@ -145,8 +158,9 @@ public:
// explicit, error
template<class... A, class En2 = void, class En = typename std::enable_if<
!std::is_constructible<T, A...>::value &&
std::is_constructible<E, A...>::value
!detail::is_constructible<T, A...>::value &&
detail::is_constructible<E, A...>::value &&
sizeof...(A) >= 1
>::type>
explicit constexpr result( A&&... a )
noexcept( std::is_nothrow_constructible<E, A...>::value )
@@ -174,6 +188,45 @@ public:
{
}
// converting
template<class T2, class E2, class En = typename std::enable_if<
std::is_convertible<T2, T>::value &&
std::is_convertible<E2, E>::value &&
!std::is_convertible<result<T2, E2> const&, T>::value
>::type>
BOOST_CXX14_CONSTEXPR result( result<T2, E2> const& r2 )
noexcept(
std::is_nothrow_constructible<T, T2 const&>::value &&
std::is_nothrow_constructible<E, E2>::value &&
std::is_nothrow_default_constructible<E2>::value &&
std::is_nothrow_copy_constructible<E2>::value )
: v_( in_place_error, r2.error() )
{
if( r2 )
{
v_.template emplace<0>( *r2 );
}
}
template<class T2, class E2, class En = typename std::enable_if<
std::is_convertible<T2, T>::value &&
std::is_convertible<E2, E>::value &&
!std::is_convertible<result<T2, E2>&&, T>::value
>::type>
BOOST_CXX14_CONSTEXPR result( result<T2, E2>&& r2 )
noexcept(
std::is_nothrow_constructible<T, T2&&>::value &&
std::is_nothrow_constructible<E, E2>::value &&
std::is_nothrow_default_constructible<E2>::value &&
std::is_nothrow_copy_constructible<E2>::value )
: v_( in_place_error, r2.error() )
{
if( r2 )
{
v_.template emplace<0>( std::move( *r2 ) );
}
}
// queries
constexpr bool has_value() const noexcept
@@ -183,7 +236,7 @@ public:
constexpr bool has_error() const noexcept
{
return v_.index() != 0;
return v_.index() == 1;
}
constexpr explicit operator bool() const noexcept
@@ -348,12 +401,26 @@ public:
// error access
constexpr E error() const
constexpr E error() const &
noexcept( std::is_nothrow_default_constructible<E>::value && std::is_nothrow_copy_constructible<E>::value )
{
return has_error()? variant2::unsafe_get<1>( v_ ): E();
}
BOOST_CXX14_CONSTEXPR E error() &&
noexcept( std::is_nothrow_default_constructible<E>::value && std::is_nothrow_move_constructible<E>::value )
{
return has_error()? std::move( variant2::unsafe_get<1>( v_ ) ): E();
}
// emplace
template<class... A>
BOOST_CXX14_CONSTEXPR T& emplace( A&&... a )
{
return v_.template emplace<0>( std::forward<A>(a)... );
}
// swap
BOOST_CXX14_CONSTEXPR void swap( result& r )
@@ -405,6 +472,14 @@ private:
variant2::variant<variant2::monostate, E> v_;
public:
using value_type = void;
using error_type = E;
static constexpr in_place_value_t in_place_value{};
static constexpr in_place_error_t in_place_error{};
public:
// constructors
@@ -463,6 +538,23 @@ public:
{
}
// converting
template<class E2, class En = typename std::enable_if<
std::is_convertible<E2, E>::value
>::type>
BOOST_CXX14_CONSTEXPR result( result<void, E2> const& r2 )
noexcept(
std::is_nothrow_constructible<E, E2>::value &&
std::is_nothrow_default_constructible<E2>::value &&
std::is_nothrow_copy_constructible<E2>::value )
: v_( in_place_error, r2.error() )
{
if( r2 )
{
this->emplace();
}
}
// queries
constexpr bool has_value() const noexcept
@@ -472,7 +564,7 @@ public:
constexpr bool has_error() const noexcept
{
return v_.index() != 0;
return v_.index() == 1;
}
constexpr explicit operator bool() const noexcept
@@ -512,12 +604,25 @@ public:
// error access
constexpr E error() const
constexpr E error() const &
noexcept( std::is_nothrow_default_constructible<E>::value && std::is_nothrow_copy_constructible<E>::value )
{
return has_error()? variant2::unsafe_get<1>( v_ ): E();
}
BOOST_CXX14_CONSTEXPR E error() &&
noexcept( std::is_nothrow_default_constructible<E>::value && std::is_nothrow_move_constructible<E>::value )
{
return has_error()? std::move( variant2::unsafe_get<1>( v_ ) ): E();
}
// emplace
BOOST_CXX14_CONSTEXPR void emplace()
{
v_.template emplace<0>();
}
// swap
BOOST_CXX14_CONSTEXPR void swap( result& r )
@@ -561,6 +666,495 @@ template<class Ch, class Tr, class E> std::basic_ostream<Ch, Tr>& operator<<( st
return os;
}
// result<T&, E>
namespace detail
{
template<class U, class A> struct reference_to_temporary: std::integral_constant<bool,
!std::is_reference<A>::value ||
!std::is_convertible<typename std::remove_reference<A>::type*, U*>::value
> {};
} // namespace detail
template<class U, class E> class result<U&, E>
{
private:
variant2::variant<U*, E> v_;
public:
using value_type = U&;
using error_type = E;
static constexpr in_place_value_t in_place_value{};
static constexpr in_place_error_t in_place_error{};
public:
// constructors
// implicit, value
template<class A, typename std::enable_if<
std::is_convertible<A, U&>::value &&
!detail::reference_to_temporary<U, A>::value &&
!std::is_convertible<A, E>::value, int>::type = 0>
constexpr result( A&& a )
noexcept( std::is_nothrow_constructible<U&, A>::value )
: v_( in_place_value, &static_cast<U&>( std::forward<A>(a) ) )
{
}
// implicit, error
template<class A = E, class = void, typename std::enable_if<
std::is_convertible<A, E>::value &&
!std::is_convertible<A, U&>::value, int>::type = 0>
constexpr result( A&& a )
noexcept( std::is_nothrow_constructible<E, A>::value )
: v_( in_place_error, std::forward<A>(a) )
{
}
// explicit, value
template<class A, class En = typename std::enable_if<
detail::is_constructible<U&, A>::value &&
!std::is_convertible<A, U&>::value &&
!detail::reference_to_temporary<U, A>::value &&
!detail::is_constructible<E, A>::value
>::type>
explicit constexpr result( A&& a )
noexcept( std::is_nothrow_constructible<U&, A>::value )
: v_( in_place_value, &static_cast<U&>( std::forward<A>(a) ) )
{
}
// explicit, error
template<class... A, class En2 = void, class En = typename std::enable_if<
!detail::is_constructible<U&, A...>::value &&
detail::is_constructible<E, A...>::value &&
sizeof...(A) >= 1
>::type>
explicit constexpr result( A&&... a )
noexcept( std::is_nothrow_constructible<E, A...>::value )
: v_( in_place_error, std::forward<A>(a)... )
{
}
// tagged, value
template<class A, class En = typename std::enable_if<
std::is_constructible<U&, A>::value &&
!detail::reference_to_temporary<U, A>::value
>::type>
constexpr result( in_place_value_t, A&& a )
noexcept( std::is_nothrow_constructible<U&, A>::value )
: v_( in_place_value, &static_cast<U&>( std::forward<A>(a) ) )
{
}
// tagged, error
template<class... A, class En = typename std::enable_if<
std::is_constructible<E, A...>::value
>::type>
constexpr result( in_place_error_t, A&&... a )
noexcept( std::is_nothrow_constructible<E, A...>::value )
: v_( in_place_error, std::forward<A>(a)... )
{
}
// converting
template<class U2, class E2, class En = typename std::enable_if<
std::is_convertible<U2&, U&>::value &&
!detail::reference_to_temporary<U, U2&>::value &&
std::is_convertible<E2, E>::value &&
!std::is_convertible<result<U2&, E2> const&, U&>::value
>::type>
BOOST_CXX14_CONSTEXPR result( result<U2&, E2> const& r2 )
noexcept(
std::is_nothrow_constructible<U&, U2&>::value &&
std::is_nothrow_constructible<E, E2>::value &&
std::is_nothrow_default_constructible<E2>::value &&
std::is_nothrow_copy_constructible<E2>::value )
: v_( in_place_error, r2.error() )
{
if( r2 )
{
this->emplace( *r2 );
}
}
// queries
constexpr bool has_value() const noexcept
{
return v_.index() == 0;
}
constexpr bool has_error() const noexcept
{
return v_.index() == 1;
}
constexpr explicit operator bool() const noexcept
{
return v_.index() == 0;
}
// checked value access
BOOST_CXX14_CONSTEXPR U& value( boost::source_location const& loc = BOOST_CURRENT_LOCATION ) const
{
if( has_value() )
{
return *variant2::unsafe_get<0>( v_ );
}
else
{
throw_exception_from_error( variant2::unsafe_get<1>( v_ ), loc );
}
}
// unchecked value access
BOOST_CXX14_CONSTEXPR U* operator->() const noexcept
{
return has_value()? variant2::unsafe_get<0>( v_ ): 0;
}
BOOST_CXX14_CONSTEXPR U& operator*() const noexcept
{
U* p = operator->();
BOOST_ASSERT( p != 0 );
return *p;
}
// error access
constexpr E error() const &
noexcept( std::is_nothrow_default_constructible<E>::value && std::is_nothrow_copy_constructible<E>::value )
{
return has_error()? variant2::unsafe_get<1>( v_ ): E();
}
BOOST_CXX14_CONSTEXPR E error() &&
noexcept( std::is_nothrow_default_constructible<E>::value && std::is_nothrow_move_constructible<E>::value )
{
return has_error()? std::move( variant2::unsafe_get<1>( v_ ) ): E();
}
// emplace
template<class A, class En = typename std::enable_if<
detail::is_constructible<U&, A>::value &&
!detail::reference_to_temporary<U, A>::value
>::type>
BOOST_CXX14_CONSTEXPR U& emplace( A&& a )
{
return *v_.template emplace<0>( &static_cast<U&>( a ) );
}
// swap
BOOST_CXX14_CONSTEXPR void swap( result& r )
noexcept( noexcept( v_.swap( r.v_ ) ) )
{
v_.swap( r.v_ );
}
friend BOOST_CXX14_CONSTEXPR void swap( result & r1, result & r2 )
noexcept( noexcept( r1.swap( r2 ) ) )
{
r1.swap( r2 );
}
// equality
friend constexpr bool operator==( result const & r1, result const & r2 )
noexcept( noexcept( r1 && r2? *r1 == *r2: r1.v_ == r2.v_ ) )
{
return r1 && r2? *r1 == *r2: r1.v_ == r2.v_;
}
friend constexpr bool operator!=( result const & r1, result const & r2 )
noexcept( noexcept( !( r1 == r2 ) ) )
{
return !( r1 == r2 );
}
};
// operator|
namespace detail
{
// is_value_convertible_to
template<class T, class U> struct is_value_convertible_to: std::is_convertible<T, U>
{
};
template<class T, class U> struct is_value_convertible_to<T, U&>:
std::integral_constant<bool,
std::is_lvalue_reference<T>::value &&
std::is_convertible<typename std::remove_reference<T>::type*, U*>::value>
{
};
// is_result
template<class T> struct is_result: std::false_type {};
template<class T, class E> struct is_result< result<T, E> >: std::true_type {};
} // namespace detail
// result | value
template<class T, class E, class U,
class En = typename std::enable_if<detail::is_value_convertible_to<U, T>::value>::type
>
T operator|( result<T, E> const& r, U&& u )
{
if( r )
{
return *r;
}
else
{
return std::forward<U>( u );
}
}
template<class T, class E, class U,
class En = typename std::enable_if<detail::is_value_convertible_to<U, T>::value>::type
>
T operator|( result<T, E>&& r, U&& u )
{
if( r )
{
return *std::move( r );
}
else
{
return std::forward<U>( u );
}
}
// result | nullary-returning-value
template<class T, class E, class F,
class U = decltype( std::declval<F>()() ),
class En = typename std::enable_if<detail::is_value_convertible_to<U, T>::value>::type
>
T operator|( result<T, E> const& r, F&& f )
{
if( r )
{
return *r;
}
else
{
return std::forward<F>( f )();
}
}
template<class T, class E, class F,
class U = decltype( std::declval<F>()() ),
class En = typename std::enable_if<detail::is_value_convertible_to<U, T>::value>::type
>
T operator|( result<T, E>&& r, F&& f )
{
if( r )
{
return *std::move( r );
}
else
{
return std::forward<F>( f )();
}
}
// result | nullary-returning-result
template<class T, class E, class F,
class U = decltype( std::declval<F>()() ),
class En1 = typename std::enable_if<detail::is_result<U>::value>::type,
class En2 = typename std::enable_if<detail::is_value_convertible_to<T, typename U::value_type>::value>::type
>
U operator|( result<T, E> const& r, F&& f )
{
if( r )
{
return *r;
}
else
{
return std::forward<F>( f )();
}
}
template<class T, class E, class F,
class U = decltype( std::declval<F>()() ),
class En1 = typename std::enable_if<detail::is_result<U>::value>::type,
class En2 = typename std::enable_if<detail::is_value_convertible_to<T, typename U::value_type>::value>::type
>
U operator|( result<T, E>&& r, F&& f )
{
if( r )
{
return *std::move( r );
}
else
{
return std::forward<F>( f )();
}
}
template<class E, class F,
class U = decltype( std::declval<F>()() ),
class En1 = typename std::enable_if<detail::is_result<U>::value>::type,
class En2 = typename std::enable_if<std::is_void<typename U::value_type>::value>::type
>
U operator|( result<void, E> const& r, F&& f )
{
if( r )
{
return {};
}
else
{
return std::forward<F>( f )();
}
}
template<class E, class F,
class U = decltype( std::declval<F>()() ),
class En1 = typename std::enable_if<detail::is_result<U>::value>::type,
class En2 = typename std::enable_if<std::is_void<typename U::value_type>::value>::type
>
U operator|( result<void, E>&& r, F&& f )
{
if( r )
{
return {};
}
else
{
return std::forward<F>( f )();
}
}
// operator&
// result & unary-returning-value
template<class T, class E, class F,
class U = decltype( std::declval<F>()( std::declval<T const&>() ) ),
class En = typename std::enable_if<!detail::is_result<U>::value>::type
>
result<U, E> operator&( result<T, E> const& r, F&& f )
{
if( r.has_error() )
{
return r.error();
}
else
{
return std::forward<F>( f )( *r );
}
}
template<class T, class E, class F,
class U = decltype( std::declval<F>()( std::declval<T>() ) ),
class En = typename std::enable_if<!detail::is_result<U>::value>::type
>
result<U, E> operator&( result<T, E>&& r, F&& f )
{
if( r.has_error() )
{
return r.error();
}
else
{
return std::forward<F>( f )( *std::move( r ) );
}
}
// result & unary-returning-result
template<class T, class E, class F,
class U = decltype( std::declval<F>()( std::declval<T const&>() ) ),
class En1 = typename std::enable_if<detail::is_result<U>::value>::type,
class En2 = typename std::enable_if<std::is_convertible<E, typename U::error_type>::value>::type
>
U operator&( result<T, E> const& r, F&& f )
{
if( r.has_error() )
{
return r.error();
}
else
{
return std::forward<F>( f )( *r );
}
}
template<class T, class E, class F,
class U = decltype( std::declval<F>()( std::declval<T>() ) ),
class En1 = typename std::enable_if<detail::is_result<U>::value>::type,
class En2 = typename std::enable_if<std::is_convertible<E, typename U::error_type>::value>::type
>
U operator&( result<T, E>&& r, F&& f )
{
if( r.has_error() )
{
return r.error();
}
else
{
return std::forward<F>( f )( *std::move( r ) );
}
}
// operator&=
// result &= unary-returning-value
template<class T, class E, class F,
class U = decltype( std::declval<F>()( std::declval<T>() ) ),
class En1 = typename std::enable_if<!detail::is_result<U>::value>::type,
class En2 = typename std::enable_if<detail::is_value_convertible_to<U, T>::value>::type
>
result<T, E>& operator&=( result<T, E>& r, F&& f )
{
if( r )
{
r = std::forward<F>( f )( *std::move( r ) );
}
return r;
}
// result &= unary-returning-result
template<class T, class E, class F,
class U = decltype( std::declval<F>()( std::declval<T>() ) ),
class En1 = typename std::enable_if<detail::is_result<U>::value>::type,
class En2 = typename std::enable_if<detail::is_value_convertible_to<typename U::value_type, T>::value>::type,
class En3 = typename std::enable_if<std::is_convertible<typename U::error_type, E>::value>::type
>
result<T, E>& operator&=( result<T, E>& r, F&& f )
{
if( r )
{
r = std::forward<F>( f )( *std::move( r ) );
}
return r;
}
} // namespace system
} // namespace boost

View File

@@ -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()
@@ -124,6 +125,17 @@ boost_test(TYPE run SOURCES std_interop_test14.cpp)
boost_test(TYPE run SOURCES ec_location_test3.cpp)
boost_test(TYPE run SOURCES ec_location_test4.cpp)
boost_test(TYPE compile SOURCES constexpr_test2.cpp)
boost_test(TYPE run SOURCES error_code_test3.cpp)
boost_test(TYPE run SOURCES std_interop_test15.cpp)
boost_test(TYPE run SOURCES win32_generic_test.cpp)
boost_test(TYPE run SOURCES ec_hash_value_test.cpp)
boost_test(TYPE run SOURCES std_interop_test16.cpp)
# result
set(BOOST_TEST_COMPILE_FEATURES cxx_std_11)
@@ -142,3 +154,25 @@ 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 compile-fail SOURCES result_or_value_fail.cpp)
boost_test(TYPE compile-fail SOURCES result_or_value_fail2.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)

View File

@@ -33,6 +33,7 @@ rule system-run ( sources + )
result += [ run $(sources) : : : <library>/boost/system//boost_system <link>shared : $(sources[1]:B)_shared ] ;
result += [ run $(sources) : : : <define>BOOST_NO_ANSI_APIS : $(sources[1]:B)_no_ansi ] ;
result += [ run $(sources) : : : <define>BOOST_SYSTEM_USE_UTF8 : $(sources[1]:B)_utf8 ] ;
result += [ run $(sources) : : : <define>BOOST_SYSTEM_DISABLE_THREADS : $(sources[1]:B)_nthr ] ;
return $(result) ;
}
@@ -61,7 +62,11 @@ run single_instance_test.cpp single_instance_lib1 single_instance_lib2 : : : <li
run single_instance_test.cpp single_instance_lib1 single_instance_lib2 : : : <link>shared : single_instance_lib_shared ;
system-run before_main_test.cpp ;
run-fail throws_assign_fail.cpp ;
run-fail throws_assign_fail.cpp : : :
# GCC 12 catches this at compile time with a warning
<toolset>gcc,<variant>release:<build>no ;
system-run constexpr_test.cpp ;
system-run win32_hresult_test.cpp ;
@@ -148,6 +153,17 @@ run std_interop_test14.cpp ;
run ec_location_test3.cpp ;
run ec_location_test4.cpp ;
compile constexpr_test2.cpp ;
run error_code_test3.cpp ;
run std_interop_test15.cpp ;
run win32_generic_test.cpp ;
run ec_hash_value_test.cpp ;
run std_interop_test16.cpp ;
# result
import ../../config/checks/config : requires ;
@@ -169,3 +185,24 @@ run result_range_for.cpp : : : $(CPP11) ;
run result_value_construct2.cpp : : : $(CPP11) ;
run result_error_construct2.cpp : : : $(CPP11) ;
run result_errc_construct.cpp : : : $(CPP11) ;
run result_convert_construct.cpp : : : $(CPP11) ;
run result_typedefs.cpp : : : $(CPP11) ;
run result_value_construct3.cpp : : : $(CPP11) ;
run result_error_construct3.cpp : : : $(CPP11) ;
run result_emplace.cpp : : : $(CPP11) ;
run result_error_construct4.cpp : : : $(CPP11) ;
run result_value_construct4.cpp : : : $(CPP11) ;
run result_value_construct5.cpp : : : $(CPP11) ;
run result_error_move.cpp : : : $(CPP11) ;
run result_value_construct6.cpp : : : $(CPP11) ;
run result_value_construct7.cpp : : : $(CPP11) ;
run result_error_construct5.cpp : : : $(CPP11) ;
run result_or_value.cpp : : : $(CPP11) ;
compile-fail result_or_value_fail.cpp : $(CPP11) ;
compile-fail result_or_value_fail2.cpp : $(CPP11) ;
run result_or_fn0v.cpp : : : $(CPP11) ;
run result_or_fn0r.cpp : : : $(CPP11) ;
run result_and_fn1v.cpp : : : $(CPP11) ;
run result_and_fn1r.cpp : : : $(CPP11) ;
run result_and_eq_fn1v.cpp : : : $(CPP11) ;
run result_and_eq_fn1r.cpp : : : $(CPP11) ;

35
test/constexpr_test2.cpp Normal file
View File

@@ -0,0 +1,35 @@
// Copyright 2022 Peter Dimov.
// Distributed under the Boost Software License, Version 1.0.
// https://www.boost.org/LICENSE_1_0.txt
#include <boost/system/error_code.hpp>
#include <boost/config.hpp>
#include <boost/config/pragma_message.hpp>
#if defined(BOOST_GCC) && BOOST_GCC >= 40700 && BOOST_GCC < 40800
BOOST_PRAGMA_MESSAGE("Skipping test, BOOST_GCC is 407xx")
#else
struct X
{
boost::system::error_code ec;
};
X const& f()
{
#if defined(BOOST_CLANG_VERSION) && BOOST_CLANG_VERSION < 30900
BOOST_STATIC_CONSTEXPR X x = {};
return x;
#else
BOOST_STATIC_CONSTEXPR X x;
return x;
#endif
}
#endif

132
test/ec_hash_value_test.cpp Normal file
View File

@@ -0,0 +1,132 @@
// Copyright 2022 Peter Dimov.
// Distributed under the Boost Software License, Version 1.0.
// http://www.boost.org/LICENSE_1_0.txt
#include <boost/system/error_code.hpp>
#include <boost/system/generic_category.hpp>
#include <boost/system/system_category.hpp>
#include <boost/core/lightweight_test.hpp>
#include <cerrno>
#if defined(BOOST_SYSTEM_HAS_SYSTEM_ERROR)
#include <system_error>
#endif
namespace sys = boost::system;
int main()
{
// normal against normal (equal, system)
{
sys::error_code e2( 0, sys::system_category() );
sys::error_code e3( e2.value(), e2.category() );
BOOST_TEST( e2 != e3 || hash_value( e2 ) == hash_value( e3 ) );
BOOST_TEST( e2 == e3 || hash_value( e2 ) != hash_value( e3 ) );
}
// normal against normal (equal, generic)
{
sys::error_code e2( EINVAL, sys::generic_category() );
sys::error_code e3( e2.value(), e2.category() );
BOOST_TEST( e2 != e3 || hash_value( e2 ) == hash_value( e3 ) );
BOOST_TEST( e2 == e3 || hash_value( e2 ) != hash_value( e3 ) );
}
// normal against normal (inequal, value, generic)
{
sys::error_code e2( 0, sys::generic_category() );
sys::error_code e3( EINVAL, sys::generic_category() );
BOOST_TEST( e2 != e3 || hash_value( e2 ) == hash_value( e3 ) );
BOOST_TEST( e2 == e3 || hash_value( e2 ) != hash_value( e3 ) );
}
// normal against normal (inequal, value, system)
{
sys::error_code e2( 1, sys::system_category() );
sys::error_code e3( 2, sys::system_category() );
BOOST_TEST( e2 != e3 || hash_value( e2 ) == hash_value( e3 ) );
BOOST_TEST( e2 == e3 || hash_value( e2 ) != hash_value( e3 ) );
}
// normal against normal (inequal, category)
{
sys::error_code e2( 0, sys::system_category() );
sys::error_code e3( 0, sys::generic_category() );
BOOST_TEST( e2 != e3 || hash_value( e2 ) == hash_value( e3 ) );
BOOST_TEST( e2 == e3 || hash_value( e2 ) != hash_value( e3 ) );
}
// empty against normal
{
sys::error_code e2;
sys::error_code e3( e2.value(), e2.category() );
BOOST_TEST( e2 != e3 || hash_value( e2 ) == hash_value( e3 ) );
BOOST_TEST( e2 == e3 || hash_value( e2 ) != hash_value( e3 ) );
}
#if defined(BOOST_SYSTEM_HAS_SYSTEM_ERROR)
// std:: wrapping against normal
{
std::error_code e1( EINVAL, std::generic_category() );
sys::error_code e2( e1 );
sys::error_code e3( e2.value(), e2.category() );
BOOST_TEST( e2 != e3 || hash_value( e2 ) == hash_value( e3 ) );
BOOST_TEST( e2 == e3 || hash_value( e2 ) != hash_value( e3 ) );
}
// empty against wrapping std:: empty
{
std::error_code e1;
sys::error_code e2( e1 );
sys::error_code e3;
BOOST_TEST( e2 != e3 || hash_value( e2 ) == hash_value( e3 ) );
BOOST_TEST( e2 == e3 || hash_value( e2 ) != hash_value( e3 ) );
}
// empty against roundtrip via std
{
sys::error_code e2;
std::error_code e1( e2 );
sys::error_code e3( e1 );
BOOST_TEST( e2 != e3 || hash_value( e2 ) == hash_value( e3 ) );
BOOST_TEST( e2 == e3 || hash_value( e2 ) != hash_value( e3 ) );
}
// normal/generic against roundtrip via std
{
sys::error_code e2( EINVAL, boost::system::generic_category() );
std::error_code e1( e2 );
sys::error_code e3( e1 );
BOOST_TEST( e2 != e3 || hash_value( e2 ) == hash_value( e3 ) );
BOOST_TEST( e2 == e3 || hash_value( e2 ) != hash_value( e3 ) );
}
// normal/system against roundtrip via std
{
sys::error_code e2( 0, boost::system::system_category() );
std::error_code e1( e2 );
sys::error_code e3( e1 );
BOOST_TEST( e2 != e3 || hash_value( e2 ) == hash_value( e3 ) );
BOOST_TEST( e2 == e3 || hash_value( e2 ) != hash_value( e3 ) );
}
#endif
return boost::report_errors();
}

View File

@@ -8,11 +8,9 @@
// See library home page at http://www.boost.org/libs/system
// Avoid spurious VC++ warnings
# define _CRT_SECURE_NO_WARNINGS
#include <boost/system/error_code.hpp>
#include <boost/core/lightweight_test.hpp>
#include <boost/core/snprintf.hpp>
#include <cstdio>
//
@@ -31,7 +29,7 @@ public:
virtual std::string message( int ev ) const
{
char buffer[ 256 ];
std::sprintf( buffer, "user message %d", ev );
boost::core::snprintf( buffer, sizeof( buffer ), "user message %d", ev );
return buffer;
}

View File

@@ -8,11 +8,9 @@
// See library home page at http://www.boost.org/libs/system
// Avoid spurious VC++ warnings
#define _CRT_SECURE_NO_WARNINGS
#include <boost/system/error_category.hpp>
#include <boost/core/lightweight_test.hpp>
#include <boost/core/snprintf.hpp>
#include <cstdio>
//
@@ -31,7 +29,7 @@ public:
virtual std::string message( int ev ) const
{
char buffer[ 256 ];
std::sprintf( buffer, "user message %d", ev );
boost::core::snprintf( buffer, sizeof( buffer ), "user message %d", ev );
return buffer;
}

69
test/error_code_test3.cpp Normal file
View 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();
}

View File

@@ -2,11 +2,9 @@
// Copyright 2018 Peter Dimov.
// Distributed under the Boost Software License, Version 1.0.
// Avoid spurious VC++ warnings
#define _CRT_SECURE_NO_WARNINGS
#include <boost/system/error_code.hpp>
#include <boost/core/lightweight_test.hpp>
#include <boost/core/snprintf.hpp>
#include <cstdio>
using namespace boost::system;
@@ -28,7 +26,7 @@ struct http_category_impl: public error_category
{
char buffer[ 32 ];
std::sprintf( buffer, "HTTP/1.0 %d", ev );
boost::core::snprintf( buffer, sizeof( buffer ), "HTTP/1.0 %d", ev );
return buffer;
}

126
test/result_and_eq_fn1r.cpp Normal file
View File

@@ -0,0 +1,126 @@
// 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();
}
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() );
}
return boost::report_errors();
}

114
test/result_and_eq_fn1v.cpp Normal file
View File

@@ -0,0 +1,114 @@
// 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;
}
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() );
}
return boost::report_errors();
}

347
test/result_and_fn1r.cpp Normal file
View File

@@ -0,0 +1,347 @@
// 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 {};
}
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() );
}
return boost::report_errors();
}

158
test/result_and_fn1v.cpp Normal file
View File

@@ -0,0 +1,158 @@
// 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 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() );
}
return boost::report_errors();
}

View 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();
}

View File

@@ -682,5 +682,151 @@ int main()
BOOST_TEST_EQ( r, r2 );
}
// reference
{
int x1 = 1;
int x2 = 2;
result<int&> r1( x1 );
result<int&> r2( x2 );
r2 = r1;
BOOST_TEST_EQ( x1, 1 );
BOOST_TEST_EQ( x2, 2 );
BOOST_TEST_EQ( r1, r2 );
BOOST_TEST_EQ( &*r1, &*r2 );
}
{
int const x1 = 1;
int const x2 = 2;
result<int const&> r1( x1 );
result<int const&> r2( x2 );
r2 = r1;
BOOST_TEST_EQ( x1, 1 );
BOOST_TEST_EQ( x2, 2 );
BOOST_TEST_EQ( r1, r2 );
BOOST_TEST_EQ( &*r1, &*r2 );
}
{
int x1 = 1;
result<int&> r1( x1 );
result<int&> r2( ENOENT, generic_category() );
r2 = r1;
BOOST_TEST_EQ( x1, 1 );
BOOST_TEST_EQ( r1, r2 );
BOOST_TEST_EQ( &*r1, &*r2 );
}
{
int x1 = 1;
int x2 = 2;
result<int&> const r1( x1 );
result<int&> r2( x2 );
r2 = r1;
BOOST_TEST_EQ( x1, 1 );
BOOST_TEST_EQ( x2, 2 );
BOOST_TEST_EQ( r1, r2 );
BOOST_TEST_EQ( &*r1, &*r2 );
}
{
int const x1 = 1;
int const x2 = 2;
result<int const &> const r1( x1 );
result<int const &> r2( x2 );
r2 = r1;
BOOST_TEST_EQ( x1, 1 );
BOOST_TEST_EQ( x2, 2 );
BOOST_TEST_EQ( r1, r2 );
BOOST_TEST_EQ( &*r1, &*r2 );
}
{
int x1 = 1;
result<int&> const r1( x1 );
result<int&> r2( ENOENT, generic_category() );
r2 = r1;
BOOST_TEST_EQ( x1, 1 );
BOOST_TEST_EQ( r1, r2 );
BOOST_TEST_EQ( &*r1, &*r2 );
}
{
int x2 = 2;
auto ec = make_error_code( errc::invalid_argument );
result<int&> r1( ec );
result<int&> r2( x2 );
r2 = r1;
BOOST_TEST_EQ( x2, 2 );
BOOST_TEST_EQ( r1, r2 );
}
{
auto ec = make_error_code( errc::invalid_argument );
result<int&> r1( ec );
result<int&> r2( ENOENT, generic_category() );
r2 = r1;
BOOST_TEST_EQ( r1, r2 );
}
{
int x2 = 2;
auto ec = make_error_code( errc::invalid_argument );
result<int&> const r1( ec );
result<int&> r2( x2 );
r2 = r1;
BOOST_TEST_EQ( x2, 2 );
BOOST_TEST_EQ( r1, r2 );
}
{
auto ec = make_error_code( errc::invalid_argument );
result<int&> const r1( ec );
result<int&> r2( ENOENT, generic_category() );
r2 = r1;
BOOST_TEST_EQ( r1, r2 );
}
return boost::report_errors();
}

View File

@@ -145,6 +145,8 @@ int main()
BOOST_TEST_EQ( X::instances, 0 );
//
{
result<void> r;
result<void> r2( r );
@@ -177,5 +179,121 @@ int main()
BOOST_TEST_EQ( r, r2 );
}
//
{
int x1 = 1;
result<int&> r1( x1 );
result<int&> r2( r1 );
BOOST_TEST_EQ( r1, r2 );
BOOST_TEST_EQ( &*r2, &x1 );
}
{
int x1 = 1;
result<int&> const r1( x1 );
result<int&> r2( r1 );
BOOST_TEST_EQ( r1, r2 );
BOOST_TEST_EQ( &*r2, &x1 );
}
{
int const x1 = 1;
result<int const&> r1( x1 );
result<int const&> r2( r1 );
BOOST_TEST_EQ( r1, r2 );
BOOST_TEST_EQ( &*r2, &x1 );
}
{
int const x1 = 1;
result<int const&> const r1( x1 );
result<int const&> r2( r1 );
BOOST_TEST_EQ( r1, r2 );
BOOST_TEST_EQ( &*r2, &x1 );
}
BOOST_TEST_EQ( X::instances, 0 );
{
X x1( 1 );
result<X&> r1( x1 );
result<X&> r2( r1 );
BOOST_TEST_EQ( r1, r2 );
BOOST_TEST_EQ( &*r2, &x1 );
BOOST_TEST_EQ( X::instances, 1 );
}
BOOST_TEST_EQ( X::instances, 0 );
{
X x1( 1 );
result<X&> const r1( x1 );
result<X&> r2( r1 );
BOOST_TEST_EQ( r1, r2 );
BOOST_TEST_EQ( &*r2, &x1 );
BOOST_TEST_EQ( X::instances, 1 );
}
BOOST_TEST_EQ( X::instances, 0 );
{
X const x1( 1 );
result<X const&> r1( x1 );
result<X const&> r2( r1 );
BOOST_TEST_EQ( r1, r2 );
BOOST_TEST_EQ( &*r2, &x1 );
BOOST_TEST_EQ( X::instances, 1 );
}
BOOST_TEST_EQ( X::instances, 0 );
{
X const x1( 1 );
result<X const&> const r1( x1 );
result<X const&> r2( r1 );
BOOST_TEST_EQ( r1, r2 );
BOOST_TEST_EQ( &*r2, &x1 );
BOOST_TEST_EQ( X::instances, 1 );
}
BOOST_TEST_EQ( X::instances, 0 );
{
auto ec = make_error_code( errc::invalid_argument );
result<int&> r1( ec );
result<int&> r2( r1 );
BOOST_TEST_EQ( r1, r2 );
}
{
auto ec = make_error_code( errc::invalid_argument );
result<int&> const r1( ec );
result<int&> r2( r1 );
BOOST_TEST_EQ( r1, r2 );
}
//
return boost::report_errors();
}

View File

@@ -12,6 +12,11 @@ struct X
{
};
struct Y
{
Y( int );
};
int main()
{
{
@@ -23,6 +28,24 @@ int main()
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;
@@ -30,6 +53,20 @@ int main()
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;
@@ -37,5 +74,34 @@ int main()
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
View 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();
}

View File

@@ -149,5 +149,83 @@ int main()
BOOST_TEST_NE( r1, r2 );
}
{
int x1 = 1;
int x2 = 2;
result<int&> r1( x1 );
result<int&> r2( x2 );
BOOST_TEST_EQ( r1, r1 );
BOOST_TEST_NE( r1, r2 );
}
{
int x1 = 1;
int x2 = 1;
result<int&> r1( x1 );
result<int&> r2( x2 );
BOOST_TEST_EQ( r1, r2 );
}
{
result<int&> r1( 1, generic_category() );
result<int&> r2( 2, generic_category() );
BOOST_TEST_EQ( r1, r1 );
BOOST_TEST_NE( r1, r2 );
}
{
int x1 = 1;
result<int&> r1( x1 );
result<int&> r2( 2, generic_category() );
BOOST_TEST_EQ( r1, r1 );
BOOST_TEST_NE( r1, r2 );
}
{
X x1( 1 );
X x2( 2 );
result<X&, Y> r1( x1 );
result<X&, Y> r2( x2 );
BOOST_TEST_EQ( r1, r1 );
BOOST_TEST_NE( r1, r2 );
}
{
X x1( 1 );
X x2( 1 );
result<X&, Y> r1( x1 );
result<X&, Y> r2( x2 );
BOOST_TEST_EQ( r1, r2 );
}
{
result<X&, Y> r1( in_place_error, 1 );
result<X&, Y> r2( in_place_error, 2 );
BOOST_TEST_EQ( r1, r1 );
BOOST_TEST_NE( r1, r2 );
}
{
X x1( 1 );
result<X&, Y> r1( x1 );
result<X&, Y> r2( in_place_error, 2 );
BOOST_TEST_EQ( r1, r1 );
BOOST_TEST_NE( r1, r2 );
}
return boost::report_errors();
}

View File

@@ -19,5 +19,14 @@ int main()
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();
}

View File

@@ -152,6 +152,8 @@ int main()
BOOST_TEST_EQ( (result<std::string, X>( "s" ).error().v_), 0 );
}
//
{
result<void> r;
@@ -208,5 +210,71 @@ int main()
BOOST_TEST_EQ( result<void>( ec ).error(), ec );
}
//
{
int x1 = 1;
result<int&> r( x1 );
BOOST_TEST( r.has_value() );
BOOST_TEST( !r.has_error() );
BOOST_TEST_EQ( r.error(), error_code() );
}
{
int x1 = 1;
result<int&> const r( x1 );
BOOST_TEST( r.has_value() );
BOOST_TEST( !r.has_error() );
BOOST_TEST_EQ( r.error(), error_code() );
}
{
int x1 = 1;
BOOST_TEST( result<int&>( x1 ).has_value() );
BOOST_TEST( !result<int&>( x1 ).has_error() );
BOOST_TEST_EQ( result<int&>( x1 ).error(), error_code() );
}
{
auto ec = make_error_code( errc::invalid_argument );
result<int&> r( ec );
BOOST_TEST( !r.has_value() );
BOOST_TEST( r.has_error() );
BOOST_TEST_EQ( r.error(), ec );
}
{
auto ec = make_error_code( errc::invalid_argument );
result<int&> const r( ec );
BOOST_TEST( !r.has_value() );
BOOST_TEST( r.has_error() );
BOOST_TEST_EQ( r.error(), ec );
}
{
auto ec = make_error_code( errc::invalid_argument );
BOOST_TEST( !result<int&>( ec ).has_value() );
BOOST_TEST( result<int&>( ec ).has_error() );
BOOST_TEST_EQ( result<int&>( ec ).error(), ec );
}
//
return boost::report_errors();
}

View File

@@ -146,8 +146,14 @@ int main()
BOOST_TEST_TRAIT_TRUE((std::is_constructible<result<std::string, X>, int>));
BOOST_TEST_TRAIT_FALSE((std::is_convertible<int, result<std::string, X>>));
BOOST_TEST_TRAIT_FALSE((std::is_constructible<result<int, X>, int>));
BOOST_TEST_TRAIT_FALSE((std::is_convertible<int, result<int, X>>));
// We'd like this to be false due to the ambiguity caused by X having
// an explicit constructor taking an int, which should be viable in this
// context, but the implicit constructor is enabled, and there's no way to
// disallow it
//
// BOOST_TEST_TRAIT_FALSE((std::is_constructible<result<int, X>, int>));
BOOST_TEST_TRAIT_TRUE((std::is_convertible<int, result<int, X>>));
}
{

View 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();
}

View File

@@ -0,0 +1,49 @@
// Copyright 2023 Peter Dimov.
// Distributed under the Boost Software License, Version 1.0.
// https://www.boost.org/LICENSE_1_0.txt
#include <boost/system/result.hpp>
#include <boost/core/lightweight_test.hpp>
using namespace boost::system;
// Eigen::Matrix4d has an explicit templated constructor
// https://github.com/boostorg/system/issues/103
// https://github.com/boostorg/json/issues/843
struct X
{
X() {}
template<class T> explicit X( T const& ) {}
};
int main()
{
{
auto ec = make_error_code( errc::invalid_argument );
result<X> r = ec;
BOOST_TEST( !r.has_value() );
BOOST_TEST( r.has_error() );
BOOST_TEST_EQ( r.error(), ec );
}
#if defined(BOOST_SYSTEM_HAS_SYSTEM_ERROR)
{
auto ec = make_error_code( std::errc::invalid_argument );
result<X> r = ec;
BOOST_TEST( !r.has_value() );
BOOST_TEST( r.has_error() );
BOOST_TEST_EQ( r.error(), ec );
}
#endif
return boost::report_errors();
}

View 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
View 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();
}

View File

@@ -508,6 +508,8 @@ int main()
BOOST_TEST_EQ( Y::instances, 0 );
//
{
result<void> r;
result<void> r2;
@@ -600,5 +602,110 @@ int main()
BOOST_TEST_EQ( r2.error(), ec );
}
//
{
int x1 = 1;
int x2 = 2;
result<int&> r1( x1 );
result<int&> r2( x2 );
r2 = std::move( r1 );
BOOST_TEST_EQ( x1, 1 );
BOOST_TEST_EQ( x2, 2 );
BOOST_TEST( r2.has_value() );
BOOST_TEST( !r2.has_error() );
BOOST_TEST_EQ( r2.value(), 1 );
BOOST_TEST_EQ( r1, r2 );
BOOST_TEST_EQ( &*r1, &*r2 );
}
{
int x1 = 1;
result<int&> r1( x1 );
result<int&> r2( ENOENT, generic_category() );
r2 = std::move( r1 );
BOOST_TEST_EQ( x1, 1 );
BOOST_TEST( r2.has_value() );
BOOST_TEST( !r2.has_error() );
BOOST_TEST_EQ( r2.value(), 1 );
BOOST_TEST_EQ( r1, r2 );
}
{
int x1 = 1;
auto ec = make_error_code( errc::invalid_argument );
result<int&> r1( ec );
result<int&> r2( x1 );
r2 = std::move( r1 );
BOOST_TEST_EQ( x1, 1 );
BOOST_TEST( !r2.has_value() );
BOOST_TEST( r2.has_error() );
BOOST_TEST_EQ( r2.error(), ec );
}
{
int x1 = 1;
auto ec = make_error_code( errc::invalid_argument );
result<int&> r2( x1 );
r2 = result<int&>( ec );
BOOST_TEST_EQ( x1, 1 );
BOOST_TEST( !r2.has_value() );
BOOST_TEST( r2.has_error() );
BOOST_TEST_EQ( r2.error(), ec );
}
{
auto ec = make_error_code( errc::invalid_argument );
result<int&> r1( ec );
result<int&> r2( ENOENT, generic_category() );
r2 = std::move( r1 );
BOOST_TEST( !r2.has_value() );
BOOST_TEST( r2.has_error() );
BOOST_TEST_EQ( r2.error(), ec );
}
{
auto ec = make_error_code( errc::invalid_argument );
result<int&> r2( ENOENT, generic_category() );
r2 = result<int&>( ec );
BOOST_TEST( !r2.has_value() );
BOOST_TEST( r2.has_error() );
BOOST_TEST_EQ( r2.error(), ec );
}
//
return boost::report_errors();
}

View File

@@ -207,6 +207,8 @@ int main()
BOOST_TEST_EQ( X::instances, 0 );
//
{
result<void> r;
result<void> r2( std::move( r ) );
@@ -245,5 +247,149 @@ int main()
BOOST_TEST_EQ( r2.error(), ec );
}
//
{
int x1 = 1;
result<int&> r1( x1 );
result<int&> r2( std::move( r1 ) );
BOOST_TEST( r1.has_value() );
BOOST_TEST( !r1.has_error() );
BOOST_TEST_EQ( r1.value(), 1 );
BOOST_TEST_EQ( &*r1, &x1 );
BOOST_TEST( r2.has_value() );
BOOST_TEST( !r2.has_error() );
BOOST_TEST_EQ( r2.value(), 1 );
BOOST_TEST_EQ( &*r2, &x1 );
}
{
int const x1 = 1;
result<int const&> r1( x1 );
result<int const&> r2( std::move( r1 ) );
BOOST_TEST( r1.has_value() );
BOOST_TEST( !r1.has_error() );
BOOST_TEST_EQ( r1.value(), 1 );
BOOST_TEST_EQ( &*r1, &x1 );
BOOST_TEST( r2.has_value() );
BOOST_TEST( !r2.has_error() );
BOOST_TEST_EQ( r2.value(), 1 );
BOOST_TEST_EQ( &*r2, &x1 );
}
{
int x1 = 1;
result<int&> r2(( result<int&>( x1 ) ));
BOOST_TEST( r2.has_value() );
BOOST_TEST( !r2.has_error() );
BOOST_TEST_EQ( r2.value(), 1 );
BOOST_TEST_EQ( &*r2, &x1 );
}
{
int const x1 = 1;
result<int const&> r2(( result<int const&>( x1 ) ));
BOOST_TEST( r2.has_value() );
BOOST_TEST( !r2.has_error() );
BOOST_TEST_EQ( r2.value(), 1 );
BOOST_TEST_EQ( &*r2, &x1 );
}
{
X x1( 1 );
result<X&> r1( x1 );
result<X&> r2( std::move( r1 ) );
BOOST_TEST( r1.has_value() );
BOOST_TEST( !r1.has_error() );
BOOST_TEST_EQ( r1.value().v_, 1 );
BOOST_TEST_EQ( &*r1, &x1 );
BOOST_TEST( r2.has_value() );
BOOST_TEST( !r2.has_error() );
BOOST_TEST_EQ( r2.value().v_, 1 );
BOOST_TEST_EQ( &*r2, &x1 );
BOOST_TEST_EQ( X::instances, 1 );
}
BOOST_TEST_EQ( X::instances, 0 );
{
X x1( 1 );
result<X&> r2(( result<X&>( x1 ) ));
BOOST_TEST( r2.has_value() );
BOOST_TEST( !r2.has_error() );
BOOST_TEST_EQ( r2.value().v_, 1 );
BOOST_TEST_EQ( &*r2, &x1 );
BOOST_TEST_EQ( X::instances, 1 );
}
BOOST_TEST_EQ( X::instances, 0 );
{
X const x1( 1 );
result<X const&> r1( x1 );
result<X const&> r2( std::move( r1 ) );
BOOST_TEST( r1.has_value() );
BOOST_TEST( !r1.has_error() );
BOOST_TEST_EQ( r1.value().v_, 1 );
BOOST_TEST_EQ( &*r1, &x1 );
BOOST_TEST( r2.has_value() );
BOOST_TEST( !r2.has_error() );
BOOST_TEST_EQ( r2.value().v_, 1 );
BOOST_TEST_EQ( &*r2, &x1 );
BOOST_TEST_EQ( X::instances, 1 );
}
BOOST_TEST_EQ( X::instances, 0 );
{
X const x1( 1 );
result<X const&> r2(( result<X const&>( x1 ) ));
BOOST_TEST( r2.has_value() );
BOOST_TEST( !r2.has_error() );
BOOST_TEST_EQ( r2.value().v_, 1 );
BOOST_TEST_EQ( &*r2, &x1 );
BOOST_TEST_EQ( X::instances, 1 );
}
BOOST_TEST_EQ( X::instances, 0 );
//
return boost::report_errors();
}

359
test/result_or_fn0r.cpp Normal file
View File

@@ -0,0 +1,359 @@
// 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
{
};
result<int, E> fi()
{
return 2;
}
result<int, E> fi2()
{
return E();
}
result<Y, E> fy()
{
return Y{ 2 };
}
result<Y, E> fy2()
{
return E();
}
result<int&, E> fri()
{
static int x = 2;
return x;
}
result<int&, E> fri2()
{
return E();
}
result<void, E> fv()
{
return {};
}
result<void, E> fv2()
{
return E();
}
int main()
{
{
result<int> r( 1 );
int x = r | fi | 3;
BOOST_TEST_EQ( x, 1 );
}
{
result<int> const r( 1 );
int x = r | fi | 3;
BOOST_TEST_EQ( x, 1 );
}
{
int x = result<int>( 1 ) | fi | 3;
BOOST_TEST_EQ( x, 1 );
}
{
result<int> r( 1 );
int x = r | fi2 | 3;
BOOST_TEST_EQ( x, 1 );
}
{
result<int> const r( 1 );
int x = r | fi2 | 3;
BOOST_TEST_EQ( x, 1 );
}
{
int x = result<int>( 1 ) | fi2 | 3;
BOOST_TEST_EQ( x, 1 );
}
{
result<int> r( in_place_error );
int x = r | fi | 3;
BOOST_TEST_EQ( x, 2 );
}
{
result<int> const r( in_place_error );
int x = r | fi | 3;
BOOST_TEST_EQ( x, 2 );
}
{
int x = result<int>( in_place_error ) | fi | 3;
BOOST_TEST_EQ( x, 2 );
}
{
result<int> r( in_place_error );
int x = r | fi2 | 3;
BOOST_TEST_EQ( x, 3 );
}
{
result<int> const r( in_place_error );
int x = r | fi2 | 3;
BOOST_TEST_EQ( x, 3 );
}
{
int x = result<int>( in_place_error ) | fi2 | 3;
BOOST_TEST_EQ( x, 3 );
}
{
Y y = result<X>( X{1} ) | fy | X{3};
BOOST_TEST_EQ( y.v_, 1 );
}
{
Y y = result<X>( X{1} ) | fy2 | X{3};
BOOST_TEST_EQ( y.v_, 1 );
}
{
Y y = result<X, E>( in_place_error ) | fy | X{3};
BOOST_TEST_EQ( y.v_, 2 );
}
{
Y y = result<X, E>( in_place_error ) | fy2 | Y{3};
BOOST_TEST_EQ( y.v_, 3 );
}
{
int x1 = 1;
int x3 = 3;
result<int&> r( x1 );
int& x = r | fri | x3;
BOOST_TEST_EQ( &x, &x1 );
}
{
int x1 = 1;
int x3 = 3;
result<int&> const r( x1 );
int& x = r | fri | x3;
BOOST_TEST_EQ( &x, &x1 );
}
{
int x1 = 1;
int x3 = 3;
int& x = result<int&>( x1 ) | fri | x3;
BOOST_TEST_EQ( &x, &x1 );
}
{
int x1 = 1;
int x3 = 3;
result<int&> r( x1 );
int& x = r | fri2 | x3;
BOOST_TEST_EQ( &x, &x1 );
}
{
int x1 = 1;
int x3 = 3;
result<int&> const r( x1 );
int& x = r | fri2 | x3;
BOOST_TEST_EQ( &x, &x1 );
}
{
int x1 = 1;
int x3 = 3;
int& x = result<int&>( x1 ) | fri2 | x3;
BOOST_TEST_EQ( &x, &x1 );
}
{
int x3 = 3;
result<int&, E> r( in_place_error );
int& x = r | fri | x3;
BOOST_TEST_EQ( &x, &*fri() );
}
{
int x3 = 3;
result<int&, E> const r( in_place_error );
int& x = r | fri | x3;
BOOST_TEST_EQ( &x, &*fri() );
}
{
int x3 = 3;
int& x = result<int&, E>( in_place_error ) | fri | x3;
BOOST_TEST_EQ( &x, &*fri() );
}
{
int x3 = 3;
result<int&, E> r( in_place_error );
int& x = r | fri2 | x3;
BOOST_TEST_EQ( &x, &x3 );
}
{
int x3 = 3;
result<int&, E> const r( in_place_error );
int& x = r | fri2 | x3;
BOOST_TEST_EQ( &x, &x3 );
}
{
int x3 = 3;
int& x = result<int&, E>( in_place_error ) | fri2 | x3;
BOOST_TEST_EQ( &x, &x3 );
}
{
result<void> r;
result<void, E> r2 = r | fv;
BOOST_TEST( r2.has_value() );
}
{
result<void> r;
result<void, E> r2 = r | fv2;
BOOST_TEST( r2.has_value() );
}
{
result<void> r( in_place_error );
result<void, E> r2 = r | fv;
BOOST_TEST( r2.has_value() );
}
{
result<void> r( in_place_error );
result<void, E> r2 = r | fv2;
BOOST_TEST( r2.has_error() );
}
{
result<void, E> r2 = result<void>() | fv;
BOOST_TEST( r2.has_value() );
}
{
result<void, E> r2 = result<void>() | fv2;
BOOST_TEST( r2.has_value() );
}
{
result<void, E> r2 = result<void>( in_place_error ) | fv;
BOOST_TEST( r2.has_value() );
}
{
result<void, E> r2 = result<void>( in_place_error ) | fv2;
BOOST_TEST( r2.has_error() );
}
return boost::report_errors();
}

162
test/result_or_fn0v.cpp Normal file
View File

@@ -0,0 +1,162 @@
// 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()
{
return 2;
}
X g()
{
return { 2 };
}
int& h()
{
static int x = 2;
return x;
}
int main()
{
{
result<int> r( 1 );
int x = r | f;
BOOST_TEST_EQ( x, 1 );
}
{
result<int> const r( 1 );
int x = r | f;
BOOST_TEST_EQ( x, 1 );
}
{
int x = result<int>( 1 ) | f;
BOOST_TEST_EQ( x, 1 );
}
{
result<int, E> r( in_place_error );
int x = r | f;
BOOST_TEST_EQ( x, 2 );
}
{
result<int, E> const r( in_place_error );
int x = r | f;
BOOST_TEST_EQ( x, 2 );
}
{
int x = result<int, E>( in_place_error ) | f;
BOOST_TEST_EQ( x, 2 );
}
{
Y y = result<Y>( in_place_value, 1 ) | g;
BOOST_TEST_EQ( y.v_, 1 );
}
{
Y y = result<Y, E>( in_place_error ) | g;
BOOST_TEST_EQ( y.v_, 2 );
}
{
int x1 = 1;
result<int&> r( x1 );
int& x = r | h;
BOOST_TEST_EQ( &x, &x1 );
}
{
int x1 = 1;
result<int&> const r( x1 );
int& x = r | h;
BOOST_TEST_EQ( &x, &x1 );
}
{
int x1 = 1;
int& x = result<int&>( x1 ) | h;
BOOST_TEST_EQ( &x, &x1 );
}
{
result<int&, E> r( in_place_error );
int& x = r | h;
BOOST_TEST_EQ( &x, &h() );
}
{
result<int&, E> const r( in_place_error );
int& x = r | h;
BOOST_TEST_EQ( &x, &h() );
}
{
int& x = result<int&, E>( in_place_error ) | h;
BOOST_TEST_EQ( &x, &h() );
}
return boost::report_errors();
}

167
test/result_or_value.cpp Normal file
View File

@@ -0,0 +1,167 @@
// 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 main()
{
{
result<int> r( 1 );
int x = r | 2;
BOOST_TEST_EQ( x, 1 );
}
{
result<int> const r( 1 );
int x = r | 2;
BOOST_TEST_EQ( x, 1 );
}
{
int x = result<int>( 1 ) | 2;
BOOST_TEST_EQ( x, 1 );
}
{
result<int, E> r( in_place_error );
int x = r | 2;
BOOST_TEST_EQ( x, 2 );
}
{
result<int, E> const r( in_place_error );
int x = r | 2;
BOOST_TEST_EQ( x, 2 );
}
{
int x = result<int, E>( in_place_error ) | 2;
BOOST_TEST_EQ( x, 2 );
}
{
Y y = result<Y>( in_place_value, 1 ) | Y{2};
BOOST_TEST_EQ( y.v_, 1 );
}
{
Y y = result<Y, E>( in_place_error ) | Y{2};
BOOST_TEST_EQ( y.v_, 2 );
}
{
Y y = result<Y>( in_place_value, 1 ) | X{2};
BOOST_TEST_EQ( y.v_, 1 );
}
{
Y y = result<Y, E>( in_place_error ) | X{2};
BOOST_TEST_EQ( y.v_, 2 );
}
{
int x1 = 1;
int x2 = 2;
result<int&> r( x1 );
int& x = r | x2;
BOOST_TEST_EQ( &x, &x1 );
}
{
int x1 = 1;
int x2 = 2;
result<int&> const r( x1 );
int& x = r | x2;
BOOST_TEST_EQ( &x, &x1 );
}
{
int x1 = 1;
int x2 = 2;
int& x = result<int&>( x1 ) | x2;
BOOST_TEST_EQ( &x, &x1 );
}
{
int x2 = 2;
result<int&, E> r( in_place_error );
int& x = r | x2;
BOOST_TEST_EQ( &x, &x2 );
}
{
int x2 = 2;
result<int&, E> const r( in_place_error );
int& x = r | x2;
BOOST_TEST_EQ( &x, &x2 );
}
{
int x2 = 2;
int& x = result<int&, E>( in_place_error ) | x2;
BOOST_TEST_EQ( &x, &x2 );
}
return boost::report_errors();
}

View File

@@ -0,0 +1,14 @@
// 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>
using namespace boost::system;
int main()
{
int x = 1;
result<int const&> r( x );
r | 2;
}

View File

@@ -0,0 +1,13 @@
// 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>
using namespace boost::system;
int main()
{
int x = 1;
result<int const&>( x ) | 2;
}

View File

@@ -259,5 +259,55 @@ int main()
BOOST_TEST_EQ( r2, r2c );
}
{
int x1 = 1;
int x2 = 2;
result<int&> r1( x1 ), r1c( r1 );
result<int&> r2( x2 ), r2c( r2 );
r1.swap( r2 );
BOOST_TEST_EQ( r1, r2c );
BOOST_TEST_EQ( r2, r1c );
swap( r1, r2 );
BOOST_TEST_EQ( r1, r1c );
BOOST_TEST_EQ( r2, r2c );
}
{
result<int&> r1( 1, generic_category() ), r1c( r1 );
result<int&> r2( 2, generic_category() ), r2c( r2 );
r1.swap( r2 );
BOOST_TEST_EQ( r1, r2c );
BOOST_TEST_EQ( r2, r1c );
swap( r1, r2 );
BOOST_TEST_EQ( r1, r1c );
BOOST_TEST_EQ( r2, r2c );
}
{
int x1 = 1;
result<int&> r1( x1 ), r1c( r1 );
result<int&> r2( 2, generic_category() ), r2c( r2 );
r1.swap( r2 );
BOOST_TEST_EQ( r1, r2c );
BOOST_TEST_EQ( r2, r1c );
swap( r1, r2 );
BOOST_TEST_EQ( r1, r1c );
BOOST_TEST_EQ( r2, r2c );
}
return boost::report_errors();
}

39
test/result_typedefs.cpp Normal file
View File

@@ -0,0 +1,39 @@
// Copyright 2022 Peter Dimov.
// Distributed under the Boost Software License, Version 1.0.
// https://www.boost.org/LICENSE_1_0.txt
#include <boost/system/result.hpp>
#include <boost/core/lightweight_test_trait.hpp>
using namespace boost::system;
struct X {};
int main()
{
BOOST_TEST_TRAIT_SAME( result<int>::value_type, int );
BOOST_TEST_TRAIT_SAME( result<int>::error_type, error_code );
BOOST_TEST_TRAIT_SAME( result<X>::value_type, X );
BOOST_TEST_TRAIT_SAME( result<X>::error_type, error_code );
BOOST_TEST_TRAIT_SAME( result<void>::value_type, void );
BOOST_TEST_TRAIT_SAME( result<void>::error_type, error_code );
BOOST_TEST_TRAIT_SAME( result<int&>::value_type, int& );
BOOST_TEST_TRAIT_SAME( result<int&>::error_type, error_code );
BOOST_TEST_TRAIT_SAME( result<int, X>::value_type, int );
BOOST_TEST_TRAIT_SAME( result<int, X>::error_type, X );
BOOST_TEST_TRAIT_SAME( result<X, X>::value_type, X );
BOOST_TEST_TRAIT_SAME( result<X, X>::error_type, X );
BOOST_TEST_TRAIT_SAME( result<void, X>::value_type, void );
BOOST_TEST_TRAIT_SAME( result<void, X>::error_type, X );
BOOST_TEST_TRAIT_SAME( result<int&, X>::value_type, int& );
BOOST_TEST_TRAIT_SAME( result<int&, X>::error_type, X );
return boost::report_errors();
}

View File

@@ -5,6 +5,7 @@
#include <boost/system/result.hpp>
#include <boost/core/lightweight_test.hpp>
#include <boost/core/lightweight_test_trait.hpp>
#include <boost/config.hpp>
#include <system_error>
using namespace boost::system;
@@ -223,7 +224,10 @@ int main()
BOOST_TEST_NOT( r );
BOOST_TEST( !r );
#if defined(BOOST_CLANG_VERSION) && BOOST_CLANG_VERSION < 30600
#else
BOOST_TEST_THROWS( r.value(), E2 );
#endif
BOOST_TEST_EQ( r.operator->(), static_cast<int*>(0) );
}
@@ -332,6 +336,8 @@ int main()
BOOST_TEST_EQ( (result<X, Y>( ec ).operator->()), static_cast<X*>(0) );
}
//
{
result<void> r;
@@ -471,7 +477,10 @@ int main()
BOOST_TEST_NOT( r );
BOOST_TEST( !r );
#if defined(BOOST_CLANG_VERSION) && BOOST_CLANG_VERSION < 30600
#else
BOOST_TEST_THROWS( r.value(), E2 );
#endif
BOOST_TEST_EQ( r.operator->(), static_cast<void*>(0) );
}
@@ -490,5 +499,179 @@ int main()
BOOST_TEST_EQ( r.operator->(), static_cast<void*>(0) );
}
//
{
int x1 = 1;
result<int&> r( x1 );
BOOST_TEST( r.has_value() );
BOOST_TEST( !r.has_error() );
BOOST_TEST( r );
BOOST_TEST_NOT( !r );
BOOST_TEST_EQ( r.value(), 1 );
BOOST_TEST_EQ( *r, 1 );
BOOST_TEST_EQ( r.operator->(), &*r );
}
{
int x1 = 1;
result<int&> const r( x1 );
BOOST_TEST( r.has_value() );
BOOST_TEST( !r.has_error() );
BOOST_TEST( r );
BOOST_TEST_NOT( !r );
BOOST_TEST_EQ( r.value(), 1 );
BOOST_TEST_EQ( *r, 1 );
BOOST_TEST_EQ( r.operator->(), &*r );
}
{
int x1 = 1;
BOOST_TEST( result<int&>( x1 ).has_value() );
BOOST_TEST( !result<int&>( x1 ).has_error() );
BOOST_TEST( result<int&>( x1 ) );
BOOST_TEST_NOT( !result<int&>( x1 ) );
BOOST_TEST_EQ( result<int&>( x1 ).value(), 1 );
BOOST_TEST_EQ( *result<int&>( x1 ), 1 );
BOOST_TEST_EQ( result<int&>( x1 ).operator->(), &x1 );
}
{
auto ec = make_error_code( errc::invalid_argument );
result<int&> r( ec );
BOOST_TEST( !r.has_value() );
BOOST_TEST( r.has_error() );
BOOST_TEST_NOT( r );
BOOST_TEST( !r );
BOOST_TEST_THROWS( r.value(), system_error );
BOOST_TEST_EQ( r.operator->(), static_cast<int*>(0) );
}
{
auto ec = make_error_code( errc::invalid_argument );
result<int&> const r( ec );
BOOST_TEST( !r.has_value() );
BOOST_TEST( r.has_error() );
BOOST_TEST_NOT( r );
BOOST_TEST( !r );
BOOST_TEST_THROWS( r.value(), system_error );
BOOST_TEST_EQ( r.operator->(), static_cast<int*>(0) );
}
{
auto ec = make_error_code( errc::invalid_argument );
BOOST_TEST( !result<int&>( ec ).has_value() );
BOOST_TEST( result<int&>( ec ).has_error() );
BOOST_TEST_NOT( result<int&>( ec ) );
BOOST_TEST( !result<int&>( ec ) );
BOOST_TEST_THROWS( result<int&>( ec ).value(), system_error );
BOOST_TEST_EQ( result<int&>( ec ).operator->(), static_cast<int*>(0) );
}
{
auto ec = make_error_code( std::errc::invalid_argument );
result<int&, std::error_code> const r( ec );
BOOST_TEST( !r.has_value() );
BOOST_TEST( r.has_error() );
BOOST_TEST_NOT( r );
BOOST_TEST( !r );
BOOST_TEST_THROWS( r.value(), std::system_error );
BOOST_TEST_EQ( r.operator->(), static_cast<int*>(0) );
}
{
result<int&, errc::errc_t> const r( in_place_error, errc::invalid_argument );
BOOST_TEST( !r.has_value() );
BOOST_TEST( r.has_error() );
BOOST_TEST_NOT( r );
BOOST_TEST( !r );
BOOST_TEST_THROWS( r.value(), system_error );
BOOST_TEST_EQ( r.operator->(), static_cast<int*>(0) );
}
{
result<int&, std::errc> const r( std::errc::invalid_argument );
BOOST_TEST( !r.has_value() );
BOOST_TEST( r.has_error() );
BOOST_TEST_NOT( r );
BOOST_TEST( !r );
BOOST_TEST_THROWS( r.value(), std::system_error );
BOOST_TEST_EQ( r.operator->(), static_cast<int*>(0) );
}
{
result<int&, std::exception_ptr> const r( std::make_exception_ptr( E2() ) );
BOOST_TEST( !r.has_value() );
BOOST_TEST( r.has_error() );
BOOST_TEST_NOT( r );
BOOST_TEST( !r );
#if defined(BOOST_CLANG_VERSION) && BOOST_CLANG_VERSION < 30600
#else
BOOST_TEST_THROWS( r.value(), E2 );
#endif
BOOST_TEST_EQ( r.operator->(), static_cast<int*>(0) );
}
{
result<int&, std::exception_ptr> const r( in_place_error );
BOOST_TEST( !r.has_value() );
BOOST_TEST( r.has_error() );
BOOST_TEST_NOT( r );
BOOST_TEST( !r );
BOOST_TEST_THROWS( r.value(), std::bad_exception );
BOOST_TEST_EQ( r.operator->(), static_cast<int*>(0) );
}
//
return boost::report_errors();
}

View File

@@ -69,6 +69,11 @@ result<std::vector<int>> fv2()
return {{ 1, 2 }};
}
result<void> fw0()
{
return {};
}
int main()
{
{
@@ -148,5 +153,12 @@ int main()
BOOST_TEST_EQ( r->at(1), 2 );
}
{
result<void> r = fw0();
BOOST_TEST( r.has_value() );
BOOST_TEST( !r.has_error() );
}
return boost::report_errors();
}

View File

@@ -0,0 +1,142 @@
// Copyright 2017, 2021, 2022 Peter Dimov.
// Distributed under the Boost Software License, Version 1.0.
// https://www.boost.org/LICENSE_1_0.txt
#include <boost/system/result.hpp>
#include <boost/core/lightweight_test.hpp>
using namespace boost::system;
struct X
{
static int instances;
int v_;
explicit X( int v ): v_( v ) { ++instances; }
X( int v1, int v2 ): v_( v1+v2 ) { ++instances; }
X( int v1, int v2, int v3 ): v_( v1+v2+v3 ) { ++instances; }
X( X const& ) = delete;
X& operator=( X const& ) = delete;
~X() { --instances; }
};
int X::instances = 0;
int main()
{
{
using R = result<int>;
R r( R::in_place_value, 0 );
BOOST_TEST( r.has_value() );
BOOST_TEST( !r.has_error() );
BOOST_TEST_EQ( r.value(), 0 );
}
{
using R = result<int, int>;
R r( R::in_place_value, 1 );
BOOST_TEST( r.has_value() );
BOOST_TEST( !r.has_error() );
BOOST_TEST_EQ( *r, 1 );
}
BOOST_TEST_EQ( X::instances, 0 );
{
using R = result<X>;
R r( R::in_place_value, 1 );
BOOST_TEST( r.has_value() );
BOOST_TEST( !r.has_error() );
BOOST_TEST_EQ( r.value().v_, 1 );
BOOST_TEST_EQ( X::instances, 1 );
}
BOOST_TEST_EQ( X::instances, 0 );
{
using R = result<X>;
R r( R::in_place_value, 1, 2 );
BOOST_TEST( r.has_value() );
BOOST_TEST( !r.has_error() );
BOOST_TEST_EQ( r.value().v_, 1+2 );
BOOST_TEST_EQ( X::instances, 1 );
}
BOOST_TEST_EQ( X::instances, 0 );
{
using R = result<X>;
R r( R::in_place_value, 1, 2, 3 );
BOOST_TEST( r.has_value() );
BOOST_TEST( !r.has_error() );
BOOST_TEST_EQ( r.value().v_, 1+2+3 );
BOOST_TEST_EQ( X::instances, 1 );
}
BOOST_TEST_EQ( X::instances, 0 );
{
using R = result<X, X>;
R r( R::in_place_value, 1 );
BOOST_TEST( r.has_value() );
BOOST_TEST( !r.has_error() );
BOOST_TEST_EQ( r->v_, 1 );
BOOST_TEST_EQ( X::instances, 1 );
}
BOOST_TEST_EQ( X::instances, 0 );
{
using R = result<void>;
R r( R::in_place_value );
BOOST_TEST( r.has_value() );
BOOST_TEST( !r.has_error() );
}
{
int x1 = 1;
using R = result<int&>;
R r( R::in_place_value, x1 );
BOOST_TEST( r.has_value() );
BOOST_TEST( !r.has_error() );
BOOST_TEST_EQ( r.value(), 1 );
}
{
int x1 = 1;
using R = result<int&, int>;
R r( R::in_place_value, x1 );
BOOST_TEST( r.has_value() );
BOOST_TEST( !r.has_error() );
BOOST_TEST_EQ( *r, 1 );
}
return boost::report_errors();
}

View File

@@ -0,0 +1,59 @@
// Copyright 2023 Peter Dimov.
// Distributed under the Boost Software License, Version 1.0.
// https://www.boost.org/LICENSE_1_0.txt
#include <boost/system/result.hpp>
#include <boost/core/lightweight_test.hpp>
using namespace boost::system;
// Tricky mixed construction cases
// https://github.com/boostorg/system/issues/104
// https://brevzin.github.io//c++/2023/01/18/optional-construction/
int main()
{
{
result<int> r( make_error_code( errc::invalid_argument ) );
result<result<int>> r2( r );
BOOST_TEST( r2.has_value() ) && BOOST_TEST_EQ( r2.value(), r );
}
{
result<int> r( 5 );
result<result<int>> r2( r );
BOOST_TEST( r2.has_value() ) && BOOST_TEST_EQ( r2.value(), r );
}
{
result<int> const r( make_error_code( errc::invalid_argument ) );
result<result<int>> r2( r );
BOOST_TEST( r2.has_value() ) && BOOST_TEST_EQ( r2.value(), r );
}
{
result<int> const r( 5 );
result<result<int>> r2( r );
BOOST_TEST( r2.has_value() ) && BOOST_TEST_EQ( r2.value(), r );
}
{
result<int> r( make_error_code( errc::invalid_argument ) );
result<result<int>> r2( std::move( r ) );
BOOST_TEST( r2.has_value() ) && BOOST_TEST_EQ( r2.value(), r );
}
{
result<int> r( 5 );
result<result<int>> r2( std::move( r ) );
BOOST_TEST( r2.has_value() ) && BOOST_TEST_EQ( r2.value(), r );
}
return boost::report_errors();
}

View File

@@ -0,0 +1,86 @@
// Copyright 2023 Peter Dimov.
// Distributed under the Boost Software License, Version 1.0.
// https://www.boost.org/LICENSE_1_0.txt
#if defined(_MSC_VER) && _MSC_VER < 1910
# pragma warning( disable: 4800 ) // forcing value to bool 'true' or 'false'
#endif
#include <boost/system/result.hpp>
#include <boost/core/lightweight_test.hpp>
#include <boost/core/lightweight_test_trait.hpp>
#include <utility>
#include <type_traits>
using namespace boost::system;
// Tricky mixed construction cases
// https://github.com/boostorg/system/issues/104
// https://brevzin.github.io//c++/2023/01/18/optional-construction/
template<class R1, class R2> void test()
{
{
R1 r1( make_error_code( errc::invalid_argument ) );
R2 r2( r1 );
BOOST_TEST( !r2.has_value() );
}
{
R1 r1( 0 );
R2 r2( r1 );
BOOST_TEST( r2.has_value() ) && BOOST_TEST_EQ( r2.value(), false );
}
{
R1 r1( 1 );
R2 r2( r1 );
BOOST_TEST( r2.has_value() ) && BOOST_TEST_EQ( r2.value(), true );
}
{
R1 r1( make_error_code( errc::invalid_argument ) );
R2 r2( std::move( r1 ) );
BOOST_TEST( !r2.has_value() );
}
{
R1 r1( 0 );
R2 r2( std::move( r1 ) );
BOOST_TEST( r2.has_value() ) && BOOST_TEST_EQ( r2.value(), false );
}
{
R1 r1( 1 );
R2 r2( std::move( r1 ) );
BOOST_TEST( r2.has_value() ) && BOOST_TEST_EQ( r2.value(), true );
}
}
struct X
{
};
int main()
{
test< result<int>, result<bool> >();
test< result<int> const, result<bool> >();
BOOST_TEST_TRAIT_FALSE((std::is_constructible<result<bool>, result<X>&>));
BOOST_TEST_TRAIT_FALSE((std::is_constructible<result<bool>, result<X> const&>));
BOOST_TEST_TRAIT_FALSE((std::is_constructible<result<bool>, result<X>&&>));
BOOST_TEST_TRAIT_FALSE((std::is_constructible<result<bool>, result<X> const&&>));
BOOST_TEST_TRAIT_FALSE((std::is_constructible<result<bool const>, result<X>&>));
BOOST_TEST_TRAIT_FALSE((std::is_constructible<result<bool const>, result<X> const&>));
BOOST_TEST_TRAIT_FALSE((std::is_constructible<result<bool const>, result<X>&&>));
BOOST_TEST_TRAIT_FALSE((std::is_constructible<result<bool const>, result<X> const&&>));
return boost::report_errors();
}

View File

@@ -0,0 +1,121 @@
// Copyright 2017, 2021, 2023 Peter Dimov.
// Distributed under the Boost Software License, Version 1.0.
// https://www.boost.org/LICENSE_1_0.txt
#include <boost/system/result.hpp>
#include <boost/core/lightweight_test.hpp>
#include <boost/core/lightweight_test_trait.hpp>
using namespace boost::system;
struct X
{
static int instances;
int v_;
explicit X( int v ): v_( v ) { ++instances; }
X( X const& ) = delete;
X& operator=( X const& ) = delete;
~X() { --instances; }
};
int X::instances = 0;
int main()
{
{
int x = 0;
result<int&> r( x );
BOOST_TEST( r.has_value() );
BOOST_TEST( !r.has_error() );
BOOST_TEST_EQ( r.value(), 0 );
}
{
int x = 0;
result<int&> r = x;
BOOST_TEST( r.has_value() );
BOOST_TEST( !r.has_error() );
BOOST_TEST_EQ( r.value(), 0 );
}
{
int x = 1;
result<int&, int> r( in_place_value, x );
BOOST_TEST( r.has_value() );
BOOST_TEST( !r.has_error() );
BOOST_TEST_EQ( *r, 1 );
}
BOOST_TEST_EQ( X::instances, 0 );
{
X x( 1 );
result<X&> r( x );
BOOST_TEST( r.has_value() );
BOOST_TEST( !r.has_error() );
BOOST_TEST_EQ( r.value().v_, 1 );
BOOST_TEST_EQ( X::instances, 1 );
}
BOOST_TEST_EQ( X::instances, 0 );
{
X x( 1 );
result<X&> r = x;
BOOST_TEST( r.has_value() );
BOOST_TEST( !r.has_error() );
BOOST_TEST_EQ( r.value().v_, 1 );
BOOST_TEST_EQ( X::instances, 1 );
}
BOOST_TEST_EQ( X::instances, 0 );
{
X x( 1 );
result<X&, X> r( in_place_value, x );
BOOST_TEST( r.has_value() );
BOOST_TEST( !r.has_error() );
BOOST_TEST_EQ( r->v_, 1 );
BOOST_TEST_EQ( X::instances, 1 );
}
BOOST_TEST_EQ( X::instances, 0 );
{
BOOST_TEST_TRAIT_TRUE((std::is_constructible<result<int&>, int&>));
BOOST_TEST_TRAIT_TRUE((std::is_convertible<int&, result<int&>>));
BOOST_TEST_TRAIT_FALSE((std::is_constructible<result<int&>, int const&>));
BOOST_TEST_TRAIT_FALSE((std::is_convertible<int const&, result<int&>>));
BOOST_TEST_TRAIT_FALSE((std::is_constructible<result<int&>, int>));
BOOST_TEST_TRAIT_FALSE((std::is_convertible<int, result<int&>>));
BOOST_TEST_TRAIT_FALSE((std::is_constructible<result<int&, int>, int&>));
BOOST_TEST_TRAIT_FALSE((std::is_constructible<result<int&, float>, int&>));
BOOST_TEST_TRAIT_FALSE((std::is_constructible<result<X&>, int>));
BOOST_TEST_TRAIT_FALSE((std::is_convertible<int, result<X&>>));
}
return boost::report_errors();
}

View File

@@ -0,0 +1,211 @@
// Copyright 2017, 2021, 2023 Peter Dimov.
// Distributed under the Boost Software License, Version 1.0.
// https://www.boost.org/LICENSE_1_0.txt
#include <boost/system/result.hpp>
#include <boost/core/lightweight_test.hpp>
#include <boost/core/lightweight_test_trait.hpp>
using namespace boost::system;
struct X
{
static int instances;
int v_;
explicit X( int v ): v_( v ) { ++instances; }
X( X const& ) = delete;
X& operator=( X const& ) = delete;
~X() { --instances; }
};
int X::instances = 0;
int main()
{
{
int x = 0;
result<int const&> r( x );
BOOST_TEST( r.has_value() );
BOOST_TEST( !r.has_error() );
BOOST_TEST_EQ( r.value(), 0 );
}
{
int const x = 0;
result<int const&> r( x );
BOOST_TEST( r.has_value() );
BOOST_TEST( !r.has_error() );
BOOST_TEST_EQ( r.value(), 0 );
}
{
int x = 0;
result<int const&> r = x;
BOOST_TEST( r.has_value() );
BOOST_TEST( !r.has_error() );
BOOST_TEST_EQ( r.value(), 0 );
}
{
int const x = 0;
result<int const&> r = x;
BOOST_TEST( r.has_value() );
BOOST_TEST( !r.has_error() );
BOOST_TEST_EQ( r.value(), 0 );
}
{
int x = 1;
result<int const&, int> r( in_place_value, x );
BOOST_TEST( r.has_value() );
BOOST_TEST( !r.has_error() );
BOOST_TEST_EQ( *r, 1 );
}
{
int const x = 1;
result<int const&, int> r( in_place_value, x );
BOOST_TEST( r.has_value() );
BOOST_TEST( !r.has_error() );
BOOST_TEST_EQ( *r, 1 );
}
BOOST_TEST_EQ( X::instances, 0 );
{
X x( 1 );
result<X const&> r( x );
BOOST_TEST( r.has_value() );
BOOST_TEST( !r.has_error() );
BOOST_TEST_EQ( r.value().v_, 1 );
BOOST_TEST_EQ( X::instances, 1 );
}
BOOST_TEST_EQ( X::instances, 0 );
{
X const x( 1 );
result<X const&> r( x );
BOOST_TEST( r.has_value() );
BOOST_TEST( !r.has_error() );
BOOST_TEST_EQ( r.value().v_, 1 );
BOOST_TEST_EQ( X::instances, 1 );
}
BOOST_TEST_EQ( X::instances, 0 );
{
X x( 1 );
result<X const&> r = x;
BOOST_TEST( r.has_value() );
BOOST_TEST( !r.has_error() );
BOOST_TEST_EQ( r.value().v_, 1 );
BOOST_TEST_EQ( X::instances, 1 );
}
BOOST_TEST_EQ( X::instances, 0 );
{
X const x( 1 );
result<X const&> r = x;
BOOST_TEST( r.has_value() );
BOOST_TEST( !r.has_error() );
BOOST_TEST_EQ( r.value().v_, 1 );
BOOST_TEST_EQ( X::instances, 1 );
}
BOOST_TEST_EQ( X::instances, 0 );
{
X x( 1 );
result<X const&, X> r( in_place_value, x );
BOOST_TEST( r.has_value() );
BOOST_TEST( !r.has_error() );
BOOST_TEST_EQ( r->v_, 1 );
BOOST_TEST_EQ( X::instances, 1 );
}
BOOST_TEST_EQ( X::instances, 0 );
{
X const x( 1 );
result<X const&, X> r( in_place_value, x );
BOOST_TEST( r.has_value() );
BOOST_TEST( !r.has_error() );
BOOST_TEST_EQ( r->v_, 1 );
BOOST_TEST_EQ( X::instances, 1 );
}
BOOST_TEST_EQ( X::instances, 0 );
{
BOOST_TEST_TRAIT_TRUE((std::is_constructible<result<int const&>, int&>));
BOOST_TEST_TRAIT_TRUE((std::is_convertible<int&, result<int const&>>));
BOOST_TEST_TRAIT_TRUE((std::is_constructible<result<int const&>, int const&>));
BOOST_TEST_TRAIT_TRUE((std::is_convertible<int const&, result<int const&>>));
BOOST_TEST_TRAIT_FALSE((std::is_constructible<result<int const&>, int>));
BOOST_TEST_TRAIT_FALSE((std::is_convertible<int, result<int const&>>));
BOOST_TEST_TRAIT_FALSE((std::is_constructible<result<double const&>, int&>));
BOOST_TEST_TRAIT_FALSE((std::is_convertible<int&, result<double const&>>));
BOOST_TEST_TRAIT_FALSE((std::is_constructible<result<double const&>, int const&>));
BOOST_TEST_TRAIT_FALSE((std::is_convertible<int const&, result<double const&>>));
BOOST_TEST_TRAIT_FALSE((std::is_constructible<result<double const&>, int>));
BOOST_TEST_TRAIT_FALSE((std::is_convertible<int, result<double const&>>));
BOOST_TEST_TRAIT_FALSE((std::is_constructible<result<int const&, int>, int&>));
BOOST_TEST_TRAIT_FALSE((std::is_constructible<result<int const&, float>, int&>));
BOOST_TEST_TRAIT_FALSE((std::is_constructible<result<int const&, int>, int const&>));
BOOST_TEST_TRAIT_FALSE((std::is_constructible<result<int const&, float>, int const&>));
BOOST_TEST_TRAIT_FALSE((std::is_constructible<result<int const&, int>, int>));
BOOST_TEST_TRAIT_FALSE((std::is_constructible<result<int const&, float>, int>));
BOOST_TEST_TRAIT_FALSE((std::is_constructible<result<X const&>, int>));
BOOST_TEST_TRAIT_FALSE((std::is_convertible<int, result<X const&>>));
BOOST_TEST_TRAIT_FALSE((std::is_constructible<result<X const&>, X const>));
BOOST_TEST_TRAIT_FALSE((std::is_convertible<X const, result<X const&>>));
}
return boost::report_errors();
}

View File

@@ -8,9 +8,6 @@
// See library home page at http://www.boost.org/libs/system
// Avoid spurious VC++ warnings
# define _CRT_SECURE_NO_WARNINGS
#include <boost/system/error_code.hpp>
#include <boost/config.hpp>
#include <boost/config/pragma_message.hpp>
@@ -30,6 +27,7 @@ int main()
#else
#include <boost/core/lightweight_test.hpp>
#include <boost/core/snprintf.hpp>
#include <system_error>
#include <cerrno>
#include <string>
@@ -127,7 +125,7 @@ public:
virtual std::string message( int ev ) const
{
char buffer[ 256 ];
std::sprintf( buffer, "user message %d", ev );
boost::core::snprintf( buffer, sizeof( buffer ), "user message %d", ev );
return buffer;
}
@@ -267,7 +265,7 @@ public:
virtual std::string message( int ev ) const
{
char buffer[ 256 ];
std::sprintf( buffer, "user2 message %d", ev );
boost::core::snprintf( buffer, sizeof( buffer ), "user2 message %d", ev );
return buffer;
}

View File

@@ -0,0 +1,94 @@
// Copyright 2021, 2022 Peter Dimov.
// Distributed under the Boost Software License, Version 1.0.
// http://www.boost.org/LICENSE_1_0.txt
#include <boost/system/error_code.hpp>
#include <boost/system/error_condition.hpp>
#include <boost/core/lightweight_test.hpp>
#include <boost/config/pragma_message.hpp>
#include <boost/config.hpp>
#include <boost/config/workaround.hpp>
#if !defined(BOOST_SYSTEM_HAS_SYSTEM_ERROR)
BOOST_PRAGMA_MESSAGE( "BOOST_SYSTEM_HAS_SYSTEM_ERROR not defined, test will be skipped" )
int main() {}
#elif defined(BOOST_SYSTEM_AVOID_STD_GENERIC_CATEGORY)
BOOST_PRAGMA_MESSAGE( "Skipping test, BOOST_SYSTEM_AVOID_STD_GENERIC_CATEGORY is defined" )
int main() {}
#else
#include <system_error>
namespace sys = boost::system;
enum my_errc
{
enomem_c = ENOMEM
};
enum my_errn
{
enomem_n = ENOMEM
};
namespace std {
template<> struct is_error_code_enum<my_errc>
{
static const bool value = true;
};
template<> struct is_error_condition_enum<my_errn>
{
static const bool value = true;
};
} // namespace std
std::error_code make_error_code( my_errc e )
{
return std::error_code( e, std::generic_category() );
}
std::error_condition make_error_condition( my_errn e )
{
return std::error_condition( e, std::generic_category() );
}
int main()
{
sys::error_code ec = make_error_code( sys::errc::not_enough_memory );
sys::error_condition en( sys::errc::not_enough_memory );
BOOST_TEST_EQ( ec, en );
BOOST_TEST_EQ( en, ec );
BOOST_TEST_EQ( ec, enomem_c );
BOOST_TEST_EQ( enomem_c, ec );
BOOST_TEST_EQ( ec, enomem_n );
BOOST_TEST_EQ( enomem_n, ec );
BOOST_TEST_EQ( en, enomem_c );
BOOST_TEST_EQ( enomem_c, en );
#if BOOST_WORKAROUND(BOOST_MSVC, == 1800)
// msvc-12.0 has op== as a member of std::error_condition
#else
BOOST_TEST_EQ( en, enomem_n );
#endif
BOOST_TEST_EQ( enomem_n, en );
return boost::report_errors();
}
#endif

View File

@@ -0,0 +1,57 @@
// Copyright 2023 Peter Dimov.
// Distributed under the Boost Software License, Version 1.0.
// http://www.boost.org/LICENSE_1_0.txt
#include <boost/system/error_category.hpp>
#include <boost/config/pragma_message.hpp>
#if !defined(BOOST_SYSTEM_HAS_SYSTEM_ERROR)
BOOST_PRAGMA_MESSAGE( "BOOST_SYSTEM_HAS_SYSTEM_ERROR not defined, test will be skipped" )
int main() {}
#else
#include <boost/core/lightweight_test.hpp>
#include <boost/core/snprintf.hpp>
#include <system_error>
// get_user_category
class user_category: public boost::system::error_category
{
public:
virtual const char * name() const BOOST_NOEXCEPT
{
return "user";
}
virtual std::string message( int ev ) const
{
char buffer[ 256 ];
boost::core::snprintf( buffer, sizeof( buffer ), "user message %d", ev );
return buffer;
}
};
boost::system::error_category const & get_user_category()
{
static user_category instance;
return instance;
}
//
bool init_lwt = (boost::core::lwt_init(), true);
std::error_category const & cat = get_user_category();
int main()
{
BOOST_TEST_CSTR_EQ( cat.name(), "user" );
return boost::report_errors();
}
#endif

View File

@@ -8,11 +8,9 @@
// See library home page at http://www.boost.org/libs/system
// Avoid spurious VC++ warnings
# define _CRT_SECURE_NO_WARNINGS
#include <boost/system/error_code.hpp>
#include <boost/core/lightweight_test.hpp>
#include <boost/core/snprintf.hpp>
#include <cstring>
#include <cstdio>
@@ -65,7 +63,7 @@ std::string sys_strerror( int ev )
{
char buffer[ 38 ];
std::sprintf( buffer, "Unknown error (%d)", ev );
boost::core::snprintf( buffer, sizeof( buffer ), "Unknown error (%d)", ev );
return buffer;
}

View File

@@ -0,0 +1,52 @@
// Copyright 2022 Peter Dimov
// Distributed under the Boost Software License, Version 1.0.
// https://www.boost.org/LICENSE_1_0.txt
#include <boost/system.hpp>
#include <boost/config.hpp>
#include <boost/config/pragma_message.hpp>
#if !defined(BOOST_SYSTEM_HAS_SYSTEM_ERROR)
BOOST_PRAGMA_MESSAGE( "Skipping test, BOOST_SYSTEM_HAS_SYSTEM_ERROR is not defined" )
int main() {}
#elif !defined(BOOST_MSSTL_VERSION) || BOOST_MSSTL_VERSION < 140
BOOST_PRAGMA_MESSAGE( "Skipping test, BOOST_MSSTL_VERSION is not defined or is less than 140" )
int main() {}
#else
#include <system_error>
#include <iostream>
int main()
{
namespace sys = boost::system;
int n = 0;
for( int i = 0; i < 65000; ++i )
{
sys::error_code ec1( i, sys::system_category() );
sys::error_condition en1 = ec1.default_error_condition();
std::error_code ec2( i, std::system_category() );
std::error_condition en2 = ec2.default_error_condition();
if( en1 != en2 )
{
std::cout << i << ": " << en1 << " (" << en1.message() << ") != cond:" << en2.category().name() << ":" << en2.value() << " (" << en2.message() << ")\n";
if( en2.category() == std::generic_category() && i != 123 ) // msvc-14.0, msvc-14.1 disagree with us on ERROR_INVALID_NAME
{
++n;
}
}
}
return n < 256 ? n: 255;
}
#endif