Unnamed: 0
int64 0
0
| repo_id
stringlengths 5
186
| file_path
stringlengths 15
223
| content
stringlengths 1
32.8M
⌀ |
---|---|---|---|
0 | repos | repos/outcome/install_dev_githooks.sh | #!/bin/sh
echo Installing post-merge hook which recursively forces all
echo submodules to latest commit after every git pull
cat <<EOT >> .git/hooks/post-merge
#!/bin/sh
git submodule foreach --recursive 'branch=\$(git config -f \$toplevel/.gitmodules submodule.\$name.branch); [ \"\$branch\" = \"\" ] && branch=master; git checkout \$branch; git merge origin/\$branch;'
EOT
chmod +x .git/hooks/post-merge
echo Installing custom 'git pull-all' command for recursively
echo forcing all submodules to latest commit
git config alias.pull-all "submodule foreach --recursive 'branch=\$(git config -f \$toplevel/.gitmodules submodule.\$name.branch); [ \"\$branch\" = \"\" ] && branch=master; git checkout \$branch; git pull;'"
|
0 | repos | repos/outcome/Readme.md | # OUTCOME - zig-pkg support
[](https://github.com/kassane/outcome/actions/workflows/unittests_zig_embedded.yml)
[](https://github.com/kassane/outcome/actions/workflows/unittests_zig.yml)
[](https://github.com/kassane/outcome/actions/workflows/unittests_zig_msvc.yml)
CTest dashboard: https://my.cdash.org/index.php?project=Boost.Outcome
All tests passing source tarballs: https://github.com/ned14/outcome/releases
Documentation: https://ned14.github.io/outcome/
## Purpose of this library
Outcome is a C++14 library for reporting and handling function failures. It can be used as a substitute for, or a complement to, the exception handling mechanism.
One use case is for contexts where using C++ exception handling is unsuitable for different reasons:
* The high relative cost of throwing and catching a C++ exception.
* Making some or all control paths explicitly detailed to aid code correctness auditing, as opposed to having hidden control paths caused by exceptions potentially thrown from any place.
* Company policy to compile with exceptions disabled.
* Maintaining a code base that was never designed with exception-safety in mind.
* Parts of the programs/frameworks that themselves implement exception handling and cannot afford to use exceptions, like propagating failure reports across threads, tasks, fibers…
## Usage as a single header file
Outcome v2 comes in single header file form. This is regenerated per commit. To fetch
on Linux:
```
wget https://github.com/kassane/outcome/raw/develop/single-header/outcome.hpp
```
On BSD:
```
fetch https://github.com/kassane/outcome/raw/develop/single-header/outcome.hpp
```
If you have `curl` installed:
```
curl -O -J -L https://github.com/kassane/outcome/raw/develop/single-header/outcome.hpp
```
Otherwise, simply download the raw file from above and place it wherever it suits you.
If you might be debugging using Microsoft Visual Studio, you may find the debugger
visualisation file at https://github.com/kassane/outcome/raw/develop/include/outcome/outcome.natvis
useful to include into your build.
## Commits and tags in this git repository can be verified using:
<pre>
-----BEGIN PGP PUBLIC KEY BLOCK-----
Version: GnuPG v2
mDMEVvMacRYJKwYBBAHaRw8BAQdAp+Qn6djfxWQYtAEvDmv4feVmGALEQH/pYpBC
llaXNQe0WE5pYWxsIERvdWdsYXMgKHMgW3VuZGVyc2NvcmVdIHNvdXJjZWZvcmdl
IHthdH0gbmVkcHJvZCBbZG90XSBjb20pIDxzcGFtdHJhcEBuZWRwcm9kLmNvbT6I
eQQTFggAIQUCVvMacQIbAwULCQgHAgYVCAkKCwIEFgIDAQIeAQIXgAAKCRCELDV4
Zvkgx4vwAP9gxeQUsp7ARMFGxfbR0xPf6fRbH+miMUg2e7rYNuHtLQD9EUoR32We
V8SjvX4r/deKniWctvCi5JccgfUwXkVzFAk=
=puFk
-----END PGP PUBLIC KEY BLOCK-----
</pre>
</center>
|
0 | repos | repos/outcome/CTestConfig.cmake | ## This file should be placed in the root directory of your project.
## Then modify the CMakeLists.txt file in the root directory of your
## project to incorporate the testing dashboard.
##
## # The following are required to submit to the CDash dashboard:
## ENABLE_TESTING()
## INCLUDE(CTest)
set(CTEST_PROJECT_NAME "Boost.Outcome")
set(CTEST_NIGHTLY_START_TIME "00:00:00 EST")
set(CTEST_DROP_METHOD "https")
set(CTEST_DROP_SITE "my.cdash.org")
set(CTEST_DROP_LOCATION "/submit.php?project=Boost.Outcome")
set(CTEST_DROP_SITE_CDASH TRUE)
|
0 | repos | repos/outcome/CMakeLists.txt | # Outcome cmake
# (C) 2016-2023 Niall Douglas <http://www.nedproductions.biz/>
# File Created: June 2016
#
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License in the accompanying file
# Licence.txt or at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
#
# Distributed under the Boost Software License, Version 1.0.
# (See accompanying file Licence.txt or copy at
# http://www.boost.org/LICENSE_1_0.txt)
cmake_minimum_required(VERSION 3.9 FATAL_ERROR)
set(OUTCOME_DEPENDENCY_QUICKCPPLIB_GIT_TAG "master" CACHE STRING "Which git tag to use for the QuickCppLib dependency")
if(NOT OUTCOME_DEPENDENCY_QUICKCPPLIB_GIT_TAG STREQUAL "master")
# Don't reuse the bootstrapped git clone as the dependency itself
if(CMAKE_BINARY_DIR)
set(CTEST_QUICKCPPLIB_CLONE_DIR "${CMAKE_BINARY_DIR}/quickcpplib-bootstrap")
else()
set(CTEST_QUICKCPPLIB_CLONE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/quickcpplib-bootstrap")
endif()
endif()
set(OUTCOME_DEPENDENCY_STATUS_CODE_GIT_TAG "master" CACHE STRING "Which git tag to use for the status-code dependency")
option(OUTCOME_BUNDLE_EMBEDDED_STATUS_CODE "Whether to bundle an embedded copy of SG14 status-code with Outcome. Used by various package managers such as vcpkg." ON)
include(cmake/QuickCppLibBootstrap.cmake)
include(QuickCppLibRequireOutOfSourceBuild)
include(QuickCppLibUtils)
include(QuickCppLibPolicies)
# Parse the version we tell cmake directly from the version header file
ParseProjectVersionFromHpp("${CMAKE_CURRENT_SOURCE_DIR}/include/outcome/detail/version.hpp" VERSIONSTRING)
# Sets the usual PROJECT_NAME etc
project(outcome VERSION ${VERSIONSTRING} LANGUAGES C CXX)
# Also set a *cmake* namespace for this project
set(PROJECT_NAMESPACE)
# Setup this cmake environment for this project
include(QuickCppLibSetupProject)
option(OUTCOME_BUNDLE_EMBEDDED_QUICKCPPLIB "Whether to bundle an embedded copy of QuickCppLib with Outcome. Used by various package managers such as vcpkg." OFF)
option(OUTCOME_ENABLE_DEPENDENCY_SMOKE_TEST "Whether to build executables which are smoke tests that Outcome is fully working. Used by various package managers such as vcpkg." OFF)
option(OUTCOME_ENABLE_CXX_MODULES "Whether to enable the building of an Outcome C++ module" OFF)
set(UNIT_TESTS_CXX_VERSION "latest" CACHE STRING "The version of C++ to use in the unit tests")
if(NOT outcome_IS_DEPENDENCY)
# This file should be updated with the last git SHA next commit
UpdateRevisionHppFromGit("${CMAKE_CURRENT_SOURCE_DIR}/include/outcome/detail/revision.hpp")
# Need to also possibly update the .natvis file
# file(STRINGS "${CMAKE_CURRENT_SOURCE_DIR}/include/outcome/detail/revision.hpp" namespace_permuter REGEX "OUTCOME_PREVIOUS_COMMIT_UNIQUE (.+)")
# if(NOT namespace_permuter MATCHES "OUTCOME_PREVIOUS_COMMIT_UNIQUE (.+)")
# indented_message(FATAL_ERROR "FATAL: ${CMAKE_CURRENT_SOURCE_DIR}/include/outcome/detail/revision.hpp was not parseable")
# endif()
# set(namespace_permuter "${CMAKE_MATCH_1}")
# file(READ "${CMAKE_CURRENT_SOURCE_DIR}/include/outcome/outcome.natvis" natvis_contents)
# string(REGEX REPLACE "outcome_v2_([0-9a-f]+)" "outcome_v2_${namespace_permuter}" new_natvis_contents "${natvis_contents}")
# if(NOT natvis_contents STREQUAL new_natvis_contents)
# file(WRITE "${CMAKE_CURRENT_SOURCE_DIR}/include/outcome/outcome.natvis" "${new_natvis_contents}")
# endif()
endif()
# Find my library dependencies
if(OUTCOME_BUNDLE_EMBEDDED_QUICKCPPLIB AND CTEST_QUICKCPPLIB_CLONE_DIR)
file(COPY "${CTEST_QUICKCPPLIB_CLONE_DIR}/repo/" DESTINATION "${CMAKE_BINARY_DIR}/quickcpplib")
find_quickcpplib_library(quickcpplib
GIT_REPOSITORY "https://github.com/ned14/quickcpplib.git"
REQUIRED
IS_HEADER_ONLY
INBUILD
INCLUDE_ALL
)
else()
find_quickcpplib_library(quickcpplib
GIT_REPOSITORY "https://github.com/ned14/quickcpplib.git"
GIT_TAG "${OUTCOME_DEPENDENCY_QUICKCPPLIB_GIT_TAG}"
REQUIRED
IS_HEADER_ONLY
)
endif()
if(OUTCOME_BUNDLE_EMBEDDED_STATUS_CODE)
ensure_git_subrepo("${CMAKE_CURRENT_SOURCE_DIR}/include/outcome/experimental/status-code/include" "https://github.com/ned14/status-code.git")
else()
find_quickcpplib_library(status-code
GIT_REPOSITORY "https://github.com/ned14/status-code.git"
GIT_TAG "${OUTCOME_DEPENDENCY_STATUS_CODE_GIT_TAG}"
REQUIRED
IS_HEADER_ONLY
)
list_filter(${PROJECT_NAME}_HEADERS EXCLUDE REGEX include/outcome/experimental/status-code/)
endif()
# Make an interface only library so dependent CMakeLists can bring in this header-only library
include(QuickCppLibMakeHeaderOnlyLibrary)
# If we have standard concepts, enable those for both myself and all inclusions
apply_cxx_concepts_to(INTERFACE outcome_hl REQUIRE_STD_CONCEPTS)
# Make preprocessed edition of this library target
if(NOT outcome_IS_DEPENDENCY OR OUTCOME_FORCE_ENABLE_PP_TARGETS)
if(NOT PYTHONINTERP_FOUND)
indented_message(WARNING "NOT rebuilding preprocessed edition of library due to python not being installed")
else()
function(make_single_header target name)
add_partial_preprocess(${target}
"${name}"
"${CMAKE_CURRENT_SOURCE_DIR}/include/outcome/detail/revision.hpp"
${ARGN}
-I ../quickcpplib/include
--passthru-defines --passthru-unfound-includes --passthru-unknown-exprs
--passthru-comments --line-directive --compress # --debug
-U __cpp_modules
-U QUICKCPPLIB_ENABLE_VALGRIND
-U DOXYGEN_SHOULD_SKIP_THIS -U DOXYGEN_IS_IN_THE_HOUSE
-U STANDARDESE_IS_IN_THE_HOUSE
-U OUTCOME_UNSTABLE_VERSION -U OUTCOME_ENABLE_ABI_PERMUTATION
-D QUICKCPPLIB_DISABLE_ABI_PERMUTATION=1
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
)
if(NOT CMAKE_VERSION VERSION_LESS 3.3)
add_dependencies(outcome_hl ${target})
endif()
endfunction()
make_single_header(outcome_hl-pp-std
"${CMAKE_CURRENT_SOURCE_DIR}/single-header/outcome.hpp"
"${CMAKE_CURRENT_SOURCE_DIR}/include/outcome.hpp")
make_single_header(outcome_hl-pp-basic
"${CMAKE_CURRENT_SOURCE_DIR}/single-header/outcome-basic.hpp"
"${CMAKE_CURRENT_SOURCE_DIR}/include/outcome/basic_outcome.hpp"
"${CMAKE_CURRENT_SOURCE_DIR}/include/outcome/try.hpp")
make_single_header(outcome_hl-pp-experimental
"${CMAKE_CURRENT_SOURCE_DIR}/single-header/outcome-experimental.hpp"
"${CMAKE_CURRENT_SOURCE_DIR}/include/outcome/experimental/status_outcome.hpp"
"${CMAKE_CURRENT_SOURCE_DIR}/include/outcome/experimental/status-code/include/status-code/nested_status_code.hpp"
"${CMAKE_CURRENT_SOURCE_DIR}/include/outcome/try.hpp")
endif()
endif()
# Set the standard definitions for these libraries and bring in the all_* helper functions
include(QuickCppLibApplyDefaultDefinitions)
# Set the C++ features this library requires
all_compile_features(PUBLIC
cxx_alias_templates
cxx_variadic_templates
cxx_noexcept
cxx_constexpr
cxx_lambda_init_captures
cxx_attributes
cxx_generic_lambdas
)
if(NOT MSVC OR CMAKE_VERSION VERSION_GREATER 3.59)
all_compile_features(PUBLIC
cxx_variable_templates
)
endif()
# Set the library dependencies this library has
if(TARGET quickcpplib::hl)
target_link_libraries(outcome_hl INTERFACE quickcpplib::hl)
endif()
if(TARGET status-code::hl)
target_link_libraries(outcome_hl INTERFACE status-code::hl)
all_compile_definitions(PUBLIC OUTCOME_USE_SYSTEM_STATUS_CODE=1)
endif()
if(OUTCOME_ENABLE_CXX_MODULES)
# Right now this is very hacky, as cmake doesn't support building C++ Modules yet
add_custom_target(outcome_module
COMMAND "${CMAKE_CXX_COMPILER}" /std:c++latest /EHsc $<$<CONFIG:Debug>:/MDd> $<$<NOT:$<CONFIG:Debug>>:/MD> /fp:precise /c "${CMAKE_CURRENT_SOURCE_DIR}/include/outcome.ixx" "-I${CMAKE_CURRENT_SOURCE_DIR}/../quickcpplib/include" "-I${CMAKE_BINARY_DIR}/quickcpplib/include"
)
all_compile_definitions(PUBLIC
OUTCOME_ENABLE_CXX_MODULES=1
)
endif()
if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/test" AND NOT outcome_IS_DEPENDENCY AND (NOT DEFINED BUILD_TESTING OR BUILD_TESTING))
# For all possible configurations of this library, add each test
list_filter(outcome_TESTS EXCLUDE REGEX "constexprs")
set(outcome_TESTS_DISABLE_PRECOMPILE_HEADERS
"outcome_hl--coroutine-support"
"outcome_hl--core-result"
"outcome_hl--fileopen"
"outcome_hl--hooks"
"outcome_hl--outcome-int-int-1"
"outcome_hl--result-int-int-1"
"outcome_hl--result-int-int-2"
)
include(QuickCppLibMakeStandardTests)
# Enable Coroutines for the coroutines support test
foreach(target ${outcome_TEST_TARGETS})
if(${target} MATCHES "coroutine-support")
apply_cxx_coroutines_to(PRIVATE ${target})
endif()
# MSVC's concepts implementation blow up unless permissive is off
if(MSVC AND NOT CLANG)
target_compile_options(${target} PRIVATE /permissive-)
endif()
endforeach()
# Duplicate all tests into C++ exceptions disabled forms
set(noexcept_tests)
set(first_test_target_noexcept)
set(first_test_target_permissive)
foreach(testsource ${outcome_TESTS})
if(testsource MATCHES ".+/(.+)[.](c|cpp|cxx)$")
set(testname ${CMAKE_MATCH_1})
if(NOT testname MATCHES "expected-pass")
set(target_name "outcome_hl--${testname}-noexcept")
add_executable(${target_name} "${testsource}")
if(NOT first_test_target_noexcept)
set(first_test_target_noexcept ${target_name})
elseif(${target_name} MATCHES "coroutine-support|fileopen|hooks|core-result")
set_target_properties(${target_name} PROPERTIES DISABLE_PRECOMPILE_HEADERS On)
elseif(COMMAND target_precompile_headers)
target_precompile_headers(${target_name} REUSE_FROM ${first_test_target_noexcept})
endif()
add_dependencies(_hl ${target_name})
list(APPEND noexcept_tests ${target_name})
if(MSVC AND NOT CLANG)
# Disable warnings "C++ exception handler used" and "noexcept used with no exception handling"
target_compile_options(${target_name} PRIVATE /wd4530 /wd4577)
# target_compile_options(${target_name} PRIVATE /permissive-) # test bug report #142
endif()
target_compile_definitions(${target_name} PRIVATE SYSTEM_ERROR2_NOT_POSIX=1 "SYSTEM_ERROR2_FATAL=::abort()")
target_link_libraries(${target_name} PRIVATE outcome::hl)
if(${target_name} MATCHES "coroutine-support")
apply_cxx_coroutines_to(PRIVATE ${target_name})
endif()
set_target_properties(${target_name} PROPERTIES
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin"
POSITION_INDEPENDENT_CODE ON
CXX_EXCEPTIONS OFF
CXX_RTTI OFF
)
add_test(NAME ${target_name} CONFIGURATIONS Debug Release RelWithDebInfo MinSizeRel
COMMAND $<TARGET_FILE:${target_name}> --reporter junit --out $<TARGET_FILE:${target_name}>.junit.xml
)
if(MSVC AND NOT CLANG)
set(target_name "outcome_hl--${testname}-permissive")
add_executable(${target_name} "${testsource}")
if(NOT first_test_target_permissive)
set(first_test_target_permissive ${target_name})
elseif(${target_name} MATCHES "coroutine-support|fileopen|core-result")
set_target_properties(${target_name} PROPERTIES DISABLE_PRECOMPILE_HEADERS On)
elseif(COMMAND target_precompile_headers)
target_precompile_headers(${target_name} REUSE_FROM ${first_test_target_permissive})
endif()
add_dependencies(_hl ${target_name})
target_link_libraries(${target_name} PRIVATE outcome::hl)
target_compile_options(${target_name} PRIVATE /permissive)
if(${target_name} MATCHES "coroutine-support")
apply_cxx_coroutines_to(PRIVATE ${target_name})
endif()
set_target_properties(${target_name} PROPERTIES
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin"
POSITION_INDEPENDENT_CODE ON
)
if(OUTCOME_ENABLE_CXX_MODULES)
set(target_name "outcome_hl--${testname}-modules")
add_executable(${target_name} "${testsource}")
add_dependencies(${target_name} outcome_module)
target_link_libraries(${target_name} PRIVATE outcome::hl)
target_compile_options(${target_name} PRIVATE /experimental:module /std:c++latest)
target_compile_definitions(${target_name} PRIVATE __cpp_modules=202001L)
set_target_properties(${target_name} PROPERTIES
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin"
POSITION_INDEPENDENT_CODE ON
DISABLE_PRECOMPILE_HEADERS On
)
endif()
endif()
endif()
endif()
endforeach()
add_custom_target(${PROJECT_NAME}-noexcept COMMENT "Building all tests with C++ exceptions disabled ...")
add_dependencies(${PROJECT_NAME}-noexcept ${noexcept_tests})
# Turn on latest C++ where possible for the test suite
if(UNIT_TESTS_CXX_VERSION STREQUAL "latest")
set(LATEST_CXX_FEATURE)
foreach(feature ${CMAKE_CXX_COMPILE_FEATURES})
if(feature STREQUAL "cxx_std_23")
set(LATEST_CXX_FEATURE "cxx_std_23")
indented_message(STATUS "NOTE: This compiler claims to support C++ 23, enabling for unit test suite")
endif()
endforeach()
if(NOT LATEST_CXX_FEATURE)
foreach(feature ${CMAKE_CXX_COMPILE_FEATURES})
if(feature STREQUAL "cxx_std_20")
set(LATEST_CXX_FEATURE "cxx_std_20")
indented_message(STATUS "NOTE: This compiler claims to support C++ 20, enabling for unit test suite")
endif()
endforeach()
endif()
if(NOT LATEST_CXX_FEATURE)
foreach(feature ${CMAKE_CXX_COMPILE_FEATURES})
if(feature STREQUAL "cxx_std_17")
set(LATEST_CXX_FEATURE "cxx_std_17")
indented_message(STATUS "NOTE: This compiler claims to support C++ 17, enabling for unit test suite")
endif()
endforeach()
endif()
elseif(UNIT_TESTS_CXX_VERSION)
set(LATEST_CXX_FEATURE "cxx_std_${UNIT_TESTS_CXX_VERSION}")
endif()
if(LATEST_CXX_FEATURE)
# Turn on latest C++ where possible for the test suite
if(ENABLE_CXX_MODULES)
target_compile_features(outcome_hl_ixx PUBLIC ${LATEST_CXX_FEATURE})
endif()
foreach(test_target ${outcome_TEST_TARGETS} ${outcome_EXAMPLE_TARGETS})
target_compile_features(${test_target} PUBLIC ${LATEST_CXX_FEATURE})
endforeach()
endif()
# Add in the documentation snippets
foreach(feature ${CMAKE_CXX_COMPILE_FEATURES})
if(feature STREQUAL cxx_std_17)
file(GLOB example_srcs RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}"
"${CMAKE_CURRENT_SOURCE_DIR}/doc/src/snippets/*.c"
"${CMAKE_CURRENT_SOURCE_DIR}/doc/src/snippets/*.cpp"
)
set(example_bins)
foreach(example_src ${example_srcs})
if(example_src MATCHES ".+/(.+)[.](c|cpp|cxx)$")
set(example_bin "${PROJECT_NAME}-snippets_${CMAKE_MATCH_1}")
add_executable(${example_bin} EXCLUDE_FROM_ALL "${example_src}")
list(APPEND example_bins ${example_bin})
target_link_libraries(${example_bin} PRIVATE outcome::hl)
set_target_properties(${example_bin} PROPERTIES
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin"
POSITION_INDEPENDENT_CODE ON
)
if(example_src MATCHES "[.]c$")
set_target_properties(${example_bin} PROPERTIES DISABLE_PRECOMPILE_HEADERS On)
else()
target_compile_features(${example_bin} PUBLIC cxx_std_17)
if(CMAKE_SYSTEM_NAME MATCHES "Linux")
target_link_libraries(${example_bin} PRIVATE stdc++fs)
elseif(CMAKE_SYSTEM_NAME MATCHES "FreeBSD" OR APPLE)
target_link_libraries(${example_bin} PRIVATE c++experimental)
endif()
endif()
endif()
endforeach()
add_custom_target(${PROJECT_NAME}-snippets COMMENT "Building all documentation snippets ...")
add_dependencies(${PROJECT_NAME}-snippets ${example_bins})
endif()
endforeach()
endif()
# Turn on pedantic warnings for all tests, examples and snippets
if(NOT MSVC)
foreach(target ${outcome_TEST_TARGETS} ${outcome_EXAMPLE_TARGETS} ${example_bins})
target_compile_options(${target} PUBLIC "-Wpedantic")
endforeach()
endif()
if(OUTCOME_ENABLE_DEPENDENCY_SMOKE_TEST)
set(OUTCOME_SMOKE_TESTS)
add_executable(outcome-dependency-smoke-test_1 "test/tests/core-result.cpp")
list(APPEND OUTCOME_SMOKE_TESTS outcome-dependency-smoke-test_1)
add_executable(outcome-dependency-smoke-test_2 "test/tests/experimental-core-result-status.cpp")
list(APPEND OUTCOME_SMOKE_TESTS outcome-dependency-smoke-test_2)
foreach(target ${OUTCOME_SMOKE_TESTS})
target_link_libraries(${target} PRIVATE outcome::hl)
set_target_properties(${target} PROPERTIES
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin"
DISABLE_PRECOMPILE_HEADERS On
)
add_test(NAME ${target} CONFIGURATIONS Debug Release RelWithDebInfo MinSizeRel
COMMAND $<TARGET_FILE:${target}> --reporter junit --out $<TARGET_FILE:${target}>.junit.xml
)
endforeach()
endif()
# Cache this library's auto scanned sources for later reuse
include(QuickCppLibCacheLibrarySources)
# Dependencies needed to consume our cmake package
set(PROJECT_PACKAGE_DEPENDENCIES "include(CMakeFindDependencyMacro)")
if(TARGET quickcpplib::hl)
string(APPEND PROJECT_PACKAGE_DEPENDENCIES "\nfind_dependency(quickcpplib)")
endif()
if(TARGET status-code::hl)
string(APPEND PROJECT_PACKAGE_DEPENDENCIES "\nfind_dependency(status-code)")
endif()
# Make available this library for install and export
include(QuickCppLibMakeInstall)
include(QuickCppLibMakeExport)
|
0 | repos | repos/outcome/.docs.cmake | # CTest script for a CI to submit to CDash a documentation generation run
cmake_minimum_required(VERSION 3.1 FATAL_ERROR)
include(cmake/QuickCppLibBootstrap.cmake)
include(QuickCppLibUtils)
CONFIGURE_CTEST_SCRIPT_FOR_CDASH("outcome" "cmake_ci")
ctest_empty_binary_directory(${CTEST_BINARY_DIRECTORY})
include(FindGit)
set(CTEST_GIT_COMMAND "${GIT_EXECUTABLE}")
find_program(HUGO_EXECUTABLE "hugo")
#checked_execute_process("git reset"
# COMMAND "${GIT_EXECUTABLE}" checkout gh-pages
# COMMAND "${GIT_EXECUTABLE}" reset --hard ae7119571a3c81cb9a683a21f2759df1d742e998
# WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/doc/html"
#)
ctest_start("Documentation")
ctest_update()
checked_execute_process("git reset"
COMMAND "${GIT_EXECUTABLE}" checkout gh-pages
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/doc/html"
)
ctest_configure()
ctest_build(TARGET outcome-snippets)
#checked_execute_process("git commit"
# COMMAND "${GIT_EXECUTABLE}" commit -a -m "upd"
# COMMAND "${GIT_EXECUTABLE}" push -f origin gh-pages
# WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/doc/html"
#)
checked_execute_process("rebuild docs"
COMMAND "${HUGO_EXECUTABLE}"
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/doc/src"
)
ctest_submit()
|
0 | repos | repos/outcome/build.zig.zon | .{
.name = "outcome",
.version = "2.2.4",
.paths = .{""},
}
|
0 | repos | repos/outcome/build.zig | const std = @import("std");
// Although this function looks imperative, note that its job is to
// declaratively construct a build graph that will be executed by an external
// runner.
pub fn build(b: *std.Build) void {
// Standard target options allows the person running `zig build` to choose
// what target to build for. Here we do not override the defaults, which
// means any target is allowed, and the default is native. Other options
// for restricting supported target set are available.
const target = b.standardTargetOptions(.{});
// Standard optimization options allow the person running `zig build` to select
// between Debug, ReleaseSafe, ReleaseFast, and ReleaseSmall. Here we do not
// set a preferred release mode, allowing the user to decide how to optimize.
const optimize = b.standardOptimizeOption(.{});
// Options
// const shared = b.option(bool, "Shared", "Build the Shared Library [default: false]") orelse false;
const tests = b.option(bool, "tests", "Build tests [default: false]") orelse false;
const lib = b.addStaticLibrary(.{
.name = "outcome",
.target = target,
.optimize = optimize,
});
lib.addIncludePath(b.path("include"));
const empty_cpp = b.addWriteFile("empty.cpp", "// bypass for zig build");
lib.addCSourceFiles(.{
.root = empty_cpp.getDirectory(),
.files = &.{"empty.cpp"},
});
lib.installHeadersDirectory(b.path("single-header"), "", .{
.exclude_extensions = &.{ "md", "experimental.hpp" },
});
b.installArtifact(lib);
if (tests) {
buildTest(b, .{
.lib = lib,
.path = "test/single-header-test.cpp",
});
buildTest(b, .{
.lib = lib,
.path = "test/constexprs/WG21_P1886a.cpp",
});
if (!lib.rootModuleTarget().isDarwin() and lib.rootModuleTarget().abi != .msvc)
buildTest(b, .{
.lib = lib,
.path = "test/constexprs/max_result_get_value.cpp",
});
buildTest(b, .{
.lib = lib,
.path = "test/constexprs/min_result_get_value.cpp",
});
if (!lib.rootModuleTarget().isDarwin() and lib.rootModuleTarget().abi != .msvc)
buildTest(b, .{
.lib = lib,
.path = "test/constexprs/max_result_construct_value_move_destruct.cpp",
});
buildTest(b, .{
.lib = lib,
.path = "test/constexprs/min_result_construct_value_move_destruct.cpp",
});
buildTest(b, .{
.lib = lib,
.path = "test/tests/coroutine-support.cpp",
});
buildTest(b, .{
.lib = lib,
.path = "test/tests/comparison.cpp",
});
buildTest(b, .{
.lib = lib,
.path = "test/tests/constexpr.cpp",
});
if (!lib.rootModuleTarget().isDarwin()) buildTest(b, .{
.lib = lib,
.path = "test/tests/core-outcome.cpp",
});
buildTest(b, .{
.lib = lib,
.path = "test/tests/core-result.cpp",
});
buildTest(b, .{
.lib = lib,
.path = "test/tests/containers.cpp",
});
buildTest(b, .{
.lib = lib,
.path = "test/tests/hooks.cpp",
});
buildTest(b, .{
.lib = lib,
.path = "test/tests/fileopen.cpp",
});
buildTest(b, .{
.lib = lib,
.path = "test/tests/default-construction.cpp",
});
buildTest(b, .{
.lib = lib,
.path = "test/tests/propagate.cpp",
});
buildTest(b, .{
.lib = lib,
.path = "test/tests/serialisation.cpp",
});
buildTest(b, .{
.lib = lib,
.path = "test/tests/noexcept-propagation.cpp",
});
buildTest(b, .{
.lib = lib,
.path = "test/tests/swap.cpp",
});
buildTest(b, .{
.lib = lib,
.path = "test/tests/udts.cpp",
});
buildTest(b, .{
.lib = lib,
.path = "test/tests/success-failure.cpp",
});
buildTest(b, .{
.lib = lib,
.path = "test/tests/value-or-error.cpp",
});
buildTest(b, .{
.lib = lib,
.path = "test/expected-pass.cpp",
});
buildTest(b, .{
.lib = lib,
.path = "test/tests/issue0007.cpp",
});
buildTest(b, .{
.lib = lib,
.path = "test/tests/issue0009.cpp",
});
buildTest(b, .{
.lib = lib,
.path = "test/tests/issue0010.cpp",
});
buildTest(b, .{
.lib = lib,
.path = "test/tests/issue0012.cpp",
});
buildTest(b, .{
.lib = lib,
.path = "test/tests/issue0016.cpp",
});
buildTest(b, .{
.lib = lib,
.path = "test/tests/issue0059.cpp",
});
buildTest(b, .{
.lib = lib,
.path = "test/tests/issue0061.cpp",
});
buildTest(b, .{
.lib = lib,
.path = "test/tests/issue0064.cpp",
});
buildTest(b, .{
.lib = lib,
.path = "test/tests/issue0065.cpp",
});
buildTest(b, .{
.lib = lib,
.path = "test/tests/issue0071.cpp",
});
buildTest(b, .{
.lib = lib,
.path = "test/tests/issue0095.cpp",
});
buildTest(b, .{
.lib = lib,
.path = "test/tests/issue0115.cpp",
});
buildTest(b, .{
.lib = lib,
.path = "test/tests/issue0116.cpp",
});
buildTest(b, .{
.lib = lib,
.path = "test/tests/issue0140.cpp",
});
buildTest(b, .{
.lib = lib,
.path = "test/tests/issue0182.cpp",
});
buildTest(b, .{
.lib = lib,
.path = "test/tests/issue0203.cpp",
});
buildTest(b, .{
.lib = lib,
.path = "test/tests/issue0210.cpp",
});
buildTest(b, .{
.lib = lib,
.path = "test/tests/issue0244.cpp",
});
buildTest(b, .{
.lib = lib,
.path = "test/tests/issue0247.cpp",
});
if (!lib.rootModuleTarget().isMusl() and lib.rootModuleTarget().abi != .msvc) {
buildTest(b, .{
.lib = lib,
.path = "include/outcome/experimental/status-code/test/issue0050.cpp",
});
buildTest(b, .{
.lib = lib,
.path = "test/tests/issue0220.cpp",
});
buildTest(b, .{
.lib = lib,
.path = "test/tests/issue0255.cpp",
});
buildTest(b, .{
.lib = lib,
.path = "include/outcome/experimental/status-code/test/result.cpp",
});
buildTest(b, .{
.lib = lib,
.path = "include/outcome/experimental/status-code/test/p0709a.cpp",
});
buildTest(b, .{
.lib = lib,
.path = "include/outcome/experimental/status-code/wg21/file_io_error.cpp",
});
buildTest(b, .{
.lib = lib,
.path = "test/tests/experimental-p0709a.cpp",
});
if (!lib.rootModuleTarget().isDarwin()) buildTest(b, .{
.lib = lib,
.path = "test/tests/experimental-core-outcome-status.cpp",
});
buildTest(b, .{
.lib = lib,
.path = "test/tests/experimental-core-result-status.cpp",
});
}
if (lib.rootModuleTarget().abi != .msvc)
buildTest(b, .{
.lib = lib,
.path = "test/tests/issue0259.cpp",
});
}
}
fn buildTest(b: *std.Build, info: BuildInfo) void {
const test_exe = b.addExecutable(.{
.name = info.filename(),
.optimize = info.lib.root_module.optimize.?,
.target = info.lib.root_module.resolved_target.?,
});
test_exe.addIncludePath(b.path("include/outcome/experimental/status-code/include"));
test_exe.addIncludePath(b.path("test/quickcpplib/include"));
test_exe.addIncludePath(b.path("test/quickcpplib/include/quickcpplib"));
test_exe.addCSourceFile(.{
.file = b.path(info.path),
.flags = &.{
"-Wall",
"-Wextra",
},
});
if (test_exe.rootModuleTarget().os.tag == .windows)
test_exe.subsystem = .Console;
if (test_exe.rootModuleTarget().abi == .msvc) {
xWin(b, test_exe);
test_exe.linkLibC();
} else test_exe.linkLibCpp();
b.installArtifact(test_exe);
const run_cmd = b.addRunArtifact(test_exe);
run_cmd.step.dependOn(b.getInstallStep());
if (b.args) |args| {
run_cmd.addArgs(args);
}
const run_step = b.step(
b.fmt("{s}", .{info.filename()}),
b.fmt("Run the {s} test", .{info.filename()}),
);
run_step.dependOn(&run_cmd.step);
}
const BuildInfo = struct {
lib: *std.Build.Step.Compile,
path: []const u8,
fn filename(self: BuildInfo) []const u8 {
var split = std.mem.splitSequence(u8, std.fs.path.basename(self.path), ".");
return split.first();
}
};
fn xWin(b: *std.Build, exe: *std.Build.Step.Compile) void {
const arch: []const u8 = switch (exe.rootModuleTarget().cpu.arch) {
.x86_64 => "x64",
.x86 => "x86",
.arm, .armeb => "arm",
.aarch64 => "arm64",
else => @panic("Unsupported Architecture"),
};
exe.setLibCFile(b.path(sdkPath("/libc.txt")));
exe.addSystemIncludePath(b.path(sdkPath("/.xwin/crt/include")));
exe.addSystemIncludePath(b.path(sdkPath("/.xwin/sdk/include")));
exe.addSystemIncludePath(b.path(sdkPath("/.xwin/sdk/include/10.0.22000/cppwinrt")));
exe.addSystemIncludePath(b.path(sdkPath("/.xwin/sdk/include/10.0.22000/ucrt")));
exe.addSystemIncludePath(b.path(sdkPath("/.xwin/sdk/include/10.0.22000/um")));
exe.addSystemIncludePath(b.path(sdkPath("/.xwin/sdk/include/10.0.22000/shared")));
exe.addLibraryPath(b.path(b.fmt(sdkPath("/.xwin/crt/lib/{s}"), .{arch})));
exe.addLibraryPath(b.path(b.fmt(sdkPath("/.xwin/sdk/lib/ucrt/{s}"), .{arch})));
exe.addLibraryPath(b.path(b.fmt(sdkPath("/.xwin/sdk/lib/um/{s}"), .{arch})));
}
fn sdkPath(comptime suffix: []const u8) []const u8 {
if (suffix[0] != '/') @compileError("relToPath requires an absolute path!");
return comptime blk: {
@setEvalBranchQuota(2000);
const root_dir = std.fs.path.dirname(@src().file) orelse ".";
break :blk root_dir ++ suffix;
};
}
|
0 | repos | repos/outcome/index.html | <html>
<head><meta http-equiv="refresh" content="0; url=doc/html/index.html" /></head>
<body>Please go to <a href="doc/index.html">doc/html/index.html</a></body>
</html>
|
0 | repos | repos/outcome/Licence.txt | This software is licensed under your choice of the following two licences:
--------------------------------- EITHER ---------------------------------
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files.
"Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions:
You must give any other recipients of the Work or Derivative Works a copy of this License; and
You must cause any modified files to carry prominent notices stating that You changed the files; and
You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and
If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License.
You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
----------------------------------- OR -----------------------------------
Boost Software License - Version 1.0 - August 17th, 2003
Permission is hereby granted, free of charge, to any person or organization
obtaining a copy of the software and accompanying documentation covered by
this license (the "Software") to use, reproduce, display, distribute,
execute, and transmit the Software, and to prepare derivative works of the
Software, and to permit third-parties to whom the Software is furnished to
do so, all subject to the following:
The copyright notices in the Software and this entire statement, including
the above license grant, this restriction and the following disclaimer,
must be included in all copies of the Software, in whole or in part, and
all derivative works of the Software, unless such copies or derivative
works are solely in the form of machine-executable object code generated by
a source language processor.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
|
0 | repos | repos/outcome/.ci.cmake | # CTest script for a CI to submit to CDash a run of configuration,
# building and testing
cmake_minimum_required(VERSION 3.1 FATAL_ERROR)
include(cmake/QuickCppLibBootstrap.cmake)
include(QuickCppLibUtils)
CONFIGURE_CTEST_SCRIPT_FOR_CDASH("outcome" "prebuilt")
list(APPEND CTEST_CONFIGURE_OPTIONS -DCMAKE_BUILD_TYPE=${CTEST_CONFIGURATION_TYPE})
ctest_empty_binary_directory(${CTEST_BINARY_DIRECTORY})
include(FindGit)
set(CTEST_GIT_COMMAND "${GIT_EXECUTABLE}")
ctest_start("Experimental")
ctest_update()
ctest_configure(OPTIONS "${CTEST_CONFIGURE_OPTIONS}")
ctest_build(TARGET _hl)
if(NOT WIN32 AND NOT APPLE)
ctest_build(TARGET outcome-snippets)
endif()
ctest_test(RETURN_VALUE retval)
set(retval2 0)
set(retval3 0)
if(("$ENV{CXX}" MATCHES "clang"))
ctest_build(TARGET _hl-asan)
set(CTEST_CONFIGURATION_TYPE "asan")
ctest_test(RETURN_VALUE retval2)
ctest_build(TARGET _hl-ubsan)
set(CTEST_CONFIGURATION_TYPE "ubsan")
ctest_test(RETURN_VALUE retval3)
endif()
merge_junit_results_into_ctest_xml()
#ctest_upload(FILES )
ctest_submit()
if(NOT retval EQUAL 0 OR NOT retval2 EQUAL 0 OR NOT retval3 EQUAL 0)
message(FATAL_ERROR "FATAL: Running tests exited with ${retval} ${retval2} ${retval3}")
endif()
|
0 | repos/outcome | repos/outcome/include/outcome.hpp | /* Include the default amount of outcome
(C) 2018-2021 Niall Douglas <http://www.nedproductions.biz/> (4 commits)
File Created: Mar 2018
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License in the accompanying file
Licence.txt or at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Distributed under the Boost Software License, Version 1.0.
(See accompanying file Licence.txt or copy at
http://www.boost.org/LICENSE_1_0.txt)
*/
#if !OUTCOME_ENABLE_CXX_MODULES || !defined(__cpp_modules) || defined(GENERATING_OUTCOME_MODULE_INTERFACE) || OUTCOME_DISABLE_CXX_MODULES
#include "outcome/coroutine_support.hpp"
#include "outcome/iostream_support.hpp"
#include "outcome/try.hpp"
#else
#include "outcome/try.hpp"
import OUTCOME_V2_CXX_MODULE_NAME;
#endif
|
0 | repos/outcome/include | repos/outcome/include/outcome/iostream_support.hpp | /* iostream specialisations for result and outcome
(C) 2017-2019 Niall Douglas <http://www.nedproductions.biz/> (21 commits)
File Created: July 2017
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License in the accompanying file
Licence.txt or at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Distributed under the Boost Software License, Version 1.0.
(See accompanying file Licence.txt or copy at
http://www.boost.org/LICENSE_1_0.txt)
*/
#ifndef OUTCOME_IOSTREAM_SUPPORT_HPP
#define OUTCOME_IOSTREAM_SUPPORT_HPP
#include "outcome.hpp"
#include <iostream>
#include <sstream>
OUTCOME_V2_NAMESPACE_BEGIN
namespace detail
{
template <class T> typename std::add_lvalue_reference<T>::type lvalueref() noexcept;
template <template <class, class> class ValueStorage, class T, class E> inline std::ostream &value_storage_out(std::ostream &s, const ValueStorage<T, E> &v)
{
s << static_cast<uint16_t>(v._status.status_value) << " " << v._status.spare_storage_value << " ";
if(v._status.have_value())
{
s << v._value; // NOLINT
}
if(v._status.have_error())
{
s << v._error; // NOLINT
}
return s;
}
template <template <class, class> class ValueStorage, class E> inline std::ostream &value_storage_out(std::ostream &s, const ValueStorage<void, E> &v)
{
s << static_cast<uint16_t>(v._status.status_value) << " " << v._status.spare_storage_value << " ";
if(v._status.have_error())
{
s << v._error; // NOLINT
}
return s;
}
template <template <class, class> class ValueStorage, class T> inline std::ostream &value_storage_out(std::ostream &s, const ValueStorage<T, void> &v)
{
s << static_cast<uint16_t>(v._status.status_value) << " " << v._status.spare_storage_value << " ";
if(v._status.have_value())
{
s << v._value; // NOLINT
}
return s;
}
template <class T, class E> inline std::ostream &operator<<(std::ostream &s, const value_storage_trivial<T, E> &v) { return value_storage_out(s, v); }
template <class T, class E> inline std::ostream &operator<<(std::ostream &s, const value_storage_nontrivial<T, E> &v) { return value_storage_out(s, v); }
template <template <class, class> class ValueStorage, class T, class E> inline std::istream &value_storage_in(std::istream &s, ValueStorage<T, E> &v)
{
using type = ValueStorage<T, E>;
v.~type();
new(&v) type;
uint16_t x, y;
s >> x >> y;
v._status.status_value = static_cast<detail::status>(x);
v._status.spare_storage_value = y;
if(v._status.have_value())
{
new(OUTCOME_ADDRESS_OF(v._value)) decltype(v._value)(); // NOLINT
s >> v._value; // NOLINT
}
if(v._status.have_error())
{
new(OUTCOME_ADDRESS_OF(v._error)) decltype(v._error)(); // NOLINT
s >> v._error; // NOLINT
}
return s;
}
template <template <class, class> class ValueStorage, class E> inline std::istream &value_storage_in(std::istream &s, ValueStorage<void, E> &v)
{
using type = ValueStorage<void, E>;
v.~type();
new(&v) type;
uint16_t x, y;
s >> x >> y;
v._status.status_value = static_cast<detail::status>(x);
v._status.spare_storage_value = y;
if(v._status.have_error())
{
new(OUTCOME_ADDRESS_OF(v._error)) decltype(v._error)(); // NOLINT
s >> v._error; // NOLINT
}
return s;
}
template <template <class, class> class ValueStorage, class T> inline std::istream &value_storage_in(std::istream &s, ValueStorage<T, void> &v)
{
using type = ValueStorage<T, void>;
v.~type();
new(&v) type;
uint16_t x, y;
s >> x >> y;
v._status.status_value = static_cast<detail::status>(x);
v._status.spare_storage_value = y;
if(v._status.have_value())
{
new(OUTCOME_ADDRESS_OF(v._value)) decltype(v._value)(); // NOLINT
s >> v._value; // NOLINT
}
return s;
}
template <class T, class E> inline std::istream &operator>>(std::istream &s, value_storage_trivial<T, E> &v) { return value_storage_in(s, v); }
template <class T, class E> inline std::istream &operator>>(std::istream &s, value_storage_nontrivial<T, E> &v) { return value_storage_in(s, v); }
OUTCOME_TEMPLATE(class T)
OUTCOME_TREQUIRES(OUTCOME_TPRED(!std::is_constructible<std::error_code, T>::value))
inline std::string safe_message(T && /*unused*/) { return {}; }
inline std::string safe_message(const std::error_code &ec) { return " (" + ec.message() + ")"; }
} // namespace detail
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class R, class S, class P)
OUTCOME_TREQUIRES(OUTCOME_TEXPR(detail::lvalueref<std::istream>() >> detail::lvalueref<R>()), OUTCOME_TEXPR(detail::lvalueref<std::istream>() >> detail::lvalueref<S>()))
inline std::istream &operator>>(std::istream &s, basic_result<R, S, P> &v)
{
s >> v._iostreams_state();
if(v.has_error())
{
s >> v.assume_error();
}
return s;
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class R, class S, class P)
OUTCOME_TREQUIRES(OUTCOME_TEXPR(detail::lvalueref<std::ostream>() << detail::lvalueref<R>()), OUTCOME_TEXPR(detail::lvalueref<std::ostream>() << detail::lvalueref<S>()))
inline std::ostream &operator<<(std::ostream &s, const basic_result<R, S, P> &v)
{
s << v._iostreams_state();
if(v.has_error())
{
s << v.assume_error();
}
return s;
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
template <class R, class S, class P> inline std::string print(const basic_result<R, S, P> &v)
{
std::stringstream s;
if(v.has_value())
{
s << v.value();
}
if(v.has_error())
{
s << v.error() << detail::safe_message(v.error());
}
return s.str();
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
template <class S, class P> inline std::string print(const basic_result<void, S, P> &v)
{
std::stringstream s;
if(v.has_value())
{
s << "(+void)";
}
if(v.has_error())
{
s << v.error() << detail::safe_message(v.error());
}
return s.str();
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
template <class R, class P> inline std::string print(const basic_result<R, void, P> &v)
{
std::stringstream s;
if(v.has_value())
{
s << v.value();
}
if(v.has_error())
{
s << "(-void)";
}
return s.str();
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
template <class P> inline std::string print(const basic_result<void, void, P> &v)
{
std::stringstream s;
if(v.has_value())
{
s << "(+void)";
}
if(v.has_error())
{
s << "(-void)";
}
return s.str();
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class R, class S, class P, class N)
OUTCOME_TREQUIRES(OUTCOME_TEXPR(detail::lvalueref<std::istream>() >> detail::lvalueref<R>()), OUTCOME_TEXPR(detail::lvalueref<std::istream>() >> detail::lvalueref<S>()), OUTCOME_TEXPR(detail::lvalueref<std::istream>() >> detail::lvalueref<P>()))
inline std::istream &operator>>(std::istream &s, outcome<R, S, P, N> &v)
{
s >> v._iostreams_state();
if(v.has_error())
{
s >> v.assume_error();
}
if(v.has_exception())
{
s >> v.assume_exception();
}
return s;
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class R, class S, class P, class N)
OUTCOME_TREQUIRES(OUTCOME_TEXPR(detail::lvalueref<std::ostream>() << detail::lvalueref<R>()), OUTCOME_TEXPR(detail::lvalueref<std::ostream>() << detail::lvalueref<S>()), OUTCOME_TEXPR(detail::lvalueref<std::ostream>() << detail::lvalueref<P>()))
inline std::ostream &operator<<(std::ostream &s, const outcome<R, S, P, N> &v)
{
s << v._iostreams_state();
if(v.has_error())
{
s << v.assume_error();
}
if(v.has_exception())
{
s << v.assume_exception();
}
return s;
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
template <class R, class S, class P, class N> inline std::string print(const outcome<R, S, P, N> &v)
{
std::stringstream s;
int total = static_cast<int>(v.has_value()) + static_cast<int>(v.has_error()) + static_cast<int>(v.has_exception());
if(total > 1)
{
s << "{ ";
}
s << print(static_cast<const basic_result<R, S, N> &>(static_cast<const detail::basic_result_final<R, S, N> &>(v))); // NOLINT
if(total > 1)
{
s << ", ";
}
if(v.has_exception())
{
#ifdef __cpp_exceptions
try
{
rethrow_exception(v.exception());
}
catch(const std::system_error &e)
{
s << "std::system_error code " << e.code() << ": " << e.what();
}
catch(const std::exception &e)
{
s << "std::exception: " << e.what();
}
catch(...)
#endif
{
s << "unknown exception";
}
}
if(total > 1)
{
s << " }";
}
return s.str();
}
OUTCOME_V2_NAMESPACE_END
#endif
|
0 | repos/outcome/include | repos/outcome/include/outcome/std_result.hpp | /* A very simple result type
(C) 2017-2019 Niall Douglas <http://www.nedproductions.biz/> (8 commits)
File Created: June 2017
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License in the accompanying file
Licence.txt or at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Distributed under the Boost Software License, Version 1.0.
(See accompanying file Licence.txt or copy at
http://www.boost.org/LICENSE_1_0.txt)
*/
#ifndef OUTCOME_STD_RESULT_HPP
#define OUTCOME_STD_RESULT_HPP
#include "basic_result.hpp"
#include "detail/trait_std_error_code.hpp"
#include "detail/trait_std_exception.hpp"
#include "policy/fail_to_compile_observers.hpp"
#include "policy/result_error_code_throw_as_system_error.hpp"
#include "policy/result_exception_ptr_rethrow.hpp"
#include "policy/throw_bad_result_access.hpp"
OUTCOME_V2_NAMESPACE_EXPORT_BEGIN
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
namespace policy
{
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
template <class T, class EC, class E>
using default_policy = std::conditional_t< //
std::is_void<EC>::value && std::is_void<E>::value,
terminate, //
std::conditional_t< //
trait::is_error_code_available<EC>::value, error_code_throw_as_system_error<T, EC, E>, //
std::conditional_t< //
trait::is_exception_ptr_available<EC>::value || trait::is_exception_ptr_available<E>::value, exception_ptr_rethrow<T, EC, E>, //
fail_to_compile_observers //
>>>;
} // namespace policy
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
template <class R, class S = std::error_code, class NoValuePolicy = policy::default_policy<R, S, void>> //
using std_result = basic_result<R, S, NoValuePolicy>;
/*! AWAITING HUGO JSON CONVERSION TOOL
type alias template <class R, class S = std::error_code> std_unchecked. Potential doc page: `std_unchecked<T, E = std::error_code>`
*/
template <class R, class S = std::error_code> using std_unchecked = std_result<R, S, policy::all_narrow>;
/*! AWAITING HUGO JSON CONVERSION TOOL
type alias template <class R, class S = std::error_code> std_checked. Potential doc page: `std_checked<T, E = std::error_code>`
*/
template <class R, class S = std::error_code> using std_checked = std_result<R, S, policy::throw_bad_result_access<S, void>>;
OUTCOME_V2_NAMESPACE_END
#endif
|
0 | repos/outcome/include | repos/outcome/include/outcome/basic_outcome.hpp | /* A less simple result type
(C) 2017-2024 Niall Douglas <http://www.nedproductions.biz/> (20 commits)
File Created: June 2017
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License in the accompanying file
Licence.txt or at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Distributed under the Boost Software License, Version 1.0.
(See accompanying file Licence.txt or copy at
http://www.boost.org/LICENSE_1_0.txt)
*/
#ifndef OUTCOME_BASIC_OUTCOME_HPP
#define OUTCOME_BASIC_OUTCOME_HPP
#include "config.hpp"
#include "basic_result.hpp"
#include "detail/basic_outcome_exception_observers.hpp"
#include "detail/basic_outcome_failure_observers.hpp"
#ifdef __clang__
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdocumentation" // Standardese markup confuses clang
#endif
OUTCOME_V2_NAMESPACE_EXPORT_BEGIN
template <class R, class S, class P, class NoValuePolicy> //
class basic_outcome;
namespace detail
{
// May be reused by basic_outcome subclasses to save load on the compiler
template <class value_type, class error_type, class exception_type> struct outcome_predicates
{
using result = result_predicates<value_type, error_type>;
// Predicate for the implicit constructors to be available
static constexpr bool implicit_constructors_enabled = //
result::implicit_constructors_enabled //
&& !detail::is_implicitly_constructible<value_type, exception_type> //
&& !detail::is_implicitly_constructible<error_type, exception_type> //
&& !detail::is_implicitly_constructible<exception_type, value_type> //
&& !detail::is_implicitly_constructible<exception_type, error_type>;
// Predicate for the value converting constructor to be available.
template <class T>
static constexpr bool enable_value_converting_constructor = //
implicit_constructors_enabled //
&& result::template enable_value_converting_constructor<T> //
&& !detail::is_implicitly_constructible<exception_type, T>; // deliberately less tolerant of ambiguity than result's edition
// Predicate for the error converting constructor to be available.
template <class T>
static constexpr bool enable_error_converting_constructor = //
implicit_constructors_enabled //
&& result::template enable_error_converting_constructor<T> //
&& !detail::is_implicitly_constructible<exception_type, T>; // deliberately less tolerant of ambiguity than result's edition
// Predicate for the error condition converting constructor to be available.
template <class ErrorCondEnum>
static constexpr bool enable_error_condition_converting_constructor = result::template enable_error_condition_converting_constructor<ErrorCondEnum> //
&& !detail::is_implicitly_constructible<exception_type, ErrorCondEnum>;
// Predicate for the exception converting constructor to be available.
template <class T>
static constexpr bool enable_exception_converting_constructor = //
implicit_constructors_enabled //
&& !is_in_place_type_t<std::decay_t<T>>::value // not in place construction
&& !detail::is_implicitly_constructible<value_type, T> && !detail::is_implicitly_constructible<error_type, T> &&
detail::is_implicitly_constructible<exception_type, T>;
// Predicate for the error + exception converting constructor to be available.
template <class T, class U>
static constexpr bool enable_error_exception_converting_constructor = //
implicit_constructors_enabled //
&& !is_in_place_type_t<std::decay_t<T>>::value // not in place construction
&& !detail::is_implicitly_constructible<value_type, T> && detail::is_implicitly_constructible<error_type, T> //
&& !detail::is_implicitly_constructible<value_type, U> && detail::is_implicitly_constructible<exception_type, U>;
// Predicate for the converting copy constructor from a compatible outcome to be available.
template <class T, class U, class V, class W>
static constexpr bool enable_compatible_conversion = //
(std::is_void<T>::value ||
detail::is_explicitly_constructible<value_type, typename basic_outcome<T, U, V, W>::value_type>) // if our value types are constructible
&&(std::is_void<U>::value ||
detail::is_explicitly_constructible<error_type, typename basic_outcome<T, U, V, W>::error_type>) // if our error types are constructible
&&(std::is_void<V>::value ||
detail::is_explicitly_constructible<exception_type, typename basic_outcome<T, U, V, W>::exception_type>) // if our exception types are constructible
;
// Predicate for the converting constructor from a make_error_code() of the input to be available.
template <class T, class U, class V, class W>
static constexpr bool enable_make_error_code_compatible_conversion = //
trait::is_error_code_available<std::decay_t<error_type>>::value // if error type has an error code
&& !enable_compatible_conversion<T, U, V, W> // and the normal compatible conversion is not available
&& (std::is_void<T>::value ||
detail::is_explicitly_constructible<value_type, typename basic_outcome<T, U, V, W>::value_type>) // and if our value types are constructible
&&detail::is_explicitly_constructible<error_type,
typename trait::is_error_code_available<U>::type> // and our error type is constructible from a make_error_code()
&& (std::is_void<V>::value ||
detail::is_explicitly_constructible<exception_type, typename basic_outcome<T, U, V, W>::exception_type>); // and our exception types are constructible
// Predicate for the implicit converting inplace constructor from a compatible input to be available.
struct disable_inplace_value_error_exception_constructor;
template <class... Args>
using choose_inplace_value_error_exception_constructor = std::conditional_t< //
((static_cast<int>(detail::is_constructible<value_type, Args...>) + static_cast<int>(detail::is_constructible<error_type, Args...>) +
static_cast<int>(detail::is_constructible<exception_type, Args...>)) > 1), //
disable_inplace_value_error_exception_constructor, //
std::conditional_t< //
detail::is_constructible<value_type, Args...>, //
value_type, //
std::conditional_t< //
detail::is_constructible<error_type, Args...>, //
error_type, //
std::conditional_t< //
detail::is_constructible<exception_type, Args...>, //
exception_type, //
disable_inplace_value_error_exception_constructor>>>>;
template <class... Args>
static constexpr bool enable_inplace_value_error_exception_constructor = //
implicit_constructors_enabled &&
!std::is_same<choose_inplace_value_error_exception_constructor<Args...>, disable_inplace_value_error_exception_constructor>::value;
};
// Select whether to use basic_outcome_failure_observers or not
template <class Base, class R, class S, class P, class NoValuePolicy>
using select_basic_outcome_failure_observers = //
std::conditional_t<trait::is_error_code_available<S>::value && trait::is_exception_ptr_available<P>::value,
basic_outcome_failure_observers<Base, R, S, P, NoValuePolicy>, Base>;
template <class T, class U, class V> constexpr inline const V &extract_exception_from_failure(const failure_type<U, V> &v)
{
return v.exception();
}
template <class T, class U, class V> constexpr inline V &&extract_exception_from_failure(failure_type<U, V> &&v)
{
return static_cast<failure_type<U, V> &&>(v).exception();
}
template <class T, class U> constexpr inline const U &extract_exception_from_failure(const failure_type<U, void> &v)
{
return v.error();
}
template <class T, class U> constexpr inline U &&extract_exception_from_failure(failure_type<U, void> &&v)
{
return static_cast<failure_type<U, void> &&>(v).error();
}
template <class T> struct is_basic_outcome
{
static constexpr bool value = false;
};
template <class R, class S, class T, class N> struct is_basic_outcome<basic_outcome<R, S, T, N>>
{
static constexpr bool value = true;
};
} // namespace detail
/*! AWAITING HUGO JSON CONVERSION TOOL
type alias template <class T> is_basic_outcome. Potential doc page: `is_basic_outcome<T>`
*/
template <class T> using is_basic_outcome = detail::is_basic_outcome<std::decay_t<T>>;
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
template <class T> static constexpr bool is_basic_outcome_v = detail::is_basic_outcome<std::decay_t<T>>::value;
namespace concepts
{
#if defined(__cpp_concepts)
/* The `basic_outcome` concept.
\requires That `U` matches a `basic_outcome`.
*/
template <class U>
concept OUTCOME_GCC6_CONCEPT_BOOL basic_outcome =
OUTCOME_V2_NAMESPACE::is_basic_outcome<U>::value ||
(requires(U v) {
OUTCOME_V2_NAMESPACE::basic_outcome<typename U::value_type, typename U::error_type, typename U::exception_type, typename U::no_value_policy_type>(v);
} && //
detail::convertible<
U, OUTCOME_V2_NAMESPACE::basic_outcome<typename U::value_type, typename U::error_type, typename U::exception_type, typename U::no_value_policy_type>> && //
detail::base_of<
OUTCOME_V2_NAMESPACE::basic_outcome<typename U::value_type, typename U::error_type, typename U::exception_type, typename U::no_value_policy_type>, U>);
#else
namespace detail
{
inline no_match match_basic_outcome(...);
template <class R, class S, class P, class NVP, class T, //
typename = typename T::value_type, //
typename = typename T::error_type, //
typename = typename T::exception_type, //
typename = typename T::no_value_policy_type, //
typename std::enable_if_t<std::is_convertible<T, OUTCOME_V2_NAMESPACE::basic_outcome<R, S, P, NVP>>::value && //
std::is_base_of<OUTCOME_V2_NAMESPACE::basic_outcome<R, S, P, NVP>, T>::value,
bool> = true>
inline OUTCOME_V2_NAMESPACE::basic_outcome<R, S, P, NVP> match_basic_outcome(OUTCOME_V2_NAMESPACE::basic_outcome<R, S, P, NVP> &&, T &&);
template <class U>
static constexpr bool basic_outcome =
OUTCOME_V2_NAMESPACE::is_basic_outcome<U>::value ||
!std::is_same<no_match, decltype(match_basic_outcome(std::declval<OUTCOME_V2_NAMESPACE::detail::devoid<U>>(),
std::declval<OUTCOME_V2_NAMESPACE::detail::devoid<U>>()))>::value;
} // namespace detail
/* The `basic_outcome` concept.
\requires That `U` matches a `basic_outcome`.
*/
template <class U> static constexpr bool basic_outcome = detail::basic_outcome<U>;
#endif
} // namespace concepts
namespace hooks
{
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
template <class R, class S, class P, class NoValuePolicy, class U>
constexpr inline void override_outcome_exception(basic_outcome<R, S, P, NoValuePolicy> *o, U &&v) noexcept;
} // namespace hooks
/*! AWAITING HUGO JSON CONVERSION TOOL
type definition template <class R, class S, class P, class NoValuePolicy> basic_outcome. Potential doc page: `basic_outcome<T, EC, EP, NoValuePolicy>`
*/
template <class R, class S, class P, class NoValuePolicy> //
class OUTCOME_NODISCARD basic_outcome
#if defined(DOXYGEN_IS_IN_THE_HOUSE) || defined(STANDARDESE_IS_IN_THE_HOUSE)
: public detail::basic_outcome_failure_observers<detail::basic_result_final<R, S, P, NoValuePolicy>, R, S, P, NoValuePolicy>,
public detail::basic_outcome_exception_observers<detail::basic_result_final<R, S, NoValuePolicy>, R, S, P, NoValuePolicy>,
public detail::basic_result_final<R, S, NoValuePolicy>
#else
: public detail::select_basic_outcome_failure_observers<
detail::basic_outcome_exception_observers<detail::basic_result_final<R, S, NoValuePolicy>, R, S, P, NoValuePolicy>, R, S, P, NoValuePolicy>
#endif
{
static_assert(trait::type_can_be_used_in_basic_result<P>, "The exception_type cannot be used");
static_assert(std::is_void<P>::value || std::is_default_constructible<P>::value, "exception_type must be void or default constructible");
using base = detail::select_basic_outcome_failure_observers<
detail::basic_outcome_exception_observers<detail::basic_result_final<R, S, NoValuePolicy>, R, S, P, NoValuePolicy>, R, S, P, NoValuePolicy>;
friend struct policy::base;
template <class T, class U, class V, class W> //
friend class basic_outcome;
template <class T, class U, class V, class W, class X>
friend constexpr inline void hooks::override_outcome_exception(basic_outcome<T, U, V, W> *o, X &&v) noexcept; // NOLINT
struct implicit_constructors_disabled_tag
{
};
struct value_converting_constructor_tag
{
};
struct error_converting_constructor_tag
{
};
struct error_condition_converting_constructor_tag
{
};
struct exception_converting_constructor_tag
{
};
struct error_exception_converting_constructor_tag
{
};
struct explicit_valueorerror_converting_constructor_tag
{
};
struct explicit_compatible_copy_conversion_tag
{
};
struct explicit_compatible_move_conversion_tag
{
};
struct explicit_make_error_code_compatible_copy_conversion_tag
{
};
struct explicit_make_error_code_compatible_move_conversion_tag
{
};
struct error_failure_tag
{
};
struct exception_failure_tag
{
};
struct disable_in_place_value_type
{
};
struct disable_in_place_error_type
{
};
struct disable_in_place_exception_type
{
};
public:
using value_type = R;
using error_type = S;
using exception_type = P;
using no_value_policy_type = NoValuePolicy;
template <class T, class U = S, class V = P, class W = NoValuePolicy> using rebind = basic_outcome<T, U, V, W>;
protected:
// Requirement predicates for outcome.
struct predicate
{
using base = detail::outcome_predicates<value_type, error_type, exception_type>;
// Predicate for any constructors to be available at all
static constexpr bool constructors_enabled =
(!std::is_same<std::decay_t<value_type>, std::decay_t<error_type>>::value || (std::is_void<value_type>::value && std::is_void<error_type>::value)) //
&& (!std::is_same<std::decay_t<value_type>, std::decay_t<exception_type>>::value ||
(std::is_void<value_type>::value && std::is_void<exception_type>::value)) //
&& (!std::is_same<std::decay_t<error_type>, std::decay_t<exception_type>>::value ||
(std::is_void<error_type>::value && std::is_void<exception_type>::value)) //
;
// Predicate for implicit constructors to be available at all
static constexpr bool implicit_constructors_enabled = constructors_enabled && base::implicit_constructors_enabled;
// Predicate for the value converting constructor to be available.
template <class T>
static constexpr bool enable_value_converting_constructor = //
constructors_enabled //
&& !std::is_same<std::decay_t<T>, basic_outcome>::value // not my type
&& base::template enable_value_converting_constructor<T>;
// Predicate for the error converting constructor to be available.
template <class T>
static constexpr bool enable_error_converting_constructor = //
constructors_enabled //
&& !std::is_same<std::decay_t<T>, basic_outcome>::value // not my type
&& base::template enable_error_converting_constructor<T>;
// Predicate for the error condition converting constructor to be available.
template <class ErrorCondEnum>
static constexpr bool enable_error_condition_converting_constructor = //
constructors_enabled //
&& !std::is_same<std::decay_t<ErrorCondEnum>, basic_outcome>::value // not my type
&& base::template enable_error_condition_converting_constructor<ErrorCondEnum>;
// Predicate for the exception converting constructor to be available.
template <class T>
static constexpr bool enable_exception_converting_constructor = //
constructors_enabled //
&& !std::is_same<std::decay_t<T>, basic_outcome>::value // not my type
&& base::template enable_exception_converting_constructor<T>;
// Predicate for the error + exception converting constructor to be available.
template <class T, class U>
static constexpr bool enable_error_exception_converting_constructor = //
constructors_enabled //
&& !std::is_same<std::decay_t<T>, basic_outcome>::value // not my type
&& base::template enable_error_exception_converting_constructor<T, U>;
// Predicate for the converting constructor from a compatible input to be available.
template <class T, class U, class V, class W>
static constexpr bool enable_compatible_conversion = //
constructors_enabled //
&& !std::is_same<basic_outcome<T, U, V, W>, basic_outcome>::value // not my type
&& base::template enable_compatible_conversion<T, U, V, W>;
// Predicate for the converting constructor from a make_error_code() of the input to be available.
template <class T, class U, class V, class W>
static constexpr bool enable_make_error_code_compatible_conversion = //
constructors_enabled //
&& !std::is_same<basic_outcome<T, U, V, W>, basic_outcome>::value // not my type
&& base::template enable_make_error_code_compatible_conversion<T, U, V, W>;
// Predicate for the inplace construction of value to be available.
template <class... Args>
static constexpr bool enable_inplace_value_constructor = //
constructors_enabled //
&& (std::is_void<value_type>::value //
|| detail::is_constructible<value_type, Args...>);
// Predicate for the inplace construction of error to be available.
template <class... Args>
static constexpr bool enable_inplace_error_constructor = //
constructors_enabled //
&& (std::is_void<error_type>::value //
|| detail::is_constructible<error_type, Args...>);
// Predicate for the inplace construction of exception to be available.
template <class... Args>
static constexpr bool enable_inplace_exception_constructor = //
constructors_enabled //
&& (std::is_void<exception_type>::value //
|| detail::is_constructible<exception_type, Args...>);
// Predicate for the implicit converting inplace constructor to be available.
template <class... Args>
static constexpr bool enable_inplace_value_error_exception_constructor = //
constructors_enabled //
&& base::template enable_inplace_value_error_exception_constructor<Args...>;
template <class... Args>
using choose_inplace_value_error_exception_constructor = typename base::template choose_inplace_value_error_exception_constructor<Args...>;
};
public:
using value_type_if_enabled =
std::conditional_t<std::is_same<value_type, error_type>::value || std::is_same<value_type, exception_type>::value, disable_in_place_value_type, value_type>;
using error_type_if_enabled =
std::conditional_t<std::is_same<error_type, value_type>::value || std::is_same<error_type, exception_type>::value, disable_in_place_error_type, error_type>;
using exception_type_if_enabled = std::conditional_t<std::is_same<exception_type, value_type>::value || std::is_same<exception_type, error_type>::value,
disable_in_place_exception_type, exception_type>;
protected:
detail::devoid<exception_type> _ptr;
public:
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class Arg, class... Args)
OUTCOME_TREQUIRES(OUTCOME_TPRED((!predicate::constructors_enabled && sizeof...(Args) >= 0)))
basic_outcome(Arg && /*unused*/, Args &&.../*unused*/) = delete; // NOLINT basic_outcome<> with any of the same type is NOT SUPPORTED, see docs!
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class T)
OUTCOME_TREQUIRES(OUTCOME_TPRED((predicate::constructors_enabled && !predicate::implicit_constructors_enabled //
&& (detail::is_implicitly_constructible<value_type, T> || detail::is_implicitly_constructible<error_type, T> ||
detail::is_implicitly_constructible<exception_type, T>) )))
basic_outcome(T && /*unused*/, implicit_constructors_disabled_tag /*unused*/ = implicit_constructors_disabled_tag()) =
delete; // NOLINT Implicit constructors disabled, use explicit in_place_type<T>, success() or failure(). see docs!
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class T)
OUTCOME_TREQUIRES(OUTCOME_TPRED(predicate::template enable_value_converting_constructor<T>))
constexpr basic_outcome(T &&t, value_converting_constructor_tag /*unused*/ = value_converting_constructor_tag()) noexcept(
detail::is_nothrow_constructible<value_type, T>) // NOLINT
: base{in_place_type<typename base::_value_type>, static_cast<T &&>(t)}
, _ptr()
{
no_value_policy_type::on_outcome_construction(this, static_cast<T &&>(t));
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class T)
OUTCOME_TREQUIRES(OUTCOME_TPRED(predicate::template enable_error_converting_constructor<T>))
constexpr basic_outcome(T &&t, error_converting_constructor_tag /*unused*/ = error_converting_constructor_tag()) noexcept(
detail::is_nothrow_constructible<error_type, T>) // NOLINT
: base{in_place_type<typename base::_error_type>, static_cast<T &&>(t)}
, _ptr()
{
no_value_policy_type::on_outcome_construction(this, static_cast<T &&>(t));
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class ErrorCondEnum)
OUTCOME_TREQUIRES(OUTCOME_TEXPR(error_type(make_error_code(ErrorCondEnum()))), //
OUTCOME_TPRED(predicate::template enable_error_condition_converting_constructor<ErrorCondEnum>))
constexpr basic_outcome(ErrorCondEnum &&t, error_condition_converting_constructor_tag /*unused*/ = error_condition_converting_constructor_tag()) noexcept(
noexcept(error_type(make_error_code(static_cast<ErrorCondEnum &&>(t))))) // NOLINT
: base{in_place_type<typename base::_error_type>, make_error_code(t)}
{
no_value_policy_type::on_outcome_construction(this, static_cast<ErrorCondEnum &&>(t));
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class T)
OUTCOME_TREQUIRES(OUTCOME_TPRED(predicate::template enable_exception_converting_constructor<T>))
constexpr basic_outcome(T &&t, exception_converting_constructor_tag /*unused*/ = exception_converting_constructor_tag()) noexcept(
detail::is_nothrow_constructible<exception_type, T>) // NOLINT
: base()
, _ptr(static_cast<T &&>(t))
{
this->_state._status.set_have_exception(true);
no_value_policy_type::on_outcome_construction(this, static_cast<T &&>(t));
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class T, class U)
OUTCOME_TREQUIRES(OUTCOME_TPRED(predicate::template enable_error_exception_converting_constructor<T, U>))
constexpr basic_outcome(T &&a, U &&b, error_exception_converting_constructor_tag /*unused*/ = error_exception_converting_constructor_tag()) noexcept(
detail::is_nothrow_constructible<error_type, T> && detail::is_nothrow_constructible<exception_type, U>) // NOLINT
: base{in_place_type<typename base::_error_type>, static_cast<T &&>(a)}
, _ptr(static_cast<U &&>(b))
{
this->_state._status.set_have_exception(true);
no_value_policy_type::on_outcome_construction(this, static_cast<T &&>(a), static_cast<U &&>(b));
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class T)
OUTCOME_TREQUIRES(OUTCOME_TPRED(convert::value_or_error<basic_outcome, std::decay_t<T>>::enable_result_inputs || !concepts::basic_result<T>), //
OUTCOME_TPRED(convert::value_or_error<basic_outcome, std::decay_t<T>>::enable_outcome_inputs || !concepts::basic_outcome<T>), //
OUTCOME_TEXPR(convert::value_or_error<basic_outcome, std::decay_t<T>>{}(std::declval<T>())))
constexpr explicit basic_outcome(T &&o,
explicit_valueorerror_converting_constructor_tag /*unused*/ = explicit_valueorerror_converting_constructor_tag()) // NOLINT
: basic_outcome{convert::value_or_error<basic_outcome, std::decay_t<T>>{}(static_cast<T &&>(o))}
{
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class T, class U, class V, class W)
OUTCOME_TREQUIRES(OUTCOME_TPRED(predicate::template enable_compatible_conversion<T, U, V, W>))
constexpr explicit basic_outcome(
const basic_outcome<T, U, V, W> &o,
explicit_compatible_copy_conversion_tag /*unused*/ = explicit_compatible_copy_conversion_tag()) noexcept(detail::is_nothrow_constructible<value_type, T> &&
detail::is_nothrow_constructible<error_type, U> &&
detail::is_nothrow_constructible<exception_type, V>)
: base{typename base::compatible_conversion_tag(), o}
, _ptr(o._ptr)
{
no_value_policy_type::on_outcome_copy_construction(this, o);
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class T, class U, class V, class W)
OUTCOME_TREQUIRES(OUTCOME_TPRED(predicate::template enable_compatible_conversion<T, U, V, W>))
constexpr explicit basic_outcome(
basic_outcome<T, U, V, W> &&o,
explicit_compatible_move_conversion_tag /*unused*/ = explicit_compatible_move_conversion_tag()) noexcept(detail::is_nothrow_constructible<value_type, T> &&
detail::is_nothrow_constructible<error_type, U> &&
detail::is_nothrow_constructible<exception_type, V>)
: base{typename base::compatible_conversion_tag(), static_cast<basic_outcome<T, U, V, W> &&>(o)}
, _ptr(static_cast<typename basic_outcome<T, U, V, W>::exception_type &&>(o._ptr))
{
no_value_policy_type::on_outcome_move_construction(this, static_cast<basic_outcome<T, U, V, W> &&>(o));
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class T, class U, class V)
OUTCOME_TREQUIRES(OUTCOME_TPRED(detail::result_predicates<value_type, error_type>::template enable_compatible_conversion<T, U, V>))
constexpr explicit basic_outcome(
const basic_result<T, U, V> &o,
explicit_compatible_copy_conversion_tag /*unused*/ = explicit_compatible_copy_conversion_tag()) noexcept(detail::is_nothrow_constructible<value_type, T> &&
detail::is_nothrow_constructible<error_type, U> &&
detail::is_nothrow_constructible<exception_type>)
: base{typename base::compatible_conversion_tag(), o}
, _ptr()
{
no_value_policy_type::on_outcome_copy_construction(this, o);
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class T, class U, class V)
OUTCOME_TREQUIRES(OUTCOME_TPRED(detail::result_predicates<value_type, error_type>::template enable_compatible_conversion<T, U, V>))
constexpr explicit basic_outcome(
basic_result<T, U, V> &&o,
explicit_compatible_move_conversion_tag /*unused*/ = explicit_compatible_move_conversion_tag()) noexcept(detail::is_nothrow_constructible<value_type, T> &&
detail::is_nothrow_constructible<error_type, U> &&
detail::is_nothrow_constructible<exception_type>)
: base{typename base::compatible_conversion_tag(), static_cast<basic_result<T, U, V> &&>(o)}
, _ptr()
{
no_value_policy_type::on_outcome_move_construction(this, static_cast<basic_result<T, U, V> &&>(o));
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class T, class U, class V)
OUTCOME_TREQUIRES(OUTCOME_TPRED(detail::result_predicates<value_type, error_type>::template enable_make_error_code_compatible_conversion<T, U, V>))
constexpr explicit basic_outcome(const basic_result<T, U, V> &o,
explicit_make_error_code_compatible_copy_conversion_tag /*unused*/ =
explicit_make_error_code_compatible_copy_conversion_tag()) noexcept(detail::is_nothrow_constructible<value_type, T> &&
noexcept(make_error_code(std::declval<U>())) &&
detail::is_nothrow_constructible<exception_type>)
: base{typename base::make_error_code_compatible_conversion_tag(), o}
, _ptr()
{
no_value_policy_type::on_outcome_copy_construction(this, o);
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class T, class U, class V)
OUTCOME_TREQUIRES(OUTCOME_TPRED(detail::result_predicates<value_type, error_type>::template enable_make_error_code_compatible_conversion<T, U, V>))
constexpr explicit basic_outcome(basic_result<T, U, V> &&o,
explicit_make_error_code_compatible_move_conversion_tag /*unused*/ =
explicit_make_error_code_compatible_move_conversion_tag()) noexcept(detail::is_nothrow_constructible<value_type, T> &&
noexcept(make_error_code(std::declval<U>())) &&
detail::is_nothrow_constructible<exception_type>)
: base{typename base::make_error_code_compatible_conversion_tag(), static_cast<basic_result<T, U, V> &&>(o)}
, _ptr()
{
no_value_policy_type::on_outcome_move_construction(this, static_cast<basic_result<T, U, V> &&>(o));
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class... Args)
OUTCOME_TREQUIRES(OUTCOME_TPRED(predicate::template enable_inplace_value_constructor<Args...>))
constexpr explicit basic_outcome(in_place_type_t<value_type_if_enabled> _, Args &&...args) noexcept(detail::is_nothrow_constructible<value_type, Args...>)
: base{_, static_cast<Args &&>(args)...}
, _ptr()
{
no_value_policy_type::on_outcome_in_place_construction(this, in_place_type<value_type>, static_cast<Args &&>(args)...);
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class U, class... Args)
OUTCOME_TREQUIRES(OUTCOME_TPRED(predicate::template enable_inplace_value_constructor<std::initializer_list<U>, Args...>))
constexpr explicit basic_outcome(in_place_type_t<value_type_if_enabled> _, std::initializer_list<U> il,
Args &&...args) noexcept(detail::is_nothrow_constructible<value_type, std::initializer_list<U>, Args...>)
: base{_, il, static_cast<Args &&>(args)...}
, _ptr()
{
no_value_policy_type::on_outcome_in_place_construction(this, in_place_type<value_type>, il, static_cast<Args &&>(args)...);
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class... Args)
OUTCOME_TREQUIRES(OUTCOME_TPRED(predicate::template enable_inplace_error_constructor<Args...>))
constexpr explicit basic_outcome(in_place_type_t<error_type_if_enabled> _, Args &&...args) noexcept(detail::is_nothrow_constructible<error_type, Args...>)
: base{_, static_cast<Args &&>(args)...}
, _ptr()
{
no_value_policy_type::on_outcome_in_place_construction(this, in_place_type<error_type>, static_cast<Args &&>(args)...);
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class U, class... Args)
OUTCOME_TREQUIRES(OUTCOME_TPRED(predicate::template enable_inplace_error_constructor<std::initializer_list<U>, Args...>))
constexpr explicit basic_outcome(in_place_type_t<error_type_if_enabled> _, std::initializer_list<U> il,
Args &&...args) noexcept(detail::is_nothrow_constructible<error_type, std::initializer_list<U>, Args...>)
: base{_, il, static_cast<Args &&>(args)...}
, _ptr()
{
no_value_policy_type::on_outcome_in_place_construction(this, in_place_type<error_type>, il, static_cast<Args &&>(args)...);
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class... Args)
OUTCOME_TREQUIRES(OUTCOME_TPRED(predicate::template enable_inplace_exception_constructor<Args...>))
constexpr explicit basic_outcome(in_place_type_t<exception_type_if_enabled> /*unused*/,
Args &&...args) noexcept(detail::is_nothrow_constructible<exception_type, Args...>)
: base()
, _ptr(static_cast<Args &&>(args)...)
{
this->_state._status.set_have_exception(true);
no_value_policy_type::on_outcome_in_place_construction(this, in_place_type<exception_type>, static_cast<Args &&>(args)...);
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class U, class... Args)
OUTCOME_TREQUIRES(OUTCOME_TPRED(predicate::template enable_inplace_exception_constructor<std::initializer_list<U>, Args...>))
constexpr explicit basic_outcome(in_place_type_t<exception_type_if_enabled> /*unused*/, std::initializer_list<U> il,
Args &&...args) noexcept(detail::is_nothrow_constructible<exception_type, std::initializer_list<U>, Args...>)
: base()
, _ptr(il, static_cast<Args &&>(args)...)
{
this->_state._status.set_have_exception(true);
no_value_policy_type::on_outcome_in_place_construction(this, in_place_type<exception_type>, il, static_cast<Args &&>(args)...);
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class A1, class A2, class... Args)
OUTCOME_TREQUIRES(OUTCOME_TPRED(predicate::template enable_inplace_value_error_exception_constructor<A1, A2, Args...>))
constexpr basic_outcome(A1 &&a1, A2 &&a2, Args &&...args) noexcept(
noexcept(typename predicate::template choose_inplace_value_error_exception_constructor<A1, A2, Args...>(std::declval<A1>(), std::declval<A2>(),
std::declval<Args>()...)))
: basic_outcome(in_place_type<typename predicate::template choose_inplace_value_error_exception_constructor<A1, A2, Args...>>, static_cast<A1 &&>(a1),
static_cast<A2 &&>(a2), static_cast<Args &&>(args)...)
{
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
constexpr basic_outcome(const success_type<void> &o) noexcept(std::is_nothrow_default_constructible<value_type>::value) // NOLINT
: base{in_place_type<typename base::_value_type>}
{
hooks::set_spare_storage(this, o.spare_storage());
no_value_policy_type::on_outcome_copy_construction(this, o);
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class T)
OUTCOME_TREQUIRES(OUTCOME_TPRED(!std::is_void<T>::value && predicate::template enable_compatible_conversion<T, void, void, void>))
constexpr basic_outcome(const success_type<T> &o) noexcept(detail::is_nothrow_constructible<value_type, T>) // NOLINT
: base{in_place_type<typename base::_value_type>, detail::extract_value_from_success<value_type>(o)}
{
hooks::set_spare_storage(this, o.spare_storage());
no_value_policy_type::on_outcome_copy_construction(this, o);
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class T)
OUTCOME_TREQUIRES(OUTCOME_TPRED(!std::is_void<T>::value && predicate::template enable_compatible_conversion<T, void, void, void>))
constexpr basic_outcome(success_type<T> &&o) noexcept(detail::is_nothrow_constructible<value_type, T>) // NOLINT
: base{in_place_type<typename base::_value_type>, detail::extract_value_from_success<value_type>(static_cast<success_type<T> &&>(o))}
{
hooks::set_spare_storage(this, o.spare_storage());
no_value_policy_type::on_outcome_move_construction(this, static_cast<success_type<T> &&>(o));
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class T)
OUTCOME_TREQUIRES(OUTCOME_TPRED(!std::is_void<T>::value && predicate::template enable_compatible_conversion<void, T, void, void>))
constexpr basic_outcome(const failure_type<T> &o,
error_failure_tag /*unused*/ = error_failure_tag()) noexcept(detail::is_nothrow_constructible<error_type, T>) // NOLINT
: base{in_place_type<typename base::_error_type>, detail::extract_error_from_failure<error_type>(o)}
, _ptr()
{
hooks::set_spare_storage(this, o.spare_storage());
no_value_policy_type::on_outcome_copy_construction(this, o);
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class T)
OUTCOME_TREQUIRES(OUTCOME_TPRED(!std::is_void<T>::value && predicate::template enable_compatible_conversion<void, void, T, void>))
constexpr basic_outcome(const failure_type<T> &o,
exception_failure_tag /*unused*/ = exception_failure_tag()) noexcept(detail::is_nothrow_constructible<exception_type, T>) // NOLINT
: base()
, _ptr(detail::extract_exception_from_failure<exception_type>(o))
{
this->_state._status.set_have_exception(true);
hooks::set_spare_storage(this, o.spare_storage());
no_value_policy_type::on_outcome_copy_construction(this, o);
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class T)
OUTCOME_TREQUIRES(OUTCOME_TPRED(!std::is_void<T>::value && predicate::template enable_make_error_code_compatible_conversion<void, T, void, void>))
constexpr basic_outcome(const failure_type<T> &o,
explicit_make_error_code_compatible_copy_conversion_tag /*unused*/ =
explicit_make_error_code_compatible_copy_conversion_tag()) noexcept(noexcept(make_error_code(std::declval<T>()))) // NOLINT
: base{in_place_type<typename base::_error_type>, make_error_code(detail::extract_error_from_failure<error_type>(o))}
, _ptr()
{
hooks::set_spare_storage(this, o.spare_storage());
no_value_policy_type::on_outcome_copy_construction(this, o);
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class T, class U)
OUTCOME_TREQUIRES(OUTCOME_TPRED(!std::is_void<U>::value && predicate::template enable_compatible_conversion<void, T, U, void>))
constexpr basic_outcome(const failure_type<T, U> &o, explicit_compatible_copy_conversion_tag /*unused*/ = explicit_compatible_copy_conversion_tag()) noexcept(
detail::is_nothrow_constructible<error_type, T> && detail::is_nothrow_constructible<exception_type, U>) // NOLINT
: base{in_place_type<typename base::_error_type>, detail::extract_error_from_failure<error_type>(o)}
, _ptr(detail::extract_exception_from_failure<exception_type>(o))
{
if(!o.has_error())
{
this->_state._status.set_have_error(false);
}
if(o.has_exception())
{
this->_state._status.set_have_exception(true);
}
hooks::set_spare_storage(this, o.spare_storage());
no_value_policy_type::on_outcome_copy_construction(this, o);
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class T)
OUTCOME_TREQUIRES(OUTCOME_TPRED(!std::is_void<T>::value && predicate::template enable_compatible_conversion<void, T, void, void>))
constexpr basic_outcome(failure_type<T> &&o,
error_failure_tag /*unused*/ = error_failure_tag()) noexcept(detail::is_nothrow_constructible<error_type, T>) // NOLINT
: base{in_place_type<typename base::_error_type>, detail::extract_error_from_failure<error_type>(static_cast<failure_type<T> &&>(o))}
, _ptr()
{
hooks::set_spare_storage(this, o.spare_storage());
no_value_policy_type::on_outcome_copy_construction(this, o);
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class T)
OUTCOME_TREQUIRES(OUTCOME_TPRED(!std::is_void<T>::value && predicate::template enable_compatible_conversion<void, void, T, void>))
constexpr basic_outcome(failure_type<T> &&o,
exception_failure_tag /*unused*/ = exception_failure_tag()) noexcept(detail::is_nothrow_constructible<exception_type, T>) // NOLINT
: base()
, _ptr(detail::extract_exception_from_failure<exception_type>(static_cast<failure_type<T> &&>(o)))
{
this->_state._status.set_have_exception(true);
hooks::set_spare_storage(this, o.spare_storage());
no_value_policy_type::on_outcome_copy_construction(this, o);
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class T)
OUTCOME_TREQUIRES(OUTCOME_TPRED(!std::is_void<T>::value && predicate::template enable_make_error_code_compatible_conversion<void, T, void, void>))
constexpr basic_outcome(failure_type<T> &&o,
explicit_make_error_code_compatible_move_conversion_tag /*unused*/ =
explicit_make_error_code_compatible_move_conversion_tag()) noexcept(noexcept(make_error_code(std::declval<T>()))) // NOLINT
: base{in_place_type<typename base::_error_type>, make_error_code(detail::extract_error_from_failure<error_type>(static_cast<failure_type<T> &&>(o)))}
, _ptr()
{
hooks::set_spare_storage(this, o.spare_storage());
no_value_policy_type::on_outcome_copy_construction(this, o);
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class T, class U)
OUTCOME_TREQUIRES(OUTCOME_TPRED(!std::is_void<U>::value && predicate::template enable_compatible_conversion<void, T, U, void>))
constexpr basic_outcome(failure_type<T, U> &&o, explicit_compatible_move_conversion_tag /*unused*/ = explicit_compatible_move_conversion_tag()) noexcept(
detail::is_nothrow_constructible<error_type, T> && detail::is_nothrow_constructible<exception_type, U>) // NOLINT
: base{in_place_type<typename base::_error_type>, detail::extract_error_from_failure<error_type>(static_cast<failure_type<T, U> &&>(o))}
, _ptr(detail::extract_exception_from_failure<exception_type>(static_cast<failure_type<T, U> &&>(o)))
{
if(!o.has_error())
{
this->_state._status.set_have_error(false);
}
if(o.has_exception())
{
this->_state._status.set_have_exception(true);
}
hooks::set_spare_storage(this, o.spare_storage());
no_value_policy_type::on_outcome_move_construction(this, static_cast<failure_type<T, U> &&>(o));
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
using base::operator==;
using base::operator!=;
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class T, class U, class V, class W)
OUTCOME_TREQUIRES(OUTCOME_TEXPR(std::declval<detail::devoid<value_type>>() == std::declval<detail::devoid<T>>()), //
OUTCOME_TEXPR(std::declval<detail::devoid<error_type>>() == std::declval<detail::devoid<U>>()), //
OUTCOME_TEXPR(std::declval<detail::devoid<exception_type>>() == std::declval<detail::devoid<V>>()))
constexpr bool operator==(const basic_outcome<T, U, V, W> &o) const noexcept( //
noexcept(std::declval<detail::devoid<value_type>>() == std::declval<detail::devoid<T>>()) //
&& noexcept(std::declval<detail::devoid<error_type>>() == std::declval<detail::devoid<U>>()) //
&& noexcept(std::declval<detail::devoid<exception_type>>() == std::declval<detail::devoid<V>>()))
{
if(this->_state._status.have_value() && o._state._status.have_value())
{
return this->_state._value == o._state._value; // NOLINT
}
if(this->_state._status.have_error() && o._state._status.have_error() //
&& this->_state._status.have_exception() && o._state._status.have_exception())
{
return this->_state._error == o._state._error && this->_ptr == o._ptr;
}
if(this->_state._status.have_error() && o._state._status.have_error())
{
return this->_state._error == o._state._error;
}
if(this->_state._status.have_exception() && o._state._status.have_exception())
{
return this->_ptr == o._ptr;
}
return false;
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class T, class U)
OUTCOME_TREQUIRES(OUTCOME_TEXPR(std::declval<error_type>() == std::declval<T>()), //
OUTCOME_TEXPR(std::declval<exception_type>() == std::declval<U>()))
constexpr bool operator==(const failure_type<T, U> &o) const noexcept( //
noexcept(std::declval<error_type>() == std::declval<T>()) && noexcept(std::declval<exception_type>() == std::declval<U>()))
{
if(this->_state._status.have_error() && o._state._status.have_error() //
&& this->_state._status.have_exception() && o._state._status.have_exception())
{
return this->_state._error == o.error() && this->_ptr == o.exception();
}
if(this->_state._status.have_error() && o._state._status.have_error())
{
return this->_state._error == o.error();
}
if(this->_state._status.have_exception() && o._state._status.have_exception())
{
return this->_ptr == o.exception();
}
return false;
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class T, class U, class V, class W)
OUTCOME_TREQUIRES(OUTCOME_TEXPR(std::declval<detail::devoid<value_type>>() != std::declval<detail::devoid<T>>()), //
OUTCOME_TEXPR(std::declval<detail::devoid<error_type>>() != std::declval<detail::devoid<U>>()), //
OUTCOME_TEXPR(std::declval<detail::devoid<exception_type>>() != std::declval<detail::devoid<V>>()))
constexpr bool operator!=(const basic_outcome<T, U, V, W> &o) const noexcept( //
noexcept(std::declval<detail::devoid<value_type>>() != std::declval<detail::devoid<T>>()) //
&& noexcept(std::declval<detail::devoid<error_type>>() != std::declval<detail::devoid<U>>()) //
&& noexcept(std::declval<detail::devoid<exception_type>>() != std::declval<detail::devoid<V>>()))
{
if(this->_state._status.have_value() && o._state._status.have_value())
{
return this->_state._value != o._state._value; // NOLINT
}
if(this->_state._status.have_error() && o._state._status.have_error() //
&& this->_state._status.have_exception() && o._state._status.have_exception())
{
return this->_state._error != o._state._error || this->_ptr != o._ptr;
}
if(this->_state._status.have_error() && o._state._status.have_error())
{
return this->_state._error != o._state._error;
}
if(this->_state._status.have_exception() && o._state._status.have_exception())
{
return this->_ptr != o._ptr;
}
return true;
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class T, class U)
OUTCOME_TREQUIRES(OUTCOME_TEXPR(std::declval<error_type>() != std::declval<T>()), //
OUTCOME_TEXPR(std::declval<exception_type>() != std::declval<U>()))
constexpr bool operator!=(const failure_type<T, U> &o) const noexcept( //
noexcept(std::declval<error_type>() == std::declval<T>()) && noexcept(std::declval<exception_type>() == std::declval<U>()))
{
if(this->_state._status.have_error() && o._state._status.have_error() //
&& this->_state._status.have_exception() && o._state._status.have_exception())
{
return this->_state._error != o.error() || this->_ptr != o.exception();
}
if(this->_state._status.have_error() && o._state._status.have_error())
{
return this->_state._error != o.error();
}
if(this->_state._status.have_exception() && o._state._status.have_exception())
{
return this->_ptr != o.exception();
}
return true;
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
constexpr void swap(basic_outcome &o) noexcept((std::is_void<value_type>::value || detail::is_nothrow_swappable<value_type>::value) //
&& (std::is_void<error_type>::value || detail::is_nothrow_swappable<error_type>::value) //
&& (std::is_void<exception_type>::value || detail::is_nothrow_swappable<exception_type>::value))
{
#ifdef __cpp_exceptions
constexpr bool value_throws = !std::is_void<value_type>::value && !detail::is_nothrow_swappable<value_type>::value;
constexpr bool error_throws = !std::is_void<error_type>::value && !detail::is_nothrow_swappable<error_type>::value;
constexpr bool exception_throws = !std::is_void<exception_type>::value && !detail::is_nothrow_swappable<exception_type>::value;
#ifdef _MSC_VER
#pragma warning(push)
#pragma warning(disable : 4127) // conditional expression is constant
#endif
if(!exception_throws && !value_throws && !error_throws)
{
// Simples
this->_state.swap(o._state);
using std::swap;
swap(this->_ptr, o._ptr);
return;
}
struct some_type
{
basic_outcome &a, &b;
bool exceptioned{false};
bool all_good{false};
~some_type()
{
if(!this->all_good)
{
// We lost one of the values
this->a._state._status.set_have_lost_consistency(true);
this->b._state._status.set_have_lost_consistency(true);
return;
}
if(this->exceptioned)
{
// The value + error swap threw an exception. Try to swap back _ptr
try
{
strong_swap(this->all_good, this->a._ptr, this->b._ptr);
}
catch(...)
{
// We lost one of the values
this->a._state._status.set_have_lost_consistency(true);
this->b._state._status.set_have_lost_consistency(true);
// throw away second exception
}
// Prevent has_value() == has_error() or has_value() == has_exception()
auto check = [](basic_outcome *t)
{
if(t->has_value() && (t->has_error() || t->has_exception()))
{
t->_state._status.set_have_error(false).set_have_exception(false);
t->_state._status.set_have_lost_consistency(true);
}
if(!t->has_value() && !(t->has_error() || t->has_exception()))
{
// Choose error, for no particular reason
t->_state._status.set_have_error(true).set_have_lost_consistency(true);
}
};
check(&this->a);
check(&this->b);
}
}
} some_type_value{*this, o};
strong_swap(some_type_value.all_good, this->_ptr, o._ptr);
some_type_value.exceptioned = true;
this->_state.swap(o._state);
some_type_value.exceptioned = false;
#ifdef _MSC_VER
#pragma warning(pop)
#endif
#else
this->_state.swap(o._state);
using std::swap;
swap(this->_ptr, o._ptr);
#endif
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
failure_type<error_type, exception_type> as_failure() const &
{
if(this->has_error() && this->has_exception())
{
return failure_type<error_type, exception_type>(this->assume_error(), this->assume_exception(), hooks::spare_storage(this));
}
if(this->has_exception())
{
return failure_type<error_type, exception_type>(in_place_type<exception_type>, this->assume_exception(), hooks::spare_storage(this));
}
return failure_type<error_type, exception_type>(in_place_type<error_type>, this->assume_error(), hooks::spare_storage(this));
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
failure_type<error_type, exception_type> as_failure() &&
{
this->_state._status.set_have_moved_from(true);
if(this->has_error() && this->has_exception())
{
return failure_type<error_type, exception_type>(static_cast<S &&>(this->assume_error()), static_cast<P &&>(this->assume_exception()),
hooks::spare_storage(this));
}
if(this->has_exception())
{
return failure_type<error_type, exception_type>(in_place_type<exception_type>, static_cast<P &&>(this->assume_exception()), hooks::spare_storage(this));
}
return failure_type<error_type, exception_type>(in_place_type<error_type>, static_cast<S &&>(this->assume_error()), hooks::spare_storage(this));
}
#ifdef __APPLE__
failure_type<error_type, exception_type> _xcode_workaround_as_failure() &&;
#endif
};
// C++ 20 operator== rewriting should take care of this for us, indeed
// if we don't disable it, we cause Concept recursion to infinity!
#if __cplusplus < 202000L && !_HAS_CXX20
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class T, class U, class V, //
class R, class S, class P, class N)
OUTCOME_TREQUIRES(OUTCOME_TEXPR(std::declval<basic_outcome<R, S, P, N>>() == std::declval<basic_result<T, U, V>>()))
constexpr inline bool operator==(const basic_result<T, U, V> &a, const basic_outcome<R, S, P, N> &b) noexcept( //
noexcept(std::declval<basic_outcome<R, S, P, N>>() == std::declval<basic_result<T, U, V>>()))
{
return b == a;
}
#endif
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class T, class U, class V, //
class R, class S, class P, class N)
OUTCOME_TREQUIRES(OUTCOME_TEXPR(std::declval<basic_outcome<R, S, P, N>>() != std::declval<basic_result<T, U, V>>()))
constexpr inline bool operator!=(const basic_result<T, U, V> &a, const basic_outcome<R, S, P, N> &b) noexcept( //
noexcept(std::declval<basic_outcome<R, S, P, N>>() != std::declval<basic_result<T, U, V>>()))
{
return b != a;
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
template <class R, class S, class P, class N> inline void swap(basic_outcome<R, S, P, N> &a, basic_outcome<R, S, P, N> &b) noexcept(noexcept(a.swap(b)))
{
a.swap(b);
}
namespace hooks
{
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
template <class R, class S, class P, class NoValuePolicy, class U>
constexpr inline void override_outcome_exception(basic_outcome<R, S, P, NoValuePolicy> *o, U &&v) noexcept
{
o->_ptr = static_cast<U &&>(v); // NOLINT
o->_state._status.set_have_exception(true);
}
} // namespace hooks
OUTCOME_V2_NAMESPACE_END
#ifdef __clang__
#pragma clang diagnostic pop
#endif
#include "detail/basic_outcome_exception_observers_impl.hpp"
#if !defined(NDEBUG)
OUTCOME_V2_NAMESPACE_BEGIN
// Check is trivial in all ways except default constructibility and standard layout
// static_assert(std::is_trivial<basic_outcome<int, long, double, policy::all_narrow>>::value, "outcome<int> is not trivial!");
// static_assert(std::is_trivially_default_constructible<basic_outcome<int, long, double, policy::all_narrow>>::value, "outcome<int> is not trivially default
// constructible!");
static_assert(std::is_trivially_copyable<basic_outcome<int, long, double, policy::all_narrow>>::value, "outcome<int> is not trivially copyable!");
static_assert(std::is_trivially_assignable<basic_outcome<int, long, double, policy::all_narrow>, basic_outcome<int, long, double, policy::all_narrow>>::value,
"outcome<int> is not trivially assignable!");
static_assert(std::is_trivially_destructible<basic_outcome<int, long, double, policy::all_narrow>>::value, "outcome<int> is not trivially destructible!");
static_assert(std::is_trivially_copy_constructible<basic_outcome<int, long, double, policy::all_narrow>>::value,
"outcome<int> is not trivially copy constructible!");
static_assert(std::is_trivially_move_constructible<basic_outcome<int, long, double, policy::all_narrow>>::value,
"outcome<int> is not trivially move constructible!");
static_assert(std::is_trivially_copy_assignable<basic_outcome<int, long, double, policy::all_narrow>>::value, "outcome<int> is not trivially copy assignable!");
static_assert(std::is_trivially_move_assignable<basic_outcome<int, long, double, policy::all_narrow>>::value, "outcome<int> is not trivially move assignable!");
// Can't be standard layout as non-static member data is defined in more than one inherited class
// static_assert(std::is_standard_layout<basic_outcome<int, long, double, policy::all_narrow>>::value, "outcome<int> is not a standard layout type!");
OUTCOME_V2_NAMESPACE_END
#endif
#endif
|
0 | repos/outcome/include | repos/outcome/include/outcome/boost_result.hpp | /* A very simple result type
(C) 2017-2020 Niall Douglas <http://www.nedproductions.biz/> (10 commits)
File Created: June 2017
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License in the accompanying file
Licence.txt or at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Distributed under the Boost Software License, Version 1.0.
(See accompanying file Licence.txt or copy at
http://www.boost.org/LICENSE_1_0.txt)
*/
#ifndef OUTCOME_BOOST_RESULT_HPP
#define OUTCOME_BOOST_RESULT_HPP
#include "config.hpp"
#include "boost/system/system_error.hpp"
#include "boost/exception_ptr.hpp"
#include "boost/version.hpp"
OUTCOME_V2_NAMESPACE_EXPORT_BEGIN
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
namespace policy
{
namespace detail
{
/* Pass through `make_error_code` function for `boost::system::error_code`.
*/
inline boost::system::error_code make_error_code(boost::system::error_code v) { return v; }
/* Pass through `make_exception_ptr` function for `boost::exception_ptr`.
*/
inline boost::exception_ptr make_exception_ptr(boost::exception_ptr v) { return v; }
} // namespace detail
} // namespace policy
OUTCOME_V2_NAMESPACE_END
#include "std_result.hpp"
// ADL injection of outcome_throw_as_system_error_with_payload
namespace boost
{
namespace system
{
inline void outcome_throw_as_system_error_with_payload(const error_code &error) { OUTCOME_THROW_EXCEPTION(system_error(error)); }
namespace errc
{
OUTCOME_TEMPLATE(class Error)
OUTCOME_TREQUIRES(OUTCOME_TPRED(is_error_code_enum<std::decay_t<Error>>::value || is_error_condition_enum<std::decay_t<Error>>::value))
inline void outcome_throw_as_system_error_with_payload(Error &&error) { OUTCOME_THROW_EXCEPTION(system_error(make_error_code(error))); }
} // namespace errc
} // namespace system
} // namespace boost
OUTCOME_V2_NAMESPACE_EXPORT_BEGIN
namespace detail
{
// Customise _set_error_is_errno
template <class State> constexpr inline void _set_error_is_errno(State &state, const boost::system::error_code &error)
{
if(error.category() == boost::system::generic_category()
#ifndef _WIN32
|| error.category() == boost::system::system_category()
#endif
)
{
state._status.set_have_error_is_errno(true);
}
}
template <class State> constexpr inline void _set_error_is_errno(State &state, const boost::system::error_condition &error)
{
if(error.category() == boost::system::generic_category()
#ifndef _WIN32
|| error.category() == boost::system::system_category()
#endif
)
{
state._status.set_have_error_is_errno(true);
}
}
template <class State> constexpr inline void _set_error_is_errno(State &state, const boost::system::errc::errc_t & /*unused*/)
{
state._status.set_have_error_is_errno(true);
}
} // namespace detail
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
namespace trait
{
namespace detail
{
// Shortcut these for lower build impact
template <> struct _is_error_code_available<boost::system::error_code>
{
static constexpr bool value = true;
using type = boost::system::error_code;
};
template <> struct _is_exception_ptr_available<boost::exception_ptr>
{
static constexpr bool value = true;
using type = boost::exception_ptr;
};
} // namespace detail
// boost::system::error_code is an error type
template <> struct is_error_type<boost::system::error_code>
{
static constexpr bool value = true;
};
// boost::system::error_code::errc_t is an error type
template <> struct is_error_type<boost::system::errc::errc_t>
{
static constexpr bool value = true;
};
// boost::exception_ptr is an error types
template <> struct is_error_type<boost::exception_ptr>
{
static constexpr bool value = true;
};
// For boost::system::error_code, boost::system::is_error_condition_enum<> is the trait we want.
template <class Enum> struct is_error_type_enum<boost::system::error_code, Enum>
{
static constexpr bool value = boost::system::is_error_condition_enum<Enum>::value;
};
} // namespace trait
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
template <class R, class S = boost::system::error_code, class NoValuePolicy = policy::default_policy<R, S, void>> //
using boost_result = basic_result<R, S, NoValuePolicy>;
/*! AWAITING HUGO JSON CONVERSION TOOL
type alias template <class R, class S = boost::system::error_code> boost_unchecked. Potential doc page: `boost_unchecked<T, E = boost::system::error_code>`
*/
template <class R, class S = boost::system::error_code> using boost_unchecked = boost_result<R, S, policy::all_narrow>;
/*! AWAITING HUGO JSON CONVERSION TOOL
type alias template <class R, class S = boost::system::error_code> boost_checked. Potential doc page: `boost_checked<T, E = boost::system::error_code>`
*/
template <class R, class S = boost::system::error_code> using boost_checked = boost_result<R, S, policy::throw_bad_result_access<S, void>>;
OUTCOME_V2_NAMESPACE_END
#endif
|
0 | repos/outcome/include | repos/outcome/include/outcome/config.hpp | /* Configure Outcome with QuickCppLib
(C) 2015-2021 Niall Douglas <http://www.nedproductions.biz/> (24 commits)
File Created: August 2015
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License in the accompanying file
Licence.txt or at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Distributed under the Boost Software License, Version 1.0.
(See accompanying file Licence.txt or copy at
http://www.boost.org/LICENSE_1_0.txt)
*/
#ifndef OUTCOME_V2_CONFIG_HPP
#define OUTCOME_V2_CONFIG_HPP
#include "detail/version.hpp"
// Pull in detection of __MINGW64_VERSION_MAJOR
#if defined(__MINGW32__) && !defined(DOXYGEN_IS_IN_THE_HOUSE)
#include <_mingw.h>
#endif
#include "quickcpplib/config.hpp"
#ifndef __cpp_variadic_templates
#error Outcome needs variadic template support in the compiler
#endif
#if __cpp_constexpr < 201304 && _MSC_FULL_VER < 191100000
#error Outcome needs constexpr (C++ 14) support in the compiler
#endif
#ifndef __cpp_variable_templates
#error Outcome needs variable template support in the compiler
#endif
#if !defined(__clang__) && defined(__GNUC__) && __GNUC__ < 6
#error Due to a bug in nested template variables parsing, Outcome does not work on GCCs earlier than v6.
#endif
#ifdef DOXYGEN_IS_IN_THE_HOUSE
#define OUTCOME_FORCEINLINE
#define OUTCOME_NODISCARD [[nodiscard]]
#define OUTCOME_TEMPLATE(...) template <__VA_ARGS__
#define OUTCOME_TREQUIRES(...) , __VA_ARGS__ >
#define OUTCOME_TEXPR(...) typename = decltype(__VA_ARGS__)
#define OUTCOME_TPRED(...) typename = std::enable_if_t<__VA_ARGS__>
#define OUTCOME_REQUIRES(...) requires __VA_ARGS__
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
#endif
#ifndef OUTCOME_SYMBOL_VISIBLE
#define OUTCOME_SYMBOL_VISIBLE QUICKCPPLIB_SYMBOL_VISIBLE
#endif
#ifndef OUTCOME_FORCEINLINE
#define OUTCOME_FORCEINLINE QUICKCPPLIB_FORCEINLINE
#endif
#ifndef OUTCOME_NODISCARD
#define OUTCOME_NODISCARD QUICKCPPLIB_NODISCARD
#endif
#ifndef OUTCOME_THREAD_LOCAL
#define OUTCOME_THREAD_LOCAL QUICKCPPLIB_THREAD_LOCAL
#endif
#ifndef OUTCOME_TEMPLATE
#define OUTCOME_TEMPLATE(...) QUICKCPPLIB_TEMPLATE(__VA_ARGS__)
#endif
#ifndef OUTCOME_TREQUIRES
#define OUTCOME_TREQUIRES(...) QUICKCPPLIB_TREQUIRES(__VA_ARGS__)
#endif
#ifndef OUTCOME_TEXPR
#define OUTCOME_TEXPR(...) QUICKCPPLIB_TEXPR(__VA_ARGS__)
#endif
#ifndef OUTCOME_TPRED
#define OUTCOME_TPRED(...) QUICKCPPLIB_TPRED(__VA_ARGS__)
#endif
#ifndef OUTCOME_REQUIRES
#define OUTCOME_REQUIRES(...) QUICKCPPLIB_REQUIRES(__VA_ARGS__)
#endif
#include "quickcpplib/import.h"
#ifndef OUTCOME_ENABLE_LEGACY_SUPPORT_FOR
#define OUTCOME_ENABLE_LEGACY_SUPPORT_FOR 220 // the v2.2 Outcome release
#endif
#include "detail/revision.hpp"
#if defined(OUTCOME_UNSTABLE_VERSION)
#define OUTCOME_V2 (QUICKCPPLIB_BIND_NAMESPACE_VERSION(outcome_v2, OUTCOME_PREVIOUS_COMMIT_UNIQUE))
#ifdef _DEBUG
#define OUTCOME_V2_CXX_MODULE_NAME QUICKCPPLIB_BIND_NAMESPACE((QUICKCPPLIB_BIND_NAMESPACE_VERSION(outcome_v2d, OUTCOME_PREVIOUS_COMMIT_UNIQUE)))
#else
#define OUTCOME_V2_CXX_MODULE_NAME QUICKCPPLIB_BIND_NAMESPACE((QUICKCPPLIB_BIND_NAMESPACE_VERSION(outcome_v2, OUTCOME_PREVIOUS_COMMIT_UNIQUE)))
#endif
#else
#define OUTCOME_V2 (QUICKCPPLIB_BIND_NAMESPACE_VERSION(outcome_v2))
#ifdef _DEBUG
#define OUTCOME_V2_CXX_MODULE_NAME QUICKCPPLIB_BIND_NAMESPACE((QUICKCPPLIB_BIND_NAMESPACE_VERSION(outcome_v2d)))
#else
#define OUTCOME_V2_CXX_MODULE_NAME QUICKCPPLIB_BIND_NAMESPACE((QUICKCPPLIB_BIND_NAMESPACE_VERSION(outcome_v2)))
#endif
#endif
#if defined(GENERATING_OUTCOME_MODULE_INTERFACE)
#define OUTCOME_V2_NAMESPACE QUICKCPPLIB_BIND_NAMESPACE(OUTCOME_V2)
#define OUTCOME_V2_NAMESPACE_BEGIN QUICKCPPLIB_BIND_NAMESPACE_BEGIN(OUTCOME_V2)
#define OUTCOME_V2_NAMESPACE_EXPORT_BEGIN QUICKCPPLIB_BIND_NAMESPACE_EXPORT_BEGIN(OUTCOME_V2)
#define OUTCOME_V2_NAMESPACE_END QUICKCPPLIB_BIND_NAMESPACE_END(OUTCOME_V2)
#else
#define OUTCOME_V2_NAMESPACE QUICKCPPLIB_BIND_NAMESPACE(OUTCOME_V2)
#define OUTCOME_V2_NAMESPACE_BEGIN QUICKCPPLIB_BIND_NAMESPACE_BEGIN(OUTCOME_V2)
#define OUTCOME_V2_NAMESPACE_EXPORT_BEGIN QUICKCPPLIB_BIND_NAMESPACE_BEGIN(OUTCOME_V2)
#define OUTCOME_V2_NAMESPACE_END QUICKCPPLIB_BIND_NAMESPACE_END(OUTCOME_V2)
#endif
#include <cstdint> // for uint32_t etc
#include <initializer_list>
#include <iosfwd> // for future serialisation
#include <new> // for placement in moves etc
#include <type_traits>
#ifndef OUTCOME_USE_STD_IN_PLACE_TYPE
#if defined(_MSC_VER) && _HAS_CXX17
#define OUTCOME_USE_STD_IN_PLACE_TYPE 1 // MSVC always has std::in_place_type
#elif __cplusplus >= 201700
// libstdc++ before GCC 6 doesn't have it, despite claiming C++ 17 support
#ifdef __has_include
#if !__has_include(<variant>)
#define OUTCOME_USE_STD_IN_PLACE_TYPE 0 // must have it if <variant> is present
#endif
#endif
#ifndef OUTCOME_USE_STD_IN_PLACE_TYPE
#define OUTCOME_USE_STD_IN_PLACE_TYPE 1
#endif
#else
#define OUTCOME_USE_STD_IN_PLACE_TYPE 0
#endif
#endif
#if OUTCOME_USE_STD_IN_PLACE_TYPE
#include <utility> // for in_place_type_t
OUTCOME_V2_NAMESPACE_BEGIN
template <class T> using in_place_type_t = std::in_place_type_t<T>;
using std::in_place_type;
OUTCOME_V2_NAMESPACE_END
#else
OUTCOME_V2_NAMESPACE_BEGIN
/*! AWAITING HUGO JSON CONVERSION TOOL
type definition template <class T> in_place_type_t. Potential doc page: `in_place_type_t<T>`
*/
template <class T> struct in_place_type_t
{
explicit in_place_type_t() = default;
};
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
template <class T> constexpr in_place_type_t<T> in_place_type{};
OUTCOME_V2_NAMESPACE_END
#endif
#if OUTCOME_USE_STD_ADDRESSOF
#include <memory> // for std::addressof
#define OUTCOME_ADDRESS_OF(...) std::addressof(__VA_ARGS__)
#else
#define OUTCOME_ADDRESS_OF(...) (&__VA_ARGS__)
#endif
#ifndef OUTCOME_ASSERT
#include <cassert>
#define OUTCOME_ASSERT(...) assert(__VA_ARGS__)
#endif
#ifndef OUTCOME_TRIVIAL_ABI
#if defined(STANDARDESE_IS_IN_THE_HOUSE) || __clang_major__ >= 7
//! Defined to be `[[clang::trivial_abi]]` when on a new enough clang compiler. Usually automatic, can be overriden.
#define OUTCOME_TRIVIAL_ABI [[clang::trivial_abi]]
#else
#define OUTCOME_TRIVIAL_ABI
#endif
#endif
OUTCOME_V2_NAMESPACE_BEGIN
namespace detail
{
// Test if type is an in_place_type_t
template <class T> struct is_in_place_type_t
{
static constexpr bool value = false;
};
template <class U> struct is_in_place_type_t<in_place_type_t<U>>
{
static constexpr bool value = true;
};
// Replace void with constructible void_type
struct empty_type
{
};
struct void_type
{
// We always compare true to another instance of me
constexpr bool operator==(void_type /*unused*/) const noexcept { return true; }
constexpr bool operator!=(void_type /*unused*/) const noexcept { return false; }
};
template <class T> using devoid = std::conditional_t<std::is_void<T>::value, void_type, T>;
template <class Output, class Input> using rebind_type5 = Output;
template <class Output, class Input>
using rebind_type4 = std::conditional_t< //
std::is_volatile<Input>::value, //
std::add_volatile_t<rebind_type5<Output, std::remove_volatile_t<Input>>>, //
rebind_type5<Output, Input>>;
template <class Output, class Input>
using rebind_type3 = std::conditional_t< //
std::is_const<Input>::value, //
std::add_const_t<rebind_type4<Output, std::remove_const_t<Input>>>, //
rebind_type4<Output, Input>>;
template <class Output, class Input>
using rebind_type2 = std::conditional_t< //
std::is_lvalue_reference<Input>::value, //
std::add_lvalue_reference_t<rebind_type3<Output, std::remove_reference_t<Input>>>, //
rebind_type3<Output, Input>>;
template <class Output, class Input>
using rebind_type = std::conditional_t< //
std::is_rvalue_reference<Input>::value, //
std::add_rvalue_reference_t<rebind_type2<Output, std::remove_reference_t<Input>>>, //
rebind_type2<Output, Input>>;
// static_assert(std::is_same_v<rebind_type<int, volatile const double &&>, volatile const int &&>, "");
/* True if type is the same or constructible. Works around a bug where clang + libstdc++
pukes on std::is_constructible<filesystem::path, void> (this bug is fixed upstream).
*/
template <class T, class U> struct _is_explicitly_constructible
{
static constexpr bool value = std::is_constructible<T, U>::value;
};
template <class T> struct _is_explicitly_constructible<T, void>
{
static constexpr bool value = false;
};
template <> struct _is_explicitly_constructible<void, void>
{
static constexpr bool value = false;
};
template <class T, class U> static constexpr bool is_explicitly_constructible = _is_explicitly_constructible<T, U>::value;
template <class T, class U> struct _is_implicitly_constructible
{
static constexpr bool value = std::is_convertible<U, T>::value;
};
template <class T> struct _is_implicitly_constructible<T, void>
{
static constexpr bool value = false;
};
template <> struct _is_implicitly_constructible<void, void>
{
static constexpr bool value = false;
};
template <class T, class U> static constexpr bool is_implicitly_constructible = _is_implicitly_constructible<T, U>::value;
template <class T, class... Args> struct _is_nothrow_constructible
{
static constexpr bool value = std::is_nothrow_constructible<T, Args...>::value;
};
template <class T> struct _is_nothrow_constructible<T, void>
{
static constexpr bool value = false;
};
template <> struct _is_nothrow_constructible<void, void>
{
static constexpr bool value = false;
};
template <class T, class... Args> static constexpr bool is_nothrow_constructible = _is_nothrow_constructible<T, Args...>::value;
template <class T, class... Args> struct _is_constructible
{
static constexpr bool value = std::is_constructible<T, Args...>::value;
};
template <class T> struct _is_constructible<T, void>
{
static constexpr bool value = false;
};
template <> struct _is_constructible<void, void>
{
static constexpr bool value = false;
};
template <class T, class... Args> static constexpr bool is_constructible = _is_constructible<T, Args...>::value;
#ifndef OUTCOME_USE_STD_IS_NOTHROW_SWAPPABLE
#if defined(_MSC_VER) && _HAS_CXX17
#define OUTCOME_USE_STD_IS_NOTHROW_SWAPPABLE 1 // MSVC always has std::is_nothrow_swappable
#elif __cplusplus >= 201700
// libstdc++ before GCC 6 doesn't have it, despite claiming C++ 17 support
#ifdef __has_include
#if !__has_include(<variant>)
#define OUTCOME_USE_STD_IS_NOTHROW_SWAPPABLE 0
#endif
#endif
#ifndef OUTCOME_USE_STD_IS_NOTHROW_SWAPPABLE
#define OUTCOME_USE_STD_IS_NOTHROW_SWAPPABLE 1
#endif
#else
#define OUTCOME_USE_STD_IS_NOTHROW_SWAPPABLE 0
#endif
#endif
// True if type is nothrow swappable
#if !defined(STANDARDESE_IS_IN_THE_HOUSE) && OUTCOME_USE_STD_IS_NOTHROW_SWAPPABLE
template <class T> using is_nothrow_swappable = std::is_nothrow_swappable<T>;
#else
template <class T> struct is_nothrow_swappable
{
static constexpr bool value = std::is_nothrow_move_constructible<T>::value && std::is_nothrow_move_assignable<T>::value;
};
#endif
} // namespace detail
OUTCOME_V2_NAMESPACE_END
#ifndef OUTCOME_THROW_EXCEPTION
#ifdef __cpp_exceptions
#define OUTCOME_THROW_EXCEPTION(expr) throw expr
#else
#ifdef __ANDROID__
#define OUTCOME_DISABLE_EXECINFO
#endif
#ifndef OUTCOME_DISABLE_EXECINFO
#ifdef _WIN32
#include "quickcpplib/execinfo_win64.h"
#else
#include <execinfo.h>
#endif
#endif // OUTCOME_DISABLE_EXECINFO
#include <cstdio>
#include <cstdlib>
OUTCOME_V2_NAMESPACE_BEGIN
namespace detail
{
QUICKCPPLIB_NORETURN inline void do_fatal_exit(const char *expr)
{
#if !defined(OUTCOME_DISABLE_EXECINFO)
void *bt[16];
size_t btlen = backtrace(bt, sizeof(bt) / sizeof(bt[0])); // NOLINT
#endif
fprintf(stderr, "FATAL: Outcome throws exception %s with exceptions disabled\n", expr); // NOLINT
#if !defined(OUTCOME_DISABLE_EXECINFO)
char **bts = backtrace_symbols(bt, btlen); // NOLINT
if(bts != nullptr)
{
for(size_t n = 0; n < btlen; n++)
{
fprintf(stderr, " %s\n", bts[n]); // NOLINT
}
free(bts); // NOLINT
}
#endif
abort();
}
} // namespace detail
OUTCOME_V2_NAMESPACE_END
#define OUTCOME_THROW_EXCEPTION(expr) OUTCOME_V2_NAMESPACE::detail::do_fatal_exit(#expr), (void) (expr)
#endif
#endif
#ifndef BOOST_OUTCOME_AUTO_TEST_CASE
#define BOOST_OUTCOME_AUTO_TEST_CASE(a, b) BOOST_AUTO_TEST_CASE(a, b)
#endif
#endif
|
0 | repos/outcome/include | repos/outcome/include/outcome/std_outcome.hpp | /* A less simple result type
(C) 2017-2019 Niall Douglas <http://www.nedproductions.biz/> (6 commits)
File Created: June 2017
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License in the accompanying file
Licence.txt or at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Distributed under the Boost Software License, Version 1.0.
(See accompanying file Licence.txt or copy at
http://www.boost.org/LICENSE_1_0.txt)
*/
#ifndef OUTCOME_STD_OUTCOME_HPP
#define OUTCOME_STD_OUTCOME_HPP
#include "basic_outcome.hpp"
#include "std_result.hpp"
#ifndef STD_BASIC_OUTCOME_FAILURE_EXCEPTION_FROM_ERROR
#define STD_BASIC_OUTCOME_FAILURE_EXCEPTION_FROM_ERROR
namespace std // NOLINT
{
inline exception_ptr basic_outcome_failure_exception_from_error(const error_code &ec) { return make_exception_ptr(system_error(ec)); }
} // namespace std
#endif
OUTCOME_V2_NAMESPACE_EXPORT_BEGIN
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
template <class R, class S = std::error_code, class P = std::exception_ptr, class NoValuePolicy = policy::default_policy<R, S, P>> //
using std_outcome = basic_outcome<R, S, P, NoValuePolicy>;
OUTCOME_V2_NAMESPACE_END
#include "policy/outcome_error_code_throw_as_system_error.hpp"
#include "policy/outcome_exception_ptr_rethrow.hpp"
#endif
|
0 | repos/outcome/include | repos/outcome/include/outcome/outcome_gdb.py | import gdb.printing
import os
def synthesise_gdb_value_from_string(s):
'''For when you want to return a synthetic string from children()'''
return gdb.Value(s + '\0').cast(gdb.lookup_type('char').pointer())
class OutcomeBasicOutcomePrinter(object):
'''Print an outcome::basic_outcome<T> and outcome::basic_result<T>'''
def __init__(self, val):
self.val = val
def children(self):
if self.val['_state']['_status']['status_value'] & 1 == 1:
yield ('value', self.val['_state']['_value'])
if self.val['_state']['_status']['status_value'] & 2 == 2:
yield ('error', self.val['_state']['_error'])
if self.val['_state']['_status']['status_value'] & 4 == 4:
yield ('exception', self.val['_ptr'])
def display_hint(self):
return None
def to_string(self):
if self.val['_state']['_status']['status_value'] & 54 == 54:
return 'errored (errno, moved from) + exceptioned'
if self.val['_state']['_status']['status_value'] & 50 == 50:
return 'errored (errno, moved from)'
if self.val['_state']['_status']['status_value'] & 38 == 38:
return 'errored + exceptioned (moved from)'
if self.val['_state']['_status']['status_value'] & 36 == 36:
return 'exceptioned (moved from)'
if self.val['_state']['_status']['status_value'] & 35 == 35:
return 'errored (moved from)'
if self.val['_state']['_status']['status_value'] & 33 == 33:
return 'valued (moved from)'
if self.val['_state']['_status']['status_value'] & 22 == 22:
return 'errored (errno) + exceptioned'
if self.val['_state']['_status']['status_value'] & 18 == 18:
return 'errored (errno)'
if self.val['_state']['_status']['status_value'] & 6 == 6:
return 'errored + exceptioned'
if self.val['_state']['_status']['status_value'] & 4 == 4:
return 'exceptioned'
if self.val['_state']['_status']['status_value'] & 2 == 2:
return 'errored'
if self.val['_state']['_status']['status_value'] & 1 == 1:
return 'valued'
if self.val['_state']['_status']['status_value'] & 0xff == 0:
return 'empty'
class OutcomeCResultStatusPrinter(object):
'''Print a C result'''
def __init__(self, val):
self.val = val
def children(self):
if self.val['flags'] & 1 == 1:
yield ('value', self.val['value'])
if self.val['flags'] & 2 == 2:
yield ('error', self.val['error'])
def display_hint(self):
return None
def to_string(self):
if self.val['flags'] & 50 == 50:
return 'errored (errno, moved from)'
if self.val['flags'] & 35 == 35:
return 'errored (moved from)'
if self.val['flags'] & 33 == 33:
return 'valued (moved from)'
if self.val['flags'] & 18 == 18:
return 'errored (errno)'
if self.val['flags'] & 2 == 2:
return 'errored'
if self.val['flags'] & 1 == 1:
return 'valued'
if self.val['flags'] & 0xff == 0:
return 'empty'
class OutcomeCStatusCodePrinter(object):
'''Print a C status code'''
def __init__(self, val):
self.val = val
def children(self):
yield ('domain', self.val['domain'])
yield ('value', self.val['value'])
def display_hint(self):
return None
def to_string(self):
s = str(self.val['domain'])
if 'posix_code_domain' in s or 'generic_code_domain' in s:
return str(self.val['value']) + ' (' + os.strerror(int(self.val['value'])) + ')'
else:
return self.val['value']
def build_pretty_printer():
pp = gdb.printing.RegexpCollectionPrettyPrinter('outcome_v2')
pp.add_printer('outcome_v2::basic_result', '^(boost::)?outcome_v2[_0-9a-f]*::basic_result<.*>$', OutcomeBasicOutcomePrinter)
pp.add_printer('outcome_v2::basic_outcome', '^(boost::)?outcome_v2[_0-9a-f]*::basic_outcome<.*>$', OutcomeBasicOutcomePrinter)
pp.add_printer('cxx_result_status_code_*', '^cxx_result_status_code_.*$', OutcomeCResultStatusPrinter)
pp.add_printer('cxx_status_code_*', '^cxx_status_code_.*$', OutcomeCStatusCodePrinter)
return pp
def register_printers(obj = None):
gdb.printing.register_pretty_printer(obj, build_pretty_printer(), replace = True)
register_printers(gdb.current_objfile())
|
0 | repos/outcome/include | repos/outcome/include/outcome/outcome.hpp | /* A less simple result type
(C) 2017-2019 Niall Douglas <http://www.nedproductions.biz/> (79 commits)
File Created: June 2017
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License in the accompanying file
Licence.txt or at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Distributed under the Boost Software License, Version 1.0.
(See accompanying file Licence.txt or copy at
http://www.boost.org/LICENSE_1_0.txt)
*/
#ifndef OUTCOME_OUTCOME_HPP
#define OUTCOME_OUTCOME_HPP
#include "result.hpp"
#include "std_outcome.hpp"
OUTCOME_V2_NAMESPACE_EXPORT_BEGIN
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
template <class R, class S = std::error_code, class P = std::exception_ptr, class NoValuePolicy = policy::default_policy<R, S, P>> //
using outcome = std_outcome<R, S, P, NoValuePolicy>;
OUTCOME_V2_NAMESPACE_END
#endif
|
0 | repos/outcome/include | repos/outcome/include/outcome/basic_result.hpp | /* A very simple result type
(C) 2017-2024 Niall Douglas <http://www.nedproductions.biz/> (14 commits)
File Created: June 2017
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License in the accompanying file
Licence.txt or at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Distributed under the Boost Software License, Version 1.0.
(See accompanying file Licence.txt or copy at
http://www.boost.org/LICENSE_1_0.txt)
*/
#ifndef OUTCOME_BASIC_RESULT_HPP
#define OUTCOME_BASIC_RESULT_HPP
#include "config.hpp"
#include "convert.hpp"
#include "detail/basic_result_final.hpp"
#include "outcome_gdb.h"
#include "policy/all_narrow.hpp"
#include "policy/terminate.hpp"
#ifdef __clang__
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdocumentation" // Standardese markup confuses clang
#endif
OUTCOME_V2_NAMESPACE_EXPORT_BEGIN
template <class R, class S, class NoValuePolicy> //
class basic_result;
namespace detail
{
// These are reused by basic_outcome to save load on the compiler
template <class value_type, class error_type> struct result_predicates
{
// Predicate for the implicit constructors to be available. Weakened to allow result<int, C enum>.
static constexpr bool implicit_constructors_enabled = //
!(trait::is_error_type<std::decay_t<value_type>>::value &&
trait::is_error_type<std::decay_t<error_type>>::value) // both value and error types are not whitelisted error types
&& ((!detail::is_implicitly_constructible<value_type, error_type> &&
!detail::is_implicitly_constructible<error_type, value_type>) // if value and error types cannot be constructed into one another
|| (trait::is_error_type<std::decay_t<error_type>>::value // if error type is a whitelisted error type
&& !detail::is_implicitly_constructible<error_type, value_type> // AND which cannot be constructed from the value type
&& std::is_integral<value_type>::value)); // AND the value type is some integral type
// Predicate for the value converting constructor to be available. Weakened to allow result<int, C enum>.
template <class T>
static constexpr bool enable_value_converting_constructor = //
implicit_constructors_enabled //
&& !is_in_place_type_t<std::decay_t<T>>::value // not in place construction
&& !trait::is_error_type_enum<error_type, std::decay_t<T>>::value // not an enum valid for my error type
&& ((detail::is_implicitly_constructible<value_type, T> && !detail::is_implicitly_constructible<error_type, T>) // is unambiguously for value type
|| (std::is_same<value_type, std::decay_t<T>>::value // OR is my value type exactly
&& detail::is_implicitly_constructible<value_type, T>) ); // and my value type is constructible from this ref form of T
// Predicate for the error converting constructor to be available. Weakened to allow result<int, C enum>.
template <class T>
static constexpr bool enable_error_converting_constructor = //
implicit_constructors_enabled //
&& !is_in_place_type_t<std::decay_t<T>>::value // not in place construction
&& !trait::is_error_type_enum<error_type, std::decay_t<T>>::value // not an enum valid for my error type
&& ((!detail::is_implicitly_constructible<value_type, T> && detail::is_implicitly_constructible<error_type, T>) // is unambiguously for error type
|| (std::is_same<error_type, std::decay_t<T>>::value // OR is my error type exactly
&& detail::is_implicitly_constructible<error_type, T>) ); // and my error type is constructible from this ref form of T
// Predicate for the error condition converting constructor to be available.
template <class ErrorCondEnum>
static constexpr bool enable_error_condition_converting_constructor = //
!is_in_place_type_t<std::decay_t<ErrorCondEnum>>::value // not in place construction
&& trait::is_error_type_enum<error_type, std::decay_t<ErrorCondEnum>>::value // is an error condition enum
/*&& !detail::is_implicitly_constructible<value_type, ErrorCondEnum> && !detail::is_implicitly_constructible<error_type, ErrorCondEnum>*/; // not
// constructible
// via any other
// means
// Predicate for the converting constructor from a compatible input to be available.
template <class T, class U, class V>
static constexpr bool enable_compatible_conversion = //
(std::is_void<T>::value ||
detail::is_explicitly_constructible<value_type, typename basic_result<T, U, V>::value_type>) // if our value types are constructible
&&(std::is_void<U>::value ||
detail::is_explicitly_constructible<error_type, typename basic_result<T, U, V>::error_type>) // if our error types are constructible
;
// Predicate for the converting constructor from a make_error_code() of the input to be available.
template <class T, class U, class V>
static constexpr bool enable_make_error_code_compatible_conversion = //
trait::is_error_code_available<std::decay_t<error_type>>::value // if error type has an error code
&& !enable_compatible_conversion<T, U, V> // and the normal compatible conversion is not available
&& (std::is_void<T>::value ||
detail::is_explicitly_constructible<value_type, typename basic_result<T, U, V>::value_type>) // and if our value types are constructible
&&detail::is_explicitly_constructible<error_type,
typename trait::is_error_code_available<U>::type>; // and our error type is constructible from a make_error_code()
// Predicate for the converting constructor from a make_exception_ptr() of the input to be available.
template <class T, class U, class V>
static constexpr bool enable_make_exception_ptr_compatible_conversion = //
trait::is_exception_ptr_available<std::decay_t<error_type>>::value // if error type has an exception ptr
&& !enable_compatible_conversion<T, U, V> // and the normal compatible conversion is not available
&& (std::is_void<T>::value ||
detail::is_explicitly_constructible<value_type, typename basic_result<T, U, V>::value_type>) // and if our value types are constructible
&&detail::is_explicitly_constructible<error_type, typename trait::is_exception_ptr_available<U>::type>; // and our error type is constructible from a
// make_exception_ptr()
// Predicate for the implicit converting inplace constructor from a compatible input to be available.
struct disable_inplace_value_error_constructor;
template <class... Args>
using choose_inplace_value_error_constructor = std::conditional_t< //
detail::is_constructible<value_type, Args...> && detail::is_constructible<error_type, Args...>, //
disable_inplace_value_error_constructor, //
std::conditional_t< //
detail::is_constructible<value_type, Args...>, //
value_type, //
std::conditional_t< //
detail::is_constructible<error_type, Args...>, //
error_type, //
disable_inplace_value_error_constructor>>>;
template <class... Args>
static constexpr bool enable_inplace_value_error_constructor =
implicit_constructors_enabled //
&& !std::is_same<choose_inplace_value_error_constructor<Args...>, disable_inplace_value_error_constructor>::value;
};
template <class T, class U> constexpr inline const U &extract_value_from_success(const success_type<U> &v)
{
return v.value();
}
template <class T, class U> constexpr inline U &&extract_value_from_success(success_type<U> &&v)
{
return static_cast<success_type<U> &&>(v).value();
}
template <class T> constexpr inline T extract_value_from_success(const success_type<void> & /*unused*/)
{
return T{};
}
template <class T, class U, class V> constexpr inline const U &extract_error_from_failure(const failure_type<U, V> &v)
{
return v.error();
}
template <class T, class U, class V> constexpr inline U &&extract_error_from_failure(failure_type<U, V> &&v)
{
return static_cast<failure_type<U, V> &&>(v).error();
}
template <class T, class V> constexpr inline T extract_error_from_failure(const failure_type<void, V> & /*unused*/)
{
return T{};
}
template <class T> struct is_basic_result
{
static constexpr bool value = false;
};
template <class R, class S, class T> struct is_basic_result<basic_result<R, S, T>>
{
static constexpr bool value = true;
};
} // namespace detail
/*! AWAITING HUGO JSON CONVERSION TOOL
type alias template <class T> is_basic_result. Potential doc page: `is_basic_result<T>`
*/
template <class T> using is_basic_result = detail::is_basic_result<std::decay_t<T>>;
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
template <class T> static constexpr bool is_basic_result_v = detail::is_basic_result<std::decay_t<T>>::value;
namespace concepts
{
#if defined(__cpp_concepts)
/* The `basic_result` concept.
\requires That `U` matches a `basic_result`.
*/
template <class U>
concept OUTCOME_GCC6_CONCEPT_BOOL basic_result =
OUTCOME_V2_NAMESPACE::is_basic_result<U>::value ||
(requires(U v) { OUTCOME_V2_NAMESPACE::basic_result<typename U::value_type, typename U::error_type, typename U::no_value_policy_type>(v); } && //
detail::convertible<U, OUTCOME_V2_NAMESPACE::basic_result<typename U::value_type, typename U::error_type, typename U::no_value_policy_type>> && //
detail::base_of<OUTCOME_V2_NAMESPACE::basic_result<typename U::value_type, typename U::error_type, typename U::no_value_policy_type>, U>);
#else
namespace detail
{
inline no_match match_basic_result(...);
template <class R, class S, class NVP, class T, //
typename = typename T::value_type, //
typename = typename T::error_type, //
typename = typename T::no_value_policy_type, //
typename std::enable_if_t<std::is_convertible<T, OUTCOME_V2_NAMESPACE::basic_result<R, S, NVP>>::value && //
std::is_base_of<OUTCOME_V2_NAMESPACE::basic_result<R, S, NVP>, T>::value,
bool> = true>
inline OUTCOME_V2_NAMESPACE::basic_result<R, S, NVP> match_basic_result(OUTCOME_V2_NAMESPACE::basic_result<R, S, NVP> &&, T &&);
template <class U>
static constexpr bool basic_result = OUTCOME_V2_NAMESPACE::is_basic_result<U>::value ||
!std::is_same<no_match, decltype(match_basic_result(std::declval<OUTCOME_V2_NAMESPACE::detail::devoid<U>>(),
std::declval<OUTCOME_V2_NAMESPACE::detail::devoid<U>>()))>::value;
} // namespace detail
/* The `basic_result` concept.
\requires That `U` matches a `basic_result`.
*/
template <class U> static constexpr bool basic_result = detail::basic_result<U>;
#endif
} // namespace concepts
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
namespace hooks
{
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
template <class R, class S, class NoValuePolicy> constexpr inline uint16_t spare_storage(const detail::basic_result_storage<R, S, NoValuePolicy> *r) noexcept
{
return r->_state._status.spare_storage_value;
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
template <class R, class S, class NoValuePolicy>
constexpr inline void set_spare_storage(detail::basic_result_storage<R, S, NoValuePolicy> *r, uint16_t v) noexcept
{
r->_state._status.spare_storage_value = v;
}
} // namespace hooks
/*! AWAITING HUGO JSON CONVERSION TOOL
type definition template <class R, class S, class NoValuePolicy> basic_result. Potential doc page: `basic_result<T, E, NoValuePolicy>`
*/
template <class R, class S, class NoValuePolicy> //
class OUTCOME_NODISCARD basic_result : public detail::basic_result_final<R, S, NoValuePolicy>
{
static_assert(trait::type_can_be_used_in_basic_result<R>, "The type R cannot be used in a basic_result");
static_assert(trait::type_can_be_used_in_basic_result<S>, "The type S cannot be used in a basic_result");
using base = detail::basic_result_final<R, S, NoValuePolicy>;
struct implicit_constructors_disabled_tag
{
};
struct value_converting_constructor_tag
{
};
struct error_converting_constructor_tag
{
};
struct error_condition_converting_constructor_tag
{
};
struct explicit_valueornone_converting_constructor_tag
{
};
struct explicit_valueorerror_converting_constructor_tag
{
};
struct explicit_compatible_copy_conversion_tag
{
};
struct explicit_compatible_move_conversion_tag
{
};
struct explicit_make_error_code_compatible_copy_conversion_tag
{
};
struct explicit_make_error_code_compatible_move_conversion_tag
{
};
struct explicit_make_exception_ptr_compatible_copy_conversion_tag
{
};
struct explicit_make_exception_ptr_compatible_move_conversion_tag
{
};
public:
using value_type = R;
using error_type = S;
using no_value_policy_type = NoValuePolicy;
using value_type_if_enabled = typename base::_value_type;
using error_type_if_enabled = typename base::_error_type;
template <class T, class U = S, class V = NoValuePolicy> using rebind = basic_result<T, U, V>;
protected:
// Requirement predicates for result.
struct predicate
{
using base = detail::result_predicates<value_type, error_type>;
// Predicate for any constructors to be available at all
static constexpr bool constructors_enabled = !std::is_same<std::decay_t<value_type>, std::decay_t<error_type>>::value;
// Predicate for implicit constructors to be available at all
static constexpr bool implicit_constructors_enabled = constructors_enabled && base::implicit_constructors_enabled;
// Predicate for the value converting constructor to be available.
template <class T>
static constexpr bool enable_value_converting_constructor = //
constructors_enabled //
&& !std::is_same<std::decay_t<T>, basic_result>::value // not my type
&& base::template enable_value_converting_constructor<T>;
// Predicate for the error converting constructor to be available.
template <class T>
static constexpr bool enable_error_converting_constructor = //
constructors_enabled //
&& !std::is_same<std::decay_t<T>, basic_result>::value // not my type
&& base::template enable_error_converting_constructor<T>;
// Predicate for the error condition converting constructor to be available.
template <class ErrorCondEnum>
static constexpr bool enable_error_condition_converting_constructor = //
constructors_enabled //
&& !std::is_same<std::decay_t<ErrorCondEnum>, basic_result>::value // not my type
&& base::template enable_error_condition_converting_constructor<ErrorCondEnum>;
// Predicate for the converting constructor from a compatible input to be available.
template <class T, class U, class V>
static constexpr bool enable_compatible_conversion = //
constructors_enabled //
&& !std::is_same<basic_result<T, U, V>, basic_result>::value // not my type
&& base::template enable_compatible_conversion<T, U, V>;
// Predicate for the converting constructor from a make_error_code() of the input to be available.
template <class T, class U, class V>
static constexpr bool enable_make_error_code_compatible_conversion = //
constructors_enabled //
&& !std::is_same<basic_result<T, U, V>, basic_result>::value // not my type
&& base::template enable_make_error_code_compatible_conversion<T, U, V>;
// Predicate for the converting constructor from a make_exception_ptr() of the input to be available.
template <class T, class U, class V>
static constexpr bool enable_make_exception_ptr_compatible_conversion = //
constructors_enabled //
&& !std::is_same<basic_result<T, U, V>, basic_result>::value // not my type
&& base::template enable_make_exception_ptr_compatible_conversion<T, U, V>;
// Predicate for the inplace construction of value to be available.
template <class... Args>
static constexpr bool enable_inplace_value_constructor = //
constructors_enabled //
&& (std::is_void<value_type>::value //
|| detail::is_constructible<value_type, Args...>);
// Predicate for the inplace construction of error to be available.
template <class... Args>
static constexpr bool enable_inplace_error_constructor = //
constructors_enabled //
&& (std::is_void<error_type>::value //
|| detail::is_constructible<error_type, Args...>);
// Predicate for the implicit converting inplace constructor to be available.
template <class... Args>
static constexpr bool enable_inplace_value_error_constructor = //
constructors_enabled //
&& base::template enable_inplace_value_error_constructor<Args...>;
template <class... Args> using choose_inplace_value_error_constructor = typename base::template choose_inplace_value_error_constructor<Args...>;
};
public:
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
basic_result() = delete;
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
basic_result(basic_result && /*unused*/) = default; // NOLINT
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
basic_result(const basic_result & /*unused*/) = default;
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
basic_result &operator=(basic_result && /*unused*/) = default; // NOLINT
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
basic_result &operator=(const basic_result & /*unused*/) = default;
~basic_result() = default;
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class Arg, class... Args)
OUTCOME_TREQUIRES(OUTCOME_TPRED(!predicate::constructors_enabled && (sizeof...(Args) >= 0)))
basic_result(Arg && /*unused*/, Args &&.../*unused*/) = delete; // NOLINT basic_result<T, T> is NOT SUPPORTED, see docs!
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class T)
OUTCOME_TREQUIRES(OUTCOME_TPRED((predicate::constructors_enabled && !predicate::implicit_constructors_enabled //
&& (detail::is_implicitly_constructible<value_type, T> || detail::is_implicitly_constructible<error_type, T>) )))
basic_result(T && /*unused*/, implicit_constructors_disabled_tag /*unused*/ = implicit_constructors_disabled_tag()) =
delete; // NOLINT Implicit constructors disabled, use explicit in_place_type<T>, success() or failure(). see docs!
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class T)
OUTCOME_TREQUIRES(OUTCOME_TPRED(predicate::template enable_value_converting_constructor<T>))
constexpr basic_result(T &&t, value_converting_constructor_tag /*unused*/ = value_converting_constructor_tag()) noexcept(
detail::is_nothrow_constructible<value_type, T>) // NOLINT
: base{in_place_type<typename base::value_type>, static_cast<T &&>(t)}
{
no_value_policy_type::on_result_construction(this, static_cast<T &&>(t));
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class T)
OUTCOME_TREQUIRES(OUTCOME_TPRED(predicate::template enable_error_converting_constructor<T>))
constexpr basic_result(T &&t, error_converting_constructor_tag /*unused*/ = error_converting_constructor_tag()) noexcept(
detail::is_nothrow_constructible<error_type, T>) // NOLINT
: base{in_place_type<typename base::error_type>, static_cast<T &&>(t)}
{
no_value_policy_type::on_result_construction(this, static_cast<T &&>(t));
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class ErrorCondEnum)
OUTCOME_TREQUIRES(OUTCOME_TEXPR(error_type(make_error_code(ErrorCondEnum()))), //
OUTCOME_TPRED(predicate::template enable_error_condition_converting_constructor<ErrorCondEnum>))
constexpr basic_result(ErrorCondEnum &&t, error_condition_converting_constructor_tag /*unused*/ = error_condition_converting_constructor_tag()) noexcept(
noexcept(error_type(make_error_code(static_cast<ErrorCondEnum &&>(t))))) // NOLINT
: base{in_place_type<typename base::error_type>, make_error_code(t)}
{
no_value_policy_type::on_result_construction(this, static_cast<ErrorCondEnum &&>(t));
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class T)
OUTCOME_TREQUIRES(OUTCOME_TPRED(convert::value_or_error<basic_result, std::decay_t<T>>::enable_result_inputs || !concepts::basic_result<T>), //
OUTCOME_TEXPR(convert::value_or_error<basic_result, std::decay_t<T>>{}(std::declval<T>())))
constexpr explicit basic_result(T &&o,
explicit_valueorerror_converting_constructor_tag /*unused*/ = explicit_valueorerror_converting_constructor_tag()) // NOLINT
: basic_result{convert::value_or_error<basic_result, std::decay_t<T>>{}(static_cast<T &&>(o))}
{
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class T, class U, class V)
OUTCOME_TREQUIRES(OUTCOME_TPRED(predicate::template enable_compatible_conversion<T, U, V>))
constexpr explicit basic_result(
const basic_result<T, U, V> &o,
explicit_compatible_copy_conversion_tag /*unused*/ = explicit_compatible_copy_conversion_tag()) noexcept(detail::is_nothrow_constructible<value_type, T> &&
detail::is_nothrow_constructible<error_type, U>)
: base{typename base::compatible_conversion_tag(), o}
{
no_value_policy_type::on_result_copy_construction(this, o);
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class T, class U, class V)
OUTCOME_TREQUIRES(OUTCOME_TPRED(predicate::template enable_compatible_conversion<T, U, V>))
constexpr explicit basic_result(
basic_result<T, U, V> &&o,
explicit_compatible_move_conversion_tag /*unused*/ = explicit_compatible_move_conversion_tag()) noexcept(detail::is_nothrow_constructible<value_type, T> &&
detail::is_nothrow_constructible<error_type, U>)
: base{typename base::compatible_conversion_tag(), static_cast<basic_result<T, U, V> &&>(o)}
{
no_value_policy_type::on_result_move_construction(this, static_cast<basic_result<T, U, V> &&>(o));
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class T, class U, class V)
OUTCOME_TREQUIRES(OUTCOME_TPRED(predicate::template enable_make_error_code_compatible_conversion<T, U, V>))
constexpr explicit basic_result(const basic_result<T, U, V> &o,
explicit_make_error_code_compatible_copy_conversion_tag /*unused*/ =
explicit_make_error_code_compatible_copy_conversion_tag()) noexcept(detail::is_nothrow_constructible<value_type, T> &&
noexcept(make_error_code(std::declval<U>())))
: base{typename base::make_error_code_compatible_conversion_tag(), o}
{
no_value_policy_type::on_result_copy_construction(this, o);
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class T, class U, class V)
OUTCOME_TREQUIRES(OUTCOME_TPRED(predicate::template enable_make_error_code_compatible_conversion<T, U, V>))
constexpr explicit basic_result(basic_result<T, U, V> &&o,
explicit_make_error_code_compatible_move_conversion_tag /*unused*/ =
explicit_make_error_code_compatible_move_conversion_tag()) noexcept(detail::is_nothrow_constructible<value_type, T> &&
noexcept(make_error_code(std::declval<U>())))
: base{typename base::make_error_code_compatible_conversion_tag(), static_cast<basic_result<T, U, V> &&>(o)}
{
no_value_policy_type::on_result_move_construction(this, static_cast<basic_result<T, U, V> &&>(o));
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class T, class U, class V)
OUTCOME_TREQUIRES(OUTCOME_TPRED(predicate::template enable_make_exception_ptr_compatible_conversion<T, U, V>))
constexpr explicit basic_result(const basic_result<T, U, V> &o,
explicit_make_exception_ptr_compatible_copy_conversion_tag /*unused*/ =
explicit_make_exception_ptr_compatible_copy_conversion_tag()) noexcept(detail::is_nothrow_constructible<value_type, T> &&
noexcept(make_exception_ptr(std::declval<U>())))
: base{typename base::make_exception_ptr_compatible_conversion_tag(), o}
{
no_value_policy_type::on_result_copy_construction(this, o);
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class T, class U, class V)
OUTCOME_TREQUIRES(OUTCOME_TPRED(predicate::template enable_make_exception_ptr_compatible_conversion<T, U, V>))
constexpr explicit basic_result(basic_result<T, U, V> &&o,
explicit_make_exception_ptr_compatible_move_conversion_tag /*unused*/ =
explicit_make_exception_ptr_compatible_move_conversion_tag()) noexcept(detail::is_nothrow_constructible<value_type, T> &&
noexcept(make_exception_ptr(std::declval<U>())))
: base{typename base::make_exception_ptr_compatible_conversion_tag(), static_cast<basic_result<T, U, V> &&>(o)}
{
no_value_policy_type::on_result_move_construction(this, static_cast<basic_result<T, U, V> &&>(o));
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class... Args)
OUTCOME_TREQUIRES(OUTCOME_TPRED(predicate::template enable_inplace_value_constructor<Args...>))
constexpr explicit basic_result(in_place_type_t<value_type_if_enabled> _, Args &&...args) noexcept(detail::is_nothrow_constructible<value_type, Args...>)
: base{_, static_cast<Args &&>(args)...}
{
no_value_policy_type::on_result_in_place_construction(this, in_place_type<value_type>, static_cast<Args &&>(args)...);
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class U, class... Args)
OUTCOME_TREQUIRES(OUTCOME_TPRED(predicate::template enable_inplace_value_constructor<std::initializer_list<U>, Args...>))
constexpr explicit basic_result(in_place_type_t<value_type_if_enabled> _, std::initializer_list<U> il,
Args &&...args) noexcept(detail::is_nothrow_constructible<value_type, std::initializer_list<U>, Args...>)
: base{_, il, static_cast<Args &&>(args)...}
{
no_value_policy_type::on_result_in_place_construction(this, in_place_type<value_type>, il, static_cast<Args &&>(args)...);
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class... Args)
OUTCOME_TREQUIRES(OUTCOME_TPRED(predicate::template enable_inplace_error_constructor<Args...>))
constexpr explicit basic_result(in_place_type_t<error_type_if_enabled> _, Args &&...args) noexcept(detail::is_nothrow_constructible<error_type, Args...>)
: base{_, static_cast<Args &&>(args)...}
{
no_value_policy_type::on_result_in_place_construction(this, in_place_type<error_type>, static_cast<Args &&>(args)...);
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class U, class... Args)
OUTCOME_TREQUIRES(OUTCOME_TPRED(predicate::template enable_inplace_error_constructor<std::initializer_list<U>, Args...>))
constexpr explicit basic_result(in_place_type_t<error_type_if_enabled> _, std::initializer_list<U> il,
Args &&...args) noexcept(detail::is_nothrow_constructible<error_type, std::initializer_list<U>, Args...>)
: base{_, il, static_cast<Args &&>(args)...}
{
no_value_policy_type::on_result_in_place_construction(this, in_place_type<error_type>, il, static_cast<Args &&>(args)...);
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class A1, class A2, class... Args)
OUTCOME_TREQUIRES(OUTCOME_TPRED(predicate::template enable_inplace_value_error_constructor<A1, A2, Args...>))
constexpr basic_result(A1 &&a1, A2 &&a2, Args &&...args) noexcept(noexcept(
typename predicate::template choose_inplace_value_error_constructor<A1, A2, Args...>(std::declval<A1>(), std::declval<A2>(), std::declval<Args>()...)))
: basic_result(in_place_type<typename predicate::template choose_inplace_value_error_constructor<A1, A2, Args...>>, static_cast<A1 &&>(a1),
static_cast<A2 &&>(a2), static_cast<Args &&>(args)...)
{
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
constexpr basic_result(const success_type<void> &o) noexcept(std::is_nothrow_default_constructible<value_type>::value) // NOLINT
: base{in_place_type<value_type_if_enabled>}
{
hooks::set_spare_storage(this, o.spare_storage());
no_value_policy_type::on_result_copy_construction(this, o);
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class T)
OUTCOME_TREQUIRES(OUTCOME_TPRED(predicate::template enable_compatible_conversion<T, void, void>))
constexpr basic_result(const success_type<T> &o) noexcept(detail::is_nothrow_constructible<value_type, T>) // NOLINT
: base{in_place_type<value_type_if_enabled>, detail::extract_value_from_success<value_type>(o)}
{
hooks::set_spare_storage(this, o.spare_storage());
no_value_policy_type::on_result_copy_construction(this, o);
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class T)
OUTCOME_TREQUIRES(OUTCOME_TPRED(!std::is_void<T>::value && predicate::template enable_compatible_conversion<T, void, void>))
constexpr basic_result(success_type<T> &&o) noexcept(detail::is_nothrow_constructible<value_type, T>) // NOLINT
: base{in_place_type<value_type_if_enabled>, detail::extract_value_from_success<value_type>(static_cast<success_type<T> &&>(o))}
{
hooks::set_spare_storage(this, o.spare_storage());
no_value_policy_type::on_result_move_construction(this, static_cast<success_type<T> &&>(o));
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class T)
OUTCOME_TREQUIRES(OUTCOME_TPRED(predicate::template enable_compatible_conversion<void, T, void>))
constexpr basic_result(const failure_type<T> &o, explicit_compatible_copy_conversion_tag /*unused*/ = explicit_compatible_copy_conversion_tag()) noexcept(
detail::is_nothrow_constructible<error_type, T>) // NOLINT
: base{in_place_type<error_type_if_enabled>, detail::extract_error_from_failure<error_type>(o)}
{
hooks::set_spare_storage(this, o.spare_storage());
no_value_policy_type::on_result_copy_construction(this, o);
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class T)
OUTCOME_TREQUIRES(OUTCOME_TPRED(predicate::template enable_compatible_conversion<void, T, void>))
constexpr basic_result(failure_type<T> &&o, explicit_compatible_move_conversion_tag /*unused*/ = explicit_compatible_move_conversion_tag()) noexcept(
detail::is_nothrow_constructible<error_type, T>) // NOLINT
: base{in_place_type<error_type_if_enabled>, detail::extract_error_from_failure<error_type>(static_cast<failure_type<T> &&>(o))}
{
hooks::set_spare_storage(this, o.spare_storage());
no_value_policy_type::on_result_move_construction(this, static_cast<failure_type<T> &&>(o));
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class T)
OUTCOME_TREQUIRES(OUTCOME_TPRED(predicate::template enable_make_error_code_compatible_conversion<void, T, void>))
constexpr basic_result(const failure_type<T> &o,
explicit_make_error_code_compatible_copy_conversion_tag /*unused*/ =
explicit_make_error_code_compatible_copy_conversion_tag()) noexcept(noexcept(make_error_code(std::declval<T>()))) // NOLINT
: base{in_place_type<error_type_if_enabled>, make_error_code(detail::extract_error_from_failure<error_type>(o))}
{
hooks::set_spare_storage(this, o.spare_storage());
no_value_policy_type::on_result_copy_construction(this, o);
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class T)
OUTCOME_TREQUIRES(OUTCOME_TPRED(predicate::template enable_make_error_code_compatible_conversion<void, T, void>))
constexpr basic_result(failure_type<T> &&o,
explicit_make_error_code_compatible_move_conversion_tag /*unused*/ =
explicit_make_error_code_compatible_move_conversion_tag()) noexcept(noexcept(make_error_code(std::declval<T>()))) // NOLINT
: base{in_place_type<error_type_if_enabled>, make_error_code(detail::extract_error_from_failure<error_type>(static_cast<failure_type<T> &&>(o)))}
{
hooks::set_spare_storage(this, o.spare_storage());
no_value_policy_type::on_result_move_construction(this, static_cast<failure_type<T> &&>(o));
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class T)
OUTCOME_TREQUIRES(OUTCOME_TPRED(predicate::template enable_make_exception_ptr_compatible_conversion<void, T, void>))
constexpr basic_result(const failure_type<T> &o,
explicit_make_exception_ptr_compatible_copy_conversion_tag /*unused*/ =
explicit_make_exception_ptr_compatible_copy_conversion_tag()) noexcept(noexcept(make_exception_ptr(std::declval<T>()))) // NOLINT
: base{in_place_type<error_type_if_enabled>, make_exception_ptr(detail::extract_error_from_failure<error_type>(o))}
{
hooks::set_spare_storage(this, o.spare_storage());
no_value_policy_type::on_result_copy_construction(this, o);
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class T)
OUTCOME_TREQUIRES(OUTCOME_TPRED(predicate::template enable_make_exception_ptr_compatible_conversion<void, T, void>))
constexpr basic_result(failure_type<T> &&o,
explicit_make_exception_ptr_compatible_move_conversion_tag /*unused*/ =
explicit_make_exception_ptr_compatible_move_conversion_tag()) noexcept(noexcept(make_exception_ptr(std::declval<T>()))) // NOLINT
: base{in_place_type<error_type_if_enabled>, make_exception_ptr(detail::extract_error_from_failure<error_type>(static_cast<failure_type<T> &&>(o)))}
{
hooks::set_spare_storage(this, o.spare_storage());
no_value_policy_type::on_result_move_construction(this, static_cast<failure_type<T> &&>(o));
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
constexpr void swap(basic_result &o) noexcept((std::is_void<value_type>::value || detail::is_nothrow_swappable<value_type>::value) //
&& (std::is_void<error_type>::value || detail::is_nothrow_swappable<error_type>::value))
{
this->_state.swap(o._state);
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
auto as_failure() const & { return failure(this->assume_error(), hooks::spare_storage(this)); }
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
auto as_failure() &&
{
this->_state._status.set_have_moved_from(true);
return failure(static_cast<basic_result &&>(*this).assume_error(), hooks::spare_storage(this));
}
#ifdef __APPLE__
failure_type<error_type> _xcode_workaround_as_failure() &&;
#endif
};
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
template <class R, class S, class P> inline void swap(basic_result<R, S, P> &a, basic_result<R, S, P> &b) noexcept(noexcept(a.swap(b)))
{
a.swap(b);
}
#if !defined(NDEBUG)
// Check is trivial in all ways except default constructibility
// static_assert(std::is_trivial<basic_result<int, long, policy::all_narrow>>::value, "result<int> is not trivial!");
// static_assert(std::is_trivially_default_constructible<basic_result<int, long, policy::all_narrow>>::value, "result<int> is not trivially default
// constructible!");
static_assert(std::is_trivially_copyable<basic_result<int, long, policy::all_narrow>>::value, "result<int> is not trivially copyable!");
static_assert(std::is_trivially_assignable<basic_result<int, long, policy::all_narrow>, basic_result<int, long, policy::all_narrow>>::value,
"result<int> is not trivially assignable!");
static_assert(std::is_trivially_destructible<basic_result<int, long, policy::all_narrow>>::value, "result<int> is not trivially destructible!");
static_assert(std::is_trivially_copy_constructible<basic_result<int, long, policy::all_narrow>>::value, "result<int> is not trivially copy constructible!");
static_assert(std::is_trivially_move_constructible<basic_result<int, long, policy::all_narrow>>::value, "result<int> is not trivially move constructible!");
static_assert(std::is_trivially_copy_assignable<basic_result<int, long, policy::all_narrow>>::value, "result<int> is not trivially copy assignable!");
static_assert(std::is_trivially_move_assignable<basic_result<int, long, policy::all_narrow>>::value, "result<int> is not trivially move assignable!");
// Also check is standard layout
static_assert(std::is_standard_layout<basic_result<int, long, policy::all_narrow>>::value, "result<int> is not a standard layout type!");
#endif
OUTCOME_V2_NAMESPACE_END
#ifdef __clang__
#pragma clang diagnostic pop
#endif
#endif
|
0 | repos/outcome/include | repos/outcome/include/outcome/trait.hpp | /* Traits for Outcome
(C) 2018-2019 Niall Douglas <http://www.nedproductions.biz/> (8 commits)
File Created: March 2018
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License in the accompanying file
Licence.txt or at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Distributed under the Boost Software License, Version 1.0.
(See accompanying file Licence.txt or copy at
http://www.boost.org/LICENSE_1_0.txt)
*/
#ifndef OUTCOME_TRAIT_HPP
#define OUTCOME_TRAIT_HPP
#include "config.hpp"
OUTCOME_V2_NAMESPACE_EXPORT_BEGIN
namespace trait
{
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
template <class R> //
static constexpr bool type_can_be_used_in_basic_result = //
(!std::is_reference<R>::value //
&& !OUTCOME_V2_NAMESPACE::detail::is_in_place_type_t<std::decay_t<R>>::value //
&& !is_success_type<R> //
&& !is_failure_type<R> //
&& !std::is_array<R>::value //
&& (std::is_void<R>::value || (std::is_object<R>::value //
&& std::is_destructible<R>::value)) //
);
/*! AWAITING HUGO JSON CONVERSION TOOL
type definition is_error_type. Potential doc page: NOT FOUND
*/
template <class T> struct is_move_bitcopying
{
static constexpr bool value = false;
};
/*! AWAITING HUGO JSON CONVERSION TOOL
type definition is_error_type. Potential doc page: NOT FOUND
*/
template <class E> struct is_error_type
{
static constexpr bool value = false;
};
/*! AWAITING HUGO JSON CONVERSION TOOL
type definition is_error_type_enum. Potential doc page: NOT FOUND
*/
template <class E, class Enum> struct is_error_type_enum
{
static constexpr bool value = false;
};
namespace detail
{
template <class T> using devoid = OUTCOME_V2_NAMESPACE::detail::devoid<T>;
template <class T> std::add_rvalue_reference_t<devoid<T>> declval() noexcept;
// From http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2015/n4436.pdf
namespace detector_impl
{
template <class...> using void_t = void;
template <class Default, class, template <class...> class Op, class... Args> struct detector
{
static constexpr bool value = false;
using type = Default;
};
template <class Default, template <class...> class Op, class... Args> struct detector<Default, void_t<Op<Args...>>, Op, Args...>
{
static constexpr bool value = true;
using type = Op<Args...>;
};
} // namespace detector_impl
template <template <class...> class Op, class... Args> using is_detected = detector_impl::detector<void, void, Op, Args...>;
template <class Arg> using result_of_make_error_code = decltype(make_error_code(declval<Arg>()));
template <class Arg> using introspect_make_error_code = is_detected<result_of_make_error_code, Arg>;
template <class Arg> using result_of_make_exception_ptr = decltype(make_exception_ptr(declval<Arg>()));
template <class Arg> using introspect_make_exception_ptr = is_detected<result_of_make_exception_ptr, Arg>;
template <class T> struct _is_error_code_available
{
static constexpr bool value = detail::introspect_make_error_code<T>::value;
using type = typename detail::introspect_make_error_code<T>::type;
};
template <class T> struct _is_exception_ptr_available
{
static constexpr bool value = detail::introspect_make_exception_ptr<T>::value;
using type = typename detail::introspect_make_exception_ptr<T>::type;
};
} // namespace detail
/*! AWAITING HUGO JSON CONVERSION TOOL
type definition is_error_code_available. Potential doc page: NOT FOUND
*/
template <class T> struct is_error_code_available
{
static constexpr bool value = detail::_is_error_code_available<std::decay_t<T>>::value;
using type = typename detail::_is_error_code_available<std::decay_t<T>>::type;
};
template <class T> constexpr bool is_error_code_available_v = detail::_is_error_code_available<std::decay_t<T>>::value;
/*! AWAITING HUGO JSON CONVERSION TOOL
type definition is_exception_ptr_available. Potential doc page: NOT FOUND
*/
template <class T> struct is_exception_ptr_available
{
static constexpr bool value = detail::_is_exception_ptr_available<std::decay_t<T>>::value;
using type = typename detail::_is_exception_ptr_available<std::decay_t<T>>::type;
};
template <class T> constexpr bool is_exception_ptr_available_v = detail::_is_exception_ptr_available<std::decay_t<T>>::value;
} // namespace trait
OUTCOME_V2_NAMESPACE_END
#endif
|
0 | repos/outcome/include | repos/outcome/include/outcome/try.hpp | /* Try operation macros
(C) 2017-2021 Niall Douglas <http://www.nedproductions.biz/> (20 commits)
File Created: July 2017
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License in the accompanying file
Licence.txt or at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Distributed under the Boost Software License, Version 1.0.
(See accompanying file Licence.txt or copy at
http://www.boost.org/LICENSE_1_0.txt)
*/
#ifndef OUTCOME_TRY_HPP
#define OUTCOME_TRY_HPP
#include "detail/try.h"
#include "success_failure.hpp"
OUTCOME_V2_NAMESPACE_BEGIN
namespace detail
{
struct has_value_overload
{
};
struct as_failure_overload
{
};
struct assume_error_overload
{
};
struct error_overload
{
};
struct assume_value_overload
{
};
struct value_overload
{
};
// #ifdef __APPLE__
// OUTCOME_TEMPLATE(class T, class R = decltype(std::declval<T>()._xcode_workaround_as_failure()))
// #else
OUTCOME_TEMPLATE(class T, class R = decltype(std::declval<T>().as_failure()))
// #endif
OUTCOME_TREQUIRES(OUTCOME_TPRED(OUTCOME_V2_NAMESPACE::is_failure_type<R>))
constexpr inline bool has_as_failure(int /*unused */)
{
return true;
}
template <class T> constexpr inline bool has_as_failure(...)
{
return false;
}
OUTCOME_TEMPLATE(class T)
OUTCOME_TREQUIRES(OUTCOME_TEXPR(std::declval<T>().assume_error()))
constexpr inline bool has_assume_error(int /*unused */)
{
return true;
}
template <class T> constexpr inline bool has_assume_error(...)
{
return false;
}
OUTCOME_TEMPLATE(class T)
OUTCOME_TREQUIRES(OUTCOME_TEXPR(std::declval<T>().error()))
constexpr inline bool has_error(int /*unused */)
{
return true;
}
template <class T> constexpr inline bool has_error(...)
{
return false;
}
OUTCOME_TEMPLATE(class T)
OUTCOME_TREQUIRES(OUTCOME_TEXPR(std::declval<T>().assume_value()))
constexpr inline bool has_assume_value(int /*unused */)
{
return true;
}
template <class T> constexpr inline bool has_assume_value(...)
{
return false;
}
OUTCOME_TEMPLATE(class T)
OUTCOME_TREQUIRES(OUTCOME_TEXPR(std::declval<T>().value()))
constexpr inline bool has_value(int /*unused */)
{
return true;
}
template <class T> constexpr inline bool has_value(...)
{
return false;
}
} // namespace detail
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class T)
OUTCOME_TREQUIRES(OUTCOME_TEXPR(std::declval<T>().has_value()))
constexpr inline bool try_operation_has_value(T &&v, detail::has_value_overload = {})
{
return v.has_value();
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class T)
OUTCOME_TREQUIRES(OUTCOME_TPRED(detail::has_as_failure<T>(5)))
constexpr inline decltype(auto) try_operation_return_as(T &&v, detail::as_failure_overload = {})
{
return static_cast<T &&>(v).as_failure();
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class T)
OUTCOME_TREQUIRES(OUTCOME_TPRED(!detail::has_as_failure<T>(5) && detail::has_assume_error<T>(5)))
constexpr inline decltype(auto) try_operation_return_as(T &&v, detail::assume_error_overload = {})
{
return failure(static_cast<T &&>(v).assume_error());
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class T)
OUTCOME_TREQUIRES(OUTCOME_TPRED(!detail::has_as_failure<T>(5) && !detail::has_assume_error<T>(5) && detail::has_error<T>(5)))
constexpr inline decltype(auto) try_operation_return_as(T &&v, detail::error_overload = {})
{
return failure(static_cast<T &&>(v).error());
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class T)
OUTCOME_TREQUIRES(OUTCOME_TPRED(detail::has_assume_value<T>(5)))
constexpr inline decltype(auto) try_operation_extract_value(T &&v, detail::assume_value_overload = {})
{
return static_cast<T &&>(v).assume_value();
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class T)
OUTCOME_TREQUIRES(OUTCOME_TPRED(!detail::has_assume_value<T>(5) && detail::has_value<T>(5)))
constexpr inline decltype(auto) try_operation_extract_value(T &&v, detail::value_overload = {})
{
return static_cast<T &&>(v).value();
}
OUTCOME_V2_NAMESPACE_END
#if !defined(__clang__) && defined(__GNUC__) && __GNUC__ >= 8
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wparentheses"
#endif
// Use if(!expr); else as some compilers assume else clauses are always unlikely
#define OUTCOME_TRYV2_SUCCESS_LIKELY(unique, retstmt, spec, ...) \
OUTCOME_TRYV2_UNIQUE_STORAGE(unique, spec, __VA_ARGS__); \
OUTCOME_TRY_LIKELY_IF(::OUTCOME_V2_NAMESPACE::try_operation_has_value(unique)); \
else \
{ /* works around ICE in GCC's coroutines implementation */ \
auto unique##_f(::OUTCOME_V2_NAMESPACE::try_operation_return_as(static_cast<decltype(unique) &&>(unique))); \
retstmt unique##_f; \
}
#define OUTCOME_TRYV3_FAILURE_LIKELY(unique, retstmt, spec, ...) \
OUTCOME_TRYV2_UNIQUE_STORAGE(unique, spec, __VA_ARGS__); \
OUTCOME_TRY_LIKELY_IF(!OUTCOME_V2_NAMESPACE::try_operation_has_value(unique)) \
{ /* works around ICE in GCC's coroutines implementation */ \
auto unique##_f(::OUTCOME_V2_NAMESPACE::try_operation_return_as(static_cast<decltype(unique) &&>(unique))); \
retstmt unique##_f; \
}
#define OUTCOME_TRY2_SUCCESS_LIKELY(unique, retstmt, var, ...) \
OUTCOME_TRYV2_SUCCESS_LIKELY(unique, retstmt, var, __VA_ARGS__); \
OUTCOME_TRY2_VAR(var) = ::OUTCOME_V2_NAMESPACE::try_operation_extract_value(static_cast<decltype(unique) &&>(unique))
#define OUTCOME_TRY2_FAILURE_LIKELY(unique, retstmt, var, ...) \
OUTCOME_TRYV3_FAILURE_LIKELY(unique, retstmt, var, __VA_ARGS__); \
OUTCOME_TRY2_VAR(var) = ::OUTCOME_V2_NAMESPACE::try_operation_extract_value(static_cast<decltype(unique) &&>(unique))
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
#define OUTCOME_TRYV(...) OUTCOME_TRYV2_SUCCESS_LIKELY(OUTCOME_TRY_UNIQUE_NAME, return, deduce, __VA_ARGS__)
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
#define OUTCOME_TRYV_FAILURE_LIKELY(...) OUTCOME_TRYV3_FAILURE_LIKELY(OUTCOME_TRY_UNIQUE_NAME, return, deduce, __VA_ARGS__)
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
#define OUTCOME_CO_TRYV(...) OUTCOME_TRYV2_SUCCESS_LIKELY(OUTCOME_TRY_UNIQUE_NAME, co_return, deduce, __VA_ARGS__)
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
#define OUTCOME_CO_TRYV_FAILURE_LIKELY(...) OUTCOME_TRYV3_FAILURE_LIKELY(OUTCOME_TRY_UNIQUE_NAME, co_return, deduce, __VA_ARGS__)
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
#define OUTCOME_TRYV2(s, ...) OUTCOME_TRYV2_SUCCESS_LIKELY(OUTCOME_TRY_UNIQUE_NAME, return, (s, ), __VA_ARGS__)
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
#define OUTCOME_TRYV2_FAILURE_LIKELY(s, ...) OUTCOME_TRYV3_FAILURE_LIKELY(OUTCOME_TRY_UNIQUE_NAME, return, (s, ), __VA_ARGS__)
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
#define OUTCOME_CO_TRYV2(s, ...) OUTCOME_TRYV2_SUCCESS_LIKELY(OUTCOME_TRY_UNIQUE_NAME, co_return, (s, ), __VA_ARGS__)
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
#define OUTCOME_CO_TRYV2_FAILURE_LIKELY(s, ...) OUTCOME_TRYV3_FAILURE_LIKELY(OUTCOME_TRY_UNIQUE_NAME, co_return, s(, ), __VA_ARGS__)
#if defined(__GNUC__) || defined(__clang__)
#define OUTCOME_TRYX2(unique, retstmt, ...) \
({ \
OUTCOME_TRYV2_SUCCESS_LIKELY(unique, retstmt, deduce, __VA_ARGS__); \
::OUTCOME_V2_NAMESPACE::try_operation_extract_value(static_cast<decltype(unique) &&>(unique)); \
})
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
#define OUTCOME_TRYX(...) OUTCOME_TRYX2(OUTCOME_TRY_UNIQUE_NAME, return, __VA_ARGS__)
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
#define OUTCOME_CO_TRYX(...) OUTCOME_TRYX2(OUTCOME_TRY_UNIQUE_NAME, co_return, __VA_ARGS__)
#endif
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
#define OUTCOME_TRYA(v, ...) OUTCOME_TRY2_SUCCESS_LIKELY(OUTCOME_TRY_UNIQUE_NAME, return, v, __VA_ARGS__)
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
#define OUTCOME_TRYA_FAILURE_LIKELY(v, ...) OUTCOME_TRY2_FAILURE_LIKELY(OUTCOME_TRY_UNIQUE_NAME, return, v, __VA_ARGS__)
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
#define OUTCOME_CO_TRYA(v, ...) OUTCOME_TRY2_SUCCESS_LIKELY(OUTCOME_TRY_UNIQUE_NAME, co_return, v, __VA_ARGS__)
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
#define OUTCOME_CO_TRYA_FAILURE_LIKELY(v, ...) OUTCOME_TRY2_FAILURE_LIKELY(OUTCOME_TRY_UNIQUE_NAME, co_return, v, __VA_ARGS__)
#define OUTCOME_TRY_INVOKE_TRY8(a, b, c, d, e, f, g, h) OUTCOME_TRYA(a, b, c, d, e, f, g, h)
#define OUTCOME_TRY_INVOKE_TRY7(a, b, c, d, e, f, g) OUTCOME_TRYA(a, b, c, d, e, f, g)
#define OUTCOME_TRY_INVOKE_TRY6(a, b, c, d, e, f) OUTCOME_TRYA(a, b, c, d, e, f)
#define OUTCOME_TRY_INVOKE_TRY5(a, b, c, d, e) OUTCOME_TRYA(a, b, c, d, e)
#define OUTCOME_TRY_INVOKE_TRY4(a, b, c, d) OUTCOME_TRYA(a, b, c, d)
#define OUTCOME_TRY_INVOKE_TRY3(a, b, c) OUTCOME_TRYA(a, b, c)
#define OUTCOME_TRY_INVOKE_TRY2(a, b) OUTCOME_TRYA(a, b)
#define OUTCOME_TRY_INVOKE_TRY1(a) OUTCOME_TRYV(a)
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
#define OUTCOME_TRY(...) OUTCOME_TRY_CALL_OVERLOAD(OUTCOME_TRY_INVOKE_TRY, __VA_ARGS__)
#define OUTCOME_TRY_FAILURE_LIKELY_INVOKE_TRY8(a, b, c, d, e, f, g, h) OUTCOME_TRYA_FAILURE_LIKELY(a, b, c, d, e, f, g, h)
#define OUTCOME_TRY_FAILURE_LIKELY_INVOKE_TRY7(a, b, c, d, e, f, g) OUTCOME_TRYA_FAILURE_LIKELY(a, b, c, d, e, f, g)
#define OUTCOME_TRY_FAILURE_LIKELY_INVOKE_TRY6(a, b, c, d, e, f) OUTCOME_TRYA_FAILURE_LIKELY(a, b, c, d, e, f)
#define OUTCOME_TRY_FAILURE_LIKELY_INVOKE_TRY5(a, b, c, d, e) OUTCOME_TRYA_FAILURE_LIKELY(a, b, c, d, e)
#define OUTCOME_TRY_FAILURE_LIKELY_INVOKE_TRY4(a, b, c, d) OUTCOME_TRYA_FAILURE_LIKELY(a, b, c, d)
#define OUTCOME_TRY_FAILURE_LIKELY_INVOKE_TRY3(a, b, c) OUTCOME_TRYA_FAILURE_LIKELY(a, b, c)
#define OUTCOME_TRY_FAILURE_LIKELY_INVOKE_TRY2(a, b) OUTCOME_TRYA_FAILURE_LIKELY(a, b)
#define OUTCOME_TRY_FAILURE_LIKELY_INVOKE_TRY1(a) OUTCOME_TRYV_FAILURE_LIKELY(a)
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
#define OUTCOME_TRY_FAILURE_LIKELY(...) OUTCOME_TRY_CALL_OVERLOAD(OUTCOME_TRY_FAILURE_LIKELY_INVOKE_TRY, __VA_ARGS__)
#define OUTCOME_CO_TRY_INVOKE_TRY8(a, b, c, d, e, f, g, h) OUTCOME_CO_TRYA(a, b, c, d, e, f, g, h)
#define OUTCOME_CO_TRY_INVOKE_TRY7(a, b, c, d, e, f, g) OUTCOME_CO_TRYA(a, b, c, d, e, f, g)
#define OUTCOME_CO_TRY_INVOKE_TRY6(a, b, c, d, e, f) OUTCOME_CO_TRYA(a, b, c, d, e, f)
#define OUTCOME_CO_TRY_INVOKE_TRY5(a, b, c, d, e) OUTCOME_CO_TRYA(a, b, c, d, e)
#define OUTCOME_CO_TRY_INVOKE_TRY4(a, b, c, d) OUTCOME_CO_TRYA(a, b, c, d)
#define OUTCOME_CO_TRY_INVOKE_TRY3(a, b, c) OUTCOME_CO_TRYA(a, b, c)
#define OUTCOME_CO_TRY_INVOKE_TRY2(a, b) OUTCOME_CO_TRYA(a, b)
#define OUTCOME_CO_TRY_INVOKE_TRY1(a) OUTCOME_CO_TRYV(a)
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
#define OUTCOME_CO_TRY(...) OUTCOME_TRY_CALL_OVERLOAD(OUTCOME_CO_TRY_INVOKE_TRY, __VA_ARGS__)
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
#define OUTCOME_TRY(...) OUTCOME_TRY_CALL_OVERLOAD(OUTCOME_TRY_INVOKE_TRY, __VA_ARGS__)
#define OUTCOME_CO_TRY_FAILURE_LIKELY_INVOKE_TRY8(a, b, c, d, e, f, g, h) OUTCOME_CO_TRYA_FAILURE_LIKELY(a, b, c, d, e, f, g, h)
#define OUTCOME_CO_TRY_FAILURE_LIKELY_INVOKE_TRY7(a, b, c, d, e, f, g) OUTCOME_CO_TRYA_FAILURE_LIKELY(a, b, c, d, e, f, g)
#define OUTCOME_CO_TRY_FAILURE_LIKELY_INVOKE_TRY6(a, b, c, d, e, f) OUTCOME_CO_TRYA_FAILURE_LIKELY(a, b, c, d, e, f)
#define OUTCOME_CO_TRY_FAILURE_LIKELY_INVOKE_TRY5(a, b, c, d, e) OUTCOME_CO_TRYA_FAILURE_LIKELY(a, b, c, d, e)
#define OUTCOME_CO_TRY_FAILURE_LIKELY_INVOKE_TRY4(a, b, c, d) OUTCOME_CO_TRYA_FAILURE_LIKELY(a, b, c, d)
#define OUTCOME_CO_TRY_FAILURE_LIKELY_INVOKE_TRY3(a, b, c) OUTCOME_CO_TRYA_FAILURE_LIKELY(a, b, c)
#define OUTCOME_CO_TRY_FAILURE_LIKELY_INVOKE_TRY2(a, b) OUTCOME_CO_TRYA_FAILURE_LIKELY(a, b)
#define OUTCOME_CO_TRY_FAILURE_LIKELY_INVOKE_TRY1(a) OUTCOME_CO_TRYV_FAILURE_LIKELY(a)
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
#define OUTCOME_CO_TRY_FAILURE_LIKELY(...) OUTCOME_TRY_CALL_OVERLOAD(OUTCOME_CO_TRY_FAILURE_LIKELY_INVOKE_TRY, __VA_ARGS__)
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
#define OUTCOME21_TRYA(v, ...) OUTCOME_TRY2_SUCCESS_LIKELY(OUTCOME_TRY_UNIQUE_NAME, return, deduce, auto &&v, __VA_ARGS__)
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
#define OUTCOME21_TRYA_FAILURE_LIKELY(v, ...) OUTCOME_TRY2_FAILURE_LIKELY(OUTCOME_TRY_UNIQUE_NAME, return, deduce, auto &&v, __VA_ARGS__)
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
#define OUTCOME21_CO_TRYA(v, ...) OUTCOME_TRY2_FAILURE_LIKELY(OUTCOME_TRY_UNIQUE_NAME, co_return, deduce, auto &&v, __VA_ARGS__)
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
#define OUTCOME21_CO_TRYA_FAILURE_LIKELY(v, ...) OUTCOME_TRY2_FAILURE_LIKELY(OUTCOME_TRY_UNIQUE_NAME, co_retrn, deduce, auto &&v, __VA_ARGS__)
#define OUTCOME21_TRY_INVOKE_TRY8(a, b, c, d, e, f, g, h) OUTCOME21_TRYA(a, b, c, d, e, f, g, h)
#define OUTCOME21_TRY_INVOKE_TRY7(a, b, c, d, e, f, g) OUTCOME21_TRYA(a, b, c, d, e, f, g)
#define OUTCOME21_TRY_INVOKE_TRY6(a, b, c, d, e, f) OUTCOME21_TRYA(a, b, c, d, e, f)
#define OUTCOME21_TRY_INVOKE_TRY5(a, b, c, d, e) OUTCOME21_TRYA(a, b, c, d, e)
#define OUTCOME21_TRY_INVOKE_TRY4(a, b, c, d) OUTCOME21_TRYA(a, b, c, d)
#define OUTCOME21_TRY_INVOKE_TRY3(a, b, c) OUTCOME21_TRYA(a, b, c)
#define OUTCOME21_TRY_INVOKE_TRY2(a, b) OUTCOME21_TRYA(a, b)
#define OUTCOME21_TRY_INVOKE_TRY1(a) OUTCOME_TRYV(a)
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
#define OUTCOME21_TRY(...) OUTCOME_TRY_CALL_OVERLOAD(OUTCOME21_TRY_INVOKE_TRY, __VA_ARGS__)
#define OUTCOME21_TRY_FAILURE_LIKELY_INVOKE_TRY8(a, b, c, d, e, f, g, h) OUTCOME21_TRYA_FAILURE_LIKELY(a, b, c, d, e, f, g, h)
#define OUTCOME21_TRY_FAILURE_LIKELY_INVOKE_TRY7(a, b, c, d, e, f, g) OUTCOME21_TRYA_FAILURE_LIKELY(a, b, c, d, e, f, g)
#define OUTCOME21_TRY_FAILURE_LIKELY_INVOKE_TRY6(a, b, c, d, e, f) OUTCOME21_TRYA_FAILURE_LIKELY(a, b, c, d, e, f)
#define OUTCOME21_TRY_FAILURE_LIKELY_INVOKE_TRY5(a, b, c, d, e) OUTCOME21_TRYA_FAILURE_LIKELY(a, b, c, d, e)
#define OUTCOME21_TRY_FAILURE_LIKELY_INVOKE_TRY4(a, b, c, d) OUTCOME21_TRYA_FAILURE_LIKELY(a, b, c, d)
#define OUTCOME21_TRY_FAILURE_LIKELY_INVOKE_TRY3(a, b, c) OUTCOME21_TRYA_FAILURE_LIKELY(a, b, c)
#define OUTCOME21_TRY_FAILURE_LIKELY_INVOKE_TRY2(a, b) OUTCOME21_TRYA_FAILURE_LIKELY(a, b)
#define OUTCOME21_TRY_FAILURE_LIKELY_INVOKE_TRY1(a) OUTCOME_TRYV_FAILURE_LIKELY(a)
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
#define OUTCOME21_TRY_FAILURE_LIKELY(...) OUTCOME_TRY_CALL_OVERLOAD(OUTCOME21_TRY_FAILURE_LIKELY_INVOKE_TRY, __VA_ARGS__)
#define OUTCOME21_CO_TRY_INVOKE_TRY8(a, b, c, d, e, f, g, h) OUTCOME21_CO_TRYA(a, b, c, d, e, f, g, h)
#define OUTCOME21_CO_TRY_INVOKE_TRY7(a, b, c, d, e, f, g) OUTCOME21_CO_TRYA(a, b, c, d, e, f, g)
#define OUTCOME21_CO_TRY_INVOKE_TRY6(a, b, c, d, e, f) OUTCOME21_CO_TRYA(a, b, c, d, e, f)
#define OUTCOME21_CO_TRY_INVOKE_TRY5(a, b, c, d, e) OUTCOME21_CO_TRYA(a, b, c, d, e)
#define OUTCOME21_CO_TRY_INVOKE_TRY4(a, b, c, d) OUTCOME21_CO_TRYA(a, b, c, d)
#define OUTCOME21_CO_TRY_INVOKE_TRY3(a, b, c) OUTCOME21_CO_TRYA(a, b, c)
#define OUTCOME21_CO_TRY_INVOKE_TRY2(a, b) OUTCOME21_CO_TRYA(a, b)
#define OUTCOME21_CO_TRY_INVOKE_TRY1(a) OUTCOME_CO_TRYV(a)
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
#define OUTCOME21_CO_TRY(...) OUTCOME_TRY_CALL_OVERLOAD(OUTCOME21_CO_TRY_INVOKE_TRY, __VA_ARGS__)
#define OUTCOME21_CO_TRY_FAILURE_LIKELY_INVOKE_TRY8(a, b, c, d, e, f, g, h) OUTCOME21_CO_TRYA_FAILURE_LIKELY(a, b, c, d, e, f, g, h)
#define OUTCOME21_CO_TRY_FAILURE_LIKELY_INVOKE_TRY7(a, b, c, d, e, f, g) OUTCOME21_CO_TRYA_FAILURE_LIKELY(a, b, c, d, e, f, g)
#define OUTCOME21_CO_TRY_FAILURE_LIKELY_INVOKE_TRY6(a, b, c, d, e, f) OUTCOME21_CO_TRYA_FAILURE_LIKELY(a, b, c, d, e, f)
#define OUTCOME21_CO_TRY_FAILURE_LIKELY_INVOKE_TRY5(a, b, c, d, e) OUTCOME21_CO_TRYA_FAILURE_LIKELY(a, b, c, d, e)
#define OUTCOME21_CO_TRY_FAILURE_LIKELY_INVOKE_TRY4(a, b, c, d) OUTCOME21_CO_TRYA_FAILURE_LIKELY(a, b, c, d)
#define OUTCOME21_CO_TRY_FAILURE_LIKELY_INVOKE_TRY3(a, b, c) OUTCOME21_CO_TRYA_FAILURE_LIKELY(a, b, c)
#define OUTCOME21_CO_TRY_FAILURE_LIKELY_INVOKE_TRY2(a, b) OUTCOME21_CO_TRYA_FAILURE_LIKELY(a, b)
#define OUTCOME21_CO_TRY_FAILURE_LIKELY_INVOKE_TRY1(a) OUTCOME_CO_TRYV_FAILURE_LIKELY(a)
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
#define OUTCOME21_CO_TRY_FAILURE_LIKELY(...) OUTCOME_TRY_CALL_OVERLOAD(OUTCOME21_CO_TRY_FAILURE_LIKELY_INVOKE_TRY, __VA_ARGS__)
#if !defined(__clang__) && defined(__GNUC__) && __GNUC__ >= 8
#pragma GCC diagnostic pop
#endif
#endif
|
0 | repos/outcome/include | repos/outcome/include/outcome/bad_access.hpp | /* Exception types throwable
(C) 2017-2019 Niall Douglas <http://www.nedproductions.biz/> (9 commits)
File Created: Oct 2017
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License in the accompanying file
Licence.txt or at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Distributed under the Boost Software License, Version 1.0.
(See accompanying file Licence.txt or copy at
http://www.boost.org/LICENSE_1_0.txt)
*/
#ifndef OUTCOME_BAD_ACCESS_HPP
#define OUTCOME_BAD_ACCESS_HPP
#include "config.hpp"
#include <stdexcept>
OUTCOME_V2_NAMESPACE_EXPORT_BEGIN
/*! AWAITING HUGO JSON CONVERSION TOOL
type definition bad_result_access. Potential doc page: `bad_result_access`
*/
class OUTCOME_SYMBOL_VISIBLE bad_result_access : public std::logic_error
{
public:
explicit bad_result_access(const char *what)
: std::logic_error(what)
{
}
};
/*! AWAITING HUGO JSON CONVERSION TOOL
type definition template <class S> bad_result_access_with. Potential doc page: `bad_result_access_with<EC>`
*/
template <class S> class OUTCOME_SYMBOL_VISIBLE bad_result_access_with : public bad_result_access
{
S _error;
public:
explicit bad_result_access_with(S v)
: bad_result_access("no value")
, _error(std::move(v))
{
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
const S &error() const & { return _error; }
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
S &error() & { return _error; }
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
const S &&error() const && { return _error; }
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
S &&error() && { return _error; }
};
/*! AWAITING HUGO JSON CONVERSION TOOL
type definition bad_outcome_access. Potential doc page: `bad_outcome_access`
*/
class OUTCOME_SYMBOL_VISIBLE bad_outcome_access : public std::logic_error
{
public:
explicit bad_outcome_access(const char *what)
: std::logic_error(what)
{
}
};
OUTCOME_V2_NAMESPACE_END
#endif
|
0 | repos/outcome/include | repos/outcome/include/outcome/outcome_gdb.h | /* Inline GDB pretty printer for result
(C) 2024 Niall Douglas <http://www.nedproductions.biz/> (6 commits)
File Created: Jun 2024
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License in the accompanying file
Licence.txt or at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Distributed under the Boost Software License, Version 1.0.
(See accompanying file Licence.txt or copy at
http://www.boost.org/LICENSE_1_0.txt)
*/
#ifndef OUTCOME_INLINE_GDB_PRETTY_PRINTER_H
#define OUTCOME_INLINE_GDB_PRETTY_PRINTER_H
#ifndef OUTCOME_DISABLE_INLINE_GDB_PRETTY_PRINTERS
#if defined(__ELF__)
#ifdef __clang__
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Woverlength-strings"
#endif
__asm__(".pushsection \".debug_gdb_scripts\", \"MS\",@progbits,1\n"
".byte 4 /* Python Text */\n"
".ascii \"gdb.inlined-script\\n\"\n"
".ascii \"import gdb.printing\\n\"\n"
".ascii \"import os\\n\"\n"
".ascii \"def synthesise_gdb_value_from_string(s):\\n\"\n"
".ascii \" '''For when you want to return a synthetic string from children()'''\\n\"\n"
".ascii \" return gdb.Value(s + '\\0').cast(gdb.lookup_type('char').pointer())\\n\"\n"
".ascii \"class OutcomeBasicOutcomePrinter(object):\\n\"\n"
".ascii \" '''Print an outcome::basic_outcome<T> and outcome::basic_result<T>'''\\n\"\n"
".ascii \" def __init__(self, val):\\n\"\n"
".ascii \" self.val = val\\n\"\n"
".ascii \" def children(self):\\n\"\n"
".ascii \" if self.val['_state']['_status']['status_value'] & 1 == 1:\\n\"\n"
".ascii \" yield ('value', self.val['_state']['_value'])\\n\"\n"
".ascii \" if self.val['_state']['_status']['status_value'] & 2 == 2:\\n\"\n"
".ascii \" yield ('error', self.val['_state']['_error'])\\n\"\n"
".ascii \" if self.val['_state']['_status']['status_value'] & 4 == 4:\\n\"\n"
".ascii \" yield ('exception', self.val['_ptr'])\\n\"\n"
".ascii \" def display_hint(self):\\n\"\n"
".ascii \" return None\\n\"\n"
".ascii \" def to_string(self):\\n\"\n"
".ascii \" if self.val['_state']['_status']['status_value'] & 54 == 54:\\n\"\n"
".ascii \" return 'errored (errno, moved from) + exceptioned'\\n\"\n"
".ascii \" if self.val['_state']['_status']['status_value'] & 50 == 50:\\n\"\n"
".ascii \" return 'errored (errno, moved from)'\\n\"\n"
".ascii \" if self.val['_state']['_status']['status_value'] & 38 == 38:\\n\"\n"
".ascii \" return 'errored + exceptioned (moved from)'\\n\"\n"
".ascii \" if self.val['_state']['_status']['status_value'] & 36 == 36:\\n\"\n"
".ascii \" return 'exceptioned (moved from)'\\n\"\n"
".ascii \" if self.val['_state']['_status']['status_value'] & 35 == 35:\\n\"\n"
".ascii \" return 'errored (moved from)'\\n\"\n"
".ascii \" if self.val['_state']['_status']['status_value'] & 33 == 33:\\n\"\n"
".ascii \" return 'valued (moved from)'\\n\"\n"
".ascii \" if self.val['_state']['_status']['status_value'] & 22 == 22:\\n\"\n"
".ascii \" return 'errored (errno) + exceptioned'\\n\"\n"
".ascii \" if self.val['_state']['_status']['status_value'] & 18 == 18:\\n\"\n"
".ascii \" return 'errored (errno)'\\n\"\n"
".ascii \" if self.val['_state']['_status']['status_value'] & 6 == 6:\\n\"\n"
".ascii \" return 'errored + exceptioned'\\n\"\n"
".ascii \" if self.val['_state']['_status']['status_value'] & 4 == 4:\\n\"\n"
".ascii \" return 'exceptioned'\\n\"\n"
".ascii \" if self.val['_state']['_status']['status_value'] & 2 == 2:\\n\"\n"
".ascii \" return 'errored'\\n\"\n"
".ascii \" if self.val['_state']['_status']['status_value'] & 1 == 1:\\n\"\n"
".ascii \" return 'valued'\\n\"\n"
".ascii \" if self.val['_state']['_status']['status_value'] & 0xff == 0:\\n\"\n"
".ascii \" return 'empty'\\n\"\n"
".ascii \"class OutcomeCResultStatusPrinter(object):\\n\"\n"
".ascii \" '''Print a C result'''\\n\"\n"
".ascii \" def __init__(self, val):\\n\"\n"
".ascii \" self.val = val\\n\"\n"
".ascii \" def children(self):\\n\"\n"
".ascii \" if self.val['flags'] & 1 == 1:\\n\"\n"
".ascii \" yield ('value', self.val['value'])\\n\"\n"
".ascii \" if self.val['flags'] & 2 == 2:\\n\"\n"
".ascii \" yield ('error', self.val['error'])\\n\"\n"
".ascii \" def display_hint(self):\\n\"\n"
".ascii \" return None\\n\"\n"
".ascii \" def to_string(self):\\n\"\n"
".ascii \" if self.val['flags'] & 50 == 50:\\n\"\n"
".ascii \" return 'errored (errno, moved from)'\\n\"\n"
".ascii \" if self.val['flags'] & 35 == 35:\\n\"\n"
".ascii \" return 'errored (moved from)'\\n\"\n"
".ascii \" if self.val['flags'] & 33 == 33:\\n\"\n"
".ascii \" return 'valued (moved from)'\\n\"\n"
".ascii \" if self.val['flags'] & 18 == 18:\\n\"\n"
".ascii \" return 'errored (errno)'\\n\"\n"
".ascii \" if self.val['flags'] & 2 == 2:\\n\"\n"
".ascii \" return 'errored'\\n\"\n"
".ascii \" if self.val['flags'] & 1 == 1:\\n\"\n"
".ascii \" return 'valued'\\n\"\n"
".ascii \" if self.val['flags'] & 0xff == 0:\\n\"\n"
".ascii \" return 'empty'\\n\"\n"
".ascii \"class OutcomeCStatusCodePrinter(object):\\n\"\n"
".ascii \" '''Print a C status code'''\\n\"\n"
".ascii \" def __init__(self, val):\\n\"\n"
".ascii \" self.val = val\\n\"\n"
".ascii \" def children(self):\\n\"\n"
".ascii \" yield ('domain', self.val['domain'])\\n\"\n"
".ascii \" yield ('value', self.val['value'])\\n\"\n"
".ascii \" def display_hint(self):\\n\"\n"
".ascii \" return None\\n\"\n"
".ascii \" def to_string(self):\\n\"\n"
".ascii \" s = str(self.val['domain'])\\n\"\n"
".ascii \" if 'posix_code_domain' in s or 'generic_code_domain' in s:\\n\"\n"
".ascii \" return str(self.val['value']) + ' (' + os.strerror(int(self.val['value'])) + ')'\\n\"\n"
".ascii \" else:\\n\"\n"
".ascii \" return self.val['value']\\n\"\n"
".ascii \"def build_pretty_printer():\\n\"\n"
".ascii \" pp = gdb.printing.RegexpCollectionPrettyPrinter('outcome_v2')\\n\"\n"
".ascii \" pp.add_printer('outcome_v2::basic_result', '^(boost::)?outcome_v2[_0-9a-f]*::basic_result<.*>$', OutcomeBasicOutcomePrinter)\\n\"\n"
".ascii \" pp.add_printer('outcome_v2::basic_outcome', '^(boost::)?outcome_v2[_0-9a-f]*::basic_outcome<.*>$', OutcomeBasicOutcomePrinter)\\n\"\n"
".ascii \" pp.add_printer('cxx_result_status_code_*', '^cxx_result_status_code_.*$', OutcomeCResultStatusPrinter)\\n\"\n"
".ascii \" pp.add_printer('cxx_status_code_*', '^cxx_status_code_.*$', OutcomeCStatusCodePrinter)\\n\"\n"
".ascii \" return pp\\n\"\n"
".ascii \"def register_printers(obj = None):\\n\"\n"
".ascii \" gdb.printing.register_pretty_printer(obj, build_pretty_printer(), replace = True)\\n\"\n"
".ascii \"register_printers(gdb.current_objfile())\\n\"\n"
".byte 0\n"
".popsection\n");
#ifdef __clang__
#pragma clang diagnostic pop
#endif
#endif
#endif
#endif
|
0 | repos/outcome/include | repos/outcome/include/outcome/coroutine_support.hpp | /* Tells C++ coroutines about Outcome's result
(C) 2019 Niall Douglas <http://www.nedproductions.biz/> (12 commits)
File Created: Oct 2019
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License in the accompanying file
Licence.txt or at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Distributed under the Boost Software License, Version 1.0.
(See accompanying file Licence.txt or copy at
http://www.boost.org/LICENSE_1_0.txt)
*/
#ifndef OUTCOME_COROUTINE_SUPPORT_HPP
#define OUTCOME_COROUTINE_SUPPORT_HPP
#include "config.hpp"
#define OUTCOME_COROUTINE_SUPPORT_NAMESPACE_BEGIN \
OUTCOME_V2_NAMESPACE_BEGIN namespace awaitables \
{
//
#define OUTCOME_COROUTINE_SUPPORT_NAMESPACE_EXPORT_BEGIN \
OUTCOME_V2_NAMESPACE_EXPORT_BEGIN namespace awaitables \
{
//
#define OUTCOME_COROUTINE_SUPPORT_NAMESPACE_END \
} \
OUTCOME_V2_NAMESPACE_END
#ifdef __cpp_exceptions
#include "utils.hpp"
OUTCOME_V2_NAMESPACE_BEGIN
namespace awaitables
{
namespace detail
{
inline bool error_is_set(std::error_code ec) noexcept { return !!ec; }
inline std::error_code error_from_exception(std::exception_ptr &&ep, std::error_code not_matched) noexcept { return OUTCOME_V2_NAMESPACE::error_from_exception(static_cast<std::exception_ptr &&>(ep), not_matched); }
} // namespace detail
} // namespace awaitables
OUTCOME_V2_NAMESPACE_END
#endif
#include "detail/coroutine_support.ipp"
#undef OUTCOME_COROUTINE_SUPPORT_NAMESPACE_BEGIN
#undef OUTCOME_COROUTINE_SUPPORT_NAMESPACE_EXPORT_BEGIN
#undef OUTCOME_COROUTINE_SUPPORT_NAMESPACE_END
#endif
|
0 | repos/outcome/include | repos/outcome/include/outcome/result.hpp | /* A very simple result type
(C) 2017-2019 Niall Douglas <http://www.nedproductions.biz/> (99 commits)
File Created: June 2017
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License in the accompanying file
Licence.txt or at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Distributed under the Boost Software License, Version 1.0.
(See accompanying file Licence.txt or copy at
http://www.boost.org/LICENSE_1_0.txt)
*/
#ifndef OUTCOME_RESULT_HPP
#define OUTCOME_RESULT_HPP
#include "std_result.hpp"
OUTCOME_V2_NAMESPACE_EXPORT_BEGIN
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
template <class R, class S = std::error_code, class NoValuePolicy = policy::default_policy<R, S, void>> //
using result = std_result<R, S, NoValuePolicy>;
/*! AWAITING HUGO JSON CONVERSION TOOL
type alias template <class R, class S = std::error_code> unchecked. Potential doc page: `unchecked<T, E = varies>`
*/
template <class R, class S = std::error_code> using unchecked = result<R, S, policy::all_narrow>;
/*! AWAITING HUGO JSON CONVERSION TOOL
type alias template <class R, class S = std::error_code> checked. Potential doc page: `checked<T, E = varies>`
*/
template <class R, class S = std::error_code> using checked = result<R, S, policy::throw_bad_result_access<S, void>>;
OUTCOME_V2_NAMESPACE_END
#endif
|
0 | repos/outcome/include | repos/outcome/include/outcome/convert.hpp | /* Says how to convert value, error and exception types
(C) 2017-2019 Niall Douglas <http://www.nedproductions.biz/> (12 commits)
File Created: Nov 2017
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License in the accompanying file
Licence.txt or at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Distributed under the Boost Software License, Version 1.0.
(See accompanying file Licence.txt or copy at
http://www.boost.org/LICENSE_1_0.txt)
*/
#ifndef OUTCOME_CONVERT_HPP
#define OUTCOME_CONVERT_HPP
#include "detail/basic_result_storage.hpp"
OUTCOME_V2_NAMESPACE_EXPORT_BEGIN
namespace concepts
{
#if defined(__cpp_concepts)
#if(defined(_MSC_VER) || defined(__clang__) || (defined(__GNUC__) && __cpp_concepts >= 201707) || OUTCOME_FORCE_STD_CXX_CONCEPTS) && \
!OUTCOME_FORCE_LEGACY_GCC_CXX_CONCEPTS
#define OUTCOME_GCC6_CONCEPT_BOOL
#else
#ifndef OUTCOME_SUPPRESS_LEGACY_CONCEPTS_WARNING
#warning "WARNING: Legacy GCC concepts are known to fail to compile in a number of important situations!"
#endif
#define OUTCOME_GCC6_CONCEPT_BOOL bool
#endif
namespace detail
{
template <class T, class U>
concept OUTCOME_GCC6_CONCEPT_BOOL SameHelper = std::is_same<T, U>::value;
template <class T, class U>
concept OUTCOME_GCC6_CONCEPT_BOOL same_as = detail::SameHelper<T, U> && detail::SameHelper<U, T>;
template <class T, class U>
concept OUTCOME_GCC6_CONCEPT_BOOL convertible = std::is_convertible<T, U>::value;
template <class T, class U>
concept OUTCOME_GCC6_CONCEPT_BOOL base_of = std::is_base_of<T, U>::value;
} // namespace detail
/* The `value_or_none` concept.
\requires That `U::value_type` exists and that `std::declval<U>().has_value()` returns a `bool` and `std::declval<U>().value()` exists.
*/
template <class U>
concept OUTCOME_GCC6_CONCEPT_BOOL value_or_none = requires(U a) {
{
a.has_value()
} -> detail::same_as<bool>;
{
a.value()
};
};
/* The `value_or_error` concept.
\requires That `U::value_type` and `U::error_type` exist;
that `std::declval<U>().has_value()` returns a `bool`, `std::declval<U>().value()` and `std::declval<U>().error()` exists.
*/
template <class U>
concept OUTCOME_GCC6_CONCEPT_BOOL value_or_error = requires(U a) {
{
a.has_value()
} -> detail::same_as<bool>;
{
a.value()
};
{
a.error()
};
};
#else
namespace detail
{
struct no_match
{
};
inline no_match match_value_or_none(...);
inline no_match match_value_or_error(...);
OUTCOME_TEMPLATE(class U)
OUTCOME_TREQUIRES(OUTCOME_TEXPR(std::declval<U>().has_value()), OUTCOME_TEXPR(std::declval<U>().value()))
inline U match_value_or_none(U &&);
OUTCOME_TEMPLATE(class U)
OUTCOME_TREQUIRES(OUTCOME_TEXPR(std::declval<U>().has_value()), OUTCOME_TEXPR(std::declval<U>().value()), OUTCOME_TEXPR(std::declval<U>().error()))
inline U match_value_or_error(U &&);
template <class U>
static constexpr bool value_or_none =
!std::is_same<no_match, decltype(match_value_or_none(std::declval<OUTCOME_V2_NAMESPACE::detail::devoid<U>>()))>::value;
template <class U>
static constexpr bool value_or_error =
!std::is_same<no_match, decltype(match_value_or_error(std::declval<OUTCOME_V2_NAMESPACE::detail::devoid<U>>()))>::value;
} // namespace detail
/* The `value_or_none` concept.
\requires That `U::value_type` exists and that `std::declval<U>().has_value()` returns a `bool` and `std::declval<U>().value()` exists.
*/
template <class U> static constexpr bool value_or_none = detail::value_or_none<U>;
/* The `value_or_error` concept.
\requires That `U::value_type` and `U::error_type` exist;
that `std::declval<U>().has_value()` returns a `bool`, `std::declval<U>().value()` and `std::declval<U>().error()` exists.
*/
template <class U> static constexpr bool value_or_error = detail::value_or_error<U>;
#endif
} // namespace concepts
namespace convert
{
#if OUTCOME_ENABLE_LEGACY_SUPPORT_FOR < 220
#if defined(__cpp_concepts)
template <class U>
concept OUTCOME_GCC6_CONCEPT_BOOL ValueOrNone = concepts::value_or_none<U>;
template <class U>
concept OUTCOME_GCC6_CONCEPT_BOOL ValueOrError = concepts::value_or_error<U>;
#else
template <class U> static constexpr bool ValueOrNone = concepts::value_or_none<U>;
template <class U> static constexpr bool ValueOrError = concepts::value_or_error<U>;
#endif
#endif
namespace detail
{
template <class T, class X> struct make_type
{
template <class U> static constexpr T value(U &&v) { return T{in_place_type<typename T::value_type>, static_cast<U &&>(v).value()}; }
template <class U> static constexpr T error(U &&v) { return T{in_place_type<typename T::error_type>, static_cast<U &&>(v).error()}; }
static constexpr T error() { return T{in_place_type<typename T::error_type>}; }
};
template <class T> struct make_type<T, void>
{
template <class U> static constexpr T value(U && /*unused*/) { return T{in_place_type<typename T::value_type>}; }
template <class U> static constexpr T error(U && /*unused*/) { return T{in_place_type<typename T::error_type>}; }
static constexpr T error() { return T{in_place_type<typename T::error_type>}; }
};
} // namespace detail
/*! AWAITING HUGO JSON CONVERSION TOOL
type definition value_or_error. Potential doc page: NOT FOUND
*/
template <class T, class U> struct value_or_error
{
static constexpr bool enable_result_inputs = false;
static constexpr bool enable_outcome_inputs = false;
OUTCOME_TEMPLATE(class X)
OUTCOME_TREQUIRES(
OUTCOME_TPRED(std::is_same<U, std::decay_t<X>>::value //
&&concepts::value_or_error<U> //
&& (std::is_void<typename std::decay_t<X>::value_type>::value ||
OUTCOME_V2_NAMESPACE::detail::is_explicitly_constructible<typename T::value_type, typename std::decay_t<X>::value_type>) //
&&(std::is_void<typename std::decay_t<X>::error_type>::value ||
OUTCOME_V2_NAMESPACE::detail::is_explicitly_constructible<typename T::error_type, typename std::decay_t<X>::error_type>) ))
constexpr T operator()(X &&v)
{
return v.has_value() ? detail::make_type<T, typename T::value_type>::value(static_cast<X &&>(v)) :
detail::make_type<T, typename U::error_type>::error(static_cast<X &&>(v));
}
};
} // namespace convert
OUTCOME_V2_NAMESPACE_END
#endif
|
0 | repos/outcome/include | repos/outcome/include/outcome/boost_outcome.hpp | /* A less simple result type
(C) 2017-2019 Niall Douglas <http://www.nedproductions.biz/> (7 commits)
File Created: June 2017
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License in the accompanying file
Licence.txt or at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Distributed under the Boost Software License, Version 1.0.
(See accompanying file Licence.txt or copy at
http://www.boost.org/LICENSE_1_0.txt)
*/
#ifndef OUTCOME_BOOST_OUTCOME_HPP
#define OUTCOME_BOOST_OUTCOME_HPP
#include "std_outcome.hpp"
#include "boost_result.hpp"
#ifndef BOOST_SYSTEM_BASIC_OUTCOME_FAILURE_EXCEPTION_FROM_ERROR
#define BOOST_SYSTEM_BASIC_OUTCOME_FAILURE_EXCEPTION_FROM_ERROR
namespace boost
{
namespace system
{
// Implement the .failure() observer.
inline boost::exception_ptr basic_outcome_failure_exception_from_error(const boost::system::error_code &ec)
{
return boost::copy_exception(boost::system::system_error(ec));
}
} // namespace system
} // namespace boost
#endif
OUTCOME_V2_NAMESPACE_EXPORT_BEGIN
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
template <class R, class S = boost::system::error_code, class P = boost::exception_ptr, class NoValuePolicy = policy::default_policy<R, S, P>> //
using boost_outcome = basic_outcome<R, S, P, NoValuePolicy>;
OUTCOME_V2_NAMESPACE_END
#endif
|
0 | repos/outcome/include | repos/outcome/include/outcome/utils.hpp | /* Tries to convert an exception ptr into its equivalent error code
(C) 2017-2019 Niall Douglas <http://www.nedproductions.biz/> (11 commits)
File Created: July 2017
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License in the accompanying file
Licence.txt or at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Distributed under the Boost Software License, Version 1.0.
(See accompanying file Licence.txt or copy at
http://www.boost.org/LICENSE_1_0.txt)
*/
#ifndef OUTCOME_UTILS_HPP
#define OUTCOME_UTILS_HPP
#include "config.hpp"
#include <exception>
#include <string>
#include <system_error>
OUTCOME_V2_NAMESPACE_BEGIN
#ifdef __cpp_exceptions
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
inline std::error_code error_from_exception(std::exception_ptr &&ep = std::current_exception(), std::error_code not_matched = std::make_error_code(std::errc::resource_unavailable_try_again)) noexcept
{
if(!ep)
{
return {};
}
try
{
std::rethrow_exception(ep);
}
catch(const std::invalid_argument & /*unused*/)
{
ep = std::exception_ptr();
return std::make_error_code(std::errc::invalid_argument);
}
catch(const std::domain_error & /*unused*/)
{
ep = std::exception_ptr();
return std::make_error_code(std::errc::argument_out_of_domain);
}
catch(const std::length_error & /*unused*/)
{
ep = std::exception_ptr();
return std::make_error_code(std::errc::argument_list_too_long);
}
catch(const std::out_of_range & /*unused*/)
{
ep = std::exception_ptr();
return std::make_error_code(std::errc::result_out_of_range);
}
catch(const std::logic_error & /*unused*/) /* base class for this group */
{
ep = std::exception_ptr();
return std::make_error_code(std::errc::invalid_argument);
}
catch(const std::system_error &e) /* also catches ios::failure */
{
ep = std::exception_ptr();
return e.code();
}
catch(const std::overflow_error & /*unused*/)
{
ep = std::exception_ptr();
return std::make_error_code(std::errc::value_too_large);
}
catch(const std::range_error & /*unused*/)
{
ep = std::exception_ptr();
return std::make_error_code(std::errc::result_out_of_range);
}
catch(const std::runtime_error & /*unused*/) /* base class for this group */
{
ep = std::exception_ptr();
return std::make_error_code(std::errc::resource_unavailable_try_again);
}
catch(const std::bad_alloc & /*unused*/)
{
ep = std::exception_ptr();
return std::make_error_code(std::errc::not_enough_memory);
}
catch(...)
{
}
return not_matched;
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
inline void try_throw_std_exception_from_error(std::error_code ec, const std::string &msg = std::string{})
{
if(!ec || (ec.category() != std::generic_category()
#ifndef _WIN32
&& ec.category() != std::system_category()
#endif
))
{
return;
}
switch(ec.value())
{
case EINVAL:
throw msg.empty() ? std::invalid_argument("invalid argument") : std::invalid_argument(msg);
case EDOM:
throw msg.empty() ? std::domain_error("domain error") : std::domain_error(msg);
case E2BIG:
throw msg.empty() ? std::length_error("length error") : std::length_error(msg);
case ERANGE:
throw msg.empty() ? std::out_of_range("out of range") : std::out_of_range(msg);
case EOVERFLOW:
throw msg.empty() ? std::overflow_error("overflow error") : std::overflow_error(msg);
case ENOMEM:
throw std::bad_alloc();
}
}
#endif
OUTCOME_V2_NAMESPACE_END
#endif
|
0 | repos/outcome/include | repos/outcome/include/outcome/success_failure.hpp | /* Type sugar for success and failure
(C) 2017-2019 Niall Douglas <http://www.nedproductions.biz/> (25 commits)
File Created: July 2017
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License in the accompanying file
Licence.txt or at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Distributed under the Boost Software License, Version 1.0.
(See accompanying file Licence.txt or copy at
http://www.boost.org/LICENSE_1_0.txt)
*/
#ifndef OUTCOME_SUCCESS_FAILURE_HPP
#define OUTCOME_SUCCESS_FAILURE_HPP
#include "config.hpp"
OUTCOME_V2_NAMESPACE_BEGIN
/*! AWAITING HUGO JSON CONVERSION TOOL
type definition template <class T> success_type. Potential doc page: `success_type<T>`
*/
template <class T> struct OUTCOME_NODISCARD success_type
{
using value_type = T;
private:
value_type _value;
uint16_t _spare_storage{0};
public:
success_type() = default;
success_type(const success_type &) = default;
success_type(success_type &&) = default; // NOLINT
success_type &operator=(const success_type &) = default;
success_type &operator=(success_type &&) = default; // NOLINT
~success_type() = default;
OUTCOME_TEMPLATE(class U)
OUTCOME_TREQUIRES(OUTCOME_TPRED(!std::is_same<success_type, std::decay_t<U>>::value))
constexpr explicit success_type(U &&v, uint16_t spare_storage = 0)
: _value(static_cast<U &&>(v)) // NOLINT
, _spare_storage(spare_storage)
{
}
constexpr value_type &value() & { return _value; }
constexpr const value_type &value() const & { return _value; }
constexpr value_type &&value() && { return static_cast<value_type &&>(_value); }
constexpr const value_type &&value() const && { return static_cast<value_type &&>(_value); }
constexpr uint16_t spare_storage() const { return _spare_storage; }
};
template <> struct OUTCOME_NODISCARD success_type<void>
{
using value_type = void;
constexpr uint16_t spare_storage() const { return 0; }
};
/*! Returns type sugar for implicitly constructing a `basic_result<T>` with a successful state,
default constructing `T` if necessary.
*/
inline constexpr success_type<void> success() noexcept
{
return success_type<void>{};
}
/*! Returns type sugar for implicitly constructing a `basic_result<T>` with a successful state.
\effects Copies the successful state supplied into the returned type sugar.
*/
OUTCOME_TEMPLATE(class T)
OUTCOME_TREQUIRES(OUTCOME_TPRED(std::is_copy_constructible<T>::value))
inline constexpr success_type<std::decay_t<T>> success(const T &v, uint16_t spare_storage = 0)
{
return success_type<std::decay_t<T>>{v, spare_storage};
}
/*! Returns type sugar for implicitly constructing a `basic_result<T>` with a successful state.
\effects Moves the successful state supplied into the returned type sugar.
*/
OUTCOME_TEMPLATE(class T)
OUTCOME_TREQUIRES(OUTCOME_TPRED(std::is_move_constructible<T>::value))
inline constexpr success_type<std::decay_t<T>> success(T &&v, uint16_t spare_storage = 0)
{
return success_type<std::decay_t<T>>{static_cast<T &&>(v), spare_storage};
}
/*! AWAITING HUGO JSON CONVERSION TOOL
type definition template <class EC, class E = void> failure_type. Potential doc page: `failure_type<EC, EP = void>`
*/
template <class EC, class E = void> struct OUTCOME_NODISCARD failure_type
{
using error_type = EC;
using exception_type = E;
private:
error_type _error;
exception_type _exception;
bool _have_error{false}, _have_exception{false};
uint16_t _spare_storage{0};
struct error_init_tag
{
};
struct exception_init_tag
{
};
public:
failure_type() = default;
failure_type(const failure_type &) = default;
failure_type(failure_type &&) = default; // NOLINT
failure_type &operator=(const failure_type &) = default;
failure_type &operator=(failure_type &&) = default; // NOLINT
~failure_type() = default;
template <class U, class V>
constexpr explicit failure_type(U &&u, V &&v, uint16_t spare_storage = 0)
: _error(static_cast<U &&>(u))
, _exception(static_cast<V &&>(v))
, _have_error(true)
, _have_exception(true)
, _spare_storage(spare_storage)
{
}
template <class U>
constexpr explicit failure_type(in_place_type_t<error_type> /*unused*/, U &&u, uint16_t spare_storage = 0, error_init_tag /*unused*/ = error_init_tag())
: _error(static_cast<U &&>(u))
, _exception()
, _have_error(true)
, _spare_storage(spare_storage)
{
}
template <class U>
constexpr explicit failure_type(in_place_type_t<exception_type> /*unused*/, U &&u, uint16_t spare_storage = 0,
exception_init_tag /*unused*/ = exception_init_tag())
: _error()
, _exception(static_cast<U &&>(u))
, _have_exception(true)
, _spare_storage(spare_storage)
{
}
constexpr bool has_error() const { return _have_error; }
constexpr bool has_exception() const { return _have_exception; }
constexpr error_type &error() & { return _error; }
constexpr const error_type &error() const & { return _error; }
constexpr error_type &&error() && { return static_cast<error_type &&>(_error); }
constexpr const error_type &&error() const && { return static_cast<error_type &&>(_error); }
constexpr exception_type &exception() & { return _exception; }
constexpr const exception_type &exception() const & { return _exception; }
constexpr exception_type &&exception() && { return static_cast<exception_type &&>(_exception); }
constexpr const exception_type &&exception() const && { return static_cast<exception_type &&>(_exception); }
constexpr uint16_t spare_storage() const { return _spare_storage; }
};
template <class EC> struct OUTCOME_NODISCARD failure_type<EC, void>
{
using error_type = EC;
using exception_type = void;
private:
error_type _error;
uint16_t _spare_storage{0};
public:
failure_type() = default;
failure_type(const failure_type &) = default;
failure_type(failure_type &&) = default; // NOLINT
failure_type &operator=(const failure_type &) = default;
failure_type &operator=(failure_type &&) = default; // NOLINT
~failure_type() = default;
OUTCOME_TEMPLATE(class U)
OUTCOME_TREQUIRES(OUTCOME_TPRED(!std::is_same<failure_type, std::decay_t<U>>::value))
constexpr explicit failure_type(U &&u, uint16_t spare_storage = 0)
: _error(static_cast<U &&>(u)) // NOLINT
, _spare_storage(spare_storage)
{
}
constexpr error_type &error() & { return _error; }
constexpr const error_type &error() const & { return _error; }
constexpr error_type &&error() && { return static_cast<error_type &&>(_error); }
constexpr const error_type &&error() const && { return static_cast<error_type &&>(_error); }
constexpr uint16_t spare_storage() const { return _spare_storage; }
};
template <class E> struct OUTCOME_NODISCARD failure_type<void, E>
{
using error_type = void;
using exception_type = E;
private:
exception_type _exception;
uint16_t _spare_storage{0};
public:
failure_type() = default;
failure_type(const failure_type &) = default;
failure_type(failure_type &&) = default; // NOLINT
failure_type &operator=(const failure_type &) = default;
failure_type &operator=(failure_type &&) = default; // NOLINT
~failure_type() = default;
OUTCOME_TEMPLATE(class V)
OUTCOME_TREQUIRES(OUTCOME_TPRED(!std::is_same<failure_type, std::decay_t<V>>::value))
constexpr explicit failure_type(V &&v, uint16_t spare_storage = 0)
: _exception(static_cast<V &&>(v)) // NOLINT
, _spare_storage(spare_storage)
{
}
constexpr exception_type &exception() & { return _exception; }
constexpr const exception_type &exception() const & { return _exception; }
constexpr exception_type &&exception() && { return static_cast<exception_type &&>(_exception); }
constexpr const exception_type &&exception() const && { return static_cast<exception_type &&>(_exception); }
constexpr uint16_t spare_storage() const { return _spare_storage; }
};
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class EC)
OUTCOME_TREQUIRES(OUTCOME_TPRED(std::is_copy_constructible<EC>::value))
inline constexpr failure_type<std::decay_t<EC>> failure(const EC &v, uint16_t spare_storage = 0)
{
return failure_type<std::decay_t<EC>>{v, spare_storage};
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class EC)
OUTCOME_TREQUIRES(OUTCOME_TPRED(std::is_move_constructible<EC>::value))
inline constexpr failure_type<std::decay_t<EC>> failure(EC &&v, uint16_t spare_storage = 0)
{
return failure_type<std::decay_t<EC>>{static_cast<EC &&>(v), spare_storage};
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class EC, class E)
OUTCOME_TREQUIRES(OUTCOME_TPRED(std::is_copy_constructible<EC>::value &&std::is_copy_constructible<E>::value))
inline constexpr failure_type<std::decay_t<EC>, std::decay_t<E>> failure(const EC &v, const E &w, uint16_t spare_storage = 0)
{
return failure_type<std::decay_t<EC>, std::decay_t<E>>{v, w, spare_storage};
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class EC, class E)
OUTCOME_TREQUIRES(OUTCOME_TPRED(std::is_copy_constructible<EC>::value &&std::is_move_constructible<E>::value))
inline constexpr failure_type<std::decay_t<EC>, std::decay_t<E>> failure(const EC &v, E &&w, uint16_t spare_storage = 0)
{
return failure_type<std::decay_t<EC>, std::decay_t<E>>{v, static_cast<E &&>(w), spare_storage};
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class EC, class E)
OUTCOME_TREQUIRES(OUTCOME_TPRED(std::is_move_constructible<EC>::value &&std::is_copy_constructible<E>::value))
inline constexpr failure_type<std::decay_t<EC>, std::decay_t<E>> failure(EC &&v, const E &w, uint16_t spare_storage = 0)
{
return failure_type<std::decay_t<EC>, std::decay_t<E>>{static_cast<EC &&>(v), w, spare_storage};
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class EC, class E)
OUTCOME_TREQUIRES(OUTCOME_TPRED(std::is_move_constructible<EC>::value &&std::is_move_constructible<E>::value))
inline constexpr failure_type<std::decay_t<EC>, std::decay_t<E>> failure(EC &&v, E &&w, uint16_t spare_storage = 0)
{
return failure_type<std::decay_t<EC>, std::decay_t<E>>{static_cast<EC &&>(v), static_cast<E &&>(w), spare_storage};
}
namespace detail
{
template <class T> struct is_success_type
{
static constexpr bool value = false;
};
template <class T> struct is_success_type<success_type<T>>
{
static constexpr bool value = true;
};
template <class T> struct is_failure_type
{
static constexpr bool value = false;
};
template <class EC, class E> struct is_failure_type<failure_type<EC, E>>
{
static constexpr bool value = true;
};
} // namespace detail
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
template <class T> static constexpr bool is_success_type = detail::is_success_type<std::decay_t<T>>::value;
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
template <class T> static constexpr bool is_failure_type = detail::is_failure_type<std::decay_t<T>>::value;
OUTCOME_V2_NAMESPACE_END
#endif
|
0 | repos/outcome/include/outcome | repos/outcome/include/outcome/policy/result_error_code_throw_as_system_error.hpp | /* Policies for result and outcome
(C) 2017-2019 Niall Douglas <http://www.nedproductions.biz/> (8 commits)
File Created: Oct 2017
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License in the accompanying file
Licence.txt or at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Distributed under the Boost Software License, Version 1.0.
(See accompanying file Licence.txt or copy at
http://www.boost.org/LICENSE_1_0.txt)
*/
#ifndef OUTCOME_POLICY_RESULT_ERROR_CODE_THROW_AS_SYSTEM_ERROR_HPP
#define OUTCOME_POLICY_RESULT_ERROR_CODE_THROW_AS_SYSTEM_ERROR_HPP
#include "../bad_access.hpp"
#include "base.hpp"
#include <system_error>
OUTCOME_V2_NAMESPACE_EXPORT_BEGIN
namespace policy
{
template <class T, class EC, class E> struct error_code_throw_as_system_error;
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
template <class T, class EC> struct error_code_throw_as_system_error<T, EC, void> : base
{
template <class Impl> static constexpr void wide_value_check(Impl &&self)
{
if(!base::_has_value(std::forward<Impl>(self)))
{
if(base::_has_error(std::forward<Impl>(self)))
{
// ADL discovered
outcome_throw_as_system_error_with_payload(base::_error(std::forward<Impl>(self)));
}
OUTCOME_THROW_EXCEPTION(bad_result_access("no value")); // NOLINT
}
}
template <class Impl> static constexpr void wide_error_check(Impl &&self)
{
if(!base::_has_error(std::forward<Impl>(self)))
{
OUTCOME_THROW_EXCEPTION(bad_result_access("no error")); // NOLINT
}
}
};
} // namespace policy
OUTCOME_V2_NAMESPACE_END
#endif
|
0 | repos/outcome/include/outcome | repos/outcome/include/outcome/policy/throw_bad_result_access.hpp | /* Policies for result and outcome
(C) 2017-2019 Niall Douglas <http://www.nedproductions.biz/> (13 commits)
File Created: Oct 2017
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License in the accompanying file
Licence.txt or at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Distributed under the Boost Software License, Version 1.0.
(See accompanying file Licence.txt or copy at
http://www.boost.org/LICENSE_1_0.txt)
*/
#ifndef OUTCOME_POLICY_THROW_BAD_RESULT_ACCESS_HPP
#define OUTCOME_POLICY_THROW_BAD_RESULT_ACCESS_HPP
#include "../bad_access.hpp"
#include "base.hpp"
OUTCOME_V2_NAMESPACE_EXPORT_BEGIN
namespace policy
{
/*! AWAITING HUGO JSON CONVERSION TOOL
type definition throw_bad_result_access. Potential doc page: NOT FOUND
*/
template <class EC, class EP> struct throw_bad_result_access : base
{
template <class Impl> static constexpr void wide_value_check(Impl &&self)
{
if(!base::_has_value(std::forward<Impl>(self)))
{
OUTCOME_THROW_EXCEPTION(bad_outcome_access("no value")); // NOLINT
}
}
template <class Impl> static constexpr void wide_error_check(Impl &&self)
{
if(!base::_has_error(std::forward<Impl>(self)))
{
OUTCOME_THROW_EXCEPTION(bad_outcome_access("no error")); // NOLINT
}
}
template <class Impl> static constexpr void wide_exception_check(Impl &&self)
{
if(!base::_has_exception(std::forward<Impl>(self)))
{
OUTCOME_THROW_EXCEPTION(bad_outcome_access("no exception")); // NOLINT
}
}
};
template <class EC> struct throw_bad_result_access<EC, void> : base
{
template <class Impl> static constexpr void wide_value_check(Impl &&self)
{
if(!base::_has_value(std::forward<Impl>(self)))
{
if(base::_has_error(std::forward<Impl>(self)))
{
OUTCOME_THROW_EXCEPTION(bad_result_access_with<EC>(base::_error(std::forward<Impl>(self))));
}
OUTCOME_THROW_EXCEPTION(bad_result_access("no value")); // NOLINT
}
}
template <class Impl> static constexpr void wide_error_check(Impl &&self)
{
if(!base::_has_error(std::forward<Impl>(self)))
{
OUTCOME_THROW_EXCEPTION(bad_result_access("no error")); // NOLINT
}
}
};
} // namespace policy
OUTCOME_V2_NAMESPACE_END
#endif
|
0 | repos/outcome/include/outcome | repos/outcome/include/outcome/policy/all_narrow.hpp | /* Policies for result and outcome
(C) 2017-2019 Niall Douglas <http://www.nedproductions.biz/> (13 commits)
File Created: Oct 2017
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License in the accompanying file
Licence.txt or at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Distributed under the Boost Software License, Version 1.0.
(See accompanying file Licence.txt or copy at
http://www.boost.org/LICENSE_1_0.txt)
*/
#ifndef OUTCOME_POLICY_ALL_NARROW_HPP
#define OUTCOME_POLICY_ALL_NARROW_HPP
#include "base.hpp"
OUTCOME_V2_NAMESPACE_EXPORT_BEGIN
namespace policy
{
/*! AWAITING HUGO JSON CONVERSION TOOL
type definition all_narrow. Potential doc page: `all_narrow`
*/
struct all_narrow : base
{
template <class Impl> static constexpr void wide_value_check(Impl &&self) { base::narrow_value_check(static_cast<Impl &&>(self)); }
template <class Impl> static constexpr void wide_error_check(Impl &&self) { base::narrow_error_check(static_cast<Impl &&>(self)); }
template <class Impl> static constexpr void wide_exception_check(Impl &&self) { base::narrow_exception_check(static_cast<Impl &&>(self)); }
};
} // namespace policy
OUTCOME_V2_NAMESPACE_END
#endif
|
0 | repos/outcome/include/outcome | repos/outcome/include/outcome/policy/outcome_exception_ptr_rethrow.hpp | /* Policies for result and outcome
(C) 2017-2019 Niall Douglas <http://www.nedproductions.biz/> (10 commits)
File Created: Oct 2017
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License in the accompanying file
Licence.txt or at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Distributed under the Boost Software License, Version 1.0.
(See accompanying file Licence.txt or copy at
http://www.boost.org/LICENSE_1_0.txt)
*/
#ifndef OUTCOME_POLICY_OUTCOME_EXCEPTION_PTR_RETHROW_HPP
#define OUTCOME_POLICY_OUTCOME_EXCEPTION_PTR_RETHROW_HPP
#include "result_exception_ptr_rethrow.hpp"
OUTCOME_V2_NAMESPACE_EXPORT_BEGIN
namespace policy
{
/*! AWAITING HUGO JSON CONVERSION TOOL
type definition exception_ptr_rethrow. Potential doc page: NOT FOUND
*/
template <class T, class EC, class E> struct exception_ptr_rethrow : base
{
template <class Impl> static constexpr void wide_value_check(Impl &&self)
{
if(!base::_has_value(std::forward<Impl>(self)))
{
if(base::_has_exception(std::forward<Impl>(self)))
{
detail::_rethrow_exception<trait::is_exception_ptr_available<E>::value>{base::_exception<T, EC, E, exception_ptr_rethrow>(std::forward<Impl>(self))};
}
if(base::_has_error(std::forward<Impl>(self)))
{
detail::_rethrow_exception<trait::is_exception_ptr_available<EC>::value>{base::_error(std::forward<Impl>(self))};
}
OUTCOME_THROW_EXCEPTION(bad_outcome_access("no value")); // NOLINT
}
}
template <class Impl> static constexpr void wide_error_check(Impl &&self)
{
if(!base::_has_error(std::forward<Impl>(self)))
{
OUTCOME_THROW_EXCEPTION(bad_outcome_access("no error")); // NOLINT
}
}
template <class Impl> static constexpr void wide_exception_check(Impl &&self)
{
if(!base::_has_exception(std::forward<Impl>(self)))
{
OUTCOME_THROW_EXCEPTION(bad_outcome_access("no exception")); // NOLINT
}
}
};
} // namespace policy
OUTCOME_V2_NAMESPACE_END
#endif
|
0 | repos/outcome/include/outcome | repos/outcome/include/outcome/policy/fail_to_compile_observers.hpp | /* Policies for result and outcome
(C) 2018-2019 Niall Douglas <http://www.nedproductions.biz/> (4 commits)
File Created: Sep 2018
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License in the accompanying file
Licence.txt or at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Distributed under the Boost Software License, Version 1.0.
(See accompanying file Licence.txt or copy at
http://www.boost.org/LICENSE_1_0.txt)
*/
#ifndef OUTCOME_POLICY_FAIL_TO_COMPILE_OBSERVERS_HPP
#define OUTCOME_POLICY_FAIL_TO_COMPILE_OBSERVERS_HPP
#include "base.hpp"
OUTCOME_V2_NAMESPACE_EXPORT_BEGIN
#define OUTCOME_FAIL_TO_COMPILE_OBSERVERS_MESSAGE \
"Attempt to wide observe value, error or " \
"exception for a basic_result/basic_outcome given an EC or EP type which is not void, and for whom " \
"trait::is_error_code_available<EC>, trait::is_exception_ptr_available<EC>, and trait::is_exception_ptr_available<EP> " \
"are all false. Please specify a NoValuePolicy to tell basic_result/basic_outcome what to do, or else use " \
"a more specific convenience type alias such as unchecked<T, E> to indicate you want the wide " \
"observers to be narrow, or checked<T, E> to indicate you always want an exception throw etc."
namespace policy
{
struct fail_to_compile_observers : base
{
template <class Impl> static constexpr void wide_value_check(Impl && /* unused */) { static_assert(!std::is_same<Impl, Impl>::value, OUTCOME_FAIL_TO_COMPILE_OBSERVERS_MESSAGE); }
template <class Impl> static constexpr void wide_error_check(Impl && /* unused */) { static_assert(!std::is_same<Impl, Impl>::value, OUTCOME_FAIL_TO_COMPILE_OBSERVERS_MESSAGE); }
template <class Impl> static constexpr void wide_exception_check(Impl && /* unused */) { static_assert(!std::is_same<Impl, Impl>::value, OUTCOME_FAIL_TO_COMPILE_OBSERVERS_MESSAGE); }
};
} // namespace policy
#undef OUTCOME_FAIL_TO_COMPILE_OBSERVERS_MESSAGE
OUTCOME_V2_NAMESPACE_END
#endif
|
0 | repos/outcome/include/outcome | repos/outcome/include/outcome/policy/outcome_error_code_throw_as_system_error.hpp | /* Policies for result and outcome
(C) 2017-2019 Niall Douglas <http://www.nedproductions.biz/> (12 commits)
File Created: Oct 2017
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License in the accompanying file
Licence.txt or at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Distributed under the Boost Software License, Version 1.0.
(See accompanying file Licence.txt or copy at
http://www.boost.org/LICENSE_1_0.txt)
*/
#ifndef OUTCOME_POLICY_OUTCOME_ERROR_CODE_THROW_AS_SYSTEM_ERROR_HPP
#define OUTCOME_POLICY_OUTCOME_ERROR_CODE_THROW_AS_SYSTEM_ERROR_HPP
#include "result_error_code_throw_as_system_error.hpp"
OUTCOME_V2_NAMESPACE_EXPORT_BEGIN
namespace policy
{
/*! AWAITING HUGO JSON CONVERSION TOOL
type definition error_code_throw_as_system_error. Potential doc page: NOT FOUND
*/
template <class T, class EC, class E> struct error_code_throw_as_system_error : base
{
template <class Impl> static constexpr void wide_value_check(Impl &&self)
{
if(!base::_has_value(std::forward<Impl>(self)))
{
if(base::_has_exception(std::forward<Impl>(self)))
{
detail::_rethrow_exception<trait::is_exception_ptr_available<E>::value>{base::_exception<T, EC, E, error_code_throw_as_system_error>(std::forward<Impl>(self))}; // NOLINT
}
if(base::_has_error(std::forward<Impl>(self)))
{
// ADL discovered
outcome_throw_as_system_error_with_payload(base::_error(std::forward<Impl>(self)));
}
OUTCOME_THROW_EXCEPTION(bad_outcome_access("no value")); // NOLINT
}
}
template <class Impl> static constexpr void wide_error_check(Impl &&self)
{
if(!base::_has_error(std::forward<Impl>(self)))
{
OUTCOME_THROW_EXCEPTION(bad_outcome_access("no error")); // NOLINT
}
}
template <class Impl> static constexpr void wide_exception_check(Impl &&self)
{
if(!base::_has_exception(std::forward<Impl>(self)))
{
OUTCOME_THROW_EXCEPTION(bad_outcome_access("no exception")); // NOLINT
}
}
};
} // namespace policy
OUTCOME_V2_NAMESPACE_END
#endif
|
0 | repos/outcome/include/outcome | repos/outcome/include/outcome/policy/terminate.hpp | /* Policies for result and outcome
(C) 2017-2019 Niall Douglas <http://www.nedproductions.biz/> (12 commits)
File Created: Oct 2017
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License in the accompanying file
Licence.txt or at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Distributed under the Boost Software License, Version 1.0.
(See accompanying file Licence.txt or copy at
http://www.boost.org/LICENSE_1_0.txt)
*/
#ifndef OUTCOME_POLICY_TERMINATE_HPP
#define OUTCOME_POLICY_TERMINATE_HPP
#include "base.hpp"
#include <cstdlib>
OUTCOME_V2_NAMESPACE_EXPORT_BEGIN
namespace policy
{
/*! AWAITING HUGO JSON CONVERSION TOOL
type definition terminate. Potential doc page: `terminate`
*/
struct terminate : base
{
template <class Impl> static constexpr void wide_value_check(Impl &&self)
{
if(!base::_has_value(static_cast<Impl &&>(self)))
{
std::abort();
}
}
template <class Impl> static constexpr void wide_error_check(Impl &&self) noexcept
{
if(!base::_has_error(static_cast<Impl &&>(self)))
{
std::abort();
}
}
template <class Impl> static constexpr void wide_exception_check(Impl &&self)
{
if(!base::_has_exception(static_cast<Impl &&>(self)))
{
std::abort();
}
}
};
} // namespace policy
OUTCOME_V2_NAMESPACE_END
#endif
|
0 | repos/outcome/include/outcome | repos/outcome/include/outcome/policy/base.hpp | /* Policies for result and outcome
(C) 2017-2020 Niall Douglas <http://www.nedproductions.biz/> (6 commits) and Andrzej Krzemieński <[email protected]> (1 commit)
File Created: Oct 2017
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License in the accompanying file
Licence.txt or at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Distributed under the Boost Software License, Version 1.0.
(See accompanying file Licence.txt or copy at
http://www.boost.org/LICENSE_1_0.txt)
*/
#ifndef OUTCOME_POLICY_BASE_HPP
#define OUTCOME_POLICY_BASE_HPP
#include "../detail/value_storage.hpp"
OUTCOME_V2_NAMESPACE_EXPORT_BEGIN
#if OUTCOME_ENABLE_LEGACY_SUPPORT_FOR < 220
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
namespace hooks
{
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
template <class T, class U> constexpr inline void hook_result_construction(T * /*unused*/, U && /*unused*/) noexcept {}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
template <class T, class U> constexpr inline void hook_result_copy_construction(T * /*unused*/, U && /*unused*/) noexcept {}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
template <class T, class U> constexpr inline void hook_result_move_construction(T * /*unused*/, U && /*unused*/) noexcept {}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
template <class T, class U, class... Args>
constexpr inline void hook_result_in_place_construction(T * /*unused*/, in_place_type_t<U> /*unused*/, Args &&... /*unused*/) noexcept
{
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
template <class T, class... U> constexpr inline void hook_outcome_construction(T * /*unused*/, U &&... /*unused*/) noexcept {}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
template <class T, class U> constexpr inline void hook_outcome_copy_construction(T * /*unused*/, U && /*unused*/) noexcept {}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
template <class T, class U> constexpr inline void hook_outcome_move_construction(T * /*unused*/, U && /*unused*/) noexcept {}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
template <class T, class U, class... Args>
constexpr inline void hook_outcome_in_place_construction(T * /*unused*/, in_place_type_t<U> /*unused*/, Args &&... /*unused*/) noexcept
{
}
} // namespace hooks
#endif
namespace policy
{
namespace detail
{
using OUTCOME_V2_NAMESPACE::detail::make_ub;
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
struct base
{
template <class... Args> static constexpr void _silence_unused(Args &&... /*unused*/) noexcept {}
protected:
template <class Impl> static constexpr void _make_ub(Impl &&self) noexcept { return detail::make_ub(static_cast<Impl &&>(self)); }
template <class Impl> static constexpr bool _has_value(Impl &&self) noexcept { return self._state._status.have_value(); }
template <class Impl> static constexpr bool _has_error(Impl &&self) noexcept { return self._state._status.have_error(); }
template <class Impl> static constexpr bool _has_exception(Impl &&self) noexcept { return self._state._status.have_exception(); }
template <class Impl> static constexpr bool _has_error_is_errno(Impl &&self) noexcept { return self._state._status.have_error_is_errno(); }
template <class Impl> static constexpr void _set_has_value(Impl &&self, bool v) noexcept { self._state._status.set_have_value(v); }
template <class Impl> static constexpr void _set_has_error(Impl &&self, bool v) noexcept { self._state._status.set_have_error(v); }
template <class Impl> static constexpr void _set_has_exception(Impl &&self, bool v) noexcept { self._state._status.set_have_exception(v); }
template <class Impl> static constexpr void _set_has_error_is_errno(Impl &&self, bool v) noexcept { self._state._status.set_have_error_is_errno(v); }
template <class Impl> static constexpr auto &&_value(Impl &&self) noexcept { return static_cast<Impl &&>(self)._state._value; }
template <class Impl> static constexpr auto &&_error(Impl &&self) noexcept { return static_cast<Impl &&>(self)._state._error; }
public:
template <class R, class S, class P, class NoValuePolicy, class Impl> static inline constexpr auto &&_exception(Impl &&self) noexcept;
template <class T, class U> static constexpr inline void on_result_construction(T *inst, U &&v) noexcept
{
#if OUTCOME_ENABLE_LEGACY_SUPPORT_FOR < 220
using namespace hooks;
hook_result_construction(inst, static_cast<U &&>(v));
#else
(void) inst;
(void) v;
#endif
}
template <class T, class U> static constexpr inline void on_result_copy_construction(T *inst, U &&v) noexcept
{
#if OUTCOME_ENABLE_LEGACY_SUPPORT_FOR < 220
using namespace hooks;
hook_result_copy_construction(inst, static_cast<U &&>(v));
#else
(void) inst;
(void) v;
#endif
}
template <class T, class U> static constexpr inline void on_result_move_construction(T *inst, U &&v) noexcept
{
#if OUTCOME_ENABLE_LEGACY_SUPPORT_FOR < 220
using namespace hooks;
hook_result_move_construction(inst, static_cast<U &&>(v));
#else
(void) inst;
(void) v;
#endif
}
template <class T, class U, class... Args>
static constexpr inline void on_result_in_place_construction(T *inst, in_place_type_t<U> _, Args &&... args) noexcept
{
#if OUTCOME_ENABLE_LEGACY_SUPPORT_FOR < 220
using namespace hooks;
hook_result_in_place_construction(inst, _, static_cast<Args &&>(args)...);
#else
(void) inst;
(void) _;
_silence_unused(static_cast<Args &&>(args)...);
#endif
}
template <class T, class... U> static constexpr inline void on_outcome_construction(T *inst, U &&... args) noexcept
{
#if OUTCOME_ENABLE_LEGACY_SUPPORT_FOR < 220
using namespace hooks;
hook_outcome_construction(inst, static_cast<U &&>(args)...);
#else
(void) inst;
_silence_unused(static_cast<U &&>(args)...);
#endif
}
template <class T, class U> static constexpr inline void on_outcome_copy_construction(T *inst, U &&v) noexcept
{
#if OUTCOME_ENABLE_LEGACY_SUPPORT_FOR < 220
using namespace hooks;
hook_outcome_copy_construction(inst, static_cast<U &&>(v));
#else
(void) inst;
(void) v;
#endif
}
template <class T, class U> static constexpr inline void on_outcome_move_construction(T *inst, U &&v) noexcept
{
#if OUTCOME_ENABLE_LEGACY_SUPPORT_FOR < 220
using namespace hooks;
hook_outcome_move_construction(inst, static_cast<U &&>(v));
#else
(void) inst;
(void) v;
#endif
}
template <class T, class U, class... Args>
static constexpr inline void on_outcome_in_place_construction(T *inst, in_place_type_t<U> _, Args &&... args) noexcept
{
#if OUTCOME_ENABLE_LEGACY_SUPPORT_FOR < 220
using namespace hooks;
hook_outcome_in_place_construction(inst, _, static_cast<Args &&>(args)...);
#else
(void) inst;
(void) _;
_silence_unused(static_cast<Args &&>(args)...);
#endif
}
template <class Impl> static constexpr void narrow_value_check(Impl &&self) noexcept
{
if(!_has_value(self))
{
_make_ub(self);
}
}
template <class Impl> static constexpr void narrow_error_check(Impl &&self) noexcept
{
if(!_has_error(self))
{
_make_ub(self);
}
}
template <class Impl> static constexpr void narrow_exception_check(Impl &&self) noexcept
{
if(!_has_exception(self))
{
_make_ub(self);
}
}
};
} // namespace policy
OUTCOME_V2_NAMESPACE_END
#endif
|
0 | repos/outcome/include/outcome | repos/outcome/include/outcome/policy/result_exception_ptr_rethrow.hpp | /* Policies for result and outcome
(C) 2017-2019 Niall Douglas <http://www.nedproductions.biz/> (6 commits)
File Created: Oct 2017
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License in the accompanying file
Licence.txt or at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Distributed under the Boost Software License, Version 1.0.
(See accompanying file Licence.txt or copy at
http://www.boost.org/LICENSE_1_0.txt)
*/
#ifndef OUTCOME_POLICY_RESULT_EXCEPTION_PTR_RETHROW_HPP
#define OUTCOME_POLICY_RESULT_EXCEPTION_PTR_RETHROW_HPP
#include "../bad_access.hpp"
#include "base.hpp"
OUTCOME_V2_NAMESPACE_EXPORT_BEGIN
namespace policy
{
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
template <class T, class EC, class E> struct exception_ptr_rethrow;
template <class T, class EC> struct exception_ptr_rethrow<T, EC, void> : base
{
template <class Impl> static constexpr void wide_value_check(Impl &&self)
{
if(!base::_has_value(std::forward<Impl>(self)))
{
if(base::_has_error(std::forward<Impl>(self)))
{
// ADL
rethrow_exception(policy::exception_ptr(base::_error(std::forward<Impl>(self))));
}
OUTCOME_THROW_EXCEPTION(bad_result_access("no value")); // NOLINT
}
}
template <class Impl> static constexpr void wide_error_check(Impl &&self)
{
if(!base::_has_error(std::forward<Impl>(self)))
{
OUTCOME_THROW_EXCEPTION(bad_result_access("no error")); // NOLINT
}
}
};
} // namespace policy
OUTCOME_V2_NAMESPACE_END
#endif
|
0 | repos/outcome/include/outcome | repos/outcome/include/outcome/detail/basic_result_error_observers.hpp | /* Error observers for a very simple basic_result type
(C) 2017-2019 Niall Douglas <http://www.nedproductions.biz/> (2 commits)
File Created: Oct 2017
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License in the accompanying file
Licence.txt or at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Distributed under the Boost Software License, Version 1.0.
(See accompanying file Licence.txt or copy at
http://www.boost.org/LICENSE_1_0.txt)
*/
#ifndef OUTCOME_BASIC_RESULT_ERROR_OBSERVERS_HPP
#define OUTCOME_BASIC_RESULT_ERROR_OBSERVERS_HPP
#include "basic_result_storage.hpp"
OUTCOME_V2_NAMESPACE_EXPORT_BEGIN
namespace detail
{
template <class Base, class EC, class NoValuePolicy> class basic_result_error_observers : public Base
{
public:
using error_type = EC;
using Base::Base;
constexpr error_type &assume_error() & noexcept
{
NoValuePolicy::narrow_error_check(static_cast<basic_result_error_observers &>(*this));
return this->_state._error;
}
constexpr const error_type &assume_error() const & noexcept
{
NoValuePolicy::narrow_error_check(static_cast<const basic_result_error_observers &>(*this));
return this->_state._error;
}
constexpr error_type &&assume_error() && noexcept
{
NoValuePolicy::narrow_error_check(static_cast<basic_result_error_observers &&>(*this));
return static_cast<error_type &&>(this->_state._error);
}
constexpr const error_type &&assume_error() const && noexcept
{
NoValuePolicy::narrow_error_check(static_cast<const basic_result_error_observers &&>(*this));
return static_cast<const error_type &&>(this->_state._error);
}
constexpr error_type &error() &
{
NoValuePolicy::wide_error_check(static_cast<basic_result_error_observers &>(*this));
return this->_state._error;
}
constexpr const error_type &error() const &
{
NoValuePolicy::wide_error_check(static_cast<const basic_result_error_observers &>(*this));
return this->_state._error;
}
constexpr error_type &&error() &&
{
NoValuePolicy::wide_error_check(static_cast<basic_result_error_observers &&>(*this));
return static_cast<error_type &&>(this->_state._error);
}
constexpr const error_type &&error() const &&
{
NoValuePolicy::wide_error_check(static_cast<const basic_result_error_observers &&>(*this));
return static_cast<const error_type &&>(this->_state._error);
}
};
template <class Base, class NoValuePolicy> class basic_result_error_observers<Base, void, NoValuePolicy> : public Base
{
public:
using Base::Base;
constexpr void assume_error() & noexcept { NoValuePolicy::narrow_error_check(static_cast<basic_result_error_observers &>(*this)); }
constexpr void assume_error() const & noexcept { NoValuePolicy::narrow_error_check(static_cast<const basic_result_error_observers &>(*this)); }
constexpr void assume_error() && noexcept { NoValuePolicy::narrow_error_check(static_cast<basic_result_error_observers &&>(*this)); }
constexpr void assume_error() const && noexcept { NoValuePolicy::narrow_error_check(static_cast<const basic_result_error_observers &&>(*this)); }
constexpr void error() & { NoValuePolicy::wide_error_check(static_cast<basic_result_error_observers &>(*this)); }
constexpr void error() const & { NoValuePolicy::wide_error_check(static_cast<const basic_result_error_observers &>(*this)); }
constexpr void error() && { NoValuePolicy::wide_error_check(static_cast<basic_result_error_observers &&>(*this)); }
constexpr void error() const && { NoValuePolicy::wide_error_check(static_cast<const basic_result_error_observers &&>(*this)); }
};
} // namespace detail
OUTCOME_V2_NAMESPACE_END
#endif
|
0 | repos/outcome/include/outcome | repos/outcome/include/outcome/detail/basic_outcome_exception_observers_impl.hpp | /* Exception observers for outcome type
(C) 2017-2019 Niall Douglas <http://www.nedproductions.biz/> (6 commits)
File Created: Oct 2017
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License in the accompanying file
Licence.txt or at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Distributed under the Boost Software License, Version 1.0.
(See accompanying file Licence.txt or copy at
http://www.boost.org/LICENSE_1_0.txt)
*/
#ifndef OUTCOME_BASIC_OUTCOME_EXCEPTION_OBSERVERS_IMPL_HPP
#define OUTCOME_BASIC_OUTCOME_EXCEPTION_OBSERVERS_IMPL_HPP
#include "basic_outcome_exception_observers.hpp"
#include "../policy/base.hpp"
OUTCOME_V2_NAMESPACE_EXPORT_BEGIN
namespace policy
{
template <class R, class S, class P, class NoValuePolicy, class Impl> inline constexpr auto &&base::_exception(Impl &&self) noexcept
{
// Impl will be some internal implementation class which has no knowledge of the _ptr stored
// beneath it. So statically cast, preserving rvalue and constness, to the derived class.
using Outcome = OUTCOME_V2_NAMESPACE::detail::rebind_type<basic_outcome<R, S, P, NoValuePolicy>, decltype(self)>;
#if defined(_MSC_VER) && _MSC_VER < 1920
// VS2017 tries a copy construction in the correct implementation despite that Outcome is always a rvalue or lvalue ref! :(
basic_outcome<R, S, P, NoValuePolicy> &_self = (basic_outcome<R, S, P, NoValuePolicy> &) (self); // NOLINT
#else
Outcome _self = static_cast<Outcome>(self); // NOLINT
#endif
return static_cast<Outcome>(_self)._ptr;
}
} // namespace policy
namespace detail
{
template <class Base, class R, class S, class P, class NoValuePolicy> inline constexpr typename basic_outcome_exception_observers<Base, R, S, P, NoValuePolicy>::exception_type &basic_outcome_exception_observers<Base, R, S, P, NoValuePolicy>::assume_exception() & noexcept
{
NoValuePolicy::narrow_exception_check(*this);
return NoValuePolicy::template _exception<R, S, P, NoValuePolicy>(*this);
}
template <class Base, class R, class S, class P, class NoValuePolicy> inline constexpr const typename basic_outcome_exception_observers<Base, R, S, P, NoValuePolicy>::exception_type &basic_outcome_exception_observers<Base, R, S, P, NoValuePolicy>::assume_exception() const &noexcept
{
NoValuePolicy::narrow_exception_check(*this);
return NoValuePolicy::template _exception<R, S, P, NoValuePolicy>(*this);
}
template <class Base, class R, class S, class P, class NoValuePolicy> inline constexpr typename basic_outcome_exception_observers<Base, R, S, P, NoValuePolicy>::exception_type &&basic_outcome_exception_observers<Base, R, S, P, NoValuePolicy>::assume_exception() && noexcept
{
NoValuePolicy::narrow_exception_check(std::move(*this));
return NoValuePolicy::template _exception<R, S, P, NoValuePolicy>(std::move(*this));
}
template <class Base, class R, class S, class P, class NoValuePolicy> inline constexpr const typename basic_outcome_exception_observers<Base, R, S, P, NoValuePolicy>::exception_type &&basic_outcome_exception_observers<Base, R, S, P, NoValuePolicy>::assume_exception() const &&noexcept
{
NoValuePolicy::narrow_exception_check(std::move(*this));
return NoValuePolicy::template _exception<R, S, P, NoValuePolicy>(std::move(*this));
}
template <class Base, class R, class S, class P, class NoValuePolicy> inline constexpr typename basic_outcome_exception_observers<Base, R, S, P, NoValuePolicy>::exception_type &basic_outcome_exception_observers<Base, R, S, P, NoValuePolicy>::exception() &
{
NoValuePolicy::wide_exception_check(*this);
return NoValuePolicy::template _exception<R, S, P, NoValuePolicy>(*this);
}
template <class Base, class R, class S, class P, class NoValuePolicy> inline constexpr const typename basic_outcome_exception_observers<Base, R, S, P, NoValuePolicy>::exception_type &basic_outcome_exception_observers<Base, R, S, P, NoValuePolicy>::exception() const &
{
NoValuePolicy::wide_exception_check(*this);
return NoValuePolicy::template _exception<R, S, P, NoValuePolicy>(*this);
}
template <class Base, class R, class S, class P, class NoValuePolicy> inline constexpr typename basic_outcome_exception_observers<Base, R, S, P, NoValuePolicy>::exception_type &&basic_outcome_exception_observers<Base, R, S, P, NoValuePolicy>::exception() &&
{
NoValuePolicy::wide_exception_check(std::move(*this));
return NoValuePolicy::template _exception<R, S, P, NoValuePolicy>(std::move(*this));
}
template <class Base, class R, class S, class P, class NoValuePolicy> inline constexpr const typename basic_outcome_exception_observers<Base, R, S, P, NoValuePolicy>::exception_type &&basic_outcome_exception_observers<Base, R, S, P, NoValuePolicy>::exception() const &&
{
NoValuePolicy::wide_exception_check(std::move(*this));
return NoValuePolicy::template _exception<R, S, P, NoValuePolicy>(std::move(*this));
}
} // namespace detail
OUTCOME_V2_NAMESPACE_END
#endif
|
0 | repos/outcome/include/outcome | repos/outcome/include/outcome/detail/revision.hpp | /* UPDATED BY SCRIPT
(C) 2017-2019 Niall Douglas <http://www.nedproductions.biz/> (225 commits)
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License in the accompanying file
Licence.txt or at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Distributed under the Boost Software License, Version 1.0.
(See accompanying file Licence.txt or copy at
http://www.boost.org/LICENSE_1_0.txt)
*/
// Note the second line of this file must ALWAYS be the git SHA, third line ALWAYS the git SHA update time
#define OUTCOME_PREVIOUS_COMMIT_REF 271fc9cf0693edb87d52fb496deb2baf54d4ebaa
#define OUTCOME_PREVIOUS_COMMIT_DATE "2024-07-18 14:03:54 +00:00"
#define OUTCOME_PREVIOUS_COMMIT_UNIQUE 271fc9cf
|
0 | repos/outcome/include/outcome | repos/outcome/include/outcome/detail/basic_result_value_observers.hpp | /* Value observers for a very simple basic_result type
(C) 2017-2019 Niall Douglas <http://www.nedproductions.biz/> (2 commits)
File Created: Oct 2017
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License in the accompanying file
Licence.txt or at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Distributed under the Boost Software License, Version 1.0.
(See accompanying file Licence.txt or copy at
http://www.boost.org/LICENSE_1_0.txt)
*/
#ifndef OUTCOME_RESULT_VALUE_OBSERVERS_HPP
#define OUTCOME_RESULT_VALUE_OBSERVERS_HPP
#include "basic_result_storage.hpp"
OUTCOME_V2_NAMESPACE_EXPORT_BEGIN
namespace detail
{
template <class Base, class R, class NoValuePolicy> class basic_result_value_observers : public Base
{
public:
using value_type = R;
using Base::Base;
constexpr value_type &assume_value() & noexcept
{
NoValuePolicy::narrow_value_check(static_cast<basic_result_value_observers &>(*this));
return this->_state._value; // NOLINT
}
constexpr const value_type &assume_value() const & noexcept
{
NoValuePolicy::narrow_value_check(static_cast<const basic_result_value_observers &>(*this));
return this->_state._value; // NOLINT
}
constexpr value_type &&assume_value() && noexcept
{
NoValuePolicy::narrow_value_check(static_cast<basic_result_value_observers &&>(*this));
return static_cast<value_type &&>(this->_state._value); // NOLINT
}
constexpr const value_type &&assume_value() const && noexcept
{
NoValuePolicy::narrow_value_check(static_cast<const basic_result_value_observers &&>(*this));
return static_cast<const value_type &&>(this->_state._value); // NOLINT
}
constexpr value_type &value() &
{
NoValuePolicy::wide_value_check(static_cast<basic_result_value_observers &>(*this));
return this->_state._value; // NOLINT
}
constexpr const value_type &value() const &
{
NoValuePolicy::wide_value_check(static_cast<const basic_result_value_observers &>(*this));
return this->_state._value; // NOLINT
}
constexpr value_type &&value() &&
{
NoValuePolicy::wide_value_check(static_cast<basic_result_value_observers &&>(*this));
return static_cast<value_type &&>(this->_state._value); // NOLINT
}
constexpr const value_type &&value() const &&
{
NoValuePolicy::wide_value_check(static_cast<const basic_result_value_observers &&>(*this));
return static_cast<const value_type &&>(this->_state._value); // NOLINT
}
};
template <class Base, class NoValuePolicy> class basic_result_value_observers<Base, void, NoValuePolicy> : public Base
{
public:
using Base::Base;
constexpr void assume_value() & noexcept { NoValuePolicy::narrow_value_check(static_cast<basic_result_value_observers &>(*this)); }
constexpr void assume_value() const & noexcept { NoValuePolicy::narrow_value_check(static_cast<const basic_result_value_observers &>(*this)); }
constexpr void assume_value() && noexcept { NoValuePolicy::narrow_value_check(static_cast<basic_result_value_observers &&>(*this)); }
constexpr void assume_value() const && noexcept { NoValuePolicy::narrow_value_check(static_cast<const basic_result_value_observers &&>(*this)); }
constexpr void value() & { NoValuePolicy::wide_value_check(static_cast<basic_result_value_observers &>(*this)); }
constexpr void value() const & { NoValuePolicy::wide_value_check(static_cast<const basic_result_value_observers &>(*this)); }
constexpr void value() && { NoValuePolicy::wide_value_check(static_cast<basic_result_value_observers &&>(*this)); }
constexpr void value() const && { NoValuePolicy::wide_value_check(static_cast<const basic_result_value_observers &&>(*this)); }
};
} // namespace detail
OUTCOME_V2_NAMESPACE_END
#endif
|
0 | repos/outcome/include/outcome | repos/outcome/include/outcome/detail/value_storage.hpp | /* Essentially an internal optional implementation :)
(C) 2017-2022 Niall Douglas <http://www.nedproductions.biz/> (24 commits)
File Created: June 2017
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License in the accompanying file
Licence.txt or at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Distributed under the Boost Software License, Version 1.0.
(See accompanying file Licence.txt or copy at
http://www.boost.org/LICENSE_1_0.txt)
*/
#ifndef OUTCOME_VALUE_STORAGE_HPP
#define OUTCOME_VALUE_STORAGE_HPP
#include "../config.hpp"
OUTCOME_V2_NAMESPACE_EXPORT_BEGIN
namespace detail
{
// Helpers for move assigning to empty storage
template <class T, bool isCopyOrMoveConstructible = std::is_copy_constructible<T>::value || std::is_move_constructible<T>::value,
bool isDefaultConstructibleAndCopyOrMoveAssignable =
std::is_default_constructible<T>::value && (std::is_copy_assignable<T>::value || std::is_move_assignable<T>::value)>
struct move_assign_to_empty;
// Prefer to use move or copy construction
template <class T> struct move_assign_to_empty<T, true, false>
{
move_assign_to_empty(T *dest, T *o) noexcept(std::is_nothrow_move_constructible<T>::value) { new(dest) T(static_cast<T &&>(*o)); }
};
template <class T> struct move_assign_to_empty<T, true, true>
{
move_assign_to_empty(T *dest, T *o) noexcept(std::is_nothrow_move_constructible<T>::value) { new(dest) T(static_cast<T &&>(*o)); }
};
// But fall back on default construction and move assign if necessary
template <class T> struct move_assign_to_empty<T, false, true>
{
move_assign_to_empty(T *dest, T *o) noexcept(std::is_nothrow_default_constructible<T>::value && std::is_nothrow_move_assignable<T>::value)
{
new(dest) T;
*dest = static_cast<T &&>(*o);
}
};
// Void does nothing
template <> struct move_assign_to_empty<void, false, false>
{
move_assign_to_empty(void *, void *) noexcept { /* nothing to assign */ }
};
template <> struct move_assign_to_empty<const void, false, false>
{
move_assign_to_empty(const void *, const void *) noexcept { /* nothing to assign */ }
};
// Helpers for copy assigning to empty storage
template <class T, bool isCopyConstructible = std::is_copy_constructible<T>::value,
bool isDefaultConstructibleAndCopyAssignable = std::is_default_constructible<T>::value && std::is_copy_assignable<T>::value>
struct copy_assign_to_empty;
// Prefer to use copy construction
template <class T> struct copy_assign_to_empty<T, true, false>
{
copy_assign_to_empty(T *dest, const T *o) noexcept(std::is_nothrow_copy_constructible<T>::value) { new(dest) T(*o); }
};
template <class T> struct copy_assign_to_empty<T, true, true>
{
copy_assign_to_empty(T *dest, const T *o) noexcept(std::is_nothrow_copy_constructible<T>::value) { new(dest) T(*o); }
};
// But fall back on default construction and copy assign if necessary
template <class T> struct copy_assign_to_empty<T, false, true>
{
copy_assign_to_empty(T *dest, const T *o) noexcept(std::is_nothrow_default_constructible<T>::value && std::is_nothrow_copy_assignable<T>::value)
{
new(dest) T;
*dest = *o;
}
};
// Void does nothing
template <> struct copy_assign_to_empty<void, false, false>
{
copy_assign_to_empty(void *, void *) noexcept { /* nothing to assign */ }
};
template <> struct copy_assign_to_empty<const void, false, false>
{
copy_assign_to_empty(const void *, const void *) noexcept { /* nothing to assign */ }
};
template <class T, bool nothrow> struct strong_swap_impl
{
constexpr strong_swap_impl(bool &allgood, T &a, T &b)
{
allgood = true;
using std::swap;
swap(a, b);
}
};
template <class T, bool nothrow> struct strong_placement_impl
{
template <class F> constexpr strong_placement_impl(bool &allgood, T *a, T *b, F &&f)
{
allgood = true;
new(a) T(static_cast<T &&>(*b));
b->~T();
f();
}
};
#ifdef __cpp_exceptions
template <class T> struct strong_swap_impl<T, false>
{
strong_swap_impl(bool &allgood, T &a, T &b)
{
allgood = true;
T v(static_cast<T &&>(a));
try
{
a = static_cast<T &&>(b);
}
catch(...)
{
// Try to put back a
try
{
a = static_cast<T &&>(v);
// fall through as all good
}
catch(...)
{
// failed to completely restore
allgood = false;
// throw away second exception
}
throw; // rethrow original exception
}
// b has been moved to a, try to move v to b
try
{
b = static_cast<T &&>(v);
}
catch(...)
{
// Try to restore a to b, and v to a
try
{
b = static_cast<T &&>(a);
a = static_cast<T &&>(v);
// fall through as all good
}
catch(...)
{
// failed to completely restore
allgood = false;
// throw away second exception
}
throw; // rethrow original exception
}
}
};
template <class T> struct strong_placement_impl<T, false>
{
template <class F> strong_placement_impl(bool &allgood, T *a, T *b, F &&f)
{
new(a) T(static_cast<T &&>(*b));
try
{
b->~T();
f();
}
catch(...)
{
// Try to put back a, but only if we are still good
if(allgood)
{
try
{
new(b) T(static_cast<T &&>(*a));
// fall through as all good
}
catch(...)
{
// failed to completely restore
allgood = false;
// throw away second exception
}
throw; // rethrow original exception
}
}
}
};
#endif
} // namespace detail
/*!
*/
OUTCOME_TEMPLATE(class T)
OUTCOME_TREQUIRES(OUTCOME_TPRED(std::is_move_constructible<T>::value &&std::is_move_assignable<T>::value))
constexpr inline void strong_swap(bool &allgood, T &a, T &b) noexcept(detail::is_nothrow_swappable<T>::value)
{
detail::strong_swap_impl<T, detail::is_nothrow_swappable<T>::value>(allgood, a, b);
}
/*!
*/
OUTCOME_TEMPLATE(class T, class F)
OUTCOME_TREQUIRES(OUTCOME_TPRED(std::is_move_constructible<T>::value &&std::is_move_assignable<T>::value))
constexpr inline void strong_placement(bool &allgood, T *a, T *b, F &&f) noexcept(std::is_nothrow_move_constructible<T>::value)
{
detail::strong_placement_impl<T, std::is_nothrow_move_constructible<T>::value>(allgood, a, b, static_cast<F &&>(f));
}
namespace detail
{
template <class T>
constexpr
#ifdef _MSC_VER
__declspec(noreturn)
#elif defined(__GNUC__) || defined(__clang__)
__attribute__((noreturn))
#endif
void
make_ub(T && /*unused*/)
{
OUTCOME_ASSERT(false); // NOLINT
#if defined(__GNUC__) || defined(__clang__)
__builtin_unreachable();
#elif defined(_MSC_VER)
__assume(0);
#endif
}
/* Outcome v1 used a C bitfield whose values were tracked by compiler optimisers nicely,
but that produces ICEs when used in constexpr.
Outcome v2.0-v2.1 used a 32 bit integer and manually set and cleared bits. Unfortunately
only GCC's optimiser tracks bit values during constant folding, and only per byte, and
even then unreliably. https://wg21.link/P1886 "Error speed benchmarking" showed just how
poorly clang and MSVC fails to optimise outcome-using code, if you manually set bits.
Outcome v2.2 therefore uses an enum with fixed values, and constexpr manipulation functions
to change the value to one of the enum's values. This is stupid to look at in source code,
but it make clang's optimiser do the right thing, so it's worth it.
*/
#define OUTCOME_USE_CONSTEXPR_ENUM_STATUS 0
enum class status : uint16_t
{
// WARNING: These bits are not tracked by abi-dumper, but changing them will break ABI!
none = 0,
have_value = (1U << 0U),
have_error = (1U << 1U),
have_exception = (2U << 1U),
have_error_exception = (3U << 1U),
// failed to complete a strong swap
have_lost_consistency = (1U << 3U),
have_value_lost_consistency = (1U << 0U) | (1U << 3U),
have_error_lost_consistency = (1U << 1U) | (1U << 3U),
have_exception_lost_consistency = (2U << 1U) | (1U << 3U),
have_error_exception_lost_consistency = (3U << 1U) | (1U << 3U),
// can errno be set from this error?
have_error_is_errno = (1U << 4U),
have_error_error_is_errno = (1U << 1U) | (1U << 4U),
have_error_exception_error_is_errno = (3U << 1U) | (1U << 4U),
have_error_lost_consistency_error_is_errno = (1U << 1U) | (1U << 3U) | (1U << 4U),
have_error_exception_lost_consistency_error_is_errno = (3U << 1U) | (1U << 3U) | (1U << 4U),
// value has been moved from
have_moved_from = (1U << 5U)
};
struct status_bitfield_type
{
status status_value{status::none};
uint16_t spare_storage_value{0}; // hooks::spare_storage()
constexpr status_bitfield_type() = default;
constexpr status_bitfield_type(status v) noexcept
: status_value(v)
{
} // NOLINT
constexpr status_bitfield_type(status v, uint16_t s) noexcept
: status_value(v)
, spare_storage_value(s)
{
}
constexpr status_bitfield_type(const status_bitfield_type &) = default;
constexpr status_bitfield_type(status_bitfield_type &&) = default;
constexpr status_bitfield_type &operator=(const status_bitfield_type &) = default;
constexpr status_bitfield_type &operator=(status_bitfield_type &&) = default;
//~status_bitfield_type() = default; // Do NOT uncomment this, it breaks older clangs!
constexpr bool have_value() const noexcept
{
#if OUTCOME_USE_CONSTEXPR_ENUM_STATUS
return (status_value == status::have_value) //
|| (status_value == status::have_value_lost_consistency) //
;
#else
return (static_cast<uint16_t>(status_value) & static_cast<uint16_t>(status::have_value)) != 0;
#endif
}
constexpr bool have_error() const noexcept
{
#if OUTCOME_USE_CONSTEXPR_ENUM_STATUS
return (status_value == status::have_error) //
|| (status_value == status::have_error_exception) //
|| (status_value == status::have_error_lost_consistency) //
|| (status_value == status::have_error_exception_lost_consistency) //
|| (status_value == status::have_error_error_is_errno) //
|| (status_value == status::have_error_exception_error_is_errno) //
|| (status_value == status::have_error_lost_consistency_error_is_errno) //
|| (status_value == status::have_error_exception_lost_consistency_error_is_errno) //
;
#else
return (static_cast<uint16_t>(status_value) & static_cast<uint16_t>(status::have_error)) != 0;
#endif
}
constexpr bool have_exception() const noexcept
{
#if OUTCOME_USE_CONSTEXPR_ENUM_STATUS
return (status_value == status::have_exception) //
|| (status_value == status::have_error_exception) //
|| (status_value == status::have_exception_lost_consistency) //
|| (status_value == status::have_error_exception_lost_consistency) //
|| (status_value == status::have_error_exception_error_is_errno) //
|| (status_value == status::have_error_exception_lost_consistency_error_is_errno) //
;
#else
return (static_cast<uint16_t>(status_value) & static_cast<uint16_t>(status::have_exception)) != 0;
#endif
}
constexpr bool have_lost_consistency() const noexcept
{
#if OUTCOME_USE_CONSTEXPR_ENUM_STATUS
return (status_value == status::have_value_lost_consistency) //
|| (status_value == status::have_error_lost_consistency) //
|| (status_value == status::have_exception_lost_consistency) //
|| (status_value == status::have_error_lost_consistency_error_is_errno) //
|| (status_value == status::have_error_exception_lost_consistency_error_is_errno) //
;
#else
return (static_cast<uint16_t>(status_value) & static_cast<uint16_t>(status::have_lost_consistency)) != 0;
#endif
}
constexpr bool have_error_is_errno() const noexcept
{
#if OUTCOME_USE_CONSTEXPR_ENUM_STATUS
return (status_value == status::have_error_error_is_errno) //
|| (status_value == status::have_error_exception_error_is_errno) //
|| (status_value == status::have_error_lost_consistency_error_is_errno) //
|| (status_value == status::have_error_exception_lost_consistency_error_is_errno) //
;
#else
return (static_cast<uint16_t>(status_value) & static_cast<uint16_t>(status::have_error_is_errno)) != 0;
#endif
}
constexpr bool have_moved_from() const noexcept
{
#if OUTCOME_USE_CONSTEXPR_ENUM_STATUS
#error Fixme
#else
return (static_cast<uint16_t>(status_value) & static_cast<uint16_t>(status::have_moved_from)) != 0;
#endif
}
constexpr status_bitfield_type &set_have_value(bool v) noexcept
{
#if OUTCOME_USE_CONSTEXPR_ENUM_STATUS
switch(status_value)
{
case status::none:
if(v)
{
status_value = status::have_value;
}
break;
case status::have_value:
if(!v)
{
status_value = status::none;
}
break;
case status::have_error:
if(v)
{
make_ub(*this);
}
break;
case status::have_exception:
if(v)
{
make_ub(*this);
}
break;
case status::have_error_exception:
if(v)
{
make_ub(*this);
}
break;
case status::have_value_lost_consistency:
if(!v)
{
status_value = status::none;
}
break;
case status::have_error_lost_consistency:
if(v)
{
make_ub(*this);
}
break;
case status::have_exception_lost_consistency:
if(v)
{
make_ub(*this);
}
break;
case status::have_error_exception_lost_consistency:
if(v)
{
make_ub(*this);
}
break;
case status::have_error_error_is_errno:
if(v)
{
make_ub(*this);
}
break;
case status::have_error_exception_error_is_errno:
if(v)
{
make_ub(*this);
}
break;
case status::have_error_lost_consistency_error_is_errno:
if(v)
{
make_ub(*this);
}
break;
case status::have_error_exception_lost_consistency_error_is_errno:
if(v)
{
make_ub(*this);
}
break;
}
#else
status_value = static_cast<status>(v ? (static_cast<uint16_t>(status_value) | static_cast<uint16_t>(status::have_value)) :
(static_cast<uint16_t>(status_value) & ~static_cast<uint16_t>(status::have_value)));
#endif
return *this;
}
constexpr status_bitfield_type &set_have_error(bool v) noexcept
{
#if OUTCOME_USE_CONSTEXPR_ENUM_STATUS
switch(status_value)
{
case status::none:
if(v)
{
status_value = status::have_error;
}
break;
case status::have_value:
if(v)
{
make_ub(*this);
}
break;
case status::have_error:
if(!v)
{
status_value = status::none;
}
break;
case status::have_exception:
if(v)
{
status_value = status::have_error_exception;
}
break;
case status::have_error_exception:
if(!v)
{
status_value = status::have_exception;
}
break;
case status::have_value_lost_consistency:
if(v)
{
make_ub(*this);
}
break;
case status::have_error_lost_consistency:
if(!v)
{
status_value = status::none;
}
break;
case status::have_exception_lost_consistency:
if(v)
{
status_value = status::have_error_exception_lost_consistency;
}
break;
case status::have_error_exception_lost_consistency:
if(!v)
{
status_value = status::have_exception_lost_consistency;
}
break;
case status::have_error_error_is_errno:
if(!v)
{
status_value = status::none;
}
break;
case status::have_error_exception_error_is_errno:
if(!v)
{
status_value = status::have_exception;
}
break;
case status::have_error_lost_consistency_error_is_errno:
if(!v)
{
status_value = status::none;
}
break;
case status::have_error_exception_lost_consistency_error_is_errno:
if(!v)
{
status_value = status::have_exception_lost_consistency;
}
break;
}
#else
status_value = static_cast<status>(v ? (static_cast<uint16_t>(status_value) | static_cast<uint16_t>(status::have_error)) :
(static_cast<uint16_t>(status_value) & ~static_cast<uint16_t>(status::have_error)));
#endif
return *this;
}
constexpr status_bitfield_type &set_have_exception(bool v) noexcept
{
#if OUTCOME_USE_CONSTEXPR_ENUM_STATUS
switch(status_value)
{
case status::none:
if(v)
{
status_value = status::have_exception;
}
break;
case status::have_value:
if(v)
{
make_ub(*this);
}
break;
case status::have_error:
if(v)
{
status_value = status::have_error_exception;
}
break;
case status::have_exception:
if(!v)
{
status_value = status::none;
}
break;
case status::have_error_exception:
if(!v)
{
status_value = status::have_error;
}
break;
case status::have_value_lost_consistency:
if(v)
{
make_ub(*this);
}
break;
case status::have_error_lost_consistency:
if(v)
{
status_value = status::have_error_exception_lost_consistency;
}
break;
case status::have_exception_lost_consistency:
if(!v)
{
status_value = status::none;
}
break;
case status::have_error_exception_lost_consistency:
if(!v)
{
status_value = status::have_error_lost_consistency;
}
break;
case status::have_error_error_is_errno:
if(v)
{
status_value = status::have_error_exception_error_is_errno;
}
break;
case status::have_error_exception_error_is_errno:
if(!v)
{
status_value = status::have_error_error_is_errno;
}
break;
case status::have_error_lost_consistency_error_is_errno:
if(v)
{
status_value = status::have_error_exception_lost_consistency_error_is_errno;
}
break;
case status::have_error_exception_lost_consistency_error_is_errno:
if(!v)
{
status_value = status::have_error_lost_consistency_error_is_errno;
}
break;
}
#else
status_value = static_cast<status>(v ? (static_cast<uint16_t>(status_value) | static_cast<uint16_t>(status::have_exception)) :
(static_cast<uint16_t>(status_value) & ~static_cast<uint16_t>(status::have_exception)));
#endif
return *this;
}
constexpr status_bitfield_type &set_have_error_is_errno(bool v) noexcept
{
#if OUTCOME_USE_CONSTEXPR_ENUM_STATUS
switch(status_value)
{
case status::none:
make_ub(*this);
break;
case status::have_value:
make_ub(*this);
break;
case status::have_error:
if(v)
{
status_value = status::have_error_error_is_errno;
}
break;
case status::have_exception:
make_ub(*this);
break;
case status::have_error_exception:
if(v)
{
status_value = status::have_error_exception_error_is_errno;
}
break;
case status::have_value_lost_consistency:
make_ub(*this);
break;
case status::have_error_lost_consistency:
if(v)
{
status_value = status::have_error_lost_consistency_error_is_errno;
}
break;
case status::have_exception_lost_consistency:
make_ub(*this);
break;
case status::have_error_exception_lost_consistency:
if(v)
{
status_value = status::have_error_exception_lost_consistency_error_is_errno;
}
break;
case status::have_error_error_is_errno:
if(!v)
{
status_value = status::have_error;
}
break;
case status::have_error_exception_error_is_errno:
if(!v)
{
status_value = status::have_error_exception;
}
break;
case status::have_error_lost_consistency_error_is_errno:
if(!v)
{
status_value = status::have_error_lost_consistency;
}
break;
case status::have_error_exception_lost_consistency_error_is_errno:
if(!v)
{
status_value = status::have_error_exception_lost_consistency;
}
break;
}
#else
status_value = static_cast<status>(v ? (static_cast<uint16_t>(status_value) | static_cast<uint16_t>(status::have_error_is_errno)) :
(static_cast<uint16_t>(status_value) & ~static_cast<uint16_t>(status::have_error_is_errno)));
#endif
return *this;
}
constexpr status_bitfield_type &set_have_lost_consistency(bool v) noexcept
{
#if OUTCOME_USE_CONSTEXPR_ENUM_STATUS
switch(status_value)
{
case status::none:
if(v)
{
make_ub(*this);
}
break;
case status::have_value:
if(v)
{
status_value = status::have_value_lost_consistency;
}
break;
case status::have_error:
if(v)
{
status_value = status::have_error_lost_consistency;
}
break;
case status::have_exception:
if(v)
{
status_value = status::have_exception_lost_consistency;
}
break;
case status::have_error_exception:
if(v)
{
status_value = status::have_error_exception_lost_consistency;
}
break;
case status::have_value_lost_consistency:
if(!v)
{
status_value = status::have_value;
}
break;
case status::have_error_lost_consistency:
if(!v)
{
status_value = status::have_error;
}
break;
case status::have_exception_lost_consistency:
if(!v)
{
status_value = status::have_exception;
}
break;
case status::have_error_exception_lost_consistency:
if(!v)
{
status_value = status::have_error_exception;
}
break;
case status::have_error_error_is_errno:
if(v)
{
status_value = status::have_error_lost_consistency_error_is_errno;
}
break;
case status::have_error_exception_error_is_errno:
if(v)
{
status_value = status::have_error_exception_lost_consistency_error_is_errno;
}
break;
case status::have_error_lost_consistency_error_is_errno:
if(!v)
{
status_value = status::have_error_exception_error_is_errno;
}
break;
case status::have_error_exception_lost_consistency_error_is_errno:
if(!v)
{
status_value = status::have_error_exception_error_is_errno;
}
break;
}
#else
status_value = static_cast<status>(v ? (static_cast<uint16_t>(status_value) | static_cast<uint16_t>(status::have_lost_consistency)) :
(static_cast<uint16_t>(status_value) & ~static_cast<uint16_t>(status::have_lost_consistency)));
#endif
return *this;
}
constexpr status_bitfield_type &set_have_moved_from(bool v) noexcept
{
#if OUTCOME_USE_CONSTEXPR_ENUM_STATUS
#error Fixme
#else
status_value = static_cast<status>(v ? (static_cast<uint16_t>(status_value) | static_cast<uint16_t>(status::have_moved_from)) :
(static_cast<uint16_t>(status_value) & ~static_cast<uint16_t>(status::have_moved_from)));
#endif
return *this;
}
};
#if !defined(NDEBUG)
// Check is trivial in all ways except default constructibility
static_assert(sizeof(status_bitfield_type) == 4, "status_bitfield_type is not sized 4 bytes!");
static_assert(std::is_trivially_copyable<status_bitfield_type>::value, "status_bitfield_type is not trivially copyable!");
static_assert(std::is_trivially_assignable<status_bitfield_type, status_bitfield_type>::value, "status_bitfield_type is not trivially assignable!");
static_assert(std::is_trivially_destructible<status_bitfield_type>::value, "status_bitfield_type is not trivially destructible!");
static_assert(std::is_trivially_copy_constructible<status_bitfield_type>::value, "status_bitfield_type is not trivially copy constructible!");
static_assert(std::is_trivially_move_constructible<status_bitfield_type>::value, "status_bitfield_type is not trivially move constructible!");
static_assert(std::is_trivially_copy_assignable<status_bitfield_type>::value, "status_bitfield_type is not trivially copy assignable!");
static_assert(std::is_trivially_move_assignable<status_bitfield_type>::value, "status_bitfield_type is not trivially move assignable!");
// Also check is standard layout
static_assert(std::is_standard_layout<status_bitfield_type>::value, "status_bitfield_type is not a standard layout type!");
#endif
template <class State> constexpr inline void _set_error_is_errno(State & /*unused*/) {}
#ifdef _MSC_VER
#pragma warning(push)
#pragma warning(disable : 4127) // conditional expression is constant
#pragma warning(disable : 4624) // destructor was implicitly defined as deleted
#endif
// Used if both T and E are trivial
template <class T, class E> struct value_storage_trivial
{
using value_type = T;
using error_type = E;
// Disable in place construction if they are the same type
struct disable_in_place_value_type
{
};
struct disable_in_place_error_type
{
};
using _value_type = std::conditional_t<std::is_same<value_type, error_type>::value, disable_in_place_value_type, value_type>;
using _error_type = std::conditional_t<std::is_same<value_type, error_type>::value, disable_in_place_error_type, error_type>;
using _value_type_ = devoid<value_type>;
using _error_type_ = devoid<error_type>;
union
{
empty_type _empty;
_value_type_ _value;
_error_type_ _error;
};
status_bitfield_type _status;
constexpr value_storage_trivial() noexcept
: _empty{}
{
}
value_storage_trivial(const value_storage_trivial &) = default; // NOLINT
value_storage_trivial(value_storage_trivial &&) = default; // NOLINT
value_storage_trivial &operator=(const value_storage_trivial &) = default; // NOLINT
value_storage_trivial &operator=(value_storage_trivial &&) = default; // NOLINT
~value_storage_trivial() = default;
constexpr explicit value_storage_trivial(status_bitfield_type status)
: _empty()
, _status(status)
{
}
template <class... Args>
constexpr explicit value_storage_trivial(in_place_type_t<_value_type> /*unused*/,
Args &&...args) noexcept(detail::is_nothrow_constructible<_value_type_, Args...>)
: _value(static_cast<Args &&>(args)...)
, _status(status::have_value)
{
}
template <class U, class... Args>
constexpr value_storage_trivial(in_place_type_t<_value_type> /*unused*/, std::initializer_list<U> il,
Args &&...args) noexcept(detail::is_nothrow_constructible<_value_type_, std::initializer_list<U>, Args...>)
: _value(il, static_cast<Args &&>(args)...)
, _status(status::have_value)
{
}
template <class... Args>
constexpr explicit value_storage_trivial(in_place_type_t<_error_type> /*unused*/,
Args &&...args) noexcept(detail::is_nothrow_constructible<_error_type_, Args...>)
: _error(static_cast<Args &&>(args)...)
, _status(status::have_error)
{
_set_error_is_errno(*this);
}
template <class U, class... Args>
constexpr value_storage_trivial(in_place_type_t<_error_type> /*unused*/, std::initializer_list<U> il,
Args &&...args) noexcept(detail::is_nothrow_constructible<_error_type_, std::initializer_list<U>, Args...>)
: _error(il, static_cast<Args &&>(args)...)
, _status(status::have_error)
{
_set_error_is_errno(*this);
}
struct nonvoid_converting_constructor_tag
{
};
template <class U, class V>
static constexpr bool enable_nonvoid_converting_constructor =
!(std::is_same<std::decay_t<U>, value_type>::value && std::is_same<std::decay_t<V>, error_type>::value) //
&& detail::is_constructible<value_type, U> && detail::is_constructible<error_type, V>;
OUTCOME_TEMPLATE(class U, class V)
OUTCOME_TREQUIRES(OUTCOME_TPRED(enable_nonvoid_converting_constructor<U, V>))
constexpr explicit value_storage_trivial(const value_storage_trivial<U, V> &o,
nonvoid_converting_constructor_tag /*unused*/ = {}) noexcept(detail::is_nothrow_constructible<_value_type_, U> &&
detail::is_nothrow_constructible<_error_type_, V>)
: value_storage_trivial(o._status.have_value() ?
value_storage_trivial(in_place_type<value_type>, o._value) :
(o._status.have_error() ? value_storage_trivial(in_place_type<error_type>, o._error) : value_storage_trivial())) // NOLINT
{
_status = o._status;
}
OUTCOME_TEMPLATE(class U, class V)
OUTCOME_TREQUIRES(OUTCOME_TPRED(enable_nonvoid_converting_constructor<U, V>))
constexpr explicit value_storage_trivial(value_storage_trivial<U, V> &&o,
nonvoid_converting_constructor_tag /*unused*/ = {}) noexcept(detail::is_nothrow_constructible<_value_type_, U> &&
detail::is_nothrow_constructible<_error_type_, V>)
: value_storage_trivial(
o._status.have_value() ?
value_storage_trivial(in_place_type<value_type>, static_cast<U &&>(o._value)) :
(o._status.have_error() ? value_storage_trivial(in_place_type<error_type>, static_cast<V &&>(o._error)) : value_storage_trivial())) // NOLINT
{
_status = o._status;
}
struct void_value_converting_constructor_tag
{
};
template <class V>
static constexpr bool enable_void_value_converting_constructor =
std::is_default_constructible<value_type>::value && detail::is_constructible<error_type, V>;
OUTCOME_TEMPLATE(class V)
OUTCOME_TREQUIRES(OUTCOME_TPRED(enable_void_value_converting_constructor<V>))
constexpr explicit value_storage_trivial(const value_storage_trivial<void, V> &o, void_value_converting_constructor_tag /*unused*/ = {}) noexcept(
std::is_nothrow_default_constructible<_value_type_>::value && detail::is_nothrow_constructible<_error_type_, V>)
: value_storage_trivial(o._status.have_value() ?
value_storage_trivial(in_place_type<value_type>) :
(o._status.have_error() ? value_storage_trivial(in_place_type<error_type>, o._error) : value_storage_trivial())) // NOLINT
{
_status = o._status;
}
OUTCOME_TEMPLATE(class V)
OUTCOME_TREQUIRES(OUTCOME_TPRED(enable_void_value_converting_constructor<V>))
constexpr explicit value_storage_trivial(value_storage_trivial<void, V> &&o, void_value_converting_constructor_tag /*unused*/ = {}) noexcept(
std::is_nothrow_default_constructible<_value_type_>::value && detail::is_nothrow_constructible<_error_type_, V>)
: value_storage_trivial(
o._status.have_value() ?
value_storage_trivial(in_place_type<value_type>) :
(o._status.have_error() ? value_storage_trivial(in_place_type<error_type>, static_cast<V &&>(o._error)) : value_storage_trivial())) // NOLINT
{
_status = o._status;
}
struct void_error_converting_constructor_tag
{
};
template <class U>
static constexpr bool enable_void_error_converting_constructor =
std::is_default_constructible<error_type>::value && detail::is_constructible<value_type, U>;
OUTCOME_TEMPLATE(class U)
OUTCOME_TREQUIRES(OUTCOME_TPRED(enable_void_error_converting_constructor<U>))
constexpr explicit value_storage_trivial(const value_storage_trivial<U, void> &o, void_error_converting_constructor_tag /*unused*/ = {}) noexcept(
detail::is_nothrow_constructible<_value_type_, U> && std::is_nothrow_default_constructible<_error_type_>::value)
: value_storage_trivial(o._status.have_value() ?
value_storage_trivial(in_place_type<value_type>, o._value) :
(o._status.have_error() ? value_storage_trivial(in_place_type<error_type>) : value_storage_trivial())) // NOLINT
{
_status = o._status;
}
OUTCOME_TEMPLATE(class U)
OUTCOME_TREQUIRES(OUTCOME_TPRED(enable_void_error_converting_constructor<U>))
constexpr explicit value_storage_trivial(value_storage_trivial<U, void> &&o, void_error_converting_constructor_tag /*unused*/ = {}) noexcept(
detail::is_nothrow_constructible<_value_type_, U> && std::is_nothrow_default_constructible<_error_type_>::value)
: value_storage_trivial(o._status.have_value() ?
value_storage_trivial(in_place_type<value_type>, static_cast<U &&>(o._value)) :
(o._status.have_error() ? value_storage_trivial(in_place_type<error_type>) : value_storage_trivial())) // NOLINT
{
_status = o._status;
}
constexpr void swap(value_storage_trivial &o) noexcept
{
// storage is trivial, so just use assignment
auto temp = static_cast<value_storage_trivial &&>(*this);
*this = static_cast<value_storage_trivial &&>(o);
o = static_cast<value_storage_trivial &&>(temp);
}
};
/* Used if T or E is non-trivial. The additional constexpr is injected in C++ 20 to enable Outcome to
work in constexpr evaluation contexts in C++ 20 where non-trivial constexpr destructors are now allowed.
*/
template <class T, class E> struct value_storage_nontrivial
{
using value_type = T;
using error_type = E;
struct disable_in_place_value_type
{
};
struct disable_in_place_error_type
{
};
using _value_type = std::conditional_t<std::is_same<value_type, error_type>::value, disable_in_place_value_type, value_type>;
using _error_type = std::conditional_t<std::is_same<value_type, error_type>::value, disable_in_place_error_type, error_type>;
using _value_type_ = devoid<value_type>;
using _error_type_ = devoid<error_type>;
union
{
empty_type _empty1;
_value_type_ _value;
};
status_bitfield_type _status;
union
{
empty_type _empty2;
_error_type_ _error;
};
#if __cplusplus >= 202000L || _HAS_CXX20
constexpr
#endif
value_storage_nontrivial() noexcept
: _empty1{}
, _empty2{}
{
}
value_storage_nontrivial &operator=(const value_storage_nontrivial &) = default; // if reaches here, copy assignment is trivial
value_storage_nontrivial &operator=(value_storage_nontrivial &&) = default; // NOLINT if reaches here, move assignment is trivial
#if __cplusplus >= 202000L || _HAS_CXX20
constexpr
#endif
value_storage_nontrivial(value_storage_nontrivial &&o) noexcept(std::is_nothrow_move_constructible<_value_type_>::value &&
std::is_nothrow_move_constructible<_error_type_>::value) // NOLINT
{
if(o._status.have_value())
{
new(OUTCOME_ADDRESS_OF(_value)) _value_type_(static_cast<_value_type_ &&>(o._value)); // NOLINT
}
else if(o._status.have_error())
{
new(OUTCOME_ADDRESS_OF(_error)) _error_type_(static_cast<_error_type_ &&>(o._error)); // NOLINT
}
_status = o._status;
o._status.set_have_moved_from(true);
}
#if __cplusplus >= 202000L || _HAS_CXX20
constexpr
#endif
value_storage_nontrivial(const value_storage_nontrivial &o) noexcept(std::is_nothrow_copy_constructible<_value_type_>::value &&
std::is_nothrow_copy_constructible<_error_type_>::value)
{
if(o._status.have_value())
{
new(OUTCOME_ADDRESS_OF(_value)) _value_type_(o._value); // NOLINT
}
else if(o._status.have_error())
{
new(OUTCOME_ADDRESS_OF(_error)) _error_type_(o._error); // NOLINT
}
_status = o._status;
}
#if __cplusplus >= 202000L || _HAS_CXX20
constexpr
#endif
explicit value_storage_nontrivial(status_bitfield_type status)
: _empty1()
, _status(status)
, _empty2()
{
}
template <class... Args>
constexpr explicit value_storage_nontrivial(in_place_type_t<_value_type> /*unused*/,
Args &&...args) noexcept(detail::is_nothrow_constructible<_value_type_, Args...>)
: _value(static_cast<Args &&>(args)...) // NOLINT
, _status(status::have_value)
{
}
template <class U, class... Args>
constexpr value_storage_nontrivial(in_place_type_t<_value_type> /*unused*/, std::initializer_list<U> il,
Args &&...args) noexcept(detail::is_nothrow_constructible<_value_type_, std::initializer_list<U>, Args...>)
: _value(il, static_cast<Args &&>(args)...)
, _status(status::have_value)
{
}
template <class... Args>
constexpr explicit value_storage_nontrivial(in_place_type_t<_error_type> /*unused*/,
Args &&...args) noexcept(detail::is_nothrow_constructible<_error_type_, Args...>)
: _status(status::have_error)
, _error(static_cast<Args &&>(args)...) // NOLINT
{
_set_error_is_errno(*this);
}
template <class U, class... Args>
constexpr value_storage_nontrivial(in_place_type_t<_error_type> /*unused*/, std::initializer_list<U> il,
Args &&...args) noexcept(detail::is_nothrow_constructible<_error_type_, std::initializer_list<U>, Args...>)
: _status(status::have_error)
, _error(il, static_cast<Args &&>(args)...)
{
_set_error_is_errno(*this);
}
struct nonvoid_converting_constructor_tag
{
};
template <class U, class V>
static constexpr bool enable_nonvoid_converting_constructor =
!(std::is_same<std::decay_t<U>, value_type>::value && std::is_same<std::decay_t<V>, error_type>::value) //
&& detail::is_constructible<value_type, U> && detail::is_constructible<error_type, V>;
OUTCOME_TEMPLATE(class U, class V)
OUTCOME_TREQUIRES(OUTCOME_TPRED(enable_nonvoid_converting_constructor<U, V>))
constexpr explicit value_storage_nontrivial(const value_storage_trivial<U, V> &o, nonvoid_converting_constructor_tag /*unused*/ = {}) noexcept(
detail::is_nothrow_constructible<_value_type_, U> && detail::is_nothrow_constructible<_error_type_, V>)
: value_storage_nontrivial(o._status.have_value() ?
value_storage_nontrivial(in_place_type<value_type>, o._value) :
(o._status.have_error() ? value_storage_nontrivial(in_place_type<error_type>, o._error) : value_storage_nontrivial()))
{
_status = o._status;
}
OUTCOME_TEMPLATE(class U, class V)
OUTCOME_TREQUIRES(OUTCOME_TPRED(enable_nonvoid_converting_constructor<U, V>))
constexpr explicit value_storage_nontrivial(value_storage_trivial<U, V> &&o, nonvoid_converting_constructor_tag /*unused*/ = {}) noexcept(
detail::is_nothrow_constructible<_value_type_, U> && detail::is_nothrow_constructible<_error_type_, V>)
: value_storage_nontrivial(
o._status.have_value() ?
value_storage_nontrivial(in_place_type<value_type>, static_cast<U &&>(o._value)) :
(o._status.have_error() ? value_storage_nontrivial(in_place_type<error_type>, static_cast<V &&>(o._error)) : value_storage_nontrivial()))
{
_status = o._status;
}
OUTCOME_TEMPLATE(class U, class V)
OUTCOME_TREQUIRES(OUTCOME_TPRED(enable_nonvoid_converting_constructor<U, V>))
constexpr explicit value_storage_nontrivial(const value_storage_nontrivial<U, V> &o, nonvoid_converting_constructor_tag /*unused*/ = {}) noexcept(
detail::is_nothrow_constructible<_value_type_, U> && detail::is_nothrow_constructible<_error_type_, V>)
: value_storage_nontrivial(o._status.have_value() ?
value_storage_nontrivial(in_place_type<value_type>, o._value) :
(o._status.have_error() ? value_storage_nontrivial(in_place_type<error_type>, o._error) : value_storage_nontrivial()))
{
_status = o._status;
}
OUTCOME_TEMPLATE(class U, class V)
OUTCOME_TREQUIRES(OUTCOME_TPRED(enable_nonvoid_converting_constructor<U, V>))
constexpr explicit value_storage_nontrivial(value_storage_nontrivial<U, V> &&o, nonvoid_converting_constructor_tag /*unused*/ = {}) noexcept(
detail::is_nothrow_constructible<_value_type_, U> && detail::is_nothrow_constructible<_error_type_, V>)
: value_storage_nontrivial(
o._status.have_value() ?
value_storage_nontrivial(in_place_type<value_type>, static_cast<U &&>(o._value)) :
(o._status.have_error() ? value_storage_nontrivial(in_place_type<error_type>, static_cast<V &&>(o._error)) : value_storage_nontrivial()))
{
_status = o._status;
}
struct void_value_converting_constructor_tag
{
};
template <class V>
static constexpr bool enable_void_value_converting_constructor =
std::is_default_constructible<value_type>::value && detail::is_constructible<error_type, V>;
OUTCOME_TEMPLATE(class V)
OUTCOME_TREQUIRES(OUTCOME_TPRED(enable_void_value_converting_constructor<V>))
constexpr explicit value_storage_nontrivial(const value_storage_trivial<void, V> &o, void_value_converting_constructor_tag /*unused*/ = {}) noexcept(
std::is_nothrow_default_constructible<_value_type_>::value && detail::is_nothrow_constructible<_error_type_, V>)
{
if(o._status.have_value())
{
new(OUTCOME_ADDRESS_OF(_value)) _value_type_(); // NOLINT
}
else if(o._status.have_error())
{
new(OUTCOME_ADDRESS_OF(_error)) _error_type_(o._error); // NOLINT
}
_status = o._status;
}
OUTCOME_TEMPLATE(class V)
OUTCOME_TREQUIRES(OUTCOME_TPRED(enable_void_value_converting_constructor<V>))
constexpr explicit value_storage_nontrivial(value_storage_trivial<void, V> &&o, void_value_converting_constructor_tag /*unused*/ = {}) noexcept(
std::is_nothrow_default_constructible<_value_type_>::value && detail::is_nothrow_constructible<_error_type_, V>)
{
if(o._status.have_value())
{
new(OUTCOME_ADDRESS_OF(_value)) _value_type_(); // NOLINT
}
else if(o._status.have_error())
{
new(OUTCOME_ADDRESS_OF(_error)) _error_type_(static_cast<_error_type_ &&>(o._error)); // NOLINT
}
_status = o._status;
o._status.set_have_moved_from(true);
}
struct void_error_converting_constructor_tag
{
};
template <class U>
static constexpr bool enable_void_error_converting_constructor =
std::is_default_constructible<error_type>::value && detail::is_constructible<value_type, U>;
OUTCOME_TEMPLATE(class U)
OUTCOME_TREQUIRES(OUTCOME_TPRED(enable_void_error_converting_constructor<U>))
constexpr explicit value_storage_nontrivial(const value_storage_trivial<U, void> &o, void_error_converting_constructor_tag /*unused*/ = {}) noexcept(
detail::is_nothrow_constructible<_value_type_, U> && std::is_nothrow_default_constructible<_error_type_>::value)
{
if(o._status.have_value())
{
new(OUTCOME_ADDRESS_OF(_value)) _value_type_(o._value); // NOLINT
}
else if(o._status.have_error())
{
new(OUTCOME_ADDRESS_OF(_error)) _error_type_(); // NOLINT
}
_status = o._status;
}
OUTCOME_TEMPLATE(class U)
OUTCOME_TREQUIRES(OUTCOME_TPRED(enable_void_error_converting_constructor<U>))
constexpr explicit value_storage_nontrivial(value_storage_trivial<U, void> &&o, void_error_converting_constructor_tag /*unused*/ = {}) noexcept(
detail::is_nothrow_constructible<_value_type_, U> && std::is_nothrow_default_constructible<_error_type_>::value)
{
if(o._status.have_value())
{
new(OUTCOME_ADDRESS_OF(_value)) _value_type_(static_cast<_value_type_ &&>(o._value)); // NOLINT
}
else if(o._status.have_error())
{
new(OUTCOME_ADDRESS_OF(_error)) _error_type_(); // NOLINT
}
_status = o._status;
o._status.set_have_moved_from(true);
}
#if __cplusplus >= 202000L || _HAS_CXX20
constexpr
#endif
~value_storage_nontrivial() noexcept(std::is_nothrow_destructible<_value_type_>::value && std::is_nothrow_destructible<_error_type_>::value)
{
if(this->_status.have_value())
{
if(!trait::is_move_bitcopying<value_type>::value || !this->_status.have_moved_from())
{
this->_value.~_value_type_(); // NOLINT
}
this->_status.set_have_value(false);
}
else if(this->_status.have_error())
{
if(!trait::is_move_bitcopying<error_type>::value || !this->_status.have_moved_from())
{
this->_error.~_error_type_(); // NOLINT
}
this->_status.set_have_error(false);
}
}
#if __cplusplus >= 202000L || _HAS_CXX20
constexpr
#endif
void
swap(value_storage_nontrivial &o) noexcept(detail::is_nothrow_swappable<_value_type_>::value && detail::is_nothrow_swappable<_error_type_>::value)
{
using std::swap;
// empty/empty
if(!_status.have_value() && !o._status.have_value() && !_status.have_error() && !o._status.have_error())
{
swap(_status, o._status);
return;
}
// value/value
if(_status.have_value() && o._status.have_value())
{
struct some_type
{
status_bitfield_type &a, &b;
bool all_good{false};
~some_type()
{
if(!this->all_good)
{
// We lost one of the values
this->a.set_have_lost_consistency(true);
this->b.set_have_lost_consistency(true);
}
}
} some_type_value{_status, o._status};
strong_swap(some_type_value.all_good, _value, o._value);
swap(_status, o._status);
return;
}
// error/error
if(_status.have_error() && o._status.have_error())
{
struct some_type
{
status_bitfield_type &a, &b;
bool all_good{false};
~some_type()
{
if(!this->all_good)
{
// We lost one of the values
this->a.set_have_lost_consistency(true);
this->b.set_have_lost_consistency(true);
}
}
} some_type_value{_status, o._status};
strong_swap(some_type_value.all_good, _error, o._error);
swap(_status, o._status);
return;
}
// Could be value/empty, error/empty, etc
if(_status.have_value() && !o._status.have_error())
{
// Move construct me into other
new(OUTCOME_ADDRESS_OF(o._value)) _value_type_(static_cast<_value_type_ &&>(_value)); // NOLINT
if(!trait::is_move_bitcopying<value_type>::value)
{
this->_value.~value_type(); // NOLINT
}
swap(_status, o._status);
return;
}
if(o._status.have_value() && !_status.have_error())
{
// Move construct other into me
new(OUTCOME_ADDRESS_OF(_value)) _value_type_(static_cast<_value_type_ &&>(o._value)); // NOLINT
if(!trait::is_move_bitcopying<value_type>::value)
{
o._value.~value_type(); // NOLINT
}
swap(_status, o._status);
return;
}
if(_status.have_error() && !o._status.have_value())
{
// Move construct me into other
new(OUTCOME_ADDRESS_OF(o._error)) _error_type_(static_cast<_error_type_ &&>(_error)); // NOLINT
if(!trait::is_move_bitcopying<error_type>::value)
{
this->_error.~error_type(); // NOLINT
}
swap(_status, o._status);
return;
}
if(o._status.have_error() && !_status.have_value())
{
// Move construct other into me
new(OUTCOME_ADDRESS_OF(_error)) _error_type_(static_cast<_error_type_ &&>(o._error)); // NOLINT
if(!trait::is_move_bitcopying<error_type>::value)
{
o._error.~error_type(); // NOLINT
}
swap(_status, o._status);
return;
}
// It can now only be value/error, or error/value
struct some_type
{
status_bitfield_type &a, &b;
_value_type_ *value, *o_value;
_error_type_ *error, *o_error;
bool all_good{true};
~some_type()
{
if(!this->all_good)
{
// We lost one of the values
this->a.set_have_lost_consistency(true);
this->b.set_have_lost_consistency(true);
}
}
} some_type_value{_status, o._status, OUTCOME_ADDRESS_OF(_value), OUTCOME_ADDRESS_OF(o._value), OUTCOME_ADDRESS_OF(_error), OUTCOME_ADDRESS_OF(o._error)};
if(_status.have_value() && o._status.have_error())
{
strong_placement(some_type_value.all_good, some_type_value.o_value, some_type_value.value, [&some_type_value] { //
strong_placement(some_type_value.all_good, some_type_value.error, some_type_value.o_error, [&some_type_value] { //
swap(some_type_value.a, some_type_value.b); //
});
});
return;
}
if(_status.have_error() && o._status.have_value())
{
strong_placement(some_type_value.all_good, some_type_value.o_error, some_type_value.error, [&some_type_value] { //
strong_placement(some_type_value.all_good, some_type_value.value, some_type_value.o_value, [&some_type_value] { //
swap(some_type_value.a, some_type_value.b); //
});
});
return;
}
// Should never reach here
make_ub(_value);
}
};
template <class Base> struct value_storage_delete_copy_constructor : Base // NOLINT
{
using Base::Base;
using value_type = typename Base::value_type;
using error_type = typename Base::error_type;
value_storage_delete_copy_constructor() = default;
value_storage_delete_copy_constructor(const value_storage_delete_copy_constructor &) = delete;
value_storage_delete_copy_constructor(value_storage_delete_copy_constructor &&) = default; // NOLINT
value_storage_delete_copy_constructor &operator=(const value_storage_delete_copy_constructor &o) = default;
value_storage_delete_copy_constructor &operator=(value_storage_delete_copy_constructor &&o) = default; // NOLINT
~value_storage_delete_copy_constructor() = default;
};
template <class Base> struct value_storage_delete_copy_assignment : Base // NOLINT
{
using Base::Base;
using value_type = typename Base::value_type;
using error_type = typename Base::error_type;
value_storage_delete_copy_assignment() = default;
value_storage_delete_copy_assignment(const value_storage_delete_copy_assignment &) = default;
value_storage_delete_copy_assignment(value_storage_delete_copy_assignment &&) = default; // NOLINT
value_storage_delete_copy_assignment &operator=(const value_storage_delete_copy_assignment &o) = delete;
value_storage_delete_copy_assignment &operator=(value_storage_delete_copy_assignment &&o) = default; // NOLINT
~value_storage_delete_copy_assignment() = default;
};
template <class Base> struct value_storage_delete_move_assignment : Base // NOLINT
{
using Base::Base;
using value_type = typename Base::value_type;
using error_type = typename Base::error_type;
value_storage_delete_move_assignment() = default;
value_storage_delete_move_assignment(const value_storage_delete_move_assignment &) = default;
value_storage_delete_move_assignment(value_storage_delete_move_assignment &&) = default; // NOLINT
value_storage_delete_move_assignment &operator=(const value_storage_delete_move_assignment &o) = default;
value_storage_delete_move_assignment &operator=(value_storage_delete_move_assignment &&o) = delete;
~value_storage_delete_move_assignment() = default;
};
template <class Base> struct value_storage_delete_move_constructor : Base // NOLINT
{
using Base::Base;
using value_type = typename Base::value_type;
using error_type = typename Base::error_type;
value_storage_delete_move_constructor() = default;
value_storage_delete_move_constructor(const value_storage_delete_move_constructor &) = default;
value_storage_delete_move_constructor(value_storage_delete_move_constructor &&) = delete;
value_storage_delete_move_constructor &operator=(const value_storage_delete_move_constructor &o) = default;
value_storage_delete_move_constructor &operator=(value_storage_delete_move_constructor &&o) = default;
~value_storage_delete_move_constructor() = default;
};
template <class Base> struct value_storage_nontrivial_move_assignment : Base // NOLINT
{
using Base::Base;
using value_type = typename Base::value_type;
using error_type = typename Base::error_type;
value_storage_nontrivial_move_assignment() = default;
value_storage_nontrivial_move_assignment(const value_storage_nontrivial_move_assignment &) = default;
value_storage_nontrivial_move_assignment(value_storage_nontrivial_move_assignment &&) = default; // NOLINT
value_storage_nontrivial_move_assignment &operator=(const value_storage_nontrivial_move_assignment &o) = default;
~value_storage_nontrivial_move_assignment() = default;
#if __cplusplus >= 202000L || _HAS_CXX20
constexpr
#endif
value_storage_nontrivial_move_assignment &
operator=(value_storage_nontrivial_move_assignment &&o) noexcept(std::is_nothrow_move_assignable<value_type>::value &&
std::is_nothrow_move_assignable<error_type>::value &&
noexcept(move_assign_to_empty<value_type>(static_cast<value_type *>(nullptr),
static_cast<value_type *>(nullptr))) &&
noexcept(move_assign_to_empty<error_type>(static_cast<error_type *>(nullptr),
static_cast<error_type *>(nullptr)))) // NOLINT
{
using _value_type_ = typename Base::_value_type_;
using _error_type_ = typename Base::_error_type_;
if(!this->_status.have_value() && !this->_status.have_error() && !o._status.have_value() && !o._status.have_error())
{
this->_status = o._status;
o._status.set_have_moved_from(true);
return *this;
}
if(this->_status.have_value() && o._status.have_value())
{
this->_value = static_cast<_value_type_ &&>(o._value); // NOLINT
this->_status = o._status;
o._status.set_have_moved_from(true);
return *this;
}
if(this->_status.have_error() && o._status.have_error())
{
this->_error = static_cast<_error_type_ &&>(o._error); // NOLINT
this->_status = o._status;
o._status.set_have_moved_from(true);
return *this;
}
if(this->_status.have_value() && !o._status.have_value() && !o._status.have_error())
{
if(!trait::is_move_bitcopying<value_type>::value || this->_status.have_moved_from())
{
this->_value.~_value_type_(); // NOLINT
}
this->_status = o._status;
o._status.set_have_moved_from(true);
return *this;
}
if(!this->_status.have_value() && !this->_status.have_error() && o._status.have_value())
{
move_assign_to_empty<_value_type_>(OUTCOME_ADDRESS_OF(this->_value), OUTCOME_ADDRESS_OF(o._value));
this->_status = o._status;
o._status.set_have_moved_from(true);
return *this;
}
if(this->_status.have_error() && !o._status.have_value() && !o._status.have_error())
{
if(!trait::is_move_bitcopying<error_type>::value || this->_status.have_moved_from())
{
this->_error.~_error_type_(); // NOLINT
}
this->_status = o._status;
o._status.set_have_moved_from(true);
return *this;
}
if(!this->_status.have_value() && !this->_status.have_error() && o._status.have_error())
{
move_assign_to_empty<_error_type_>(OUTCOME_ADDRESS_OF(this->_error), OUTCOME_ADDRESS_OF(o._error));
this->_status = o._status;
o._status.set_have_moved_from(true);
return *this;
}
if(this->_status.have_value() && o._status.have_error())
{
if(!trait::is_move_bitcopying<value_type>::value || this->_status.have_moved_from())
{
this->_value.~_value_type_(); // NOLINT
}
move_assign_to_empty<_error_type_>(OUTCOME_ADDRESS_OF(this->_error), OUTCOME_ADDRESS_OF(o._error));
this->_status = o._status;
o._status.set_have_moved_from(true);
return *this;
}
if(this->_status.have_error() && o._status.have_value())
{
if(!trait::is_move_bitcopying<error_type>::value || this->_status.have_moved_from())
{
this->_error.~_error_type_(); // NOLINT
}
move_assign_to_empty<_value_type_>(OUTCOME_ADDRESS_OF(this->_value), OUTCOME_ADDRESS_OF(o._value));
this->_status = o._status;
o._status.set_have_moved_from(true);
return *this;
}
// Should never reach here
make_ub(this->_value);
}
};
template <class Base> struct value_storage_nontrivial_copy_assignment : Base // NOLINT
{
using Base::Base;
using value_type = typename Base::value_type;
using error_type = typename Base::error_type;
value_storage_nontrivial_copy_assignment() = default;
value_storage_nontrivial_copy_assignment(const value_storage_nontrivial_copy_assignment &) = default;
value_storage_nontrivial_copy_assignment(value_storage_nontrivial_copy_assignment &&) = default; // NOLINT
value_storage_nontrivial_copy_assignment &operator=(value_storage_nontrivial_copy_assignment &&o) = default; // NOLINT
~value_storage_nontrivial_copy_assignment() = default;
#if __cplusplus >= 202000L || _HAS_CXX20
constexpr
#endif
value_storage_nontrivial_copy_assignment &
operator=(const value_storage_nontrivial_copy_assignment &o) noexcept(
std::is_nothrow_copy_assignable<value_type>::value && std::is_nothrow_copy_assignable<error_type>::value &&
noexcept(copy_assign_to_empty<value_type>(static_cast<value_type *>(nullptr), static_cast<value_type *>(nullptr))) &&
noexcept(copy_assign_to_empty<error_type>(static_cast<error_type *>(nullptr), static_cast<error_type *>(nullptr))))
{
using _value_type_ = typename Base::_value_type_;
using _error_type_ = typename Base::_error_type_;
if(!this->_status.have_value() && !this->_status.have_error() && !o._status.have_value() && !o._status.have_error())
{
this->_status = o._status;
return *this;
}
if(this->_status.have_value() && o._status.have_value())
{
this->_value = o._value; // NOLINT
this->_status = o._status;
return *this;
}
if(this->_status.have_error() && o._status.have_error())
{
this->_error = o._error; // NOLINT
this->_status = o._status;
return *this;
}
if(this->_status.have_value() && !o._status.have_value() && !o._status.have_error())
{
if(!trait::is_move_bitcopying<value_type>::value || this->_status.have_moved_from())
{
this->_value.~_value_type_(); // NOLINT
}
this->_status = o._status;
return *this;
}
if(!this->_status.have_value() && !this->_status.have_error() && o._status.have_value())
{
copy_assign_to_empty<_value_type_>(OUTCOME_ADDRESS_OF(this->_value), OUTCOME_ADDRESS_OF(o._value));
this->_status = o._status;
return *this;
}
if(this->_status.have_error() && !o._status.have_value() && !o._status.have_error())
{
if(!trait::is_move_bitcopying<error_type>::value || this->_status.have_moved_from())
{
this->_error.~_error_type_(); // NOLINT
}
this->_status = o._status;
return *this;
}
if(!this->_status.have_value() && !this->_status.have_error() && o._status.have_error())
{
copy_assign_to_empty<_error_type_>(OUTCOME_ADDRESS_OF(this->_error), OUTCOME_ADDRESS_OF(o._error));
this->_status = o._status;
return *this;
}
if(this->_status.have_value() && o._status.have_error())
{
if(!trait::is_move_bitcopying<value_type>::value || this->_status.have_moved_from())
{
this->_value.~_value_type_(); // NOLINT
}
copy_assign_to_empty<_error_type_>(OUTCOME_ADDRESS_OF(this->_error), OUTCOME_ADDRESS_OF(o._error));
this->_status = o._status;
return *this;
}
if(this->_status.have_error() && o._status.have_value())
{
if(!trait::is_move_bitcopying<error_type>::value || this->_status.have_moved_from())
{
this->_error.~_error_type_(); // NOLINT
}
copy_assign_to_empty<_value_type_>(OUTCOME_ADDRESS_OF(this->_value), OUTCOME_ADDRESS_OF(o._value));
this->_status = o._status;
return *this;
}
// Should never reach here
make_ub(this->_value);
}
};
#ifdef _MSC_VER
#pragma warning(pop)
#endif
// is_trivially_copyable is true even if type is not copyable, so handle that here
template <class T> struct is_storage_trivial
{
static constexpr bool value = std::is_void<T>::value || (std::is_trivially_copy_constructible<T>::value && std::is_trivially_copyable<T>::value);
};
// work around libstdc++ 7 bug
template <> struct is_storage_trivial<void>
{
static constexpr bool value = true;
};
template <> struct is_storage_trivial<const void>
{
static constexpr bool value = true;
};
// Ability to do copy assigns needs more than just copy assignment
template <class T> struct is_copy_assignable
{
static constexpr bool value = std::is_copy_assignable<T>::value && (std::is_copy_constructible<T>::value || std::is_default_constructible<T>::value);
};
// Ability to do move assigns needs more than just move assignment
template <class T> struct is_move_assignable
{
static constexpr bool value = std::is_move_assignable<T>::value && (std::is_move_constructible<T>::value || std::is_default_constructible<T>::value);
};
template <class T, class E>
using value_storage_select_trivality =
std::conditional_t<is_storage_trivial<T>::value && is_storage_trivial<E>::value, value_storage_trivial<T, E>, value_storage_nontrivial<T, E>>;
template <class T, class E>
using value_storage_select_move_constructor =
std::conditional_t<std::is_move_constructible<devoid<T>>::value && std::is_move_constructible<devoid<E>>::value, value_storage_select_trivality<T, E>,
value_storage_delete_move_constructor<value_storage_select_trivality<T, E>>>;
template <class T, class E>
using value_storage_select_copy_constructor =
std::conditional_t<std::is_copy_constructible<devoid<T>>::value && std::is_copy_constructible<devoid<E>>::value, value_storage_select_move_constructor<T, E>,
value_storage_delete_copy_constructor<value_storage_select_move_constructor<T, E>>>;
template <class T, class E>
using value_storage_select_move_assignment =
std::conditional_t<std::is_trivially_move_assignable<devoid<T>>::value && std::is_trivially_move_assignable<devoid<E>>::value,
value_storage_select_copy_constructor<T, E>,
std::conditional_t<is_move_assignable<devoid<T>>::value && is_move_assignable<devoid<E>>::value,
value_storage_nontrivial_move_assignment<value_storage_select_copy_constructor<T, E>>,
value_storage_delete_move_assignment<value_storage_select_copy_constructor<T, E>>>>;
template <class T, class E>
using value_storage_select_copy_assignment =
std::conditional_t<std::is_trivially_copy_assignable<devoid<T>>::value && std::is_trivially_copy_assignable<devoid<E>>::value,
value_storage_select_move_assignment<T, E>,
std::conditional_t<is_copy_assignable<devoid<T>>::value && is_copy_assignable<devoid<E>>::value,
value_storage_nontrivial_copy_assignment<value_storage_select_move_assignment<T, E>>,
value_storage_delete_copy_assignment<value_storage_select_move_assignment<T, E>>>>;
template <class T, class E> using value_storage_select_impl = value_storage_select_copy_assignment<T, E>;
#ifndef NDEBUG
// Check is trivial in all ways except default constructibility
// static_assert(std::is_trivial<value_storage_select_impl<int, long>>::value, "value_storage_select_impl<int, long> is not trivial!");
// static_assert(std::is_trivially_default_constructible<value_storage_select_impl<int, long>>::value, "value_storage_select_impl<int, long> is not
// trivially default constructible!");
static_assert(std::is_trivially_copyable<value_storage_select_impl<int, long>>::value, "value_storage_select_impl<int, long> is not trivially copyable!");
static_assert(std::is_trivially_assignable<value_storage_select_impl<int, long>, value_storage_select_impl<int, long>>::value,
"value_storage_select_impl<int, long> is not trivially assignable!");
static_assert(std::is_trivially_destructible<value_storage_select_impl<int, long>>::value,
"value_storage_select_impl<int, long> is not trivially destructible!");
static_assert(std::is_trivially_copy_constructible<value_storage_select_impl<int, long>>::value,
"value_storage_select_impl<int, long> is not trivially copy constructible!");
static_assert(std::is_trivially_move_constructible<value_storage_select_impl<int, long>>::value,
"value_storage_select_impl<int, long> is not trivially move constructible!");
static_assert(std::is_trivially_copy_assignable<value_storage_select_impl<int, long>>::value,
"value_storage_select_impl<int, long> is not trivially copy assignable!");
static_assert(std::is_trivially_move_assignable<value_storage_select_impl<int, long>>::value,
"value_storage_select_impl<int, long> is not trivially move assignable!");
// Also check is standard layout
static_assert(std::is_standard_layout<value_storage_select_impl<int, long>>::value, "value_storage_select_impl<int, long> is not a standard layout type!");
#endif
} // namespace detail
OUTCOME_V2_NAMESPACE_END
#endif
|
0 | repos/outcome/include/outcome | repos/outcome/include/outcome/detail/version.hpp | /* Sets Outcome version
(C) 2017-2023 Niall Douglas <http://www.nedproductions.biz/> (4 commits)
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License in the accompanying file
Licence.txt or at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Distributed under the Boost Software License, Version 1.0.
(See accompanying file Licence.txt or copy at
http://www.boost.org/LICENSE_1_0.txt)
*/
/*! AWAITING HUGO JSON CONVERSION TOOL */
#define OUTCOME_VERSION_MAJOR 2
/*! AWAITING HUGO JSON CONVERSION TOOL */
#define OUTCOME_VERSION_MINOR 2
/*! AWAITING HUGO JSON CONVERSION TOOL */
#define OUTCOME_VERSION_PATCH 9
/*! AWAITING HUGO JSON CONVERSION TOOL */
#define OUTCOME_VERSION_REVISION 0 // Revision version for cmake and DLL version stamping
/*! AWAITING HUGO JSON CONVERSION TOOL */
#ifdef OUTCOME_ENABLE_ABI_PERMUTATION
#define OUTCOME_UNSTABLE_VERSION
#endif
|
0 | repos/outcome/include/outcome | repos/outcome/include/outcome/detail/coroutine_support.ipp | /* Tells C++ coroutines about Outcome's result
(C) 2019-2023 Niall Douglas <http://www.nedproductions.biz/> (12 commits)
File Created: Oct 2019
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License in the accompanying file
Licence.txt or at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Distributed under the Boost Software License, Version 1.0.
(See accompanying file Licence.txt or copy at
http://www.boost.org/LICENSE_1_0.txt)
*/
#ifndef OUTCOME_COROUTINE_SUPPORT_NAMESPACE_BEGIN
#error This header must only be included by outcome/coroutine_support.hpp or outcome/experimental/coroutine_support.hpp
#endif
#ifndef OUTCOME_DETAIL_COROUTINE_SUPPORT_HPP
#define OUTCOME_DETAIL_COROUTINE_SUPPORT_HPP
#include <atomic>
#include <exception>
#ifndef OUTCOME_COROUTINE_HEADER_TYPE
#if __has_include(<coroutine>)
#define OUTCOME_COROUTINE_HEADER_TYPE 1
#elif __has_include(<experimental/coroutine>)
#define OUTCOME_COROUTINE_HEADER_TYPE 2
#else
#define OUTCOME_COROUTINE_HEADER_TYPE 0
#endif
#endif
#if OUTCOME_COROUTINE_HEADER_TYPE && (__cpp_impl_coroutine || (defined(_MSC_VER) && __cpp_coroutines))
#ifndef OUTCOME_HAVE_NOOP_COROUTINE
#if defined(__has_builtin)
#if __has_builtin(__builtin_coro_noop) || (!defined(__clang__) && __GNUC__ >= 10)
#define OUTCOME_HAVE_NOOP_COROUTINE 1
#endif
#endif
#endif
#ifndef OUTCOME_HAVE_NOOP_COROUTINE
#if _MSC_VER >= 1928 || (!defined(__clang__) && __GNUC__ >= 10)
#define OUTCOME_HAVE_NOOP_COROUTINE 1
#else
#define OUTCOME_HAVE_NOOP_COROUTINE 0
#endif
#endif
#if OUTCOME_COROUTINE_HEADER_TYPE == 1
#include <coroutine>
OUTCOME_V2_NAMESPACE_BEGIN
namespace awaitables
{
template <class Promise = void> using coroutine_handle = std::coroutine_handle<Promise>;
template <class... Args> using coroutine_traits = std::coroutine_traits<Args...>;
using std::suspend_always;
using std::suspend_never;
#if OUTCOME_HAVE_NOOP_COROUTINE
using std::noop_coroutine;
#endif
} // namespace awaitables
OUTCOME_V2_NAMESPACE_END
#define OUTCOME_FOUND_COROUTINE_HEADER 1
#elif OUTCOME_COROUTINE_HEADER_TYPE == 2
#include <experimental/coroutine>
OUTCOME_V2_NAMESPACE_BEGIN
namespace awaitables
{
template <class Promise = void> using coroutine_handle = std::experimental::coroutine_handle<Promise>;
template <class... Args> using coroutine_traits = std::experimental::coroutine_traits<Args...>;
using std::experimental::suspend_always;
using std::experimental::suspend_never;
#if OUTCOME_HAVE_NOOP_COROUTINE
using std::experimental::noop_coroutine;
#endif
} // namespace awaitables
OUTCOME_V2_NAMESPACE_END
#define OUTCOME_FOUND_COROUTINE_HEADER 1
#endif
#endif
#ifndef OUTCOME_V2_AWAITABLES_DEBUG_PRINTER
// #include <iostream>
// #define OUTCOME_V2_AWAITABLES_DEBUG_PRINTER(...) std::cout << __VA_ARGS__ << std::endl;
#define OUTCOME_V2_AWAITABLES_DEBUG_PRINTER(...)
#endif
OUTCOME_V2_NAMESPACE_EXPORT_BEGIN
namespace awaitables
{
namespace detail
{
struct error_type_not_found
{
};
struct exception_type_not_found
{
};
template <class T> struct type_found
{
using type = T;
};
template <class T, class U = typename T::error_type> constexpr inline type_found<U> extract_error_type(int /*unused*/)
{
return {};
}
template <class T> constexpr inline type_found<error_type_not_found> extract_error_type(...)
{
return {};
}
template <class T, class U = typename T::exception_type> constexpr inline type_found<U> extract_exception_type(int /*unused*/)
{
return {};
}
template <class T> constexpr inline type_found<exception_type_not_found> extract_exception_type(...)
{
return {};
}
OUTCOME_TEMPLATE(class T, class U)
OUTCOME_TREQUIRES(OUTCOME_TPRED(OUTCOME_V2_NAMESPACE::detail::is_constructible<U, T>))
inline bool try_set_error(T &&e, U *result)
{
new(result) U(static_cast<T &&>(e));
return true;
}
template <class T> inline bool try_set_error(T && /*unused*/, ...)
{
return false;
}
OUTCOME_TEMPLATE(class T, class U)
OUTCOME_TREQUIRES(OUTCOME_TPRED(OUTCOME_V2_NAMESPACE::detail::is_constructible<U, T>))
inline void set_or_rethrow(T &e, U *result)
{
new(result) U(e);
}
template <class T> inline void set_or_rethrow(T &e, ...)
{
rethrow_exception(e);
}
template <class T> class fake_atomic
{
T _v;
public:
constexpr fake_atomic(T v)
: _v(v)
{
}
T load(std::memory_order /*unused*/) { return _v; }
void store(T v, std::memory_order /*unused*/) { _v = v; }
bool compare_exchange_strong(T &expected, T v, std::memory_order /*unused*/, std::memory_order /*unused*/)
{
if(_v == expected)
{
_v = v;
return true;
}
return false;
}
};
#ifdef OUTCOME_FOUND_COROUTINE_HEADER
template <class Awaitable, bool suspend_initial, bool use_atomic, bool is_void> struct outcome_promise_type
{
using container_type = typename Awaitable::container_type;
using result_set_type = std::conditional_t<use_atomic, std::atomic<bool>, fake_atomic<bool>>;
union
{
OUTCOME_V2_NAMESPACE::detail::empty_type _default{};
container_type result;
};
result_set_type result_set{false}, pending_first_resumption{is_initially_suspended};
coroutine_handle<> continuation;
static constexpr bool is_initially_suspended = suspend_initial;
static constexpr bool is_using_atomics = use_atomic;
outcome_promise_type() noexcept { OUTCOME_V2_AWAITABLES_DEBUG_PRINTER(this << " promise constructed"); }
outcome_promise_type(const outcome_promise_type &) = delete;
outcome_promise_type(outcome_promise_type &&) = delete;
outcome_promise_type &operator=(const outcome_promise_type &) = delete;
outcome_promise_type &operator=(outcome_promise_type &&) = delete;
~outcome_promise_type()
{
OUTCOME_V2_AWAITABLES_DEBUG_PRINTER(this << " promise destructs");
if(result_set.load(std::memory_order_acquire))
{
result.~container_type(); // could throw
}
}
auto get_return_object()
{
OUTCOME_V2_AWAITABLES_DEBUG_PRINTER(this << " promise returns awaitable");
return Awaitable{*this}; // could throw bad_alloc
}
void return_value(container_type &&value)
{
OUTCOME_V2_AWAITABLES_DEBUG_PRINTER(this << " promise returns value");
OUTCOME_ASSERT(!result_set.load(std::memory_order_acquire));
if(result_set.load(std::memory_order_acquire))
{
result.~container_type(); // could throw
}
new(&result) container_type(static_cast<container_type &&>(value)); // could throw
result_set.store(true, std::memory_order_release);
}
void return_value(const container_type &value)
{
OUTCOME_V2_AWAITABLES_DEBUG_PRINTER(this << " promise returns value");
OUTCOME_ASSERT(!result_set.load(std::memory_order_acquire));
if(result_set.load(std::memory_order_acquire))
{
result.~container_type(); // could throw
}
new(&result) container_type(value); // could throw
result_set.store(true, std::memory_order_release);
}
void unhandled_exception()
{
OUTCOME_V2_AWAITABLES_DEBUG_PRINTER(this << " promise unhandled exception");
OUTCOME_ASSERT(!result_set.load(std::memory_order_acquire));
if(result_set.load(std::memory_order_acquire))
{
result.~container_type();
}
#ifdef __cpp_exceptions
auto e = std::current_exception();
auto ec = detail::error_from_exception(static_cast<decltype(e) &&>(e), {});
// Try to set error code first
if(!detail::error_is_set(ec) || !detail::try_set_error(static_cast<decltype(ec) &&>(ec), &result))
{
detail::set_or_rethrow(e, &result); // could throw
}
#else
std::terminate();
#endif
result_set.store(true, std::memory_order_release);
}
auto initial_suspend() noexcept
{
OUTCOME_V2_AWAITABLES_DEBUG_PRINTER(this << " promise initial suspend = " << suspend_initial);
struct awaiter
{
constexpr bool await_ready() noexcept { return !suspend_initial; }
void await_resume() noexcept {}
void await_suspend(coroutine_handle<> /*unused*/) noexcept {}
};
return awaiter{};
}
auto final_suspend() noexcept
{
struct awaiter
{
// If we don't force a final suspend, promise will get deleted before awaitable
// TODO: Implement detachable awaitables
constexpr bool await_ready() noexcept { return false; }
void await_resume() noexcept {}
#if OUTCOME_HAVE_NOOP_COROUTINE
coroutine_handle<> await_suspend(coroutine_handle<outcome_promise_type> self) noexcept
{
if(self.promise().continuation)
{
OUTCOME_V2_AWAITABLES_DEBUG_PRINTER(&self.promise() << " promise final suspend will resume coroutine " << self.promise().continuation.address());
}
else
{
OUTCOME_V2_AWAITABLES_DEBUG_PRINTER(&self.promise() << " promise final suspend will exit");
}
return self.promise().continuation ? self.promise().continuation : noop_coroutine();
}
#else
void await_suspend(coroutine_handle<outcome_promise_type> self)
{
if(self.promise().continuation)
{
OUTCOME_V2_AWAITABLES_DEBUG_PRINTER(&self.promise() << " promise final suspend will resume coroutine " << self.promise().continuation.address());
return self.promise().continuation.resume();
}
else
{
OUTCOME_V2_AWAITABLES_DEBUG_PRINTER(&self.promise() << " promise final suspend will exit");
}
}
#endif
};
return awaiter{};
}
};
template <class Awaitable, bool suspend_initial, bool use_atomic> struct outcome_promise_type<Awaitable, suspend_initial, use_atomic, true>
{
using container_type = void;
using result_set_type = std::conditional_t<use_atomic, std::atomic<bool>, fake_atomic<bool>>;
result_set_type result_set{false}, pending_first_resumption{is_initially_suspended};
coroutine_handle<> continuation;
static constexpr bool is_initially_suspended = suspend_initial;
static constexpr bool is_using_atomics = use_atomic;
outcome_promise_type() { OUTCOME_V2_AWAITABLES_DEBUG_PRINTER(this << " promise constructed"); }
outcome_promise_type(const outcome_promise_type &) = delete;
outcome_promise_type(outcome_promise_type &&) = delete;
outcome_promise_type &operator=(const outcome_promise_type &) = delete;
outcome_promise_type &operator=(outcome_promise_type &&) = delete;
~outcome_promise_type() = default;
auto get_return_object()
{
OUTCOME_V2_AWAITABLES_DEBUG_PRINTER(this << " promise returns awaitable");
return Awaitable{*this}; // could throw bad_alloc
}
void return_void() noexcept
{
OUTCOME_V2_AWAITABLES_DEBUG_PRINTER(this << " promise returns void");
OUTCOME_ASSERT(!result_set.load(std::memory_order_acquire));
result_set.store(true, std::memory_order_release);
}
void unhandled_exception()
{
OUTCOME_V2_AWAITABLES_DEBUG_PRINTER(this << " promise unhandled exception");
OUTCOME_ASSERT(!result_set.load(std::memory_order_acquire));
std::rethrow_exception(std::current_exception()); // throws
}
auto initial_suspend() noexcept
{
OUTCOME_V2_AWAITABLES_DEBUG_PRINTER(this << " promise initial suspend = " << suspend_initial);
struct awaiter
{
constexpr bool await_ready() noexcept { return !suspend_initial; }
void await_resume() noexcept {}
void await_suspend(coroutine_handle<> /*unused*/) noexcept {}
};
return awaiter{};
}
auto final_suspend() noexcept
{
struct awaiter
{
// If we don't force a final suspend, promise will get deleted before awaitable
// TODO: Implement detachable awaitables
constexpr bool await_ready() noexcept { return false; }
void await_resume() noexcept {}
#if OUTCOME_HAVE_NOOP_COROUTINE
coroutine_handle<> await_suspend(coroutine_handle<outcome_promise_type> self) noexcept
{
if(self.promise().continuation)
{
OUTCOME_V2_AWAITABLES_DEBUG_PRINTER(&self.promise() << " promise final suspend will resume coroutine " << self.promise().continuation.address());
}
else
{
OUTCOME_V2_AWAITABLES_DEBUG_PRINTER(&self.promise() << " promise final suspend will exit");
}
return self.promise().continuation ? self.promise().continuation : noop_coroutine();
}
#else
void await_suspend(coroutine_handle<outcome_promise_type> self)
{
if(self.promise().continuation)
{
OUTCOME_V2_AWAITABLES_DEBUG_PRINTER(&self.promise() << " promise final suspend will resume coroutine " << self.promise().continuation.address());
return self.promise().continuation.resume();
}
else
{
OUTCOME_V2_AWAITABLES_DEBUG_PRINTER(&self.promise() << " promise final suspend will exit");
}
}
#endif
};
return awaiter{};
}
};
template <class Awaitable, bool suspend_initial, bool use_atomic>
constexpr inline auto move_result_from_promise_if_not_void(outcome_promise_type<Awaitable, suspend_initial, use_atomic, false> &p)
{
return static_cast<typename Awaitable::container_type &&>(p.result);
}
template <class Awaitable, bool suspend_initial, bool use_atomic>
constexpr inline void move_result_from_promise_if_not_void(outcome_promise_type<Awaitable, suspend_initial, use_atomic, true> & /*unused*/)
{
}
template <class Cont, class Executor, bool suspend_initial, bool use_atomic> struct OUTCOME_NODISCARD awaitable
{
using container_type = Cont;
using value_type = Cont;
using executor_type = Executor;
using promise_type = outcome_promise_type<awaitable, suspend_initial, use_atomic, std::is_void<container_type>::value>;
coroutine_handle<promise_type> _h;
awaitable(awaitable &&o) noexcept
: _h(static_cast<coroutine_handle<promise_type> &&>(o._h))
{
o._h = nullptr;
}
awaitable(const awaitable &o) = delete;
awaitable &operator=(awaitable &&) = delete; // as per P1056
awaitable &operator=(const awaitable &) = delete;
~awaitable()
{
OUTCOME_V2_AWAITABLES_DEBUG_PRINTER(&_h.promise() << " awaitable destructs");
if(_h)
{
_h.destroy();
}
}
explicit awaitable(promise_type &p) // could throw
: _h(coroutine_handle<promise_type>::from_promise(p))
{
OUTCOME_V2_AWAITABLES_DEBUG_PRINTER(&_h.promise() << " awaitable constructs for coroutine " << _h.address()
<< " shall resume on first suspend = " << promise_type::is_initially_suspended);
}
bool valid() const noexcept { return _h != nullptr; }
bool await_ready() noexcept
{
OUTCOME_V2_AWAITABLES_DEBUG_PRINTER(&_h.promise() << " await_ready = " << _h.promise().result_set.load(std::memory_order_acquire));
return _h.promise().result_set.load(std::memory_order_acquire);
}
container_type await_resume()
{
OUTCOME_V2_AWAITABLES_DEBUG_PRINTER(&_h.promise() << " await_resume");
OUTCOME_ASSERT(_h.promise().result_set.load(std::memory_order_acquire));
if(!_h.promise().result_set.load(std::memory_order_acquire))
{
std::terminate();
}
return detail::move_result_from_promise_if_not_void(_h.promise());
}
#if OUTCOME_HAVE_NOOP_COROUTINE
coroutine_handle<> await_suspend(coroutine_handle<> cont) noexcept
{
OUTCOME_V2_AWAITABLES_DEBUG_PRINTER(&_h.promise() << " await_suspend suspends coroutine " << cont.address());
auto &p = _h.promise();
p.continuation = cont;
bool expected = true;
if(p.pending_first_resumption.compare_exchange_strong(expected, false, std::memory_order_acq_rel, std::memory_order_relaxed))
{
OUTCOME_V2_AWAITABLES_DEBUG_PRINTER(&_h.promise()
<< " await_suspend does one time first resumption of initially suspended coroutine " << _h.address());
return _h;
}
return noop_coroutine();
}
#else
void await_suspend(coroutine_handle<> cont)
{
OUTCOME_V2_AWAITABLES_DEBUG_PRINTER(&_h.promise() << " await_suspend suspends coroutine " << cont.address());
auto &p = _h.promise();
p.continuation = cont;
bool expected = true;
if(p.pending_first_resumption.compare_exchange_strong(expected, false, std::memory_order_acq_rel, std::memory_order_relaxed))
{
OUTCOME_V2_AWAITABLES_DEBUG_PRINTER(&_h.promise()
<< " await_suspend does one time first resumption of initially suspended coroutine " << _h.address());
_h.resume();
}
}
#endif
};
template <class ContType, class Executor, bool suspend_initial, bool use_atomic> struct generator
{
using container_type = ContType;
using value_type = ContType;
using executor_type = Executor;
class promise_type
{
friend struct generator;
using result_set_type = std::conditional_t<use_atomic, std::atomic<int8_t>, fake_atomic<int8_t>>;
union
{
OUTCOME_V2_NAMESPACE::detail::empty_type _default{};
container_type result;
};
result_set_type result_set{0};
coroutine_handle<> continuation;
public:
promise_type() {}
promise_type(const promise_type &) = delete;
promise_type(promise_type &&) = delete;
promise_type &operator=(const promise_type &) = delete;
promise_type &operator=(promise_type &&) = delete;
~promise_type()
{
if(result_set.load(std::memory_order_acquire) == 1)
{
result.~container_type(); // could throw
}
}
auto get_return_object()
{
return generator{*this}; // could throw bad_alloc
}
void return_void() noexcept
{
OUTCOME_ASSERT(result_set.load(std::memory_order_acquire) >= 0);
if(result_set.load(std::memory_order_acquire) == 1)
{
result.~container_type(); // could throw
}
result_set.store(-1, std::memory_order_release);
}
suspend_always yield_value(container_type &&value)
{
OUTCOME_ASSERT(result_set.load(std::memory_order_acquire) >= 0);
if(result_set.load(std::memory_order_acquire) == 1)
{
result.~container_type(); // could throw
}
new(&result) container_type(static_cast<container_type &&>(value)); // could throw
result_set.store(1, std::memory_order_release);
return {};
}
suspend_always yield_value(const container_type &value)
{
OUTCOME_ASSERT(result_set.load(std::memory_order_acquire) >= 0);
if(result_set.load(std::memory_order_acquire) == 1)
{
result.~container_type(); // could throw
}
new(&result) container_type(value); // could throw
result_set.store(1, std::memory_order_release);
return {};
}
void unhandled_exception()
{
OUTCOME_ASSERT(result_set.load(std::memory_order_acquire) >= 0);
if(result_set.load(std::memory_order_acquire) == 1)
{
result.~container_type();
}
#ifdef __cpp_exceptions
auto e = std::current_exception();
auto ec = detail::error_from_exception(static_cast<decltype(e) &&>(e), {});
// Try to set error code first
if(!detail::error_is_set(ec) || !detail::try_set_error(static_cast<decltype(ec) &&>(ec), &result))
{
detail::set_or_rethrow(e, &result); // could throw
}
#else
std::terminate();
#endif
result_set.store(1, std::memory_order_release);
}
auto initial_suspend() noexcept
{
struct awaiter
{
bool await_ready() noexcept { return !suspend_initial; }
void await_resume() noexcept {}
void await_suspend(coroutine_handle<> /*unused*/) noexcept {}
};
return awaiter{};
}
auto final_suspend() noexcept
{
struct awaiter
{
bool await_ready() noexcept { return false; }
void await_resume() noexcept {}
#if OUTCOME_HAVE_NOOP_COROUTINE
coroutine_handle<> await_suspend(coroutine_handle<promise_type> self) noexcept
{
return self.promise().continuation ? self.promise().continuation : noop_coroutine();
}
#else
void await_suspend(coroutine_handle<promise_type> self)
{
if(self.promise().continuation)
{
return self.promise().continuation.resume();
}
}
#endif
};
return awaiter{};
}
};
coroutine_handle<promise_type> _h;
generator(generator &&o) noexcept
: _h(static_cast<coroutine_handle<promise_type> &&>(o._h))
{
o._h = nullptr;
}
generator(const generator &o) = delete;
generator &operator=(generator &&) = delete; // as per P1056
generator &operator=(const generator &) = delete;
~generator()
{
if(_h)
{
_h.destroy();
}
}
explicit generator(promise_type &p) // could throw
: _h(coroutine_handle<promise_type>::from_promise(p))
{
}
explicit operator bool() const // could throw
{
return valid();
}
bool valid() const // could throw
{
auto &p = _h.promise();
if(p.result_set.load(std::memory_order_acquire) == 0)
{
const_cast<generator *>(this)->_h();
}
return p.result_set.load(std::memory_order_acquire) >= 0;
}
container_type operator()() // could throw
{
auto &p = _h.promise();
if(p.result_set.load(std::memory_order_acquire) == 0)
{
_h();
}
OUTCOME_ASSERT(p.result_set.load(std::memory_order_acquire) >= 0);
if(p.result_set.load(std::memory_order_acquire) < 0)
{
std::terminate();
}
container_type ret(static_cast<container_type &&>(p.result));
p.result.~container_type(); // could throw
p.result_set.store(0, std::memory_order_release);
return ret;
}
#if OUTCOME_HAVE_NOOP_COROUTINE
coroutine_handle<> await_suspend(coroutine_handle<> cont) noexcept
{
_h.promise().continuation = cont;
return _h;
}
#else
void await_suspend(coroutine_handle<> cont)
{
_h.promise().continuation = cont;
_h.resume();
}
#endif
};
#endif
} // namespace detail
} // namespace awaitables
OUTCOME_V2_NAMESPACE_END
#endif
#ifdef OUTCOME_FOUND_COROUTINE_HEADER
OUTCOME_COROUTINE_SUPPORT_NAMESPACE_EXPORT_BEGIN
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
template <class T, class Executor = void> using eager = OUTCOME_V2_NAMESPACE::awaitables::detail::awaitable<T, Executor, false, false>;
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
template <class T, class Executor = void> using atomic_eager = OUTCOME_V2_NAMESPACE::awaitables::detail::awaitable<T, Executor, false, true>;
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
template <class T, class Executor = void> using lazy = OUTCOME_V2_NAMESPACE::awaitables::detail::awaitable<T, Executor, true, false>;
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
template <class T, class Executor = void> using atomic_lazy = OUTCOME_V2_NAMESPACE::awaitables::detail::awaitable<T, Executor, true, true>;
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
template <class T, class Executor = void> using generator = OUTCOME_V2_NAMESPACE::awaitables::detail::generator<T, Executor, true, false>;
OUTCOME_COROUTINE_SUPPORT_NAMESPACE_END
#endif
|
0 | repos/outcome/include/outcome | repos/outcome/include/outcome/detail/try.h | /* Try operation macros
(C) 2017-2024 Niall Douglas <http://www.nedproductions.biz/> (20 commits)
File Created: July 2017
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License in the accompanying file
Licence.txt or at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Distributed under the Boost Software License, Version 1.0.
(See accompanying file Licence.txt or copy at
http://www.boost.org/LICENSE_1_0.txt)
*/
#ifndef OUTCOME_TRY_H
#define OUTCOME_TRY_H
#if !defined(__clang__) && defined(__GNUC__) && __GNUC__ >= 8
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wparentheses"
#endif
#define OUTCOME_TRY_GLUE2(x, y) x##y
#define OUTCOME_TRY_GLUE(x, y) OUTCOME_TRY_GLUE2(x, y)
#define OUTCOME_TRY_UNIQUE_NAME OUTCOME_TRY_GLUE(_outcome_try_unique_name_temporary, __COUNTER__)
#define OUTCOME_TRY_RETURN_ARG_COUNT(_1_, _2_, _3_, _4_, _5_, _6_, _7_, _8_, count, ...) count
#define OUTCOME_TRY_EXPAND_ARGS(args) OUTCOME_TRY_RETURN_ARG_COUNT args
#define OUTCOME_TRY_COUNT_ARGS_MAX8(...) OUTCOME_TRY_EXPAND_ARGS((__VA_ARGS__, 8, 7, 6, 5, 4, 3, 2, 1, 0))
#define OUTCOME_TRY_OVERLOAD_MACRO2(name, count) name##count
#define OUTCOME_TRY_OVERLOAD_MACRO1(name, count) OUTCOME_TRY_OVERLOAD_MACRO2(name, count)
#define OUTCOME_TRY_OVERLOAD_MACRO(name, count) OUTCOME_TRY_OVERLOAD_MACRO1(name, count)
#define OUTCOME_TRY_OVERLOAD_GLUE(x, y) x y
#define OUTCOME_TRY_CALL_OVERLOAD(name, ...) \
OUTCOME_TRY_OVERLOAD_GLUE(OUTCOME_TRY_OVERLOAD_MACRO(name, OUTCOME_TRY_COUNT_ARGS_MAX8(__VA_ARGS__)), (__VA_ARGS__))
#define _OUTCOME_TRY_RETURN_ARG_COUNT(_1_, _2_, _3_, _4_, _5_, _6_, _7_, _8_, count, ...) count
#define _OUTCOME_TRY_EXPAND_ARGS(args) _OUTCOME_TRY_RETURN_ARG_COUNT args
#define _OUTCOME_TRY_COUNT_ARGS_MAX8(...) _OUTCOME_TRY_EXPAND_ARGS((__VA_ARGS__, 8, 7, 6, 5, 4, 3, 2, 1, 0))
#define _OUTCOME_TRY_OVERLOAD_MACRO2(name, count) name##count
#define _OUTCOME_TRY_OVERLOAD_MACRO1(name, count) _OUTCOME_TRY_OVERLOAD_MACRO2(name, count)
#define _OUTCOME_TRY_OVERLOAD_MACRO(name, count) _OUTCOME_TRY_OVERLOAD_MACRO1(name, count)
#define _OUTCOME_TRY_OVERLOAD_GLUE(x, y) x y
#define _OUTCOME_TRY_CALL_OVERLOAD(name, ...) \
_OUTCOME_TRY_OVERLOAD_GLUE(_OUTCOME_TRY_OVERLOAD_MACRO(name, _OUTCOME_TRY_COUNT_ARGS_MAX8(__VA_ARGS__)), (__VA_ARGS__))
#if !defined(OUTCOME_TRY_LIKELY_IF) && defined(__has_cpp_attribute)
#if __has_cpp_attribute(likely)
#define OUTCOME_TRY_LIKELY_IF(...) if(__VA_ARGS__) [[likely]]
#endif
#endif
#ifndef OUTCOME_TRY_LIKELY_IF
#if defined(__clang__) || defined(__GNUC__)
#define OUTCOME_TRY_LIKELY_IF(...) if(__builtin_expect(!!(__VA_ARGS__), 1))
#else
#define OUTCOME_TRY_LIKELY_IF(...) if(__VA_ARGS__)
#endif
#endif
#ifdef __cplusplus
#define OUTCOME_TRYV2_UNIQUE_STORAGE_AUTO(...) auto
#else
#define OUTCOME_TRYV2_UNIQUE_STORAGE_AUTO(...) __typeof__(__VA_ARGS__)
#endif
#define OUTCOME_TRYV2_UNIQUE_STORAGE_UNPACK(...) __VA_ARGS__
#define OUTCOME_TRYV2_UNIQUE_STORAGE_DEDUCE3(unique, ...) OUTCOME_TRYV2_UNIQUE_STORAGE_AUTO(__VA_ARGS__) unique = (__VA_ARGS__)
#define OUTCOME_TRYV2_UNIQUE_STORAGE_DEDUCE2(x) x
#define OUTCOME_TRYV2_UNIQUE_STORAGE_DEDUCE(unique, x, ...) OUTCOME_TRYV2_UNIQUE_STORAGE_DEDUCE2(OUTCOME_TRYV2_UNIQUE_STORAGE_DEDUCE3(unique, __VA_ARGS__))
#define OUTCOME_TRYV2_UNIQUE_STORAGE_SPECIFIED3(unique, x, y, ...) x unique = (__VA_ARGS__)
#define OUTCOME_TRYV2_UNIQUE_STORAGE_SPECIFIED2(x) x
#define OUTCOME_TRYV2_UNIQUE_STORAGE_SPECIFIED(unique, ...) \
OUTCOME_TRYV2_UNIQUE_STORAGE_SPECIFIED2(OUTCOME_TRYV2_UNIQUE_STORAGE_SPECIFIED3(unique, __VA_ARGS__))
#define OUTCOME_TRYV2_UNIQUE_STORAGE1(...) OUTCOME_TRYV2_UNIQUE_STORAGE_DEDUCE
#define OUTCOME_TRYV2_UNIQUE_STORAGE2(...) OUTCOME_TRYV2_UNIQUE_STORAGE_SPECIFIED
#define OUTCOME_TRYV2_UNIQUE_STORAGE(unique, spec, ...) \
_OUTCOME_TRY_CALL_OVERLOAD(OUTCOME_TRYV2_UNIQUE_STORAGE, OUTCOME_TRYV2_UNIQUE_STORAGE_UNPACK spec) \
(unique, OUTCOME_TRYV2_UNIQUE_STORAGE_UNPACK spec, __VA_ARGS__)
#define OUTCOME_TRY2_VAR_SECOND2(x, var) var
#define OUTCOME_TRY2_VAR_SECOND3(x, y, ...) x y
#define OUTCOME_TRY2_VAR(spec) _OUTCOME_TRY_CALL_OVERLOAD(OUTCOME_TRY2_VAR_SECOND, OUTCOME_TRYV2_UNIQUE_STORAGE_UNPACK spec, spec)
#if !defined(__clang__) && defined(__GNUC__) && __GNUC__ >= 8
#pragma GCC diagnostic pop
#endif
#endif
|
0 | repos/outcome/include/outcome | repos/outcome/include/outcome/detail/basic_result_storage.hpp | /* Storage for a very simple basic_result type
(C) 2017-2019 Niall Douglas <http://www.nedproductions.biz/> (6 commits)
File Created: Oct 2017
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License in the accompanying file
Licence.txt or at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Distributed under the Boost Software License, Version 1.0.
(See accompanying file Licence.txt or copy at
http://www.boost.org/LICENSE_1_0.txt)
*/
#ifndef OUTCOME_BASIC_RESULT_STORAGE_HPP
#define OUTCOME_BASIC_RESULT_STORAGE_HPP
#include "../success_failure.hpp"
#include "../trait.hpp"
#include "value_storage.hpp"
OUTCOME_V2_NAMESPACE_EXPORT_BEGIN
namespace detail
{
template <class R, class EC, class NoValuePolicy> class basic_result_storage;
} // namespace detail
namespace hooks
{
template <class R, class S, class NoValuePolicy> constexpr inline uint16_t spare_storage(const detail::basic_result_storage<R, S, NoValuePolicy> *r) noexcept;
template <class R, class S, class NoValuePolicy>
constexpr inline void set_spare_storage(detail::basic_result_storage<R, S, NoValuePolicy> *r, uint16_t v) noexcept;
} // namespace hooks
namespace policy
{
struct base;
} // namespace policy
namespace detail
{
template <class R, class EC, class NoValuePolicy> //
class basic_result_storage
{
static_assert(trait::type_can_be_used_in_basic_result<R>, "The type R cannot be used in a basic_result");
static_assert(trait::type_can_be_used_in_basic_result<EC>, "The type S cannot be used in a basic_result");
friend struct policy::base;
template <class T, class U, class V> //
friend class basic_result_storage;
template <class T, class U, class V> friend class basic_result_final;
template <class T, class U, class V>
friend constexpr inline uint16_t hooks::spare_storage(const detail::basic_result_storage<T, U, V> *r) noexcept; // NOLINT
template <class T, class U, class V>
friend constexpr inline void hooks::set_spare_storage(detail::basic_result_storage<T, U, V> *r, uint16_t v) noexcept; // NOLINT
struct disable_in_place_value_type
{
};
struct disable_in_place_error_type
{
};
protected:
using _value_type = std::conditional_t<std::is_same<R, EC>::value, disable_in_place_value_type, R>;
using _error_type = std::conditional_t<std::is_same<R, EC>::value, disable_in_place_error_type, EC>;
using _state_type = value_storage_select_impl<_value_type, _error_type>;
#ifdef STANDARDESE_IS_IN_THE_HOUSE
value_storage_trivial<_value_type, _error_type> _state;
#else
_state_type _state;
#endif
public:
// Used by iostream support to access state
_state_type &_iostreams_state() { return _state; }
const _state_type &_iostreams_state() const { return _state; }
protected:
basic_result_storage() = default;
basic_result_storage(const basic_result_storage &) = default; // NOLINT
basic_result_storage(basic_result_storage &&) = default; // NOLINT
basic_result_storage &operator=(const basic_result_storage &) = default; // NOLINT
basic_result_storage &operator=(basic_result_storage &&) = default; // NOLINT
~basic_result_storage() = default;
template <class... Args>
constexpr explicit basic_result_storage(in_place_type_t<_value_type> _,
Args &&... args) noexcept(detail::is_nothrow_constructible<_value_type, Args...>)
: _state{_, static_cast<Args &&>(args)...}
{
}
template <class U, class... Args>
constexpr basic_result_storage(in_place_type_t<_value_type> _, std::initializer_list<U> il,
Args &&... args) noexcept(detail::is_nothrow_constructible<_value_type, std::initializer_list<U>, Args...>)
: _state{_, il, static_cast<Args &&>(args)...}
{
}
template <class... Args>
constexpr explicit basic_result_storage(in_place_type_t<_error_type> _,
Args &&... args) noexcept(detail::is_nothrow_constructible<_error_type, Args...>)
: _state{_, static_cast<Args &&>(args)...}
{
}
template <class U, class... Args>
constexpr basic_result_storage(in_place_type_t<_error_type> _, std::initializer_list<U> il,
Args &&... args) noexcept(detail::is_nothrow_constructible<_error_type, std::initializer_list<U>, Args...>)
: _state{_, il, static_cast<Args &&>(args)...}
{
}
struct compatible_conversion_tag
{
};
template <class T, class U, class V>
constexpr basic_result_storage(compatible_conversion_tag /*unused*/, const basic_result_storage<T, U, V> &o) noexcept(
detail::is_nothrow_constructible<_value_type, T> &&detail::is_nothrow_constructible<_error_type, U>)
: _state(o._state)
{
}
template <class T, class U, class V>
constexpr basic_result_storage(compatible_conversion_tag /*unused*/, basic_result_storage<T, U, V> &&o) noexcept(
detail::is_nothrow_constructible<_value_type, T> &&detail::is_nothrow_constructible<_error_type, U>)
: _state(static_cast<decltype(o._state) &&>(o._state))
{
}
struct make_error_code_compatible_conversion_tag
{
};
template <class T, class U, class V>
constexpr basic_result_storage(make_error_code_compatible_conversion_tag /*unused*/, const basic_result_storage<T, U, V> &o) noexcept(
detail::is_nothrow_constructible<_value_type, T> &&noexcept(make_error_code(std::declval<U>())))
: _state(o._state._status.have_value() ? _state_type(in_place_type<_value_type>, o._state._value) :
_state_type(in_place_type<_error_type>, make_error_code(o._state._error)))
{
}
template <class T, class U, class V>
constexpr basic_result_storage(make_error_code_compatible_conversion_tag /*unused*/, basic_result_storage<T, U, V> &&o) noexcept(
detail::is_nothrow_constructible<_value_type, T> &&noexcept(make_error_code(std::declval<U>())))
: _state(o._state._status.have_value() ? _state_type(in_place_type<_value_type>, static_cast<T &&>(o._state._value)) :
_state_type(in_place_type<_error_type>, make_error_code(static_cast<U &&>(o._state._error))))
{
}
struct make_exception_ptr_compatible_conversion_tag
{
};
template <class T, class U, class V>
constexpr basic_result_storage(make_exception_ptr_compatible_conversion_tag /*unused*/, const basic_result_storage<T, U, V> &o) noexcept(
detail::is_nothrow_constructible<_value_type, T> &&noexcept(make_exception_ptr(std::declval<U>())))
: _state(o._state._status.have_value() ? _state_type(in_place_type<_value_type>, o._state._value) :
_state_type(in_place_type<_error_type>, make_exception_ptr(o._state._error)))
{
}
template <class T, class U, class V>
constexpr basic_result_storage(make_exception_ptr_compatible_conversion_tag /*unused*/, basic_result_storage<T, U, V> &&o) noexcept(
detail::is_nothrow_constructible<_value_type, T> &&noexcept(make_exception_ptr(std::declval<U>())))
: _state(o._state._status.have_value() ? _state_type(in_place_type<_value_type>, static_cast<T &&>(o._state._value)) :
_state_type(in_place_type<_error_type>, make_exception_ptr(static_cast<U &&>(o._state._error))))
{
}
};
} // namespace detail
OUTCOME_V2_NAMESPACE_END
#endif
|
0 | repos/outcome/include/outcome | repos/outcome/include/outcome/detail/trait_std_exception.hpp | /* Traits for Outcome
(C) 2018-2019 Niall Douglas <http://www.nedproductions.biz/> (3 commits)
File Created: March 2018
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License in the accompanying file
Licence.txt or at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Distributed under the Boost Software License, Version 1.0.
(See accompanying file Licence.txt or copy at
http://www.boost.org/LICENSE_1_0.txt)
*/
#ifndef OUTCOME_TRAIT_STD_EXCEPTION_HPP
#define OUTCOME_TRAIT_STD_EXCEPTION_HPP
#include "../config.hpp"
#include <exception>
OUTCOME_V2_NAMESPACE_BEGIN
namespace policy
{
namespace detail
{
/* Pass through `make_exception_ptr` function for `std::exception_ptr`.
*/
inline std::exception_ptr make_exception_ptr(std::exception_ptr v) { return v; }
// Try ADL, if not use fall backs above
template <class T> constexpr inline decltype(auto) exception_ptr(T &&v) { return make_exception_ptr(std::forward<T>(v)); }
} // namespace detail
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
template <class T> constexpr inline decltype(auto) exception_ptr(T &&v) { return detail::exception_ptr(std::forward<T>(v)); }
namespace detail
{
template <bool has_error_payload> struct _rethrow_exception
{
template <class Exception> explicit _rethrow_exception(Exception && /*unused*/) // NOLINT
{
}
};
template <> struct _rethrow_exception<true>
{
template <class Exception> explicit _rethrow_exception(Exception &&excpt) // NOLINT
{
// ADL
rethrow_exception(policy::exception_ptr(std::forward<Exception>(excpt)));
}
};
} // namespace detail
} // namespace policy
namespace trait
{
namespace detail
{
// Shortcut this for lower build impact
template <> struct _is_exception_ptr_available<std::exception_ptr>
{
static constexpr bool value = true;
using type = std::exception_ptr;
};
} // namespace detail
// std::exception_ptr is an error type
template <> struct is_error_type<std::exception_ptr>
{
static constexpr bool value = true;
};
} // namespace trait
OUTCOME_V2_NAMESPACE_END
#endif
|
0 | repos/outcome/include/outcome | repos/outcome/include/outcome/detail/basic_outcome_exception_observers.hpp | /* Exception observers for outcome type
(C) 2017-2019 Niall Douglas <http://www.nedproductions.biz/> (3 commits)
File Created: Oct 2017
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License in the accompanying file
Licence.txt or at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Distributed under the Boost Software License, Version 1.0.
(See accompanying file Licence.txt or copy at
http://www.boost.org/LICENSE_1_0.txt)
*/
#ifndef OUTCOME_BASIC_OUTCOME_EXCEPTION_OBSERVERS_HPP
#define OUTCOME_BASIC_OUTCOME_EXCEPTION_OBSERVERS_HPP
#include "basic_result_storage.hpp"
OUTCOME_V2_NAMESPACE_EXPORT_BEGIN
namespace detail
{
template <class Base, class R, class S, class P, class NoValuePolicy> class basic_outcome_exception_observers : public Base
{
public:
using exception_type = P;
using Base::Base;
constexpr inline exception_type &assume_exception() & noexcept;
constexpr inline const exception_type &assume_exception() const & noexcept;
constexpr inline exception_type &&assume_exception() && noexcept;
constexpr inline const exception_type &&assume_exception() const && noexcept;
constexpr inline exception_type &exception() &;
constexpr inline const exception_type &exception() const &;
constexpr inline exception_type &&exception() &&;
constexpr inline const exception_type &&exception() const &&;
};
// Exception observers not present
template <class Base, class R, class S, class NoValuePolicy> class basic_outcome_exception_observers<Base, R, S, void, NoValuePolicy> : public Base
{
public:
using Base::Base;
constexpr void assume_exception() & noexcept { NoValuePolicy::narrow_exception_check(*this); }
constexpr void assume_exception() const & noexcept { NoValuePolicy::narrow_exception_check(*this); }
constexpr void assume_exception() && noexcept { NoValuePolicy::narrow_exception_check(std::move(*this)); }
constexpr void assume_exception() const && noexcept { NoValuePolicy::narrow_exception_check(std::move(*this)); }
constexpr void exception() & { NoValuePolicy::wide_exception_check(*this); }
constexpr void exception() const & { NoValuePolicy::wide_exception_check(*this); }
constexpr void exception() && { NoValuePolicy::wide_exception_check(std::move(*this)); }
constexpr void exception() const && { NoValuePolicy::wide_exception_check(std::move(*this)); }
};
} // namespace detail
OUTCOME_V2_NAMESPACE_END
#endif
|
0 | repos/outcome/include/outcome | repos/outcome/include/outcome/detail/trait_std_error_code.hpp | /* Traits for Outcome
(C) 2018-2019 Niall Douglas <http://www.nedproductions.biz/> (6 commits)
File Created: March 2018
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License in the accompanying file
Licence.txt or at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Distributed under the Boost Software License, Version 1.0.
(See accompanying file Licence.txt or copy at
http://www.boost.org/LICENSE_1_0.txt)
*/
#ifndef OUTCOME_TRAIT_STD_ERROR_CODE_HPP
#define OUTCOME_TRAIT_STD_ERROR_CODE_HPP
#include "../config.hpp"
#include <system_error>
OUTCOME_V2_NAMESPACE_BEGIN
namespace detail
{
// Customise _set_error_is_errno
template <class State> constexpr inline void _set_error_is_errno(State &state, const std::error_code &error)
{
if(error.category() == std::generic_category()
#ifndef _WIN32
|| error.category() == std::system_category()
#endif
)
{
state._status.set_have_error_is_errno(true);
}
}
template <class State> constexpr inline void _set_error_is_errno(State &state, const std::error_condition &error)
{
if(error.category() == std::generic_category()
#ifndef _WIN32
|| error.category() == std::system_category()
#endif
)
{
state._status.set_have_error_is_errno(true);
}
}
template <class State> constexpr inline void _set_error_is_errno(State &state, const std::errc & /*unused*/) {
state._status.set_have_error_is_errno(true);
}
} // namespace detail
namespace policy
{
namespace detail
{
/* Pass through `make_error_code` function for `std::error_code`.
*/
inline std::error_code make_error_code(std::error_code v) { return v; }
// Try ADL, if not use fall backs above
template <class T> constexpr inline decltype(auto) error_code(T &&v) { return make_error_code(std::forward<T>(v)); }
struct std_enum_overload_tag
{
};
} // namespace detail
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
template <class T> constexpr inline decltype(auto) error_code(T &&v) { return detail::error_code(std::forward<T>(v)); }
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
// inline void outcome_throw_as_system_error_with_payload(...) = delete; // To use the error_code_throw_as_system_error policy with a custom Error type, you must define a outcome_throw_as_system_error_with_payload() free function to say how to handle the payload
inline void outcome_throw_as_system_error_with_payload(const std::error_code &error) { OUTCOME_THROW_EXCEPTION(std::system_error(error)); } // NOLINT
OUTCOME_TEMPLATE(class Error)
OUTCOME_TREQUIRES(OUTCOME_TPRED(std::is_error_code_enum<std::decay_t<Error>>::value || std::is_error_condition_enum<std::decay_t<Error>>::value))
inline void outcome_throw_as_system_error_with_payload(Error &&error, detail::std_enum_overload_tag /*unused*/ = detail::std_enum_overload_tag()) { OUTCOME_THROW_EXCEPTION(std::system_error(make_error_code(error))); } // NOLINT
} // namespace policy
namespace trait
{
namespace detail
{
template <> struct _is_error_code_available<std::error_code>
{
// Shortcut this for lower build impact
static constexpr bool value = true;
using type = std::error_code;
};
} // namespace detail
// std::error_code is an error type
template <> struct is_error_type<std::error_code>
{
static constexpr bool value = true;
};
// For std::error_code, std::is_error_condition_enum<> is the trait we want.
template <class Enum> struct is_error_type_enum<std::error_code, Enum>
{
static constexpr bool value = std::is_error_condition_enum<Enum>::value;
};
} // namespace trait
OUTCOME_V2_NAMESPACE_END
#endif
|
0 | repos/outcome/include/outcome | repos/outcome/include/outcome/detail/basic_result_final.hpp | /* Finaliser for a very simple result type
(C) 2017-2019 Niall Douglas <http://www.nedproductions.biz/> (5 commits)
File Created: Oct 2017
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License in the accompanying file
Licence.txt or at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Distributed under the Boost Software License, Version 1.0.
(See accompanying file Licence.txt or copy at
http://www.boost.org/LICENSE_1_0.txt)
*/
#ifndef OUTCOME_BASIC_RESULT_FINAL_HPP
#define OUTCOME_BASIC_RESULT_FINAL_HPP
#include "basic_result_error_observers.hpp"
#include "basic_result_value_observers.hpp"
OUTCOME_V2_NAMESPACE_EXPORT_BEGIN
namespace detail
{
template <class R, class EC, class NoValuePolicy> using select_basic_result_impl = basic_result_error_observers<basic_result_value_observers<basic_result_storage<R, EC, NoValuePolicy>, R, NoValuePolicy>, EC, NoValuePolicy>;
template <class R, class S, class NoValuePolicy>
class basic_result_final
#if defined(DOXYGEN_IS_IN_THE_HOUSE)
: public basic_result_error_observers<basic_result_value_observers<basic_result_storage<R, S, NoValuePolicy>, R, NoValuePolicy>, S, NoValuePolicy>
#else
: public select_basic_result_impl<R, S, NoValuePolicy>
#endif
{
using base = select_basic_result_impl<R, S, NoValuePolicy>;
public:
using base::base;
constexpr explicit operator bool() const noexcept { return this->_state._status.have_value(); }
constexpr bool has_value() const noexcept { return this->_state._status.have_value(); }
constexpr bool has_error() const noexcept { return this->_state._status.have_error(); }
constexpr bool has_exception() const noexcept { return this->_state._status.have_exception(); }
constexpr bool has_lost_consistency() const noexcept { return this->_state._status.have_lost_consistency(); }
constexpr bool has_failure() const noexcept { return this->_state._status.have_error() || this->_state._status.have_exception(); }
OUTCOME_TEMPLATE(class T, class U, class V)
OUTCOME_TREQUIRES(OUTCOME_TEXPR(std::declval<detail::devoid<R>>() == std::declval<detail::devoid<T>>()), //
OUTCOME_TEXPR(std::declval<detail::devoid<S>>() == std::declval<detail::devoid<U>>()))
constexpr bool operator==(const basic_result_final<T, U, V> &o) const noexcept( //
noexcept(std::declval<detail::devoid<R>>() == std::declval<detail::devoid<T>>()) && noexcept(std::declval<detail::devoid<S>>() == std::declval<detail::devoid<U>>()))
{
if(this->_state._status.have_value() && o._state._status.have_value())
{
return this->_state._value == o._state._value; // NOLINT
}
if(this->_state._status.have_error() && o._state._status.have_error())
{
return this->_state._error == o._state._error;
}
return false;
}
OUTCOME_TEMPLATE(class T)
OUTCOME_TREQUIRES(OUTCOME_TEXPR(std::declval<R>() == std::declval<T>()))
constexpr bool operator==(const success_type<T> &o) const noexcept( //
noexcept(std::declval<R>() == std::declval<T>()))
{
if(this->_state._status.have_value())
{
return this->_state._value == o.value();
}
return false;
}
constexpr bool operator==(const success_type<void> &o) const noexcept
{
(void) o;
return this->_state._status.have_value();
}
OUTCOME_TEMPLATE(class T)
OUTCOME_TREQUIRES(OUTCOME_TEXPR(std::declval<S>() == std::declval<T>()))
constexpr bool operator==(const failure_type<T, void> &o) const noexcept( //
noexcept(std::declval<S>() == std::declval<T>()))
{
if(this->_state._status.have_error())
{
return this->_state._error == o.error();
}
return false;
}
OUTCOME_TEMPLATE(class T, class U, class V)
OUTCOME_TREQUIRES(OUTCOME_TEXPR(std::declval<detail::devoid<R>>() != std::declval<detail::devoid<T>>()), //
OUTCOME_TEXPR(std::declval<detail::devoid<S>>() != std::declval<detail::devoid<U>>()))
constexpr bool operator!=(const basic_result_final<T, U, V> &o) const noexcept( //
noexcept(std::declval<detail::devoid<R>>() != std::declval<detail::devoid<T>>()) && noexcept(std::declval<detail::devoid<S>>() != std::declval<detail::devoid<U>>()))
{
if(this->_state._status.have_value() && o._state._status.have_value())
{
return this->_state._value != o._state._value;
}
if(this->_state._status.have_error() && o._state._status.have_error())
{
return this->_state._error != o._state._error;
}
return true;
}
OUTCOME_TEMPLATE(class T)
OUTCOME_TREQUIRES(OUTCOME_TEXPR(std::declval<R>() != std::declval<T>()))
constexpr bool operator!=(const success_type<T> &o) const noexcept( //
noexcept(std::declval<R>() != std::declval<T>()))
{
if(this->_state._status.have_value())
{
return this->_state._value != o.value();
}
return false;
}
constexpr bool operator!=(const success_type<void> &o) const noexcept
{
(void) o;
return !this->_state._status.have_value();
}
OUTCOME_TEMPLATE(class T)
OUTCOME_TREQUIRES(OUTCOME_TEXPR(std::declval<S>() != std::declval<T>()))
constexpr bool operator!=(const failure_type<T, void> &o) const noexcept( //
noexcept(std::declval<S>() != std::declval<T>()))
{
if(this->_state._status.have_error())
{
return this->_state._error != o.error();
}
return true;
}
};
template <class T, class U, class V, class W> constexpr inline bool operator==(const success_type<W> &a, const basic_result_final<T, U, V> &b) noexcept(noexcept(b == a)) { return b == a; }
template <class T, class U, class V, class W> constexpr inline bool operator==(const failure_type<W, void> &a, const basic_result_final<T, U, V> &b) noexcept(noexcept(b == a)) { return b == a; }
template <class T, class U, class V, class W> constexpr inline bool operator!=(const success_type<W> &a, const basic_result_final<T, U, V> &b) noexcept(noexcept(b == a)) { return b != a; }
template <class T, class U, class V, class W> constexpr inline bool operator!=(const failure_type<W, void> &a, const basic_result_final<T, U, V> &b) noexcept(noexcept(b == a)) { return b != a; }
} // namespace detail
OUTCOME_V2_NAMESPACE_END
#endif
|
0 | repos/outcome/include/outcome | repos/outcome/include/outcome/detail/basic_outcome_failure_observers.hpp | /* Failure observers for outcome type
(C) 2017-2019 Niall Douglas <http://www.nedproductions.biz/> (7 commits)
File Created: Oct 2017
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License in the accompanying file
Licence.txt or at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Distributed under the Boost Software License, Version 1.0.
(See accompanying file Licence.txt or copy at
http://www.boost.org/LICENSE_1_0.txt)
*/
#ifndef OUTCOME_BASIC_OUTCOME_FAILURE_OBSERVERS_HPP
#define OUTCOME_BASIC_OUTCOME_FAILURE_OBSERVERS_HPP
#include "basic_result_storage.hpp"
#include <exception>
OUTCOME_V2_NAMESPACE_EXPORT_BEGIN
namespace detail
{
namespace adl
{
struct search_detail_adl
{
};
// Do NOT use template requirements here!
template <class S, typename = decltype(basic_outcome_failure_exception_from_error(std::declval<S>()))>
inline auto _delayed_lookup_basic_outcome_failure_exception_from_error(const S &ec, search_detail_adl /*unused*/)
{
// ADL discovered
return basic_outcome_failure_exception_from_error(ec);
}
} // namespace adl
#if defined(_MSC_VER) && _MSC_VER <= 1923 // VS2019
// VS2017 and VS2019 with /permissive- chokes on the correct form due to over eager early instantiation.
template <class S, class P> inline void _delayed_lookup_basic_outcome_failure_exception_from_error(...) { static_assert(sizeof(S) == 0, "No specialisation for these error and exception types available!"); }
#else
template <class S, class P> inline void _delayed_lookup_basic_outcome_failure_exception_from_error(...) = delete; // NOLINT No specialisation for these error and exception types available!
#endif
template <class exception_type> inline exception_type current_exception_or_fatal(std::exception_ptr e) { std::rethrow_exception(e); }
template <> inline std::exception_ptr current_exception_or_fatal<std::exception_ptr>(std::exception_ptr e) { return e; }
template <class Base, class R, class S, class P, class NoValuePolicy> class basic_outcome_failure_observers : public Base
{
public:
using exception_type = P;
using Base::Base;
exception_type failure() const noexcept
{
#ifdef __cpp_exceptions
try
#endif
{
if(this->_state._status.have_exception())
{
return this->assume_exception();
}
if(this->_state._status.have_error())
{
return _delayed_lookup_basic_outcome_failure_exception_from_error(this->assume_error(), adl::search_detail_adl());
}
return exception_type();
}
#ifdef __cpp_exceptions
catch(...)
{
// Return the failure if exception_type is std::exception_ptr,
// otherwise terminate same as throwing an exception inside noexcept
return current_exception_or_fatal<exception_type>(std::current_exception());
}
#endif
}
};
} // namespace detail
OUTCOME_V2_NAMESPACE_END
#endif
|
0 | repos/outcome/include/outcome | repos/outcome/include/outcome/experimental/status_result.hpp | /* A very simple result type
(C) 2018-2020 Niall Douglas <http://www.nedproductions.biz/> (11 commits)
File Created: Apr 2018
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License in the accompanying file
Licence.txt or at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Distributed under the Boost Software License, Version 1.0.
(See accompanying file Licence.txt or copy at
http://www.boost.org/LICENSE_1_0.txt)
*/
#ifndef OUTCOME_EXPERIMENTAL_STATUS_RESULT_HPP
#define OUTCOME_EXPERIMENTAL_STATUS_RESULT_HPP
#include "../basic_result.hpp"
#include "../policy/fail_to_compile_observers.hpp"
#ifndef SYSTEM_ERROR2_USE_STD_ADDRESSOF
#if OUTCOME_USE_STD_ADDRESSOF
#define SYSTEM_ERROR2_USE_STD_ADDRESSOF 1
#endif
#endif
#if __PCPP_ALWAYS_TRUE__
#include "status-code/include/status-code/system_error2.hpp"
#elif !OUTCOME_USE_SYSTEM_STATUS_CODE && __has_include("status-code/include/status-code/system_error2.hpp")
#include "status-code/include/status-code/system_error2.hpp"
#else
#include <status-code/system_error2.hpp>
#endif
OUTCOME_V2_NAMESPACE_EXPORT_BEGIN
namespace trait
{
namespace detail
{
// Shortcut this for lower build impact. Used to tell outcome's converting constructors
// that they can do E => EC or E => EP as necessary.
template <class DomainType> struct _is_error_code_available<SYSTEM_ERROR2_NAMESPACE::status_code<DomainType>>
{
static constexpr bool value = true;
using type = SYSTEM_ERROR2_NAMESPACE::status_code<DomainType>;
};
template <class DomainType> struct _is_error_code_available<SYSTEM_ERROR2_NAMESPACE::errored_status_code<DomainType>>
{
static constexpr bool value = true;
using type = SYSTEM_ERROR2_NAMESPACE::errored_status_code<DomainType>;
};
} // namespace detail
#if 0 // Do NOT enable weakened implicit construction for these types
template <class DomainType> struct is_error_type<SYSTEM_ERROR2_NAMESPACE::status_code<DomainType>>
{
static constexpr bool value = true;
};
template <> struct is_error_type<SYSTEM_ERROR2_NAMESPACE::errc>
{
static constexpr bool value = true;
};
template <class DomainType, class Enum> struct is_error_type_enum<SYSTEM_ERROR2_NAMESPACE::status_code<DomainType>, Enum>
{
static constexpr bool value = boost::system::is_error_condition_enum<Enum>::value;
};
#endif
template <class DomainType> struct is_move_bitcopying<SYSTEM_ERROR2_NAMESPACE::status_code<DomainType>>
{
static constexpr bool value = SYSTEM_ERROR2_NAMESPACE::traits::is_move_bitcopying<SYSTEM_ERROR2_NAMESPACE::status_code<DomainType>>::value;
};
template <class DomainType> struct is_move_bitcopying<SYSTEM_ERROR2_NAMESPACE::errored_status_code<DomainType>>
{
static constexpr bool value = SYSTEM_ERROR2_NAMESPACE::traits::is_move_bitcopying<SYSTEM_ERROR2_NAMESPACE::errored_status_code<DomainType>>::value;
};
} // namespace trait
namespace detail
{
// Customise _set_error_is_errno
template <class State> constexpr inline void _set_error_is_errno(State &state, const SYSTEM_ERROR2_NAMESPACE::generic_code & /*unused*/)
{
state._status.set_have_error_is_errno(true);
}
#ifndef SYSTEM_ERROR2_NOT_POSIX
template <class State> constexpr inline void _set_error_is_errno(State &state, const SYSTEM_ERROR2_NAMESPACE::posix_code & /*unused*/)
{
state._status.set_have_error_is_errno(true);
}
#endif
template <class State> constexpr inline void _set_error_is_errno(State &state, const SYSTEM_ERROR2_NAMESPACE::errc & /*unused*/)
{
state._status.set_have_error_is_errno(true);
}
} // namespace detail
namespace experimental
{
using namespace SYSTEM_ERROR2_NAMESPACE;
using OUTCOME_V2_NAMESPACE::failure;
using OUTCOME_V2_NAMESPACE::success;
namespace policy
{
using namespace OUTCOME_V2_NAMESPACE::policy;
template <class T, class EC, class E> struct status_code_throw
{
static_assert(!std::is_same<T, T>::value,
"policy::status_code_throw not specialised for these types, did you use status_result<T, status_code<DomainType>, E>?");
};
template <class T, class DomainType> struct status_code_throw<T, status_code<DomainType>, void> : base
{
using _base = base;
template <class Impl> static constexpr void wide_value_check(Impl &&self)
{
if(!base::_has_value(static_cast<Impl &&>(self)))
{
if(base::_has_error(static_cast<Impl &&>(self)))
{
#ifdef __cpp_exceptions
base::_error(static_cast<Impl &&>(self)).throw_exception();
#else
OUTCOME_THROW_EXCEPTION("wide value check failed");
#endif
}
}
}
template <class Impl> static constexpr void wide_error_check(Impl &&self) { _base::narrow_error_check(static_cast<Impl &&>(self)); }
};
template <class T, class DomainType>
struct status_code_throw<T, errored_status_code<DomainType>, void> : status_code_throw<T, status_code<DomainType>, void>
{
status_code_throw() = default;
using status_code_throw<T, status_code<DomainType>, void>::status_code_throw;
};
template <class T, class EC>
using default_status_result_policy = std::conditional_t< //
std::is_void<EC>::value, //
OUTCOME_V2_NAMESPACE::policy::terminate, //
std::conditional_t<is_status_code<EC>::value || is_errored_status_code<EC>::value, //
status_code_throw<T, EC, void>, //
OUTCOME_V2_NAMESPACE::policy::fail_to_compile_observers //
>>;
} // namespace policy
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
template <class R, class S = erased_errored_status_code<typename system_code::value_type>,
class NoValuePolicy = policy::default_status_result_policy<R, S>> //
using status_result = basic_result<R, S, NoValuePolicy>;
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class R, class S, class NoValuePolicy)
OUTCOME_TREQUIRES(OUTCOME_TPRED(std::is_copy_constructible<R>::value && (is_status_code<S>::value || is_errored_status_code<S>::value)))
inline basic_result<R, S, NoValuePolicy> clone(const basic_result<R, S, NoValuePolicy> &v)
{
if(v)
{
return success_type<R>(v.assume_value());
}
return failure_type<S>(v.assume_error().clone(), hooks::spare_storage(&v));
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class S, class NoValuePolicy)
OUTCOME_TREQUIRES(OUTCOME_TPRED(is_status_code<S>::value || is_errored_status_code<S>::value))
inline basic_result<void, S, NoValuePolicy> clone(const basic_result<void, S, NoValuePolicy> &v)
{
if(v)
{
return success_type<void>();
}
return failure_type<S>(v.assume_error().clone(), hooks::spare_storage(&v));
}
} // namespace experimental
OUTCOME_V2_NAMESPACE_END
#endif
|
0 | repos/outcome/include/outcome | repos/outcome/include/outcome/experimental/status_outcome.hpp | /* A less simple result type
(C) 2018-2019 Niall Douglas <http://www.nedproductions.biz/> (17 commits)
File Created: Apr 2018
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License in the accompanying file
Licence.txt or at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Distributed under the Boost Software License, Version 1.0.
(See accompanying file Licence.txt or copy at
http://www.boost.org/LICENSE_1_0.txt)
*/
#ifndef OUTCOME_EXPERIMENTAL_STATUS_OUTCOME_HPP
#define OUTCOME_EXPERIMENTAL_STATUS_OUTCOME_HPP
#include "../basic_outcome.hpp"
#include "../detail/trait_std_exception.hpp"
#include "status_result.hpp"
// Boost.Outcome #include "boost/exception_ptr.hpp"
SYSTEM_ERROR2_NAMESPACE_BEGIN
template <class DomainType> inline std::exception_ptr basic_outcome_failure_exception_from_error(const status_code<DomainType> &sc)
{
(void) sc;
#ifdef __cpp_exceptions
try
{
sc.throw_exception();
}
catch(...)
{
return std::current_exception();
}
#endif
return {};
}
SYSTEM_ERROR2_NAMESPACE_END
OUTCOME_V2_NAMESPACE_EXPORT_BEGIN
namespace experimental
{
namespace policy
{
template <class T, class EC, class E>
using default_status_outcome_policy = std::conditional_t< //
std::is_void<EC>::value && std::is_void<E>::value, //
OUTCOME_V2_NAMESPACE::policy::terminate, //
std::conditional_t<(is_status_code<EC>::value || is_errored_status_code<EC>::value) &&
(std::is_void<E>::value || OUTCOME_V2_NAMESPACE::trait::is_exception_ptr_available<E>::value), //
status_code_throw<T, EC, E>, //
OUTCOME_V2_NAMESPACE::policy::fail_to_compile_observers //
>>;
} // namespace policy
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
template <class R, class S = erased_errored_status_code<typename system_code::value_type>, class P = std::exception_ptr,
class NoValuePolicy = policy::default_status_outcome_policy<R, S, P>> //
using status_outcome = basic_outcome<R, S, P, NoValuePolicy>;
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class R, class S, class P, class NoValuePolicy)
OUTCOME_TREQUIRES(OUTCOME_TPRED(std::is_copy_constructible<R>::value &&std::is_copy_constructible<P>::value &&
(is_status_code<S>::value || is_errored_status_code<S>::value)))
inline basic_outcome<R, S, P, NoValuePolicy> clone(const basic_outcome<R, S, P, NoValuePolicy> &v)
{
if(v)
{
return success_type<R>(v.assume_value());
}
if(v.has_error() && v.has_exception())
{
return failure_type<S, P>(v.assume_error().clone(), v.assume_exception(), hooks::spare_storage(&v));
}
if(v.has_exception())
{
return failure_type<S, P>(in_place_type<P>, v.assume_exception(), hooks::spare_storage(&v));
}
return failure_type<S, P>(in_place_type<S>, v.assume_error().clone(), hooks::spare_storage(&v));
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class S, class P, class NoValuePolicy)
OUTCOME_TREQUIRES(OUTCOME_TPRED(std::is_copy_constructible<P>::value && (is_status_code<S>::value || is_errored_status_code<S>::value)))
inline basic_outcome<void, S, P, NoValuePolicy> clone(const basic_outcome<void, S, P, NoValuePolicy> &v)
{
if(v)
{
return success_type<void>();
}
if(v.has_error() && v.has_exception())
{
return failure_type<S, P>(v.assume_error().clone(), v.assume_exception(), hooks::spare_storage(&v));
}
if(v.has_exception())
{
return failure_type<S, P>(in_place_type<P>, v.assume_exception(), hooks::spare_storage(&v));
}
return failure_type<S, P>(in_place_type<S>, v.assume_error().clone(), hooks::spare_storage(&v));
}
namespace policy
{
template <class T, class DomainType, class E> struct status_code_throw<T, status_code<DomainType>, E> : base
{
using _base = base;
template <class Impl> static constexpr void wide_value_check(Impl &&self)
{
if(!base::_has_value(static_cast<Impl &&>(self)))
{
if(base::_has_exception(static_cast<Impl &&>(self)))
{
OUTCOME_V2_NAMESPACE::policy::detail::_rethrow_exception<trait::is_exception_ptr_available<E>::value>(
base::_exception<T, status_code<DomainType>, E, status_code_throw>(static_cast<Impl &&>(self))); // NOLINT
}
if(base::_has_error(static_cast<Impl &&>(self)))
{
#ifdef __cpp_exceptions
base::_error(static_cast<Impl &&>(self)).throw_exception();
#else
OUTCOME_THROW_EXCEPTION("wide value check failed");
#endif
}
}
}
template <class Impl> static constexpr void wide_error_check(Impl &&self) { _base::narrow_error_check(static_cast<Impl &&>(self)); }
template <class Impl> static constexpr void wide_exception_check(Impl &&self) { _base::narrow_exception_check(static_cast<Impl &&>(self)); }
};
template <class T, class DomainType, class E>
struct status_code_throw<T, errored_status_code<DomainType>, E> : status_code_throw<T, status_code<DomainType>, E>
{
status_code_throw() = default;
using status_code_throw<T, status_code<DomainType>, E>::status_code_throw;
};
} // namespace policy
} // namespace experimental
OUTCOME_V2_NAMESPACE_END
#endif
|
0 | repos/outcome/include/outcome | repos/outcome/include/outcome/experimental/result.h | /* C interface for result
(C) 2017-2024 Niall Douglas <http://www.nedproductions.biz/> (6 commits)
File Created: Aug 2017
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License in the accompanying file
Licence.txt or at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Distributed under the Boost Software License, Version 1.0.
(See accompanying file Licence.txt or copy at
http://www.boost.org/LICENSE_1_0.txt)
*/
#ifndef OUTCOME_EXPERIMENTAL_RESULT_H
#define OUTCOME_EXPERIMENTAL_RESULT_H
#include <assert.h>
#include <stddef.h> // for size_t
#include <stdint.h> // for intptr_t
#include "../detail/try.h"
#ifndef OUTCOME_C_WEAK
#ifdef _MSC_VER
#define OUTCOME_C_WEAK inline
#else
#define OUTCOME_C_WEAK __attribute__((weak))
#endif
#endif
#ifndef OUTCOME_C_MSVC_FORCE_EMIT
#ifdef _MSC_VER
#ifdef __cplusplus
#define OUTCOME_C_MSVC_FORCE_EMIT(x) extern "C" __declspec(selectany) void *x##_emit = x;
#else
#define OUTCOME_C_MSVC_FORCE_EMIT(x) extern __declspec(selectany) void *x##_emit = x;
#endif
#else
#define OUTCOME_C_MSVC_FORCE_EMIT(x)
#endif
#endif
#ifndef OUTCOME_C_NODISCARD
#if __STDC_VERSION__ >= 202000L || __cplusplus >= 201700L
#define OUTCOME_C_NODISCARD [[nodiscard]]
#ifdef __cplusplus
#define OUTCOME_C_NODISCARD_EXTERN_C extern "C" [[nodiscard]]
#else
#define OUTCOME_C_NODISCARD_EXTERN_C [[nodiscard]] extern
#endif
#elif defined(__GNUC__) || defined(__clang__)
#define OUTCOME_C_NODISCARD __attribute__((warn_unused_result))
#ifdef __cplusplus
#define OUTCOME_C_NODISCARD_EXTERN_C extern "C" __attribute__((warn_unused_result))
#else
#define OUTCOME_C_NODISCARD_EXTERN_C extern __attribute__((warn_unused_result))
#endif
#else
#define OUTCOME_C_NODISCARD
#define OUTCOME_C_NODISCARD_EXTERN_C extern
#endif
#endif
#include "../outcome_gdb.h"
#ifdef __cplusplus
extern "C"
{
#endif
#define CXX_DECLARE_RESULT(ident, R, S) \
struct cxx_result_##ident \
{ \
union \
{ \
R value; \
S error; \
}; \
unsigned flags; \
}
#define CXX_RESULT(ident) struct cxx_result_##ident
#define CXX_RESULT_HAS_VALUE(r) (((r).flags & 1U) == 1U)
#define CXX_RESULT_HAS_ERROR(r) (((r).flags & 2U) == 2U)
#define CXX_RESULT_ERROR_IS_ERRNO(r) (((r).flags & (1U << 4U)) == (1U << 4U))
/***************************** <system_error2> support ******************************/
#define CXX_DECLARE_STATUS_CODE(ident, value_type) \
struct cxx_status_code_##ident \
{ \
void *domain; \
value_type value; \
};
#define CXX_STATUS_CODE(ident) struct cxx_status_code_##ident
extern OUTCOME_C_WEAK void outcome_make_result_status_code_success(void *out, size_t bytes, size_t offset, const void *toset, size_t tosetbytes);
extern OUTCOME_C_WEAK void outcome_make_result_status_code_failure_posix(void *out, size_t bytes, size_t offset, int errcode);
extern OUTCOME_C_WEAK void outcome_make_result_status_code_failure_system(void *out, size_t bytes, size_t offset, intptr_t errcode);
extern int outcome_status_code_equal(const void *a, const void *b);
extern int outcome_status_code_equal_generic(const void *a, int errcode);
extern const char *outcome_status_code_message(const void *a);
#ifdef __cplusplus
#define CXX_DECLARE_RESULT_STATUS_CODE_CXX(ident, R, S) \
static_assert(std::is_trivially_copyable<R>::value || OUTCOME_V2_NAMESPACE::trait::is_move_bitcopying<R>::value, \
"R must be trivially copyable or move bitcopying to be used in a C Result"); \
static_assert(std::is_trivially_copyable<S>::value || OUTCOME_V2_NAMESPACE::trait::is_move_bitcopying<S>::value, \
"S must be trivially copyable or move bitcopying to be used in a C Result"); \
inline OUTCOME_V2_NAMESPACE::experimental::status_result<R> to_result(const cxx_result_status_code_##ident &v) \
{ \
union type_punner_t \
{ \
cxx_result_status_code_##ident c; \
OUTCOME_V2_NAMESPACE::experimental::status_result<R> cpp; \
\
type_punner_t() \
: c{} \
{ \
} \
~type_punner_t() {} \
} pun; \
\
pun.c = v; \
return std::move(pun.cpp); \
} \
OUTCOME_C_NODISCARD inline cxx_result_status_code_##ident to_##ident(OUTCOME_V2_NAMESPACE::experimental::status_result<R> v) \
{ \
union type_punner_t \
{ \
OUTCOME_V2_NAMESPACE::experimental::status_result<R> cpp; \
cxx_result_status_code_##ident c; \
\
type_punner_t(OUTCOME_V2_NAMESPACE::experimental::status_result<R> v) \
: cpp(std::move(v)) \
{ \
} \
~type_punner_t() {} \
} pun{std::move(v)}; \
\
return pun.c; \
}
#else
#define CXX_DECLARE_RESULT_STATUS_CODE_CXX(ident, R, S)
#endif
#define CXX_DECLARE_RESULT_STATUS_CODE(ident, R, S) \
struct cxx_result_status_code_##ident \
{ \
R value; \
unsigned flags; \
S error; \
}; \
OUTCOME_C_NODISCARD_EXTERN_C OUTCOME_C_WEAK struct cxx_result_status_code_##ident outcome_make_result_##ident##_success(R value) \
{ \
struct cxx_result_status_code_##ident ret; \
assert(outcome_make_result_status_code_success); /* If this fails, you need to compile this file at least once in C++. */ \
outcome_make_result_status_code_success((void *) &ret, sizeof(ret), offsetof(struct cxx_result_status_code_##ident, flags), (const void *) &value, \
sizeof(value)); \
return ret; \
} \
OUTCOME_C_MSVC_FORCE_EMIT(outcome_make_result_##ident##_success) \
OUTCOME_C_NODISCARD_EXTERN_C OUTCOME_C_WEAK struct cxx_result_status_code_##ident outcome_make_result_##ident##_failure_posix(int errcode) \
{ \
struct cxx_result_status_code_##ident ret; \
assert(outcome_make_result_status_code_failure_posix); /* If this fails, you need to compile this file at least once in C++. */ \
outcome_make_result_status_code_failure_posix((void *) &ret, sizeof(ret), offsetof(struct cxx_result_status_code_##ident, flags), errcode); \
return ret; \
} \
OUTCOME_C_MSVC_FORCE_EMIT(outcome_make_result_##ident##_failure_posix) \
OUTCOME_C_NODISCARD_EXTERN_C OUTCOME_C_WEAK struct cxx_result_status_code_##ident outcome_make_result_##ident##_failure_system(intptr_t errcode) \
{ \
struct cxx_result_status_code_##ident ret; \
assert(outcome_make_result_status_code_failure_system); /* If this fails, you need to compile this file at least once in C++. */ \
outcome_make_result_status_code_failure_system((void *) &ret, sizeof(ret), offsetof(struct cxx_result_status_code_##ident, flags), errcode); \
return ret; \
} \
OUTCOME_C_MSVC_FORCE_EMIT(outcome_make_result_##ident##_failure_system) \
CXX_DECLARE_RESULT_STATUS_CODE_CXX(ident, R, S)
#define CXX_RESULT_STATUS_CODE(ident) struct cxx_result_status_code_##ident
#define CXX_TO_RESULT_STATUS_CODE(ident, ...) to_##ident(__VA_ARGS__)
#define CXX_MAKE_RESULT_STATUS_CODE_SUCCESS(ident, ...) outcome_make_result_##ident##_success(__VA_ARGS__)
#define CXX_MAKE_RESULT_STATUS_CODE_FAILURE_POSIX(ident, ...) outcome_make_result_##ident##_failure_posix(__VA_ARGS__)
#define CXX_MAKE_RESULT_STATUS_CODE_FAILURE_SYSTEM(ident, ...) outcome_make_result_##ident##_failure_system(__VA_ARGS__)
struct cxx_status_code_posix
{
void *domain;
int value;
};
#define CXX_DECLARE_RESULT_ERRNO(ident, R) CXX_DECLARE_RESULT_STATUS_CODE(posix_##ident, R, struct cxx_status_code_posix)
#define CXX_RESULT_ERRNO(ident) CXX_RESULT_STATUS_CODE(posix_##ident)
struct cxx_status_code_system
{
void *domain;
intptr_t value;
};
#define CXX_DECLARE_RESULT_SYSTEM(ident, R) CXX_DECLARE_RESULT_STATUS_CODE(system_##ident, R, struct cxx_status_code_system)
#define CXX_RESULT_SYSTEM(ident) CXX_RESULT_STATUS_CODE(system_##ident)
#define CXX_TO_RESULT_SYSTEM_CODE(ident, ...) to_system_##ident(__VA_ARGS__)
#define CXX_MAKE_RESULT_SYSTEM_SUCCESS(ident, ...) CXX_MAKE_RESULT_STATUS_CODE_SUCCESS(system_##ident, __VA_ARGS__)
#define CXX_MAKE_RESULT_SYSTEM_FAILURE_POSIX(ident, ...) CXX_MAKE_RESULT_STATUS_CODE_FAILURE_POSIX(system_##ident, __VA_ARGS__)
#define CXX_MAKE_RESULT_SYSTEM_FAILURE_SYSTEM(ident, ...) CXX_MAKE_RESULT_STATUS_CODE_FAILURE_SYSTEM(system_##ident, __VA_ARGS__)
#define CXX_RESULT_SYSTEM_TRY_IMPLV(unique, retstmt, cleanup, spec, ...) \
OUTCOME_TRYV2_UNIQUE_STORAGE(unique, spec, __VA_ARGS__); \
OUTCOME_TRY_LIKELY_IF(CXX_RESULT_HAS_VALUE(unique)); \
else \
{ \
retstmt; \
}
#define CXX_RESULT_SYSTEM_TRY_IMPLA(unique, retstmt, cleanup, var, ...) \
CXX_RESULT_SYSTEM_TRY_IMPLV(unique, retstmt, cleanup, var, __VA_ARGS__) \
OUTCOME_TRY2_VAR(var) = unique.value
#define CXX_RESULT_SYSTEM_TRY_IMPL_RETURN(unique, ident) \
CXX_RESULT_SYSTEM(ident) unique##_f; \
unique##_f.flags = (unique).flags; \
unique##_f.error = (unique).error; \
return unique##_f
#define CXX_RESULT_SYSTEM_TRY_WITH_SPEC_AND_CLEANUP_AND_NEW_RETURN_TYPE(unique, spec, ident, cleanup, ...) \
CXX_RESULT_SYSTEM_TRY_IMPLA(unique, CXX_RESULT_SYSTEM_TRY_IMPL_RETURN(unique, ident), cleanup, spec, __VA_ARGS__)
#define CXX_RESULT_SYSTEM_TRY_WITH_SPEC_AND_CLEANUP(unique, spec, cleanup, ...) CXX_RESULT_SYSTEM_TRY_IMPLA(unique, return unique, cleanup, spec, __VA_ARGS__)
#define CXX_RESULT_SYSTEM_TRY_WITH_CLEANUP(unique, cleanup, ...) CXX_RESULT_SYSTEM_TRY_IMPLV(unique, return unique, cleanup, deduce, __VA_ARGS__)
#define CXX_RESULT_SYSTEM_TRY_SAME_RETURN_TYPE(unique, ...) CXX_RESULT_SYSTEM_TRY_IMPLV(unique, return unique, , deduce, __VA_ARGS__)
#define CXX_RESULT_SYSTEM_TRY_INVOKE_TRY8(a, b, c, d, e, f, g, h) \
CXX_RESULT_SYSTEM_TRY_WITH_SPEC_AND_CLEANUP_AND_NEW_RETURN_TYPE(OUTCOME_TRY_UNIQUE_NAME, a, b, c, d, e, f, g, h)
#define CXX_RESULT_SYSTEM_TRY_INVOKE_TRY7(a, b, c, d, e, f, g) \
CXX_RESULT_SYSTEM_TRY_WITH_SPEC_AND_CLEANUP_AND_NEW_RETURN_TYPE(OUTCOME_TRY_UNIQUE_NAME, a, b, c, d, e, f, g)
#define CXX_RESULT_SYSTEM_TRY_INVOKE_TRY6(a, b, c, d, e, f) \
CXX_RESULT_SYSTEM_TRY_WITH_SPEC_AND_CLEANUP_AND_NEW_RETURN_TYPE(OUTCOME_TRY_UNIQUE_NAME, a, b, c, d, e, f)
#define CXX_RESULT_SYSTEM_TRY_INVOKE_TRY5(a, b, c, d, e) CXX_RESULT_SYSTEM_TRY_WITH_SPEC_AND_CLEANUP_AND_NEW_RETURN_TYPE(OUTCOME_TRY_UNIQUE_NAME, a, b, c, d, e)
#define CXX_RESULT_SYSTEM_TRY_INVOKE_TRY4(a, b, c, d) CXX_RESULT_SYSTEM_TRY_WITH_SPEC_AND_CLEANUP_AND_NEW_RETURN_TYPE(OUTCOME_TRY_UNIQUE_NAME, a, b, c, d)
#define CXX_RESULT_SYSTEM_TRY_INVOKE_TRY3(a, b, c) CXX_RESULT_SYSTEM_TRY_WITH_SPEC_AND_CLEANUP(OUTCOME_TRY_UNIQUE_NAME, a, b, c)
#define CXX_RESULT_SYSTEM_TRY_INVOKE_TRY2(a, b) CXX_RESULT_SYSTEM_TRY_WITH_CLEANUP(OUTCOME_TRY_UNIQUE_NAME, a, b)
#define CXX_RESULT_SYSTEM_TRY_INVOKE_TRY1(expr) CXX_RESULT_SYSTEM_TRY_SAME_RETURN_TYPE(OUTCOME_TRY_UNIQUE_NAME, expr)
#define CXX_RESULT_SYSTEM_TRY(...) OUTCOME_TRY_CALL_OVERLOAD(CXX_RESULT_SYSTEM_TRY_INVOKE_TRY, __VA_ARGS__)
#define CXX_MAKE_RESULT_SYSTEM_FROM_ENUM(ident, enum_name, ...) outcome_make_result_##ident##_failure_system_enum_##enum_name(__VA_ARGS__)
#ifndef __cplusplus
// Declares the function in C, needs to occur at least once in a C++ source file to get implemented
#define CXX_DECLARE_RESULT_SYSTEM_FROM_ENUM(ident, enum_name, uuid, ...) \
OUTCOME_C_NODISCARD_EXTERN_C struct cxx_result_status_code_system_##ident outcome_make_result_##ident##_failure_system_enum_##enum_name(enum enum_name v);
#else
}
#include "../config.hpp"
#include "status-code/include/status-code/config.hpp"
#include "status-code/include/status-code/system_code.hpp"
#include "status_result.hpp"
#include "status-code/include/status-code/posix_code.hpp"
#ifdef _WIN32
#include "status-code/include/status-code/win32_code.hpp"
#endif
#include <algorithm>
#include <cstring>
#if defined(__GNUC__) && !defined(__clang__)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
#endif
// You need to include this C header in at least one C++ source file to have these C helper functions be implemented
extern "C" OUTCOME_C_WEAK void outcome_make_result_status_code_success(void *out, size_t bytes, size_t offset, const void *toset, size_t tosetbytes)
{
union type_punner_t
{
OUTCOME_V2_NAMESPACE::experimental::status_result<intptr_t> cpp;
struct cxx_status_code
{
intptr_t value;
unsigned flags;
cxx_status_code_system error;
} c;
type_punner_t()
: cpp(0)
{
}
~type_punner_t() {}
} pun;
static_assert(sizeof(pun.cpp) == sizeof(pun.c), "");
static constexpr size_t punoffset = offsetof(type_punner_t::cxx_status_code, flags);
assert(bytes - tosetbytes >= sizeof(pun.cpp) - punoffset);
const size_t tocopy = std::min(bytes - tosetbytes, sizeof(pun.c) - punoffset);
memcpy(out, toset, tosetbytes);
memcpy((void *) ((char *) out + offset), (const void *) ((const char *) &pun.c + punoffset), tocopy);
}
OUTCOME_C_MSVC_FORCE_EMIT(outcome_make_result_status_code_success)
extern "C" OUTCOME_C_WEAK void outcome_make_result_status_code_failure_posix(void *out, size_t bytes, size_t offset, int errcode)
{
using value_type = OUTCOME_V2_NAMESPACE::experimental::posix_code::value_type;
union type_punner_t
{
OUTCOME_V2_NAMESPACE::experimental::status_result<intptr_t> cpp;
struct cxx_status_code
{
intptr_t value;
unsigned flags;
cxx_status_code_system error;
} c;
explicit type_punner_t(OUTCOME_V2_NAMESPACE::experimental::status_result<intptr_t> res)
: cpp(std::move(res))
{
}
~type_punner_t() {}
} pun{OUTCOME_V2_NAMESPACE::experimental::posix_code(errcode)};
static_assert(sizeof(pun.cpp) == sizeof(pun.c), "");
static constexpr size_t punoffset = offsetof(type_punner_t::cxx_status_code, flags);
assert(bytes - offset >= sizeof(pun.cpp) - punoffset);
const size_t tocopy = std::min(bytes - offset, sizeof(pun.cpp) - punoffset);
memcpy(out, (void *) &pun.c, sizeof(value_type));
memcpy((void *) ((char *) out + offset), (const void *) ((const char *) &pun.c + punoffset), tocopy);
}
OUTCOME_C_MSVC_FORCE_EMIT(outcome_make_result_status_code_failure_posix)
extern "C" OUTCOME_C_WEAK void outcome_make_result_status_code_failure_system(void *out, size_t bytes, size_t offset, intptr_t errcode)
{
using value_type = OUTCOME_V2_NAMESPACE::experimental::system_code::value_type;
union type_punner_t
{
OUTCOME_V2_NAMESPACE::experimental::status_result<intptr_t> cpp;
struct cxx_status_code
{
intptr_t value;
unsigned flags;
cxx_status_code_system error;
} c;
explicit type_punner_t(OUTCOME_V2_NAMESPACE::experimental::status_result<intptr_t> res)
: cpp(std::move(res))
{
}
~type_punner_t() {}
} pun{
#ifdef _WIN32
OUTCOME_V2_NAMESPACE::experimental::win32_code((OUTCOME_V2_NAMESPACE::experimental::win32::DWORD) errcode)
#else
OUTCOME_V2_NAMESPACE::experimental::posix_code((int) errcode)
#endif
};
static_assert(sizeof(pun.cpp) == sizeof(pun.c), "");
static constexpr size_t punoffset = offsetof(type_punner_t::cxx_status_code, flags);
assert(bytes - offset >= sizeof(pun.cpp) - punoffset);
const size_t tocopy = std::min(bytes - offset, sizeof(pun.cpp) - punoffset);
memcpy(out, (void *) &pun.c, sizeof(value_type));
memcpy((void *) ((char *) out + offset), (const void *) ((const char *) &pun.c + punoffset), tocopy);
}
OUTCOME_C_MSVC_FORCE_EMIT(outcome_make_result_status_code_failure_system)
extern "C" OUTCOME_C_WEAK int outcome_status_code_equal(const void *_a, const void *_b)
{
const auto *a = (const SYSTEM_ERROR2_NAMESPACE::system_code *) _a;
const auto *b = (const SYSTEM_ERROR2_NAMESPACE::system_code *) _b;
return *a == *b;
}
OUTCOME_C_MSVC_FORCE_EMIT(outcome_status_code_equal)
extern "C" OUTCOME_C_WEAK int outcome_status_code_equal_generic(const void *_a, int errcode)
{
const auto *a = (const SYSTEM_ERROR2_NAMESPACE::system_code *) _a;
return *a == (SYSTEM_ERROR2_NAMESPACE::errc) errcode;
}
OUTCOME_C_MSVC_FORCE_EMIT(outcome_status_code_equal_generic)
extern "C" OUTCOME_C_WEAK const char *outcome_status_code_message(const void *_a)
{
static thread_local SYSTEM_ERROR2_NAMESPACE::system_code::string_ref msg((const char *) nullptr, 0);
const auto *a = (const SYSTEM_ERROR2_NAMESPACE::system_code *) _a;
msg = a->message();
return msg.c_str();
}
OUTCOME_C_MSVC_FORCE_EMIT(outcome_status_code_message)
OUTCOME_V2_NAMESPACE_BEGIN
namespace experimental
{
namespace detail
{
template <class RetType, class EnumType> inline RetType outcome_make_result_failure_system_enum(EnumType v)
{
using value_type = OUTCOME_V2_NAMESPACE::experimental::system_code::value_type;
union type_punner_t
{
OUTCOME_V2_NAMESPACE::experimental::status_result<intptr_t> cpp;
struct cxx_status_code
{
intptr_t value;
unsigned flags;
cxx_status_code_system error;
} c;
explicit type_punner_t(OUTCOME_V2_NAMESPACE::experimental::status_result<intptr_t> res)
: cpp(std::move(res))
{
}
~type_punner_t() {}
} pun{OUTCOME_V2_NAMESPACE::experimental::quick_status_code_from_enum_code<EnumType>(v)};
static constexpr size_t bytes = sizeof(RetType);
static constexpr size_t offset = offsetof(RetType, flags);
static constexpr size_t punoffset = offsetof(typename type_punner_t::cxx_status_code, flags);
assert(bytes - offset >= sizeof(pun.cpp) - punoffset);
const size_t tocopy = std::min(bytes - offset, sizeof(pun.cpp) - punoffset);
RetType ret;
memcpy(&ret, (void *) &pun.c, sizeof(value_type));
memcpy((void *) ((char *) &ret + offset), (const void *) ((const char *) &pun.c + punoffset), tocopy);
return ret;
}
} // namespace detail
} // namespace experimental
OUTCOME_V2_NAMESPACE_END
// Unique UUID for the enum PLEASE use https://www.random.org/cgi-bin/randbyte?nbytes=16&format=h
// .. is sequence of {enum_name::value, "text description", {errc::equivalent, ...}},
#define CXX_DECLARE_RESULT_SYSTEM_FROM_ENUM(ident, enum_name, uuid, ...) \
SYSTEM_ERROR2_NAMESPACE_BEGIN \
template <> struct quick_status_code_from_enum<enum enum_name> : quick_status_code_from_enum_defaults<enum enum_name> \
{ \
static constexpr const auto domain_name = #enum_name; \
static constexpr const auto domain_uuid = uuid; \
static const std::initializer_list<mapping> &value_mappings() \
{ \
static const std::initializer_list<mapping> v = {__VA_ARGS__}; \
return v; \
} \
}; \
SYSTEM_ERROR2_NAMESPACE_END \
extern "C" OUTCOME_C_NODISCARD OUTCOME_C_WEAK struct cxx_result_status_code_system_##ident outcome_make_result_##ident##_failure_system_enum_##enum_name( \
enum enum_name v) \
{ \
return OUTCOME_V2_NAMESPACE::experimental::detail::outcome_make_result_failure_system_enum<struct cxx_result_status_code_system_##ident>(v); \
} \
OUTCOME_C_MSVC_FORCE_EMIT(outcome_make_result_##ident##_failure_system_enum_##enum_name)
#if defined(__GNUC__) && !defined(__clang__)
#pragma GCC diagnostic pop
#endif
#endif
#endif
|
0 | repos/outcome/include/outcome | repos/outcome/include/outcome/experimental/coroutine_support.hpp | /* Tells C++ coroutines about Outcome's result
(C) 2019 Niall Douglas <http://www.nedproductions.biz/> (12 commits)
File Created: Oct 2019
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License in the accompanying file
Licence.txt or at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Distributed under the Boost Software License, Version 1.0.
(See accompanying file Licence.txt or copy at
http://www.boost.org/LICENSE_1_0.txt)
*/
#ifndef OUTCOME_EXPERIMENTAL_COROUTINE_SUPPORT_HPP
#define OUTCOME_EXPERIMENTAL_COROUTINE_SUPPORT_HPP
#include "../config.hpp"
#define OUTCOME_COROUTINE_SUPPORT_NAMESPACE_BEGIN \
OUTCOME_V2_NAMESPACE_BEGIN namespace experimental \
{ \
namespace awaitables \
{
//
#define OUTCOME_COROUTINE_SUPPORT_NAMESPACE_EXPORT_BEGIN \
OUTCOME_V2_NAMESPACE_EXPORT_BEGIN namespace experimental \
{ \
namespace awaitables \
{
//
#define OUTCOME_COROUTINE_SUPPORT_NAMESPACE_END \
} \
} \
OUTCOME_V2_NAMESPACE_END
#ifdef __cpp_exceptions
#if !OUTCOME_USE_SYSTEM_STATUS_CODE && __has_include("status-code/include/status-code/system_code_from_exception.hpp")
#include "status-code/include/status-code/system_code_from_exception.hpp"
#else
#include <status-code/system_code_from_exception.hpp>
#endif
OUTCOME_V2_NAMESPACE_BEGIN
namespace awaitables
{
namespace detail
{
inline bool error_is_set(SYSTEM_ERROR2_NAMESPACE::system_code &sc) noexcept { return sc.failure(); }
inline SYSTEM_ERROR2_NAMESPACE::system_code error_from_exception(std::exception_ptr &&ep = std::current_exception(), SYSTEM_ERROR2_NAMESPACE::system_code not_matched = SYSTEM_ERROR2_NAMESPACE::generic_code(SYSTEM_ERROR2_NAMESPACE::errc::resource_unavailable_try_again)) noexcept
{
return SYSTEM_ERROR2_NAMESPACE::system_code_from_exception(static_cast<std::exception_ptr &&>(ep), static_cast<SYSTEM_ERROR2_NAMESPACE::system_code &&>(not_matched));
}
} // namespace detail
} // namespace awaitables
OUTCOME_V2_NAMESPACE_END
#endif
#include "../detail/coroutine_support.ipp"
#undef OUTCOME_COROUTINE_SUPPORT_NAMESPACE_BEGIN
#undef OUTCOME_COROUTINE_SUPPORT_NAMESPACE_EXPORT_BEGIN
#undef OUTCOME_COROUTINE_SUPPORT_NAMESPACE_END
#endif
|
0 | repos/outcome | repos/outcome/attic/appveyor.yml | # version format
version: 2.00.{build}-{branch}
# branches to build
branches:
only:
- develop
- better_optimisation
skip_tags: true
image: Visual Studio 2017
init:
- git config --global core.longpaths true
clone_folder: c:\boost.outcome
platform:
- x86
- x64
configuration: Release
before_build:
- git checkout develop
- git submodule update --init --recursive
- pip install ply
build_script:
- if "%PLATFORM%" == "x86" set "CTEST_CONFIGURE_OPTIONS=-A Win32"
- ctest -S .ci.cmake -V
after_build:
before_test:
test_script:
after_test:
on_success:
on_failure:
on_finish:
- ps: (new-object net.webclient).UploadFile("https://ci.appveyor.com/api/testresults/junit/$($env:APPVEYOR_JOB_ID)", (Resolve-Path cmake_ci\merged_junit_results.xml))
|
0 | repos/outcome | repos/outcome/attic/.travis.yml | dist: trusty
language: cpp
compiler:
- g++-6
# - clang-4.0
sudo: false
os:
- linux
# - osx
osx_image: xcode9
branches:
only:
- develop
- better_optimisation
notifications:
email:
recipients:
- [email protected]
addons:
apt:
sources:
- ubuntu-toolchain-r-test
# - george-edison55-precise-backports
# - george-edison55-cmake-3.x
- llvm-toolchain-trusty-4.0
packages:
- g++-6
- clang-4.0
- cmake
- cmake-data
# - abi-compliance-checker
- abi-dumper
- python3
- python3-pip
env:
# - __="Code bloat tests"
# - __="ABI stability" NAME=TravisABICheck
# - __="Documentation" NAME=TravisDocumentation
- __="cmake tests" NAME=TravisLinuxWorker
# - __="cmake tests osx" NAME=TravisOSXWorker
# - __="Installability"
#matrix:
# exclude:
# - os: osx
# compiler: g++-6
# - os: linux
# compiler: clang-4.0
# env: __="ABI stability" NAME=TravisABICheck
# - os: linux
# compiler: clang-4.0
# env: __="Documentation" NAME=TravisDocumentation
# - os: linux
# env: __="cmake tests osx" NAME=TravisOSXWorker
# - os: osx
# env: __="Code bloat tests"
# - os: osx
# env: __="ABI stability" NAME=TravisABICheck
# - os: osx
# env: __="Documentation" NAME=TravisDocumentation
# - os: osx
# env: __="cmake tests" NAME=TravisLinuxWorker
cache:
apt: true
directories:
- hugo_bin
before_install:
- git config --global push.default simple
- git config --global user.name "Jenkins nedprod CI"
- git config --global user.email "foo@nowhere"
- if [ ! -f "hugo_bin/hugo" ]; then
wget -O hugo.tar.gz https://github.com/gohugoio/hugo/releases/download/v0.52/hugo_0.52_Linux-64bit.tar.gz;
mkdir hugo_bin;
tar xf hugo.tar.gz -C hugo_bin;
fi;
ls -l hugo_bin;
export PATH=$PATH:`pwd`/hugo_bin;
script:
-
if [ "$__" = "Code bloat tests" ]; then
cd test/constexprs;
./compile_and_count.py;
cat results.posix.xml;
if grep -q "failure message" results.posix.xml; then
exit 1;
fi;
fi
-
if [ "$__" = "ABI stability" ]; then
pip install ply --user `whoami`;
if [ "$CXX" = "g++" ]; then export CXX=g++-6; export NAME=TravisABICheck; fi;
mkdir build;
cd build;
cmake .. -DCMAKE_BUILD_TYPE=Release;
make outcome_hl-pp-abi;
cd ../abi-compliance;
sh ./check-abi.sh abi_dumps/Outcome/2.1/binary_only.dump;
fi
# sh ./check-api-abi.sh abi_dumps/Outcome/2.1/ABI.dump;
# -
# if [ "$__" = "cmake tests" ]; then
# if [ "$CXX" = "g++" ]; then export CXX=g++-6; export NAME=TravisLinuxWorkerGCC; fi;
# if [ "$CXX" = "clang++" ]; then export CXX=clang++-4.0; export NAME=TravisLinuxWorkerClang; fi;
# ctest -S .ci.cmake -V;
# fi
-
if [ "$__" = "cmake tests osx" ]; then
ctest -S .ci.cmake -V;
fi
- >
if [ "$__" = "Documentation" ]; then
cd doc/html;
git checkout gh-pages;
cd ../..;
CXX=clang++-4.0 ctest -S .docs.cmake -V;
cd doc/html;
echo "google-site-verification: google5fc8a1f8de4b73f0.html" > google5fc8a1f8de4b73f0.html;
git add . || true;
git commit -a -m "Travis CI updates documentation" || true;
git push -f https://jenkins-nedprod:[email protected]/ned14/outcome gh-pages;
cd ../..;
fi
-
if [ "$__" = "Installability" ]; then
if [ "$TRAVIS_OS_NAME" = "linux" ]; then
if [ "$CXX" = "g++" ]; then export CXX=g++-6; export NAME=TravisLinuxWorkerGCC; fi;
if [ "$CXX" = "clang++" ]; then export CXX=clang++-4.0; export NAME=TravisLinuxWorkerClang; fi;
fi;
git clone --depth 1 https://github.com/ned14/quickcpplib.git;
pip3 install --user gitpython;
python3 quickcpplib/scripts/test_cpp-pm_install.py conan/test_package/example.cpp quickcpplib quickcpplib::hl https://github.com/ned14/quickcpplib master outcome outcome::hl https://github.com/ned14/outcome master;
cd test_cpp-pm_install;
mkdir build;
cd build;
cmake .. -DCMAKE_BUILD_TYPE=Release;
make;
fi
after_success:
-
if [ "$__" = "cmake tests" ]; then
pip install --user gitpython;
git remote add outcome https://github.com/ned14/outcome;
git fetch outcome;
git submodule update --init;
cd ..;
git clone https://github.com/boostorg/outcome boost-outcome;
cd boost-outcome;
git checkout -b develop origin/develop;
git checkout master;
git remote add outcome https://github.com/ned14/outcome;
git fetch outcome;
git checkout -b orig-develop outcome/develop;
git checkout -b orig-master outcome/master;
git checkout master;
cd ..;
git clone --depth 1 https://github.com/ned14/quickcpplib.git;
python quickcpplib/scripts/boostify_git_repo.py boost-outcome outcome ned14/outcome@;
cd boost-outcome;
git checkout master;
cd doc/src;
rm -rf ../html;
HUGO_BOOSTDOCDISABLECOMMONHEADING=1 hugo;
cd ../html;
git add . || true;
cd ../..;
git commit -a -m "Travis CI regenerates Boost.Outcome docs" || true;
git checkout develop;
cd doc/src;
rm -rf ../html;
HUGO_BOOSTDOCDISABLECOMMONHEADING=1 hugo;
cd ../html;
git add . || true;
cd ../..;
git commit -a -m "Travis CI regenerates Boost.Outcome docs" || true;
git push https://jenkins-nedprod:[email protected]/boostorg/outcome master || true;
git push https://jenkins-nedprod:[email protected]/boostorg/outcome develop || true;
cd doc;
rm -rf html;
git clone -b gh-pages --single-branch https://github.com/boostorg/outcome html;
cd src;
hugo;
cd ../html;
git add . || true;
git commit -a -m "Travis CI regenerates Boost.Outcome docs" || true;
git push -f https://jenkins-nedprod:[email protected]/boostorg/outcome gh-pages;
cd ../..;
fi
after_failure:
|
0 | repos/outcome | repos/outcome/single-header/outcome-basic.hpp | /* A less simple result type
(C) 2017-2024 Niall Douglas <http://www.nedproductions.biz/> (20 commits)
File Created: June 2017
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License in the accompanying file
Licence.txt or at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Distributed under the Boost Software License, Version 1.0.
(See accompanying file Licence.txt or copy at
http://www.boost.org/LICENSE_1_0.txt)
*/
#ifndef OUTCOME_BASIC_OUTCOME_HPP
#define OUTCOME_BASIC_OUTCOME_HPP
/* Configure Outcome with QuickCppLib
(C) 2015-2021 Niall Douglas <http://www.nedproductions.biz/> (24 commits)
File Created: August 2015
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License in the accompanying file
Licence.txt or at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Distributed under the Boost Software License, Version 1.0.
(See accompanying file Licence.txt or copy at
http://www.boost.org/LICENSE_1_0.txt)
*/
#ifndef OUTCOME_V2_CONFIG_HPP
#define OUTCOME_V2_CONFIG_HPP
/* Sets Outcome version
(C) 2017-2023 Niall Douglas <http://www.nedproductions.biz/> (4 commits)
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License in the accompanying file
Licence.txt or at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Distributed under the Boost Software License, Version 1.0.
(See accompanying file Licence.txt or copy at
http://www.boost.org/LICENSE_1_0.txt)
*/
/*! AWAITING HUGO JSON CONVERSION TOOL */
#define OUTCOME_VERSION_MAJOR 2
/*! AWAITING HUGO JSON CONVERSION TOOL */
#define OUTCOME_VERSION_MINOR 2
/*! AWAITING HUGO JSON CONVERSION TOOL */
#define OUTCOME_VERSION_PATCH 9
/*! AWAITING HUGO JSON CONVERSION TOOL */
#define OUTCOME_VERSION_REVISION 0 // Revision version for cmake and DLL version stamping
/*! AWAITING HUGO JSON CONVERSION TOOL */
// Pull in detection of __MINGW64_VERSION_MAJOR
#if defined(__MINGW32__) && !0L
#include <_mingw.h>
#endif
/* Configure QuickCppLib
(C) 2016-2021 Niall Douglas <http://www.nedproductions.biz/> (8 commits)
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License in the accompanying file
Licence.txt or at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Distributed under the Boost Software License, Version 1.0.
(See accompanying file Licence.txt or copy at
http://www.boost.org/LICENSE_1_0.txt)
*/
#ifndef QUICKCPPLIB_CONFIG_HPP
#define QUICKCPPLIB_CONFIG_HPP
/* Provides SG-10 feature checking for all C++ compilers
(C) 2014-2017 Niall Douglas <http://www.nedproductions.biz/> (13 commits)
File Created: Nov 2014
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License in the accompanying file
Licence.txt or at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Distributed under the Boost Software License, Version 1.0.
(See accompanying file Licence.txt or copy at
http://www.boost.org/LICENSE_1_0.txt)
*/
#ifndef QUICKCPPLIB_HAS_FEATURE_H
#define QUICKCPPLIB_HAS_FEATURE_H
#if __cplusplus >= 201103L
// Some of these macros ended up getting removed by ISO standards,
// they are prefixed with ////
////#if !defined(__cpp_alignas)
////#define __cpp_alignas 190000
////#endif
////#if !defined(__cpp_default_function_template_args)
////#define __cpp_default_function_template_args 190000
////#endif
////#if !defined(__cpp_defaulted_functions)
////#define __cpp_defaulted_functions 190000
////#endif
////#if !defined(__cpp_deleted_functions)
////#define __cpp_deleted_functions 190000
////#endif
////#if !defined(__cpp_generalized_initializers)
////#define __cpp_generalized_initializers 190000
////#endif
////#if !defined(__cpp_implicit_moves)
////#define __cpp_implicit_moves 190000
////#endif
////#if !defined(__cpp_inline_namespaces)
////#define __cpp_inline_namespaces 190000
////#endif
////#if !defined(__cpp_local_type_template_args)
////#define __cpp_local_type_template_args 190000
////#endif
////#if !defined(__cpp_noexcept)
////#define __cpp_noexcept 190000
////#endif
////#if !defined(__cpp_nonstatic_member_init)
////#define __cpp_nonstatic_member_init 190000
////#endif
////#if !defined(__cpp_nullptr)
////#define __cpp_nullptr 190000
////#endif
////#if !defined(__cpp_override_control)
////#define __cpp_override_control 190000
////#endif
////#if !defined(__cpp_thread_local)
////#define __cpp_thread_local 190000
////#endif
////#if !defined(__cpp_auto_type)
////#define __cpp_auto_type 190000
////#endif
////#if !defined(__cpp_strong_enums)
////#define __cpp_strong_enums 190000
////#endif
////#if !defined(__cpp_trailing_return)
////#define __cpp_trailing_return 190000
////#endif
////#if !defined(__cpp_unrestricted_unions)
////#define __cpp_unrestricted_unions 190000
////#endif
#if !defined(__cpp_alias_templates)
#define __cpp_alias_templates 190000
#endif
#if !defined(__cpp_attributes)
#define __cpp_attributes 190000
#endif
#if !defined(__cpp_constexpr)
#if __cplusplus >= 201402L
#define __cpp_constexpr 201304 // relaxed constexpr
#else
#define __cpp_constexpr 190000
#endif
#endif
#if !defined(__cpp_decltype)
#define __cpp_decltype 190000
#endif
#if !defined(__cpp_delegating_constructors)
#define __cpp_delegating_constructors 190000
#endif
#if !defined(__cpp_explicit_conversion) //// renamed from __cpp_explicit_conversions
#define __cpp_explicit_conversion 190000
#endif
#if !defined(__cpp_inheriting_constructors)
#define __cpp_inheriting_constructors 190000
#endif
#if !defined(__cpp_initializer_lists) //// NEW
#define __cpp_initializer_lists 190000
#endif
#if !defined(__cpp_lambdas)
#define __cpp_lambdas 190000
#endif
#if !defined(__cpp_nsdmi)
#define __cpp_nsdmi 190000 //// NEW
#endif
#if !defined(__cpp_range_based_for) //// renamed from __cpp_range_for
#define __cpp_range_based_for 190000
#endif
#if !defined(__cpp_raw_strings)
#define __cpp_raw_strings 190000
#endif
#if !defined(__cpp_ref_qualifiers) //// renamed from __cpp_reference_qualified_functions
#define __cpp_ref_qualifiers 190000
#endif
#if !defined(__cpp_rvalue_references)
#define __cpp_rvalue_references 190000
#endif
#if !defined(__cpp_static_assert)
#define __cpp_static_assert 190000
#endif
#if !defined(__cpp_unicode_characters) //// NEW
#define __cpp_unicode_characters 190000
#endif
#if !defined(__cpp_unicode_literals)
#define __cpp_unicode_literals 190000
#endif
#if !defined(__cpp_user_defined_literals)
#define __cpp_user_defined_literals 190000
#endif
#if !defined(__cpp_variadic_templates)
#define __cpp_variadic_templates 190000
#endif
#endif
#if __cplusplus >= 201402L
// Some of these macros ended up getting removed by ISO standards,
// they are prefixed with ////
////#if !defined(__cpp_contextual_conversions)
////#define __cpp_contextual_conversions 190000
////#endif
////#if !defined(__cpp_digit_separators)
////#define __cpp_digit_separators 190000
////#endif
////#if !defined(__cpp_relaxed_constexpr)
////#define __cpp_relaxed_constexpr 190000
////#endif
////#if !defined(__cpp_runtime_arrays)
////# define __cpp_runtime_arrays 190000
////#endif
#if !defined(__cpp_aggregate_nsdmi)
#define __cpp_aggregate_nsdmi 190000
#endif
#if !defined(__cpp_binary_literals)
#define __cpp_binary_literals 190000
#endif
#if !defined(__cpp_decltype_auto)
#define __cpp_decltype_auto 190000
#endif
#if !defined(__cpp_generic_lambdas)
#define __cpp_generic_lambdas 190000
#endif
#if !defined(__cpp_init_captures)
#define __cpp_init_captures 190000
#endif
#if !defined(__cpp_return_type_deduction)
#define __cpp_return_type_deduction 190000
#endif
#if !defined(__cpp_sized_deallocation)
#define __cpp_sized_deallocation 190000
#endif
#if !defined(__cpp_variable_templates)
#define __cpp_variable_templates 190000
#endif
#endif
// VS2010: _MSC_VER=1600
// VS2012: _MSC_VER=1700
// VS2013: _MSC_VER=1800
// VS2015: _MSC_VER=1900
// VS2017: _MSC_VER=1910
#if defined(_MSC_VER) && !defined(__clang__)
#if !defined(__cpp_exceptions) && defined(_CPPUNWIND)
#define __cpp_exceptions 190000
#endif
#if !defined(__cpp_rtti) && defined(_CPPRTTI)
#define __cpp_rtti 190000
#endif
// C++ 11
#if !defined(__cpp_alias_templates) && _MSC_VER >= 1800
#define __cpp_alias_templates 190000
#endif
#if !defined(__cpp_attributes)
#define __cpp_attributes 190000
#endif
#if !defined(__cpp_constexpr) && _MSC_FULL_VER >= 190023506 /* VS2015 */
#define __cpp_constexpr 190000
#endif
#if !defined(__cpp_decltype) && _MSC_VER >= 1600
#define __cpp_decltype 190000
#endif
#if !defined(__cpp_delegating_constructors) && _MSC_VER >= 1800
#define __cpp_delegating_constructors 190000
#endif
#if !defined(__cpp_explicit_conversion) && _MSC_VER >= 1800
#define __cpp_explicit_conversion 190000
#endif
#if !defined(__cpp_inheriting_constructors) && _MSC_VER >= 1900
#define __cpp_inheriting_constructors 190000
#endif
#if !defined(__cpp_initializer_lists) && _MSC_VER >= 1900
#define __cpp_initializer_lists 190000
#endif
#if !defined(__cpp_lambdas) && _MSC_VER >= 1600
#define __cpp_lambdas 190000
#endif
#if !defined(__cpp_nsdmi) && _MSC_VER >= 1900
#define __cpp_nsdmi 190000
#endif
#if !defined(__cpp_range_based_for) && _MSC_VER >= 1700
#define __cpp_range_based_for 190000
#endif
#if !defined(__cpp_raw_strings) && _MSC_VER >= 1800
#define __cpp_raw_strings 190000
#endif
#if !defined(__cpp_ref_qualifiers) && _MSC_VER >= 1900
#define __cpp_ref_qualifiers 190000
#endif
#if !defined(__cpp_rvalue_references) && _MSC_VER >= 1600
#define __cpp_rvalue_references 190000
#endif
#if !defined(__cpp_static_assert) && _MSC_VER >= 1600
#define __cpp_static_assert 190000
#endif
//#if !defined(__cpp_unicode_literals)
//# define __cpp_unicode_literals 190000
//#endif
#if !defined(__cpp_user_defined_literals) && _MSC_VER >= 1900
#define __cpp_user_defined_literals 190000
#endif
#if !defined(__cpp_variadic_templates) && _MSC_VER >= 1800
#define __cpp_variadic_templates 190000
#endif
// C++ 14
//#if !defined(__cpp_aggregate_nsdmi)
//#define __cpp_aggregate_nsdmi 190000
//#endif
#if !defined(__cpp_binary_literals) && _MSC_VER >= 1900
#define __cpp_binary_literals 190000
#endif
#if !defined(__cpp_decltype_auto) && _MSC_VER >= 1900
#define __cpp_decltype_auto 190000
#endif
#if !defined(__cpp_generic_lambdas) && _MSC_VER >= 1900
#define __cpp_generic_lambdas 190000
#endif
#if !defined(__cpp_init_captures) && _MSC_VER >= 1900
#define __cpp_init_captures 190000
#endif
#if !defined(__cpp_return_type_deduction) && _MSC_VER >= 1900
#define __cpp_return_type_deduction 190000
#endif
#if !defined(__cpp_sized_deallocation) && _MSC_VER >= 1900
#define __cpp_sized_deallocation 190000
#endif
#if !defined(__cpp_variable_templates) && _MSC_FULL_VER >= 190023506
#define __cpp_variable_templates 190000
#endif
#endif // _MSC_VER
// Much to my surprise, GCC's support of these is actually incomplete, so fill in the gaps
#if (defined(__GNUC__) && !defined(__clang__))
#define QUICKCPPLIB_GCC (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__)
#if !defined(__cpp_exceptions) && defined(__EXCEPTIONS)
#define __cpp_exceptions 190000
#endif
#if !defined(__cpp_rtti) && defined(__GXX_RTTI)
#define __cpp_rtti 190000
#endif
// C++ 11
#if defined(__GXX_EXPERIMENTAL_CXX0X__)
#if !defined(__cpp_alias_templates) && (QUICKCPPLIB_GCC >= 40700)
#define __cpp_alias_templates 190000
#endif
#if !defined(__cpp_attributes) && (QUICKCPPLIB_GCC >= 40800)
#define __cpp_attributes 190000
#endif
#if !defined(__cpp_constexpr) && (QUICKCPPLIB_GCC >= 40600)
#define __cpp_constexpr 190000
#endif
#if !defined(__cpp_decltype) && (QUICKCPPLIB_GCC >= 40300)
#define __cpp_decltype 190000
#endif
#if !defined(__cpp_delegating_constructors) && (QUICKCPPLIB_GCC >= 40700)
#define __cpp_delegating_constructors 190000
#endif
#if !defined(__cpp_explicit_conversion) && (QUICKCPPLIB_GCC >= 40500)
#define __cpp_explicit_conversion 190000
#endif
#if !defined(__cpp_inheriting_constructors) && (QUICKCPPLIB_GCC >= 40800)
#define __cpp_inheriting_constructors 190000
#endif
#if !defined(__cpp_initializer_lists) && (QUICKCPPLIB_GCC >= 40800)
#define __cpp_initializer_lists 190000
#endif
#if !defined(__cpp_lambdas) && (QUICKCPPLIB_GCC >= 40500)
#define __cpp_lambdas 190000
#endif
#if !defined(__cpp_nsdmi) && (QUICKCPPLIB_GCC >= 40700)
#define __cpp_nsdmi 190000
#endif
#if !defined(__cpp_range_based_for) && (QUICKCPPLIB_GCC >= 40600)
#define __cpp_range_based_for 190000
#endif
#if !defined(__cpp_raw_strings) && (QUICKCPPLIB_GCC >= 40500)
#define __cpp_raw_strings 190000
#endif
#if !defined(__cpp_ref_qualifiers) && (QUICKCPPLIB_GCC >= 40801)
#define __cpp_ref_qualifiers 190000
#endif
// __cpp_rvalue_reference deviation
#if !defined(__cpp_rvalue_references) && defined(__cpp_rvalue_reference)
#define __cpp_rvalue_references __cpp_rvalue_reference
#endif
#if !defined(__cpp_static_assert) && (QUICKCPPLIB_GCC >= 40300)
#define __cpp_static_assert 190000
#endif
#if !defined(__cpp_unicode_characters) && (QUICKCPPLIB_GCC >= 40500)
#define __cpp_unicode_characters 190000
#endif
#if !defined(__cpp_unicode_literals) && (QUICKCPPLIB_GCC >= 40500)
#define __cpp_unicode_literals 190000
#endif
#if !defined(__cpp_user_defined_literals) && (QUICKCPPLIB_GCC >= 40700)
#define __cpp_user_defined_literals 190000
#endif
#if !defined(__cpp_variadic_templates) && (QUICKCPPLIB_GCC >= 40400)
#define __cpp_variadic_templates 190000
#endif
// C++ 14
// Every C++ 14 supporting GCC does the right thing here
#endif // __GXX_EXPERIMENTAL_CXX0X__
#endif // GCC
// clang deviates in some places from the present SG-10 draft, plus older
// clangs are quite incomplete
#if defined(__clang__)
#define QUICKCPPLIB_CLANG (__clang_major__ * 10000 + __clang_minor__ * 100 + __clang_patchlevel__)
#if !defined(__cpp_exceptions) && (defined(__EXCEPTIONS) || defined(_CPPUNWIND))
#define __cpp_exceptions 190000
#endif
#if !defined(__cpp_rtti) && (defined(__GXX_RTTI) || defined(_CPPRTTI))
#define __cpp_rtti 190000
#endif
// C++ 11
#if defined(__GXX_EXPERIMENTAL_CXX0X__)
#if !defined(__cpp_alias_templates) && (QUICKCPPLIB_CLANG >= 30000)
#define __cpp_alias_templates 190000
#endif
#if !defined(__cpp_attributes) && (QUICKCPPLIB_CLANG >= 30300)
#define __cpp_attributes 190000
#endif
#if !defined(__cpp_constexpr) && (QUICKCPPLIB_CLANG >= 30100)
#define __cpp_constexpr 190000
#endif
#if !defined(__cpp_decltype) && (QUICKCPPLIB_CLANG >= 20900)
#define __cpp_decltype 190000
#endif
#if !defined(__cpp_delegating_constructors) && (QUICKCPPLIB_CLANG >= 30000)
#define __cpp_delegating_constructors 190000
#endif
#if !defined(__cpp_explicit_conversion) && (QUICKCPPLIB_CLANG >= 30000)
#define __cpp_explicit_conversion 190000
#endif
#if !defined(__cpp_inheriting_constructors) && (QUICKCPPLIB_CLANG >= 30300)
#define __cpp_inheriting_constructors 190000
#endif
#if !defined(__cpp_initializer_lists) && (QUICKCPPLIB_CLANG >= 30100)
#define __cpp_initializer_lists 190000
#endif
#if !defined(__cpp_lambdas) && (QUICKCPPLIB_CLANG >= 30100)
#define __cpp_lambdas 190000
#endif
#if !defined(__cpp_nsdmi) && (QUICKCPPLIB_CLANG >= 30000)
#define __cpp_nsdmi 190000
#endif
#if !defined(__cpp_range_based_for) && (QUICKCPPLIB_CLANG >= 30000)
#define __cpp_range_based_for 190000
#endif
// __cpp_raw_string_literals deviation
#if !defined(__cpp_raw_strings) && defined(__cpp_raw_string_literals)
#define __cpp_raw_strings __cpp_raw_string_literals
#endif
#if !defined(__cpp_raw_strings) && (QUICKCPPLIB_CLANG >= 30000)
#define __cpp_raw_strings 190000
#endif
#if !defined(__cpp_ref_qualifiers) && (QUICKCPPLIB_CLANG >= 20900)
#define __cpp_ref_qualifiers 190000
#endif
// __cpp_rvalue_reference deviation
#if !defined(__cpp_rvalue_references) && defined(__cpp_rvalue_reference)
#define __cpp_rvalue_references __cpp_rvalue_reference
#endif
#if !defined(__cpp_rvalue_references) && (QUICKCPPLIB_CLANG >= 20900)
#define __cpp_rvalue_references 190000
#endif
#if !defined(__cpp_static_assert) && (QUICKCPPLIB_CLANG >= 20900)
#define __cpp_static_assert 190000
#endif
#if !defined(__cpp_unicode_characters) && (QUICKCPPLIB_CLANG >= 30000)
#define __cpp_unicode_characters 190000
#endif
#if !defined(__cpp_unicode_literals) && (QUICKCPPLIB_CLANG >= 30000)
#define __cpp_unicode_literals 190000
#endif
// __cpp_user_literals deviation
#if !defined(__cpp_user_defined_literals) && defined(__cpp_user_literals)
#define __cpp_user_defined_literals __cpp_user_literals
#endif
#if !defined(__cpp_user_defined_literals) && (QUICKCPPLIB_CLANG >= 30100)
#define __cpp_user_defined_literals 190000
#endif
#if !defined(__cpp_variadic_templates) && (QUICKCPPLIB_CLANG >= 20900)
#define __cpp_variadic_templates 190000
#endif
// C++ 14
// Every C++ 14 supporting clang does the right thing here
#endif // __GXX_EXPERIMENTAL_CXX0X__
#endif // clang
#endif
/*
This is a dummy header file which is a placeholder for the real config.hpp which
gets generated by the build system. This file is here to allow the library to be
used without the build system.
*/
#if defined(min)
#error "You must not define min() as a macro, because this is unsupported and known to break e.g. LLFIO"
#elif defined(max)
#error "You must not define max() as a macro, because this is unsupported and known to break e.g. LLFIO"
#endif
#define QUICKCPPLIB_VERSION_GLUE2(a, b) a##b
#define QUICKCPPLIB_VERSION_GLUE(a, b) QUICKCPPLIB_VERSION_GLUE2(a, b)
// clang-format off
#define QUICKCPPLIB_NAMESPACE quickcpplib
#define QUICKCPPLIB_NAMESPACE_BEGIN namespace quickcpplib {
#define QUICKCPPLIB_NAMESPACE_END }
// clang-format on
#ifdef _MSC_VER
#define QUICKCPPLIB_BIND_MESSAGE_PRAGMA2(x) __pragma(message(x))
#define QUICKCPPLIB_BIND_MESSAGE_PRAGMA(x) QUICKCPPLIB_BIND_MESSAGE_PRAGMA2(x)
#define QUICKCPPLIB_BIND_MESSAGE_PREFIX(type) __FILE__ "(" QUICKCPPLIB_BIND_STRINGIZE2(__LINE__) "): " type ": "
#define QUICKCPPLIB_BIND_MESSAGE_(type, prefix, msg) QUICKCPPLIB_BIND_MESSAGE_PRAGMA(prefix msg)
#else
#define QUICKCPPLIB_BIND_MESSAGE_PRAGMA2(x) _Pragma(#x)
#define QUICKCPPLIB_BIND_MESSAGE_PRAGMA(type, x) QUICKCPPLIB_BIND_MESSAGE_PRAGMA2(type x)
#define QUICKCPPLIB_BIND_MESSAGE_(type, prefix, msg) QUICKCPPLIB_BIND_MESSAGE_PRAGMA(type, msg)
#endif
//! Have the compiler output a message
#define QUICKCPPLIB_MESSAGE(msg) QUICKCPPLIB_BIND_MESSAGE_(message, QUICKCPPLIB_BIND_MESSAGE_PREFIX("message"), msg)
//! Have the compiler output a note
#define QUICKCPPLIB_NOTE(msg) QUICKCPPLIB_BIND_MESSAGE_(message, QUICKCPPLIB_BIND_MESSAGE_PREFIX("note"), msg)
//! Have the compiler output a warning
#define QUICKCPPLIB_WARNING(msg) QUICKCPPLIB_BIND_MESSAGE_(GCC warning, QUICKCPPLIB_BIND_MESSAGE_PREFIX("warning"), msg)
//! Have the compiler output an error
#define QUICKCPPLIB_ERROR(msg) QUICKCPPLIB_BIND_MESSAGE_(GCC error, QUICKCPPLIB_BIND_MESSAGE_PREFIX("error"), msg)
#define QUICKCPPLIB_ANNOTATE_RWLOCK_CREATE(p)
#define QUICKCPPLIB_ANNOTATE_RWLOCK_DESTROY(p)
#define QUICKCPPLIB_ANNOTATE_RWLOCK_ACQUIRED(p, s)
#define QUICKCPPLIB_ANNOTATE_RWLOCK_RELEASED(p, s)
#define QUICKCPPLIB_ANNOTATE_IGNORE_READS_BEGIN()
#define QUICKCPPLIB_ANNOTATE_IGNORE_READS_END()
#define QUICKCPPLIB_ANNOTATE_IGNORE_WRITES_BEGIN()
#define QUICKCPPLIB_ANNOTATE_IGNORE_WRITES_END()
#define QUICKCPPLIB_DRD_IGNORE_VAR(x)
#define QUICKCPPLIB_DRD_STOP_IGNORING_VAR(x)
#define QUICKCPPLIB_RUNNING_ON_VALGRIND (0)
#ifndef QUICKCPPLIB_IN_ADDRESS_SANITIZER
#if defined(__has_feature)
#if __has_feature(address_sanitizer) || defined(__SANITIZE_ADDRESS__)
#define QUICKCPPLIB_IN_ADDRESS_SANITIZER 1
#endif
#elif defined(__SANITIZE_ADDRESS__)
#define QUICKCPPLIB_IN_ADDRESS_SANITIZER 1
#endif
#endif
#ifndef QUICKCPPLIB_IN_ADDRESS_SANITIZER
#define QUICKCPPLIB_IN_ADDRESS_SANITIZER 0
#endif
#ifndef QUICKCPPLIB_IN_THREAD_SANITIZER
#if defined(__has_feature)
#if __has_feature(thread_sanitizer) || defined(__SANITIZE_THREAD__)
#define QUICKCPPLIB_IN_THREAD_SANITIZER 1
#endif
#elif defined(__SANITIZE_THREAD__)
#define QUICKCPPLIB_IN_THREAD_SANITIZER 1
#endif
#endif
#ifndef QUICKCPPLIB_IN_THREAD_SANITIZER
#define QUICKCPPLIB_IN_THREAD_SANITIZER 0
#endif
#ifndef QUICKCPPLIB_IN_UNDEFINED_SANITIZER
#if defined(__has_feature)
#if __has_feature(undefined_behavior_sanitizer) || defined(__SANITIZE_UNDEFINED__) || (__GNUC__ <= 9 && defined(__SANITIZE_ADDRESS__))
#define QUICKCPPLIB_IN_UNDEFINED_SANITIZER 1
#endif
#elif defined(__SANITIZE_UNDEFINED__) || (__GNUC__ <= 9 && defined(__SANITIZE_ADDRESS__))
#define QUICKCPPLIB_IN_UNDEFINED_SANITIZER 1
#endif
#endif
#ifndef QUICKCPPLIB_IN_UNDEFINED_SANITIZER
#define QUICKCPPLIB_IN_UNDEFINED_SANITIZER 0
#endif
#if QUICKCPPLIB_IN_THREAD_SANITIZER
#define QUICKCPPLIB_DISABLE_THREAD_SANITIZE __attribute__((no_sanitize_thread))
#else
#define QUICKCPPLIB_DISABLE_THREAD_SANITIZE
#endif
#if QUICKCPPLIB_IN_THREAD_SANITIZER
#define QUICKCPPLIB_DISABLE_THREAD_SANITIZE __attribute__((no_sanitize_thread))
#else
#define QUICKCPPLIB_DISABLE_THREAD_SANITIZE
#endif
#if QUICKCPPLIB_IN_UNDEFINED_SANITIZER
#define QUICKCPPLIB_DISABLE_UNDEFINED_SANITIZE __attribute__((no_sanitize_undefined))
#else
#define QUICKCPPLIB_DISABLE_UNDEFINED_SANITIZE
#endif
#ifndef QUICKCPPLIB_SMT_PAUSE
#if !defined(__clang__) && defined(_MSC_VER) && _MSC_VER >= 1310 && (defined(_M_IX86) || defined(_M_X64))
extern "C" void _mm_pause();
#if !defined(_M_ARM64EC)
#pragma intrinsic(_mm_pause)
#endif
#define QUICKCPPLIB_SMT_PAUSE _mm_pause();
#elif !defined(__c2__) && defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
#define QUICKCPPLIB_SMT_PAUSE __asm__ __volatile__("rep; nop" : : : "memory");
#endif
#endif
#ifndef QUICKCPPLIB_FORCEINLINE
#if defined(_MSC_VER)
#define QUICKCPPLIB_FORCEINLINE __forceinline
#elif defined(__GNUC__)
#define QUICKCPPLIB_FORCEINLINE __attribute__((always_inline))
#else
#define QUICKCPPLIB_FORCEINLINE
#endif
#endif
#ifndef QUICKCPPLIB_NOINLINE
#if defined(_MSC_VER)
#define QUICKCPPLIB_NOINLINE __declspec(noinline)
#elif defined(__GNUC__)
#define QUICKCPPLIB_NOINLINE __attribute__((noinline))
#else
#define QUICKCPPLIB_NOINLINE
#endif
#endif
#if defined(QUICKCPPLIB_REQUIRE_CXX_STANDARD)
#define QUICKCPPLIB_REQUIRE_CXX17 (QUICKCPPLIB_REQUIRE_CXX_STANDARD >= 201703L)
#define QUICKCPPLIB_REQUIRE_CXX20 (QUICKCPPLIB_REQUIRE_CXX_STANDARD >= 202002L)
#define QUICKCPPLIB_USE_STD_BYTE QUICKCPPLIB_REQUIRE_CXX17
#define QUICKCPPLIB_USE_STD_OPTIONAL QUICKCPPLIB_REQUIRE_CXX17
#define QUICKCPPLIB_USE_STD_SPAN QUICKCPPLIB_REQUIRE_CXX20
#endif // ^^^ defined QUICKCPPLIB_REQUIRE_CXX_STANDARD ^^^
#if !defined(QUICKCPPLIB_USE_SYSTEM_BYTE_LITE)
#define QUICKCPPLIB_USE_SYSTEM_BYTE_LITE 0
#endif
#if !defined(QUICKCPPLIB_USE_SYSTEM_SPAN_LITE)
#define QUICKCPPLIB_USE_SYSTEM_SPAN_LITE 0
#endif
#ifdef __has_cpp_attribute
#define QUICKCPPLIB_HAS_CPP_ATTRIBUTE(attr, edition) (__has_cpp_attribute(attr) >= (edition) && __cplusplus >= (edition))
#else
#define QUICKCPPLIB_HAS_CPP_ATTRIBUTE(attr, edition) (0)
#endif
#if !defined(QUICKCPPLIB_NORETURN)
#if QUICKCPPLIB_HAS_CPP_ATTRIBUTE(noreturn, 201100)
#define QUICKCPPLIB_NORETURN [[noreturn]]
#elif defined(_MSC_VER)
#define QUICKCPPLIB_NORETURN __declspec(noreturn)
#elif defined(__GNUC__)
#define QUICKCPPLIB_NORETURN __attribute__((__noreturn__))
#else
#define QUICKCPPLIB_NORETURN
#endif
#endif
#ifndef QUICKCPPLIB_NODISCARD
#if 0L || (_HAS_CXX17 && _MSC_VER >= 1911 /* VS2017.3 */)
#define QUICKCPPLIB_NODISCARD [[nodiscard]]
#endif
#endif
#ifndef QUICKCPPLIB_NODISCARD
#if QUICKCPPLIB_HAS_CPP_ATTRIBUTE(nodiscard, 201700) && (!defined(__GNUC__) || !defined(__cpp_concepts) || __cpp_concepts >= 202000L /* -fconcepts-ts and [[nodiscard]] don't mix on GCC \
*/)
#define QUICKCPPLIB_NODISCARD [[nodiscard]]
#elif defined(__clang__) // deliberately not GCC
#define QUICKCPPLIB_NODISCARD __attribute__((warn_unused_result))
#elif defined(_MSC_VER)
// _Must_inspect_result_ expands into this
#define QUICKCPPLIB_NODISCARD __declspec( "SAL_name" "(" "\"_Must_inspect_result_\"" "," "\"\"" "," "\"2\"" ")") __declspec("SAL_begin") __declspec("SAL_post") __declspec("SAL_mustInspect") __declspec("SAL_post") __declspec("SAL_checkReturn") __declspec("SAL_end")
#endif
#endif
#ifndef QUICKCPPLIB_NODISCARD
#define QUICKCPPLIB_NODISCARD
#endif
#ifndef QUICKCPPLIB_SYMBOL_VISIBLE
#if defined(_MSC_VER)
#define QUICKCPPLIB_SYMBOL_VISIBLE
#elif defined(__GNUC__)
#define QUICKCPPLIB_SYMBOL_VISIBLE __attribute__((visibility("default")))
#else
#define QUICKCPPLIB_SYMBOL_VISIBLE
#endif
#endif
#ifndef QUICKCPPLIB_SYMBOL_EXPORT
#if defined(_MSC_VER)
#define QUICKCPPLIB_SYMBOL_EXPORT __declspec(dllexport)
#elif defined(__GNUC__)
#define QUICKCPPLIB_SYMBOL_EXPORT __attribute__((visibility("default")))
#else
#define QUICKCPPLIB_SYMBOL_EXPORT
#endif
#endif
#ifndef QUICKCPPLIB_SYMBOL_IMPORT
#if defined(_MSC_VER)
#define QUICKCPPLIB_SYMBOL_IMPORT __declspec(dllimport)
#elif defined(__GNUC__)
#define QUICKCPPLIB_SYMBOL_IMPORT
#else
#define QUICKCPPLIB_SYMBOL_IMPORT
#endif
#endif
#ifndef QUICKCPPLIB_THREAD_LOCAL
#if _MSC_VER >= 1800
#define QUICKCPPLIB_THREAD_LOCAL_IS_CXX11 1
#elif __cplusplus >= 201103L
#if __GNUC__ >= 5 && !defined(__clang__)
#define QUICKCPPLIB_THREAD_LOCAL_IS_CXX11 1
#elif defined(__has_feature)
#if __has_feature(cxx_thread_local)
#define QUICKCPPLIB_THREAD_LOCAL_IS_CXX11 1
#endif
#endif
#endif
#ifdef QUICKCPPLIB_THREAD_LOCAL_IS_CXX11
#define QUICKCPPLIB_THREAD_LOCAL thread_local
#endif
#ifndef QUICKCPPLIB_THREAD_LOCAL
#if defined(_MSC_VER)
#define QUICKCPPLIB_THREAD_LOCAL __declspec(thread)
#elif defined(__GNUC__)
#define QUICKCPPLIB_THREAD_LOCAL __thread
#else
#error Unknown compiler, cannot set QUICKCPPLIB_THREAD_LOCAL
#endif
#endif
#endif
#ifndef QUICKCPPLIB_DISABLE_EXECINFO
#if defined(__EMSCRIPTEN__)
#define QUICKCPPLIB_DISABLE_EXECINFO 1
#endif
#endif
#ifndef QUICKCPPLIB_PLATFORM_NATIVE_BITLENGTH
#if defined(__SIZEOF_POINTER__)
#define QUICKCPPLIB_PLATFORM_NATIVE_BITLENGTH (__SIZEOF_POINTER__ * __CHAR_BIT__)
#elif defined(_WIN64) || defined(__x86_64__) || defined(_M_X64) || defined(__aarch64__) || defined(_M_ARM64) || defined(__ia64__) || defined(_M_IA64) || defined(__ppc64__)
#define QUICKCPPLIB_PLATFORM_NATIVE_BITLENGTH (64)
#else
#define QUICKCPPLIB_PLATFORM_NATIVE_BITLENGTH (32)
#endif
#endif
/* MSVC capable preprocessor macro overloading
(C) 2014-2017 Niall Douglas <http://www.nedproductions.biz/> (3 commits)
File Created: Aug 2014
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License in the accompanying file
Licence.txt or at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Distributed under the Boost Software License, Version 1.0.
(See accompanying file Licence.txt or copy at
http://www.boost.org/LICENSE_1_0.txt)
*/
#ifndef QUICKCPPLIB_PREPROCESSOR_MACRO_OVERLOAD_H
#define QUICKCPPLIB_PREPROCESSOR_MACRO_OVERLOAD_H
#define QUICKCPPLIB_GLUE(x, y) x y
#define QUICKCPPLIB_RETURN_ARG_COUNT(_1_, _2_, _3_, _4_, _5_, _6_, _7_, _8_, count, ...) count
#define QUICKCPPLIB_EXPAND_ARGS(args) QUICKCPPLIB_RETURN_ARG_COUNT args
#define QUICKCPPLIB_COUNT_ARGS_MAX8(...) QUICKCPPLIB_EXPAND_ARGS((__VA_ARGS__, 8, 7, 6, 5, 4, 3, 2, 1, 0))
#define QUICKCPPLIB_OVERLOAD_MACRO2(name, count) name##count
#define QUICKCPPLIB_OVERLOAD_MACRO1(name, count) QUICKCPPLIB_OVERLOAD_MACRO2(name, count)
#define QUICKCPPLIB_OVERLOAD_MACRO(name, count) QUICKCPPLIB_OVERLOAD_MACRO1(name, count)
#define QUICKCPPLIB_CALL_OVERLOAD(name, ...) QUICKCPPLIB_GLUE(QUICKCPPLIB_OVERLOAD_MACRO(name, QUICKCPPLIB_COUNT_ARGS_MAX8(__VA_ARGS__)), (__VA_ARGS__))
#define QUICKCPPLIB_GLUE_(x, y) x y
#define QUICKCPPLIB_RETURN_ARG_COUNT_(_1_, _2_, _3_, _4_, _5_, _6_, _7_, _8_, count, ...) count
#define QUICKCPPLIB_EXPAND_ARGS_(args) QUICKCPPLIB_RETURN_ARG_COUNT_ args
#define QUICKCPPLIB_COUNT_ARGS_MAX8_(...) QUICKCPPLIB_EXPAND_ARGS_((__VA_ARGS__, 8, 7, 6, 5, 4, 3, 2, 1, 0))
#define QUICKCPPLIB_OVERLOAD_MACRO2_(name, count) name##count
#define QUICKCPPLIB_OVERLOAD_MACRO1_(name, count) QUICKCPPLIB_OVERLOAD_MACRO2_(name, count)
#define QUICKCPPLIB_OVERLOAD_MACRO_(name, count) QUICKCPPLIB_OVERLOAD_MACRO1_(name, count)
#define QUICKCPPLIB_CALL_OVERLOAD_(name, ...) QUICKCPPLIB_GLUE_(QUICKCPPLIB_OVERLOAD_MACRO_(name, QUICKCPPLIB_COUNT_ARGS_MAX8_(__VA_ARGS__)), (__VA_ARGS__))
#endif
#if defined(__cpp_concepts) && !defined(QUICKCPPLIB_DISABLE_CONCEPTS_SUPPORT)
#define QUICKCPPLIB_TREQUIRES_EXPAND8(a, b, c, d, e, f, g, h) a &&QUICKCPPLIB_TREQUIRES_EXPAND7(b, c, d, e, f, g, h)
#define QUICKCPPLIB_TREQUIRES_EXPAND7(a, b, c, d, e, f, g) a &&QUICKCPPLIB_TREQUIRES_EXPAND6(b, c, d, e, f, g)
#define QUICKCPPLIB_TREQUIRES_EXPAND6(a, b, c, d, e, f) a &&QUICKCPPLIB_TREQUIRES_EXPAND5(b, c, d, e, f)
#define QUICKCPPLIB_TREQUIRES_EXPAND5(a, b, c, d, e) a &&QUICKCPPLIB_TREQUIRES_EXPAND4(b, c, d, e)
#define QUICKCPPLIB_TREQUIRES_EXPAND4(a, b, c, d) a &&QUICKCPPLIB_TREQUIRES_EXPAND3(b, c, d)
#define QUICKCPPLIB_TREQUIRES_EXPAND3(a, b, c) a &&QUICKCPPLIB_TREQUIRES_EXPAND2(b, c)
#define QUICKCPPLIB_TREQUIRES_EXPAND2(a, b) a &&QUICKCPPLIB_TREQUIRES_EXPAND1(b)
#define QUICKCPPLIB_TREQUIRES_EXPAND1(a) a
//! Expands into a && b && c && ...
#define QUICKCPPLIB_TREQUIRES(...) requires QUICKCPPLIB_CALL_OVERLOAD(QUICKCPPLIB_TREQUIRES_EXPAND, __VA_ARGS__)
#define QUICKCPPLIB_TEMPLATE(...) template <__VA_ARGS__>
#define QUICKCPPLIB_TEXPR(...) requires { (__VA_ARGS__); }
#define QUICKCPPLIB_TPRED(...) (__VA_ARGS__)
#if !defined(_MSC_VER) || _MSC_FULL_VER >= 192400000 // VS 2019 16.3 is broken here
#define QUICKCPPLIB_REQUIRES(...) requires(__VA_ARGS__)
#else
#define QUICKCPPLIB_REQUIRES(...)
#endif
#else
#define QUICKCPPLIB_TEMPLATE(...) template <__VA_ARGS__
#define QUICKCPPLIB_TREQUIRES(...) , __VA_ARGS__ >
#define QUICKCPPLIB_TEXPR(...) typename = decltype(__VA_ARGS__)
#ifdef _MSC_VER
// MSVC gives an error if every specialisation of a template is always ill-formed, so
// the more powerful SFINAE form below causes pukeage :(
#define QUICKCPPLIB_TPRED(...) typename = typename std::enable_if<(__VA_ARGS__)>::type
#else
#define QUICKCPPLIB_TPRED(...) typename std::enable_if<(__VA_ARGS__), bool>::type = true
#endif
#define QUICKCPPLIB_REQUIRES(...)
#endif
#endif
#ifndef __cpp_variadic_templates
#error Outcome needs variadic template support in the compiler
#endif
#if __cpp_constexpr < 201304 && _MSC_FULL_VER < 191100000
#error Outcome needs constexpr (C++ 14) support in the compiler
#endif
#ifndef __cpp_variable_templates
#error Outcome needs variable template support in the compiler
#endif
#if !defined(__clang__) && defined(__GNUC__) && __GNUC__ < 6
#error Due to a bug in nested template variables parsing, Outcome does not work on GCCs earlier than v6.
#endif
#ifndef OUTCOME_SYMBOL_VISIBLE
#define OUTCOME_SYMBOL_VISIBLE QUICKCPPLIB_SYMBOL_VISIBLE
#endif
#ifndef OUTCOME_FORCEINLINE
#define OUTCOME_FORCEINLINE QUICKCPPLIB_FORCEINLINE
#endif
#ifndef OUTCOME_NODISCARD
#define OUTCOME_NODISCARD QUICKCPPLIB_NODISCARD
#endif
#ifndef OUTCOME_THREAD_LOCAL
#define OUTCOME_THREAD_LOCAL QUICKCPPLIB_THREAD_LOCAL
#endif
#ifndef OUTCOME_TEMPLATE
#define OUTCOME_TEMPLATE(...) QUICKCPPLIB_TEMPLATE(__VA_ARGS__)
#endif
#ifndef OUTCOME_TREQUIRES
#define OUTCOME_TREQUIRES(...) QUICKCPPLIB_TREQUIRES(__VA_ARGS__)
#endif
#ifndef OUTCOME_TEXPR
#define OUTCOME_TEXPR(...) QUICKCPPLIB_TEXPR(__VA_ARGS__)
#endif
#ifndef OUTCOME_TPRED
#define OUTCOME_TPRED(...) QUICKCPPLIB_TPRED(__VA_ARGS__)
#endif
#ifndef OUTCOME_REQUIRES
#define OUTCOME_REQUIRES(...) QUICKCPPLIB_REQUIRES(__VA_ARGS__)
#endif
/* Convenience macros for importing local namespace binds
(C) 2014-2017 Niall Douglas <http://www.nedproductions.biz/> (9 commits)
File Created: Aug 2014
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License in the accompanying file
Licence.txt or at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Distributed under the Boost Software License, Version 1.0.
(See accompanying file Licence.txt or copy at
http://www.boost.org/LICENSE_1_0.txt)
*/
#ifndef QUICKCPPLIB_BIND_IMPORT_HPP
#define QUICKCPPLIB_BIND_IMPORT_HPP
/* 2014-10-9 ned: I lost today figuring out the below. I really hate the C preprocessor now.
*
* Anyway, infinity = 8. It's easy to expand below if needed.
*/
#define QUICKCPPLIB_BIND_STRINGIZE(a) #a
#define QUICKCPPLIB_BIND_STRINGIZE2(a) QUICKCPPLIB_BIND_STRINGIZE(a)
#define QUICKCPPLIB_BIND_NAMESPACE_VERSION8(a, b, c, d, e, f, g, h) a##_##b##_##c##_##d##_##e##_##f##_##g##_##h
#define QUICKCPPLIB_BIND_NAMESPACE_VERSION7(a, b, c, d, e, f, g) a##_##b##_##c##_##d##_##e##_##f##_##g
#define QUICKCPPLIB_BIND_NAMESPACE_VERSION6(a, b, c, d, e, f) a##_##b##_##c##_##d##_##e##_##f
#define QUICKCPPLIB_BIND_NAMESPACE_VERSION5(a, b, c, d, e) a##_##b##_##c##_##d##_##e
#define QUICKCPPLIB_BIND_NAMESPACE_VERSION4(a, b, c, d) a##_##b##_##c##_##d
#define QUICKCPPLIB_BIND_NAMESPACE_VERSION3(a, b, c) a##_##b##_##c
#define QUICKCPPLIB_BIND_NAMESPACE_VERSION2(a, b) a##_##b
#define QUICKCPPLIB_BIND_NAMESPACE_VERSION1(a) a
//! Concatenates each parameter with _
#define QUICKCPPLIB_BIND_NAMESPACE_VERSION(...) QUICKCPPLIB_CALL_OVERLOAD(QUICKCPPLIB_BIND_NAMESPACE_VERSION, __VA_ARGS__)
#define QUICKCPPLIB_BIND_NAMESPACE_SELECT_2(name, modifier) name
#define QUICKCPPLIB_BIND_NAMESPACE_SELECT2(name, modifier) ::name
#define QUICKCPPLIB_BIND_NAMESPACE_SELECT_1(name) name
#define QUICKCPPLIB_BIND_NAMESPACE_SELECT1(name) ::name
#define QUICKCPPLIB_BIND_NAMESPACE_SELECT_(...) QUICKCPPLIB_CALL_OVERLOAD_(QUICKCPPLIB_BIND_NAMESPACE_SELECT_, __VA_ARGS__)
#define QUICKCPPLIB_BIND_NAMESPACE_SELECT(...) QUICKCPPLIB_CALL_OVERLOAD_(QUICKCPPLIB_BIND_NAMESPACE_SELECT, __VA_ARGS__)
#define QUICKCPPLIB_BIND_NAMESPACE_EXPAND8(a, b, c, d, e, f, g, h) QUICKCPPLIB_BIND_NAMESPACE_SELECT_ a QUICKCPPLIB_BIND_NAMESPACE_SELECT b QUICKCPPLIB_BIND_NAMESPACE_SELECT c QUICKCPPLIB_BIND_NAMESPACE_SELECT d QUICKCPPLIB_BIND_NAMESPACE_SELECT e QUICKCPPLIB_BIND_NAMESPACE_SELECT f QUICKCPPLIB_BIND_NAMESPACE_SELECT g QUICKCPPLIB_BIND_NAMESPACE_SELECT h
#define QUICKCPPLIB_BIND_NAMESPACE_EXPAND7(a, b, c, d, e, f, g) QUICKCPPLIB_BIND_NAMESPACE_SELECT_ a QUICKCPPLIB_BIND_NAMESPACE_SELECT b QUICKCPPLIB_BIND_NAMESPACE_SELECT c QUICKCPPLIB_BIND_NAMESPACE_SELECT d QUICKCPPLIB_BIND_NAMESPACE_SELECT e QUICKCPPLIB_BIND_NAMESPACE_SELECT f QUICKCPPLIB_BIND_NAMESPACE_SELECT g
#define QUICKCPPLIB_BIND_NAMESPACE_EXPAND6(a, b, c, d, e, f) QUICKCPPLIB_BIND_NAMESPACE_SELECT_ a QUICKCPPLIB_BIND_NAMESPACE_SELECT b QUICKCPPLIB_BIND_NAMESPACE_SELECT c QUICKCPPLIB_BIND_NAMESPACE_SELECT d QUICKCPPLIB_BIND_NAMESPACE_SELECT e QUICKCPPLIB_BIND_NAMESPACE_SELECT f
#define QUICKCPPLIB_BIND_NAMESPACE_EXPAND5(a, b, c, d, e) QUICKCPPLIB_BIND_NAMESPACE_SELECT_ a QUICKCPPLIB_BIND_NAMESPACE_SELECT b QUICKCPPLIB_BIND_NAMESPACE_SELECT c QUICKCPPLIB_BIND_NAMESPACE_SELECT d QUICKCPPLIB_BIND_NAMESPACE_SELECT e
#define QUICKCPPLIB_BIND_NAMESPACE_EXPAND4(a, b, c, d) QUICKCPPLIB_BIND_NAMESPACE_SELECT_ a QUICKCPPLIB_BIND_NAMESPACE_SELECT b QUICKCPPLIB_BIND_NAMESPACE_SELECT c QUICKCPPLIB_BIND_NAMESPACE_SELECT d
#define QUICKCPPLIB_BIND_NAMESPACE_EXPAND3(a, b, c) QUICKCPPLIB_BIND_NAMESPACE_SELECT_ a QUICKCPPLIB_BIND_NAMESPACE_SELECT b QUICKCPPLIB_BIND_NAMESPACE_SELECT c
#define QUICKCPPLIB_BIND_NAMESPACE_EXPAND2(a, b) QUICKCPPLIB_BIND_NAMESPACE_SELECT_ a QUICKCPPLIB_BIND_NAMESPACE_SELECT b
#define QUICKCPPLIB_BIND_NAMESPACE_EXPAND1(a) QUICKCPPLIB_BIND_NAMESPACE_SELECT_ a
//! Expands into a::b::c:: ...
#define QUICKCPPLIB_BIND_NAMESPACE(...) QUICKCPPLIB_CALL_OVERLOAD(QUICKCPPLIB_BIND_NAMESPACE_EXPAND, __VA_ARGS__)
#define QUICKCPPLIB_BIND_NAMESPACE_BEGIN_NAMESPACE_SELECT2(name, modifier) modifier namespace name {
#define QUICKCPPLIB_BIND_NAMESPACE_BEGIN_NAMESPACE_SELECT1(name) namespace name {
#define QUICKCPPLIB_BIND_NAMESPACE_BEGIN_NAMESPACE_SELECT(...) QUICKCPPLIB_CALL_OVERLOAD_(QUICKCPPLIB_BIND_NAMESPACE_BEGIN_NAMESPACE_SELECT, __VA_ARGS__)
#define QUICKCPPLIB_BIND_NAMESPACE_BEGIN_EXPAND8(a, b, c, d, e, f, g, h) QUICKCPPLIB_BIND_NAMESPACE_BEGIN_NAMESPACE_SELECT a QUICKCPPLIB_BIND_NAMESPACE_BEGIN_EXPAND7(b, c, d, e, f, g, h)
#define QUICKCPPLIB_BIND_NAMESPACE_BEGIN_EXPAND7(a, b, c, d, e, f, g) QUICKCPPLIB_BIND_NAMESPACE_BEGIN_NAMESPACE_SELECT a QUICKCPPLIB_BIND_NAMESPACE_BEGIN_EXPAND6(b, c, d, e, f, g)
#define QUICKCPPLIB_BIND_NAMESPACE_BEGIN_EXPAND6(a, b, c, d, e, f) QUICKCPPLIB_BIND_NAMESPACE_BEGIN_NAMESPACE_SELECT a QUICKCPPLIB_BIND_NAMESPACE_BEGIN_EXPAND5(b, c, d, e, f)
#define QUICKCPPLIB_BIND_NAMESPACE_BEGIN_EXPAND5(a, b, c, d, e) QUICKCPPLIB_BIND_NAMESPACE_BEGIN_NAMESPACE_SELECT a QUICKCPPLIB_BIND_NAMESPACE_BEGIN_EXPAND4(b, c, d, e)
#define QUICKCPPLIB_BIND_NAMESPACE_BEGIN_EXPAND4(a, b, c, d) QUICKCPPLIB_BIND_NAMESPACE_BEGIN_NAMESPACE_SELECT a QUICKCPPLIB_BIND_NAMESPACE_BEGIN_EXPAND3(b, c, d)
#define QUICKCPPLIB_BIND_NAMESPACE_BEGIN_EXPAND3(a, b, c) QUICKCPPLIB_BIND_NAMESPACE_BEGIN_NAMESPACE_SELECT a QUICKCPPLIB_BIND_NAMESPACE_BEGIN_EXPAND2(b, c)
#define QUICKCPPLIB_BIND_NAMESPACE_BEGIN_EXPAND2(a, b) QUICKCPPLIB_BIND_NAMESPACE_BEGIN_NAMESPACE_SELECT a QUICKCPPLIB_BIND_NAMESPACE_BEGIN_EXPAND1(b)
#define QUICKCPPLIB_BIND_NAMESPACE_BEGIN_EXPAND1(a) QUICKCPPLIB_BIND_NAMESPACE_BEGIN_NAMESPACE_SELECT a
//! Expands into namespace a { namespace b { namespace c ...
#define QUICKCPPLIB_BIND_NAMESPACE_BEGIN(...) QUICKCPPLIB_CALL_OVERLOAD(QUICKCPPLIB_BIND_NAMESPACE_BEGIN_EXPAND, __VA_ARGS__)
#define QUICKCPPLIB_BIND_NAMESPACE_EXPORT_BEGIN_NAMESPACE_SELECT2(name, modifier) modifier namespace name {
#define QUICKCPPLIB_BIND_NAMESPACE_EXPORT_BEGIN_NAMESPACE_SELECT1(name) export namespace name {
#define QUICKCPPLIB_BIND_NAMESPACE_EXPORT_BEGIN_NAMESPACE_SELECT(...) QUICKCPPLIB_CALL_OVERLOAD_(QUICKCPPLIB_BIND_NAMESPACE_EXPORT_BEGIN_NAMESPACE_SELECT, __VA_ARGS__)
#define QUICKCPPLIB_BIND_NAMESPACE_EXPORT_BEGIN_EXPAND8(a, b, c, d, e, f, g, h) QUICKCPPLIB_BIND_NAMESPACE_EXPORT_BEGIN_NAMESPACE_SELECT a QUICKCPPLIB_BIND_NAMESPACE_EXPORT_BEGIN_EXPAND7(b, c, d, e, f, g, h)
#define QUICKCPPLIB_BIND_NAMESPACE_EXPORT_BEGIN_EXPAND7(a, b, c, d, e, f, g) QUICKCPPLIB_BIND_NAMESPACE_EXPORT_BEGIN_NAMESPACE_SELECT a QUICKCPPLIB_BIND_NAMESPACE_EXPORT_BEGIN_EXPAND6(b, c, d, e, f, g)
#define QUICKCPPLIB_BIND_NAMESPACE_EXPORT_BEGIN_EXPAND6(a, b, c, d, e, f) QUICKCPPLIB_BIND_NAMESPACE_EXPORT_BEGIN_NAMESPACE_SELECT a QUICKCPPLIB_BIND_NAMESPACE_EXPORT_BEGIN_EXPAND5(b, c, d, e, f)
#define QUICKCPPLIB_BIND_NAMESPACE_EXPORT_BEGIN_EXPAND5(a, b, c, d, e) QUICKCPPLIB_BIND_NAMESPACE_EXPORT_BEGIN_NAMESPACE_SELECT a QUICKCPPLIB_BIND_NAMESPACE_EXPORT_BEGIN_EXPAND4(b, c, d, e)
#define QUICKCPPLIB_BIND_NAMESPACE_EXPORT_BEGIN_EXPAND4(a, b, c, d) QUICKCPPLIB_BIND_NAMESPACE_EXPORT_BEGIN_NAMESPACE_SELECT a QUICKCPPLIB_BIND_NAMESPACE_EXPORT_BEGIN_EXPAND3(b, c, d)
#define QUICKCPPLIB_BIND_NAMESPACE_EXPORT_BEGIN_EXPAND3(a, b, c) QUICKCPPLIB_BIND_NAMESPACE_EXPORT_BEGIN_NAMESPACE_SELECT a QUICKCPPLIB_BIND_NAMESPACE_EXPORT_BEGIN_EXPAND2(b, c)
#define QUICKCPPLIB_BIND_NAMESPACE_EXPORT_BEGIN_EXPAND2(a, b) QUICKCPPLIB_BIND_NAMESPACE_EXPORT_BEGIN_NAMESPACE_SELECT a QUICKCPPLIB_BIND_NAMESPACE_EXPORT_BEGIN_EXPAND1(b)
#define QUICKCPPLIB_BIND_NAMESPACE_EXPORT_BEGIN_EXPAND1(a) QUICKCPPLIB_BIND_NAMESPACE_EXPORT_BEGIN_NAMESPACE_SELECT a
//! Expands into export namespace a { namespace b { namespace c ...
#define QUICKCPPLIB_BIND_NAMESPACE_EXPORT_BEGIN(...) QUICKCPPLIB_CALL_OVERLOAD(QUICKCPPLIB_BIND_NAMESPACE_EXPORT_BEGIN_EXPAND, __VA_ARGS__)
#define QUICKCPPLIB_BIND_NAMESPACE_END_NAMESPACE_SELECT2(name, modifier) }
#define QUICKCPPLIB_BIND_NAMESPACE_END_NAMESPACE_SELECT1(name) }
#define QUICKCPPLIB_BIND_NAMESPACE_END_NAMESPACE_SELECT(...) QUICKCPPLIB_CALL_OVERLOAD_(QUICKCPPLIB_BIND_NAMESPACE_END_NAMESPACE_SELECT, __VA_ARGS__)
#define QUICKCPPLIB_BIND_NAMESPACE_END_EXPAND8(a, b, c, d, e, f, g, h) QUICKCPPLIB_BIND_NAMESPACE_END_NAMESPACE_SELECT a QUICKCPPLIB_BIND_NAMESPACE_END_EXPAND7(b, c, d, e, f, g, h)
#define QUICKCPPLIB_BIND_NAMESPACE_END_EXPAND7(a, b, c, d, e, f, g) QUICKCPPLIB_BIND_NAMESPACE_END_NAMESPACE_SELECT a QUICKCPPLIB_BIND_NAMESPACE_END_EXPAND6(b, c, d, e, f, g)
#define QUICKCPPLIB_BIND_NAMESPACE_END_EXPAND6(a, b, c, d, e, f) QUICKCPPLIB_BIND_NAMESPACE_END_NAMESPACE_SELECT a QUICKCPPLIB_BIND_NAMESPACE_END_EXPAND5(b, c, d, e, f)
#define QUICKCPPLIB_BIND_NAMESPACE_END_EXPAND5(a, b, c, d, e) QUICKCPPLIB_BIND_NAMESPACE_END_NAMESPACE_SELECT a QUICKCPPLIB_BIND_NAMESPACE_END_EXPAND4(b, c, d, e)
#define QUICKCPPLIB_BIND_NAMESPACE_END_EXPAND4(a, b, c, d) QUICKCPPLIB_BIND_NAMESPACE_END_NAMESPACE_SELECT a QUICKCPPLIB_BIND_NAMESPACE_END_EXPAND3(b, c, d)
#define QUICKCPPLIB_BIND_NAMESPACE_END_EXPAND3(a, b, c) QUICKCPPLIB_BIND_NAMESPACE_END_NAMESPACE_SELECT a QUICKCPPLIB_BIND_NAMESPACE_END_EXPAND2(b, c)
#define QUICKCPPLIB_BIND_NAMESPACE_END_EXPAND2(a, b) QUICKCPPLIB_BIND_NAMESPACE_END_NAMESPACE_SELECT a QUICKCPPLIB_BIND_NAMESPACE_END_EXPAND1(b)
#define QUICKCPPLIB_BIND_NAMESPACE_END_EXPAND1(a) QUICKCPPLIB_BIND_NAMESPACE_END_NAMESPACE_SELECT a
//! Expands into } } ...
#define QUICKCPPLIB_BIND_NAMESPACE_END(...) QUICKCPPLIB_CALL_OVERLOAD(QUICKCPPLIB_BIND_NAMESPACE_END_EXPAND, __VA_ARGS__)
//! Expands into a static const char string array used to mark BindLib compatible namespaces
#define QUICKCPPLIB_BIND_DECLARE(decl, desc) static const char *quickcpplib_out[] = {#decl, desc};
#endif
#ifndef OUTCOME_ENABLE_LEGACY_SUPPORT_FOR
#define OUTCOME_ENABLE_LEGACY_SUPPORT_FOR 220 // the v2.2 Outcome release
#endif
/* UPDATED BY SCRIPT
(C) 2017-2019 Niall Douglas <http://www.nedproductions.biz/> (225 commits)
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License in the accompanying file
Licence.txt or at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Distributed under the Boost Software License, Version 1.0.
(See accompanying file Licence.txt or copy at
http://www.boost.org/LICENSE_1_0.txt)
*/
// Note the second line of this file must ALWAYS be the git SHA, third line ALWAYS the git SHA update time
#define OUTCOME_PREVIOUS_COMMIT_REF b01ac71096775daf18d9a57a69be5e129f421a67
#define OUTCOME_PREVIOUS_COMMIT_DATE "2024-07-17 20:54:50 +00:00"
#define OUTCOME_PREVIOUS_COMMIT_UNIQUE b01ac710
#define OUTCOME_V2 (QUICKCPPLIB_BIND_NAMESPACE_VERSION(outcome_v2))
#ifdef _DEBUG
#define OUTCOME_V2_CXX_MODULE_NAME QUICKCPPLIB_BIND_NAMESPACE((QUICKCPPLIB_BIND_NAMESPACE_VERSION(outcome_v2d)))
#else
#define OUTCOME_V2_CXX_MODULE_NAME QUICKCPPLIB_BIND_NAMESPACE((QUICKCPPLIB_BIND_NAMESPACE_VERSION(outcome_v2)))
#endif
#if defined(GENERATING_OUTCOME_MODULE_INTERFACE)
#define OUTCOME_V2_NAMESPACE QUICKCPPLIB_BIND_NAMESPACE(OUTCOME_V2)
#define OUTCOME_V2_NAMESPACE_BEGIN QUICKCPPLIB_BIND_NAMESPACE_BEGIN(OUTCOME_V2)
#define OUTCOME_V2_NAMESPACE_EXPORT_BEGIN QUICKCPPLIB_BIND_NAMESPACE_EXPORT_BEGIN(OUTCOME_V2)
#define OUTCOME_V2_NAMESPACE_END QUICKCPPLIB_BIND_NAMESPACE_END(OUTCOME_V2)
#else
#define OUTCOME_V2_NAMESPACE QUICKCPPLIB_BIND_NAMESPACE(OUTCOME_V2)
#define OUTCOME_V2_NAMESPACE_BEGIN QUICKCPPLIB_BIND_NAMESPACE_BEGIN(OUTCOME_V2)
#define OUTCOME_V2_NAMESPACE_EXPORT_BEGIN QUICKCPPLIB_BIND_NAMESPACE_BEGIN(OUTCOME_V2)
#define OUTCOME_V2_NAMESPACE_END QUICKCPPLIB_BIND_NAMESPACE_END(OUTCOME_V2)
#endif
#include <cstdint> // for uint32_t etc
#include <initializer_list>
#include <iosfwd> // for future serialisation
#include <new> // for placement in moves etc
#include <type_traits>
#ifndef OUTCOME_USE_STD_IN_PLACE_TYPE
#if defined(_MSC_VER) && _HAS_CXX17
#define OUTCOME_USE_STD_IN_PLACE_TYPE 1 // MSVC always has std::in_place_type
#elif __cplusplus >= 201700
// libstdc++ before GCC 6 doesn't have it, despite claiming C++ 17 support
#ifdef __has_include
#if !__has_include(<variant>)
#define OUTCOME_USE_STD_IN_PLACE_TYPE 0 // must have it if <variant> is present
#endif
#endif
#ifndef OUTCOME_USE_STD_IN_PLACE_TYPE
#define OUTCOME_USE_STD_IN_PLACE_TYPE 1
#endif
#else
#define OUTCOME_USE_STD_IN_PLACE_TYPE 0
#endif
#endif
#if OUTCOME_USE_STD_IN_PLACE_TYPE
#include <utility> // for in_place_type_t
OUTCOME_V2_NAMESPACE_BEGIN
template <class T> using in_place_type_t = std::in_place_type_t<T>;
using std::in_place_type;
OUTCOME_V2_NAMESPACE_END
#else
OUTCOME_V2_NAMESPACE_BEGIN
/*! AWAITING HUGO JSON CONVERSION TOOL
type definition template <class T> in_place_type_t. Potential doc page: `in_place_type_t<T>`
*/
template <class T> struct in_place_type_t
{
explicit in_place_type_t() = default;
};
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
template <class T> constexpr in_place_type_t<T> in_place_type{};
OUTCOME_V2_NAMESPACE_END
#endif
#if OUTCOME_USE_STD_ADDRESSOF
#include <memory> // for std::addressof
#define OUTCOME_ADDRESS_OF(...) std::addressof(__VA_ARGS__)
#else
#define OUTCOME_ADDRESS_OF(...) (&__VA_ARGS__)
#endif
#ifndef OUTCOME_ASSERT
#include <cassert>
#define OUTCOME_ASSERT(...) assert(__VA_ARGS__)
#endif
#ifndef OUTCOME_TRIVIAL_ABI
#if 0L || __clang_major__ >= 7
//! Defined to be `[[clang::trivial_abi]]` when on a new enough clang compiler. Usually automatic, can be overriden.
#define OUTCOME_TRIVIAL_ABI [[clang::trivial_abi]]
#else
#define OUTCOME_TRIVIAL_ABI
#endif
#endif
OUTCOME_V2_NAMESPACE_BEGIN
namespace detail
{
// Test if type is an in_place_type_t
template <class T> struct is_in_place_type_t
{
static constexpr bool value = false;
};
template <class U> struct is_in_place_type_t<in_place_type_t<U>>
{
static constexpr bool value = true;
};
// Replace void with constructible void_type
struct empty_type
{
};
struct void_type
{
// We always compare true to another instance of me
constexpr bool operator==(void_type /*unused*/) const noexcept { return true; }
constexpr bool operator!=(void_type /*unused*/) const noexcept { return false; }
};
template <class T> using devoid = std::conditional_t<std::is_void<T>::value, void_type, T>;
template <class Output, class Input> using rebind_type5 = Output;
template <class Output, class Input>
using rebind_type4 = std::conditional_t< //
std::is_volatile<Input>::value, //
std::add_volatile_t<rebind_type5<Output, std::remove_volatile_t<Input>>>, //
rebind_type5<Output, Input>>;
template <class Output, class Input>
using rebind_type3 = std::conditional_t< //
std::is_const<Input>::value, //
std::add_const_t<rebind_type4<Output, std::remove_const_t<Input>>>, //
rebind_type4<Output, Input>>;
template <class Output, class Input>
using rebind_type2 = std::conditional_t< //
std::is_lvalue_reference<Input>::value, //
std::add_lvalue_reference_t<rebind_type3<Output, std::remove_reference_t<Input>>>, //
rebind_type3<Output, Input>>;
template <class Output, class Input>
using rebind_type = std::conditional_t< //
std::is_rvalue_reference<Input>::value, //
std::add_rvalue_reference_t<rebind_type2<Output, std::remove_reference_t<Input>>>, //
rebind_type2<Output, Input>>;
// static_assert(std::is_same_v<rebind_type<int, volatile const double &&>, volatile const int &&>, "");
/* True if type is the same or constructible. Works around a bug where clang + libstdc++
pukes on std::is_constructible<filesystem::path, void> (this bug is fixed upstream).
*/
template <class T, class U> struct _is_explicitly_constructible
{
static constexpr bool value = std::is_constructible<T, U>::value;
};
template <class T> struct _is_explicitly_constructible<T, void>
{
static constexpr bool value = false;
};
template <> struct _is_explicitly_constructible<void, void>
{
static constexpr bool value = false;
};
template <class T, class U> static constexpr bool is_explicitly_constructible = _is_explicitly_constructible<T, U>::value;
template <class T, class U> struct _is_implicitly_constructible
{
static constexpr bool value = std::is_convertible<U, T>::value;
};
template <class T> struct _is_implicitly_constructible<T, void>
{
static constexpr bool value = false;
};
template <> struct _is_implicitly_constructible<void, void>
{
static constexpr bool value = false;
};
template <class T, class U> static constexpr bool is_implicitly_constructible = _is_implicitly_constructible<T, U>::value;
template <class T, class... Args> struct _is_nothrow_constructible
{
static constexpr bool value = std::is_nothrow_constructible<T, Args...>::value;
};
template <class T> struct _is_nothrow_constructible<T, void>
{
static constexpr bool value = false;
};
template <> struct _is_nothrow_constructible<void, void>
{
static constexpr bool value = false;
};
template <class T, class... Args> static constexpr bool is_nothrow_constructible = _is_nothrow_constructible<T, Args...>::value;
template <class T, class... Args> struct _is_constructible
{
static constexpr bool value = std::is_constructible<T, Args...>::value;
};
template <class T> struct _is_constructible<T, void>
{
static constexpr bool value = false;
};
template <> struct _is_constructible<void, void>
{
static constexpr bool value = false;
};
template <class T, class... Args> static constexpr bool is_constructible = _is_constructible<T, Args...>::value;
#ifndef OUTCOME_USE_STD_IS_NOTHROW_SWAPPABLE
#if defined(_MSC_VER) && _HAS_CXX17
#define OUTCOME_USE_STD_IS_NOTHROW_SWAPPABLE 1 // MSVC always has std::is_nothrow_swappable
#elif __cplusplus >= 201700
// libstdc++ before GCC 6 doesn't have it, despite claiming C++ 17 support
#ifdef __has_include
#if !__has_include(<variant>)
#define OUTCOME_USE_STD_IS_NOTHROW_SWAPPABLE 0
#endif
#endif
#ifndef OUTCOME_USE_STD_IS_NOTHROW_SWAPPABLE
#define OUTCOME_USE_STD_IS_NOTHROW_SWAPPABLE 1
#endif
#else
#define OUTCOME_USE_STD_IS_NOTHROW_SWAPPABLE 0
#endif
#endif
// True if type is nothrow swappable
#if !0L && OUTCOME_USE_STD_IS_NOTHROW_SWAPPABLE
template <class T> using is_nothrow_swappable = std::is_nothrow_swappable<T>;
#else
template <class T> struct is_nothrow_swappable
{
static constexpr bool value = std::is_nothrow_move_constructible<T>::value && std::is_nothrow_move_assignable<T>::value;
};
#endif
} // namespace detail
OUTCOME_V2_NAMESPACE_END
#ifndef OUTCOME_THROW_EXCEPTION
#ifdef __cpp_exceptions
#define OUTCOME_THROW_EXCEPTION(expr) throw expr
#else
#ifdef __ANDROID__
#define OUTCOME_DISABLE_EXECINFO
#endif
#ifndef OUTCOME_DISABLE_EXECINFO
#ifdef _WIN32
/* Implements backtrace() et al from glibc on win64
(C) 2016-2017 Niall Douglas <http://www.nedproductions.biz/> (4 commits)
File Created: Mar 2016
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License in the accompanying file
Licence.txt or at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Distributed under the Boost Software License, Version 1.0.
(See accompanying file Licence.txt or copy at
http://www.boost.org/LICENSE_1_0.txt)
*/
#ifndef BOOST_BINDLIB_EXECINFO_WIN64_H
#define BOOST_BINDLIB_EXECINFO_WIN64_H
#ifndef _WIN32
#error Can only be included on Windows
#endif
#include <sal.h>
#include <stddef.h>
#ifdef QUICKCPPLIB_EXPORTS
#define EXECINFO_DECL extern __declspec(dllexport)
#else
#if defined(__cplusplus) && (!defined(QUICKCPPLIB_HEADERS_ONLY) || QUICKCPPLIB_HEADERS_ONLY == 1) && !0L
#define EXECINFO_DECL inline
#elif defined(QUICKCPPLIB_DYN_LINK) && !defined(QUICKCPPLIB_STATIC_LINK)
#define EXECINFO_DECL extern __declspec(dllimport)
#else
#define EXECINFO_DECL extern
#endif
#endif
#ifdef __cplusplus
extern "C" {
#endif
//! Fill the array of void * at bt with up to len entries, returning entries filled.
EXECINFO_DECL _Check_return_ size_t backtrace(_Out_writes_(len) void **bt, _In_ size_t len);
//! Returns a malloced block of string representations of the input backtrace.
EXECINFO_DECL _Check_return_ _Ret_writes_maybenull_(len) char **backtrace_symbols(_In_reads_(len) void *const *bt, _In_ size_t len);
// extern void backtrace_symbols_fd(void *const *bt, size_t len, int fd);
#ifdef __cplusplus
}
#if (!defined(QUICKCPPLIB_HEADERS_ONLY) || QUICKCPPLIB_HEADERS_ONLY == 1) && !0L
#define QUICKCPPLIB_INCLUDED_BY_HEADER 1
/* Implements backtrace() et al from glibc on win64
(C) 2016-2017 Niall Douglas <http://www.nedproductions.biz/> (14 commits)
File Created: Mar 2016
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License in the accompanying file
Licence.txt or at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Distributed under the Boost Software License, Version 1.0.
(See accompanying file Licence.txt or copy at
http://www.boost.org/LICENSE_1_0.txt)
*/
/* Implements backtrace() et al from glibc on win64
(C) 2016-2017 Niall Douglas <http://www.nedproductions.biz/> (4 commits)
File Created: Mar 2016
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License in the accompanying file
Licence.txt or at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Distributed under the Boost Software License, Version 1.0.
(See accompanying file Licence.txt or copy at
http://www.boost.org/LICENSE_1_0.txt)
*/
#include <atomic>
#include <stdlib.h> // for abort
#include <string.h>
// To avoid including windows.h, this source has been macro expanded and win32 function shimmed for C++ only
#if defined(__cplusplus) && !defined(__clang__)
namespace win32
{
extern _Ret_maybenull_ void *__stdcall LoadLibraryA(_In_ const char *lpLibFileName);
typedef int(__stdcall *GetProcAddress_returntype)();
extern GetProcAddress_returntype __stdcall GetProcAddress(_In_ void *hModule, _In_ const char *lpProcName);
extern _Success_(return != 0) unsigned short __stdcall RtlCaptureStackBackTrace(_In_ unsigned long FramesToSkip, _In_ unsigned long FramesToCapture,
_Out_writes_to_(FramesToCapture, return ) void **BackTrace,
_Out_opt_ unsigned long *BackTraceHash);
extern _Success_(return != 0)
_When_((cchWideChar == -1) && (cbMultiByte != 0),
_Post_equal_to_(_String_length_(lpMultiByteStr) +
1)) int __stdcall WideCharToMultiByte(_In_ unsigned int CodePage, _In_ unsigned long dwFlags, const wchar_t *lpWideCharStr,
_In_ int cchWideChar, _Out_writes_bytes_to_opt_(cbMultiByte, return ) char *lpMultiByteStr,
_In_ int cbMultiByte, _In_opt_ const char *lpDefaultChar, _Out_opt_ int *lpUsedDefaultChar);
#pragma comment(lib, "kernel32.lib")
#if (defined(__x86_64__) || defined(_M_X64)) || (defined(__aarch64__) || defined(_M_ARM64))
#pragma comment(linker, "/alternatename:?LoadLibraryA@win32@@YAPEAXPEBD@Z=LoadLibraryA")
#pragma comment(linker, "/alternatename:?GetProcAddress@win32@@YAP6AHXZPEAXPEBD@Z=GetProcAddress")
#pragma comment(linker, "/alternatename:?RtlCaptureStackBackTrace@win32@@YAGKKPEAPEAXPEAK@Z=RtlCaptureStackBackTrace")
#pragma comment(linker, "/alternatename:?WideCharToMultiByte@win32@@YAHIKPEB_WHPEADHPEBDPEAH@Z=WideCharToMultiByte")
#elif defined(__x86__) || defined(_M_IX86) || defined(__i386__)
#pragma comment(linker, "/alternatename:?LoadLibraryA@win32@@YGPAXPBD@Z=__imp__LoadLibraryA@4")
#pragma comment(linker, "/alternatename:?GetProcAddress@win32@@YGP6GHXZPAXPBD@Z=__imp__GetProcAddress@8")
#pragma comment(linker, "/alternatename:?RtlCaptureStackBackTrace@win32@@YGGKKPAPAXPAK@Z=__imp__RtlCaptureStackBackTrace@16")
#pragma comment(linker, "/alternatename:?WideCharToMultiByte@win32@@YGHIKPB_WHPADHPBDPAH@Z=__imp__WideCharToMultiByte@32")
#elif defined(__arm__) || defined(_M_ARM)
#pragma comment(linker, "/alternatename:?LoadLibraryA@win32@@YAPAXPBD@Z=LoadLibraryA")
#pragma comment(linker, "/alternatename:?GetProcAddress@win32@@YAP6AHXZPAXPBD@Z=GetProcAddress")
#pragma comment(linker, "/alternatename:?RtlCaptureStackBackTrace@win32@@YAGKKPAPAXPAK@Z=RtlCaptureStackBackTrace")
#pragma comment(linker, "/alternatename:?WideCharToMultiByte@win32@@YAHIKPB_WHPADHPBDPAH@Z=WideCharToMultiByte")
#else
#error Unknown architecture
#endif
} // namespace win32
#else
#ifndef WIN32_LEAN_AND_MEAN
#define WIN32_LEAN_AND_MEAN
#endif
#ifndef NOMINMAX
#define NOMINMAX
#endif
#include <Windows.h>
#endif
#ifdef __cplusplus
namespace
{
#endif
typedef struct _IMAGEHLP_LINE64
{
unsigned long SizeOfStruct;
void *Key;
unsigned long LineNumber;
wchar_t *FileName;
unsigned long long int Address;
} IMAGEHLP_LINE64, *PIMAGEHLP_LINE64;
typedef int(__stdcall *SymInitialize_t)(_In_ void *hProcess, _In_opt_ const wchar_t *UserSearchPath, _In_ int fInvadeProcess);
typedef int(__stdcall *SymGetLineFromAddr64_t)(_In_ void *hProcess, _In_ unsigned long long int dwAddr, _Out_ unsigned long *pdwDisplacement,
_Out_ PIMAGEHLP_LINE64 Line);
static std::atomic<unsigned> dbghelp_init_lock;
#if defined(__cplusplus) && !defined(__clang__)
static void *dbghelp;
#else
static HMODULE dbghelp;
#endif
static SymInitialize_t SymInitialize;
static SymGetLineFromAddr64_t SymGetLineFromAddr64;
static void load_dbghelp()
{
#if defined(__cplusplus) && !defined(__clang__)
using win32::GetProcAddress;
using win32::LoadLibraryA;
#endif
while(dbghelp_init_lock.exchange(1, std::memory_order_acq_rel))
;
if(dbghelp)
{
dbghelp_init_lock.store(0, std::memory_order_release);
return;
}
dbghelp = LoadLibraryA("DBGHELP.DLL");
if(dbghelp)
{
SymInitialize = (SymInitialize_t) GetProcAddress(dbghelp, "SymInitializeW");
if(!SymInitialize)
abort();
if(!SymInitialize((void *) (size_t) -1 /*GetCurrentProcess()*/, NULL, 1))
abort();
SymGetLineFromAddr64 = (SymGetLineFromAddr64_t) GetProcAddress(dbghelp, "SymGetLineFromAddrW64");
if(!SymGetLineFromAddr64)
abort();
}
dbghelp_init_lock.store(0, std::memory_order_release);
}
#ifdef __cplusplus
}
#endif
#ifdef __cplusplus
extern "C"
{
#endif
_Check_return_ size_t backtrace(_Out_writes_(len) void **bt, _In_ size_t len)
{
#if defined(__cplusplus) && !defined(__clang__)
using win32::RtlCaptureStackBackTrace;
#endif
return RtlCaptureStackBackTrace(1, (unsigned long) len, bt, NULL);
}
#ifdef _MSC_VER
#pragma warning(push)
#pragma warning(disable : 6385 6386) // MSVC static analyser can't grok this function. clang's analyser gives it thumbs up.
#endif
_Check_return_ _Ret_writes_maybenull_(len) char **backtrace_symbols(_In_reads_(len) void *const *bt, _In_ size_t len)
{
#if defined(__cplusplus) && !defined(__clang__)
using win32::WideCharToMultiByte;
#endif
size_t bytes = (len + 1) * sizeof(void *) + 256, n;
if(!len)
return NULL;
else
{
char **ret = (char **) malloc(bytes);
char *p = (char *) (ret + len + 1), *end = (char *) ret + bytes;
if(!ret)
return NULL;
for(n = 0; n < len + 1; n++)
ret[n] = NULL;
load_dbghelp();
for(n = 0; n < len; n++)
{
unsigned long displ;
IMAGEHLP_LINE64 ihl;
memset(&ihl, 0, sizeof(ihl));
ihl.SizeOfStruct = sizeof(IMAGEHLP_LINE64);
int please_realloc = 0;
if(!bt[n])
{
ret[n] = NULL;
}
else
{
// Keep offset till later
ret[n] = (char *) ((char *) p - (char *) ret);
{
static std::atomic<unsigned> symlock(0);
while(symlock.exchange(1, std::memory_order_acq_rel))
;
if(!SymGetLineFromAddr64 || !SymGetLineFromAddr64((void *) (size_t) -1 /*GetCurrentProcess()*/, (size_t) bt[n], &displ, &ihl))
{
symlock.store(0, std::memory_order_release);
if(n == 0)
{
free(ret);
return NULL;
}
ihl.FileName = (wchar_t *) L"unknown";
ihl.LineNumber = 0;
}
else
{
symlock.store(0, std::memory_order_release);
}
}
retry:
if(please_realloc)
{
char **temp = (char **) realloc(ret, bytes + 256);
if(!temp)
{
free(ret);
return NULL;
}
p = (char *) temp + (p - (char *) ret);
ret = temp;
bytes += 256;
end = (char *) ret + bytes;
}
if(ihl.FileName && ihl.FileName[0])
{
int plen = WideCharToMultiByte(65001 /*CP_UTF8*/, 0, ihl.FileName, -1, p, (int) (end - p), NULL, NULL);
if(!plen)
{
please_realloc = 1;
goto retry;
}
p[plen - 1] = 0;
p += plen - 1;
}
else
{
if(end - p < 16)
{
please_realloc = 1;
goto retry;
}
_ui64toa_s((size_t) bt[n], p, end - p, 16);
p = strchr(p, 0);
}
if(end - p < 16)
{
please_realloc = 1;
goto retry;
}
*p++ = ':';
_itoa_s(ihl.LineNumber, p, end - p, 10);
p = strchr(p, 0) + 1;
}
}
for(n = 0; n < len; n++)
{
if(ret[n])
ret[n] = (char *) ret + (size_t) ret[n];
}
return ret;
}
}
#ifdef _MSC_VER
#pragma warning(pop)
#endif
// extern void backtrace_symbols_fd(void *const *bt, size_t len, int fd);
#ifdef __cplusplus
}
#endif
#undef QUICKCPPLIB_INCLUDED_BY_HEADER
#endif
#endif
#endif
#else
#include <execinfo.h>
#endif
#endif // OUTCOME_DISABLE_EXECINFO
#include <cstdio>
#include <cstdlib>
OUTCOME_V2_NAMESPACE_BEGIN
namespace detail
{
QUICKCPPLIB_NORETURN inline void do_fatal_exit(const char *expr)
{
#if !defined(OUTCOME_DISABLE_EXECINFO)
void *bt[16];
size_t btlen = backtrace(bt, sizeof(bt) / sizeof(bt[0])); // NOLINT
#endif
fprintf(stderr, "FATAL: Outcome throws exception %s with exceptions disabled\n", expr); // NOLINT
#if !defined(OUTCOME_DISABLE_EXECINFO)
char **bts = backtrace_symbols(bt, btlen); // NOLINT
if(bts != nullptr)
{
for(size_t n = 0; n < btlen; n++)
{
fprintf(stderr, " %s\n", bts[n]); // NOLINT
}
free(bts); // NOLINT
}
#endif
abort();
}
} // namespace detail
OUTCOME_V2_NAMESPACE_END
#define OUTCOME_THROW_EXCEPTION(expr) OUTCOME_V2_NAMESPACE::detail::do_fatal_exit(#expr), (void) (expr)
#endif
#endif
#ifndef BOOST_OUTCOME_AUTO_TEST_CASE
#define BOOST_OUTCOME_AUTO_TEST_CASE(a, b) BOOST_AUTO_TEST_CASE(a, b)
#endif
#endif
/* A very simple result type
(C) 2017-2024 Niall Douglas <http://www.nedproductions.biz/> (14 commits)
File Created: June 2017
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License in the accompanying file
Licence.txt or at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Distributed under the Boost Software License, Version 1.0.
(See accompanying file Licence.txt or copy at
http://www.boost.org/LICENSE_1_0.txt)
*/
#ifndef OUTCOME_BASIC_RESULT_HPP
#define OUTCOME_BASIC_RESULT_HPP
/* Says how to convert value, error and exception types
(C) 2017-2019 Niall Douglas <http://www.nedproductions.biz/> (12 commits)
File Created: Nov 2017
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License in the accompanying file
Licence.txt or at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Distributed under the Boost Software License, Version 1.0.
(See accompanying file Licence.txt or copy at
http://www.boost.org/LICENSE_1_0.txt)
*/
#ifndef OUTCOME_CONVERT_HPP
#define OUTCOME_CONVERT_HPP
/* Storage for a very simple basic_result type
(C) 2017-2019 Niall Douglas <http://www.nedproductions.biz/> (6 commits)
File Created: Oct 2017
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License in the accompanying file
Licence.txt or at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Distributed under the Boost Software License, Version 1.0.
(See accompanying file Licence.txt or copy at
http://www.boost.org/LICENSE_1_0.txt)
*/
#ifndef OUTCOME_BASIC_RESULT_STORAGE_HPP
#define OUTCOME_BASIC_RESULT_STORAGE_HPP
/* Type sugar for success and failure
(C) 2017-2019 Niall Douglas <http://www.nedproductions.biz/> (25 commits)
File Created: July 2017
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License in the accompanying file
Licence.txt or at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Distributed under the Boost Software License, Version 1.0.
(See accompanying file Licence.txt or copy at
http://www.boost.org/LICENSE_1_0.txt)
*/
#ifndef OUTCOME_SUCCESS_FAILURE_HPP
#define OUTCOME_SUCCESS_FAILURE_HPP
OUTCOME_V2_NAMESPACE_BEGIN
/*! AWAITING HUGO JSON CONVERSION TOOL
type definition template <class T> success_type. Potential doc page: `success_type<T>`
*/
template <class T> struct OUTCOME_NODISCARD success_type
{
using value_type = T;
private:
value_type _value;
uint16_t _spare_storage{0};
public:
success_type() = default;
success_type(const success_type &) = default;
success_type(success_type &&) = default; // NOLINT
success_type &operator=(const success_type &) = default;
success_type &operator=(success_type &&) = default; // NOLINT
~success_type() = default;
OUTCOME_TEMPLATE(class U)
OUTCOME_TREQUIRES(OUTCOME_TPRED(!std::is_same<success_type, std::decay_t<U>>::value))
constexpr explicit success_type(U &&v, uint16_t spare_storage = 0)
: _value(static_cast<U &&>(v)) // NOLINT
, _spare_storage(spare_storage)
{
}
constexpr value_type &value() & { return _value; }
constexpr const value_type &value() const & { return _value; }
constexpr value_type &&value() && { return static_cast<value_type &&>(_value); }
constexpr const value_type &&value() const && { return static_cast<value_type &&>(_value); }
constexpr uint16_t spare_storage() const { return _spare_storage; }
};
template <> struct OUTCOME_NODISCARD success_type<void>
{
using value_type = void;
constexpr uint16_t spare_storage() const { return 0; }
};
/*! Returns type sugar for implicitly constructing a `basic_result<T>` with a successful state,
default constructing `T` if necessary.
*/
inline constexpr success_type<void> success() noexcept
{
return success_type<void>{};
}
/*! Returns type sugar for implicitly constructing a `basic_result<T>` with a successful state.
\effects Copies the successful state supplied into the returned type sugar.
*/
OUTCOME_TEMPLATE(class T)
OUTCOME_TREQUIRES(OUTCOME_TPRED(std::is_copy_constructible<T>::value))
inline constexpr success_type<std::decay_t<T>> success(const T &v, uint16_t spare_storage = 0)
{
return success_type<std::decay_t<T>>{v, spare_storage};
}
/*! Returns type sugar for implicitly constructing a `basic_result<T>` with a successful state.
\effects Moves the successful state supplied into the returned type sugar.
*/
OUTCOME_TEMPLATE(class T)
OUTCOME_TREQUIRES(OUTCOME_TPRED(std::is_move_constructible<T>::value))
inline constexpr success_type<std::decay_t<T>> success(T &&v, uint16_t spare_storage = 0)
{
return success_type<std::decay_t<T>>{static_cast<T &&>(v), spare_storage};
}
/*! AWAITING HUGO JSON CONVERSION TOOL
type definition template <class EC, class E = void> failure_type. Potential doc page: `failure_type<EC, EP = void>`
*/
template <class EC, class E = void> struct OUTCOME_NODISCARD failure_type
{
using error_type = EC;
using exception_type = E;
private:
error_type _error;
exception_type _exception;
bool _have_error{false}, _have_exception{false};
uint16_t _spare_storage{0};
struct error_init_tag
{
};
struct exception_init_tag
{
};
public:
failure_type() = default;
failure_type(const failure_type &) = default;
failure_type(failure_type &&) = default; // NOLINT
failure_type &operator=(const failure_type &) = default;
failure_type &operator=(failure_type &&) = default; // NOLINT
~failure_type() = default;
template <class U, class V>
constexpr explicit failure_type(U &&u, V &&v, uint16_t spare_storage = 0)
: _error(static_cast<U &&>(u))
, _exception(static_cast<V &&>(v))
, _have_error(true)
, _have_exception(true)
, _spare_storage(spare_storage)
{
}
template <class U>
constexpr explicit failure_type(in_place_type_t<error_type> /*unused*/, U &&u, uint16_t spare_storage = 0, error_init_tag /*unused*/ = error_init_tag())
: _error(static_cast<U &&>(u))
, _exception()
, _have_error(true)
, _spare_storage(spare_storage)
{
}
template <class U>
constexpr explicit failure_type(in_place_type_t<exception_type> /*unused*/, U &&u, uint16_t spare_storage = 0,
exception_init_tag /*unused*/ = exception_init_tag())
: _error()
, _exception(static_cast<U &&>(u))
, _have_exception(true)
, _spare_storage(spare_storage)
{
}
constexpr bool has_error() const { return _have_error; }
constexpr bool has_exception() const { return _have_exception; }
constexpr error_type &error() & { return _error; }
constexpr const error_type &error() const & { return _error; }
constexpr error_type &&error() && { return static_cast<error_type &&>(_error); }
constexpr const error_type &&error() const && { return static_cast<error_type &&>(_error); }
constexpr exception_type &exception() & { return _exception; }
constexpr const exception_type &exception() const & { return _exception; }
constexpr exception_type &&exception() && { return static_cast<exception_type &&>(_exception); }
constexpr const exception_type &&exception() const && { return static_cast<exception_type &&>(_exception); }
constexpr uint16_t spare_storage() const { return _spare_storage; }
};
template <class EC> struct OUTCOME_NODISCARD failure_type<EC, void>
{
using error_type = EC;
using exception_type = void;
private:
error_type _error;
uint16_t _spare_storage{0};
public:
failure_type() = default;
failure_type(const failure_type &) = default;
failure_type(failure_type &&) = default; // NOLINT
failure_type &operator=(const failure_type &) = default;
failure_type &operator=(failure_type &&) = default; // NOLINT
~failure_type() = default;
OUTCOME_TEMPLATE(class U)
OUTCOME_TREQUIRES(OUTCOME_TPRED(!std::is_same<failure_type, std::decay_t<U>>::value))
constexpr explicit failure_type(U &&u, uint16_t spare_storage = 0)
: _error(static_cast<U &&>(u)) // NOLINT
, _spare_storage(spare_storage)
{
}
constexpr error_type &error() & { return _error; }
constexpr const error_type &error() const & { return _error; }
constexpr error_type &&error() && { return static_cast<error_type &&>(_error); }
constexpr const error_type &&error() const && { return static_cast<error_type &&>(_error); }
constexpr uint16_t spare_storage() const { return _spare_storage; }
};
template <class E> struct OUTCOME_NODISCARD failure_type<void, E>
{
using error_type = void;
using exception_type = E;
private:
exception_type _exception;
uint16_t _spare_storage{0};
public:
failure_type() = default;
failure_type(const failure_type &) = default;
failure_type(failure_type &&) = default; // NOLINT
failure_type &operator=(const failure_type &) = default;
failure_type &operator=(failure_type &&) = default; // NOLINT
~failure_type() = default;
OUTCOME_TEMPLATE(class V)
OUTCOME_TREQUIRES(OUTCOME_TPRED(!std::is_same<failure_type, std::decay_t<V>>::value))
constexpr explicit failure_type(V &&v, uint16_t spare_storage = 0)
: _exception(static_cast<V &&>(v)) // NOLINT
, _spare_storage(spare_storage)
{
}
constexpr exception_type &exception() & { return _exception; }
constexpr const exception_type &exception() const & { return _exception; }
constexpr exception_type &&exception() && { return static_cast<exception_type &&>(_exception); }
constexpr const exception_type &&exception() const && { return static_cast<exception_type &&>(_exception); }
constexpr uint16_t spare_storage() const { return _spare_storage; }
};
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class EC)
OUTCOME_TREQUIRES(OUTCOME_TPRED(std::is_copy_constructible<EC>::value))
inline constexpr failure_type<std::decay_t<EC>> failure(const EC &v, uint16_t spare_storage = 0)
{
return failure_type<std::decay_t<EC>>{v, spare_storage};
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class EC)
OUTCOME_TREQUIRES(OUTCOME_TPRED(std::is_move_constructible<EC>::value))
inline constexpr failure_type<std::decay_t<EC>> failure(EC &&v, uint16_t spare_storage = 0)
{
return failure_type<std::decay_t<EC>>{static_cast<EC &&>(v), spare_storage};
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class EC, class E)
OUTCOME_TREQUIRES(OUTCOME_TPRED(std::is_copy_constructible<EC>::value &&std::is_copy_constructible<E>::value))
inline constexpr failure_type<std::decay_t<EC>, std::decay_t<E>> failure(const EC &v, const E &w, uint16_t spare_storage = 0)
{
return failure_type<std::decay_t<EC>, std::decay_t<E>>{v, w, spare_storage};
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class EC, class E)
OUTCOME_TREQUIRES(OUTCOME_TPRED(std::is_copy_constructible<EC>::value &&std::is_move_constructible<E>::value))
inline constexpr failure_type<std::decay_t<EC>, std::decay_t<E>> failure(const EC &v, E &&w, uint16_t spare_storage = 0)
{
return failure_type<std::decay_t<EC>, std::decay_t<E>>{v, static_cast<E &&>(w), spare_storage};
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class EC, class E)
OUTCOME_TREQUIRES(OUTCOME_TPRED(std::is_move_constructible<EC>::value &&std::is_copy_constructible<E>::value))
inline constexpr failure_type<std::decay_t<EC>, std::decay_t<E>> failure(EC &&v, const E &w, uint16_t spare_storage = 0)
{
return failure_type<std::decay_t<EC>, std::decay_t<E>>{static_cast<EC &&>(v), w, spare_storage};
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class EC, class E)
OUTCOME_TREQUIRES(OUTCOME_TPRED(std::is_move_constructible<EC>::value &&std::is_move_constructible<E>::value))
inline constexpr failure_type<std::decay_t<EC>, std::decay_t<E>> failure(EC &&v, E &&w, uint16_t spare_storage = 0)
{
return failure_type<std::decay_t<EC>, std::decay_t<E>>{static_cast<EC &&>(v), static_cast<E &&>(w), spare_storage};
}
namespace detail
{
template <class T> struct is_success_type
{
static constexpr bool value = false;
};
template <class T> struct is_success_type<success_type<T>>
{
static constexpr bool value = true;
};
template <class T> struct is_failure_type
{
static constexpr bool value = false;
};
template <class EC, class E> struct is_failure_type<failure_type<EC, E>>
{
static constexpr bool value = true;
};
} // namespace detail
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
template <class T> static constexpr bool is_success_type = detail::is_success_type<std::decay_t<T>>::value;
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
template <class T> static constexpr bool is_failure_type = detail::is_failure_type<std::decay_t<T>>::value;
OUTCOME_V2_NAMESPACE_END
#endif
/* Traits for Outcome
(C) 2018-2019 Niall Douglas <http://www.nedproductions.biz/> (8 commits)
File Created: March 2018
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License in the accompanying file
Licence.txt or at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Distributed under the Boost Software License, Version 1.0.
(See accompanying file Licence.txt or copy at
http://www.boost.org/LICENSE_1_0.txt)
*/
#ifndef OUTCOME_TRAIT_HPP
#define OUTCOME_TRAIT_HPP
OUTCOME_V2_NAMESPACE_EXPORT_BEGIN
namespace trait
{
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
template <class R> //
static constexpr bool type_can_be_used_in_basic_result = //
(!std::is_reference<R>::value //
&& !OUTCOME_V2_NAMESPACE::detail::is_in_place_type_t<std::decay_t<R>>::value //
&& !is_success_type<R> //
&& !is_failure_type<R> //
&& !std::is_array<R>::value //
&& (std::is_void<R>::value || (std::is_object<R>::value //
&& std::is_destructible<R>::value)) //
);
/*! AWAITING HUGO JSON CONVERSION TOOL
type definition is_error_type. Potential doc page: NOT FOUND
*/
template <class T> struct is_move_bitcopying
{
static constexpr bool value = false;
};
/*! AWAITING HUGO JSON CONVERSION TOOL
type definition is_error_type. Potential doc page: NOT FOUND
*/
template <class E> struct is_error_type
{
static constexpr bool value = false;
};
/*! AWAITING HUGO JSON CONVERSION TOOL
type definition is_error_type_enum. Potential doc page: NOT FOUND
*/
template <class E, class Enum> struct is_error_type_enum
{
static constexpr bool value = false;
};
namespace detail
{
template <class T> using devoid = OUTCOME_V2_NAMESPACE::detail::devoid<T>;
template <class T> std::add_rvalue_reference_t<devoid<T>> declval() noexcept;
// From http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2015/n4436.pdf
namespace detector_impl
{
template <class...> using void_t = void;
template <class Default, class, template <class...> class Op, class... Args> struct detector
{
static constexpr bool value = false;
using type = Default;
};
template <class Default, template <class...> class Op, class... Args> struct detector<Default, void_t<Op<Args...>>, Op, Args...>
{
static constexpr bool value = true;
using type = Op<Args...>;
};
} // namespace detector_impl
template <template <class...> class Op, class... Args> using is_detected = detector_impl::detector<void, void, Op, Args...>;
template <class Arg> using result_of_make_error_code = decltype(make_error_code(declval<Arg>()));
template <class Arg> using introspect_make_error_code = is_detected<result_of_make_error_code, Arg>;
template <class Arg> using result_of_make_exception_ptr = decltype(make_exception_ptr(declval<Arg>()));
template <class Arg> using introspect_make_exception_ptr = is_detected<result_of_make_exception_ptr, Arg>;
template <class T> struct _is_error_code_available
{
static constexpr bool value = detail::introspect_make_error_code<T>::value;
using type = typename detail::introspect_make_error_code<T>::type;
};
template <class T> struct _is_exception_ptr_available
{
static constexpr bool value = detail::introspect_make_exception_ptr<T>::value;
using type = typename detail::introspect_make_exception_ptr<T>::type;
};
} // namespace detail
/*! AWAITING HUGO JSON CONVERSION TOOL
type definition is_error_code_available. Potential doc page: NOT FOUND
*/
template <class T> struct is_error_code_available
{
static constexpr bool value = detail::_is_error_code_available<std::decay_t<T>>::value;
using type = typename detail::_is_error_code_available<std::decay_t<T>>::type;
};
template <class T> constexpr bool is_error_code_available_v = detail::_is_error_code_available<std::decay_t<T>>::value;
/*! AWAITING HUGO JSON CONVERSION TOOL
type definition is_exception_ptr_available. Potential doc page: NOT FOUND
*/
template <class T> struct is_exception_ptr_available
{
static constexpr bool value = detail::_is_exception_ptr_available<std::decay_t<T>>::value;
using type = typename detail::_is_exception_ptr_available<std::decay_t<T>>::type;
};
template <class T> constexpr bool is_exception_ptr_available_v = detail::_is_exception_ptr_available<std::decay_t<T>>::value;
} // namespace trait
OUTCOME_V2_NAMESPACE_END
#endif
/* Essentially an internal optional implementation :)
(C) 2017-2022 Niall Douglas <http://www.nedproductions.biz/> (24 commits)
File Created: June 2017
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License in the accompanying file
Licence.txt or at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Distributed under the Boost Software License, Version 1.0.
(See accompanying file Licence.txt or copy at
http://www.boost.org/LICENSE_1_0.txt)
*/
#ifndef OUTCOME_VALUE_STORAGE_HPP
#define OUTCOME_VALUE_STORAGE_HPP
OUTCOME_V2_NAMESPACE_EXPORT_BEGIN
namespace detail
{
// Helpers for move assigning to empty storage
template <class T, bool isCopyOrMoveConstructible = std::is_copy_constructible<T>::value || std::is_move_constructible<T>::value,
bool isDefaultConstructibleAndCopyOrMoveAssignable =
std::is_default_constructible<T>::value && (std::is_copy_assignable<T>::value || std::is_move_assignable<T>::value)>
struct move_assign_to_empty;
// Prefer to use move or copy construction
template <class T> struct move_assign_to_empty<T, true, false>
{
move_assign_to_empty(T *dest, T *o) noexcept(std::is_nothrow_move_constructible<T>::value) { new(dest) T(static_cast<T &&>(*o)); }
};
template <class T> struct move_assign_to_empty<T, true, true>
{
move_assign_to_empty(T *dest, T *o) noexcept(std::is_nothrow_move_constructible<T>::value) { new(dest) T(static_cast<T &&>(*o)); }
};
// But fall back on default construction and move assign if necessary
template <class T> struct move_assign_to_empty<T, false, true>
{
move_assign_to_empty(T *dest, T *o) noexcept(std::is_nothrow_default_constructible<T>::value && std::is_nothrow_move_assignable<T>::value)
{
new(dest) T;
*dest = static_cast<T &&>(*o);
}
};
// Void does nothing
template <> struct move_assign_to_empty<void, false, false>
{
move_assign_to_empty(void *, void *) noexcept { /* nothing to assign */ }
};
template <> struct move_assign_to_empty<const void, false, false>
{
move_assign_to_empty(const void *, const void *) noexcept { /* nothing to assign */ }
};
// Helpers for copy assigning to empty storage
template <class T, bool isCopyConstructible = std::is_copy_constructible<T>::value,
bool isDefaultConstructibleAndCopyAssignable = std::is_default_constructible<T>::value && std::is_copy_assignable<T>::value>
struct copy_assign_to_empty;
// Prefer to use copy construction
template <class T> struct copy_assign_to_empty<T, true, false>
{
copy_assign_to_empty(T *dest, const T *o) noexcept(std::is_nothrow_copy_constructible<T>::value) { new(dest) T(*o); }
};
template <class T> struct copy_assign_to_empty<T, true, true>
{
copy_assign_to_empty(T *dest, const T *o) noexcept(std::is_nothrow_copy_constructible<T>::value) { new(dest) T(*o); }
};
// But fall back on default construction and copy assign if necessary
template <class T> struct copy_assign_to_empty<T, false, true>
{
copy_assign_to_empty(T *dest, const T *o) noexcept(std::is_nothrow_default_constructible<T>::value && std::is_nothrow_copy_assignable<T>::value)
{
new(dest) T;
*dest = *o;
}
};
// Void does nothing
template <> struct copy_assign_to_empty<void, false, false>
{
copy_assign_to_empty(void *, void *) noexcept { /* nothing to assign */ }
};
template <> struct copy_assign_to_empty<const void, false, false>
{
copy_assign_to_empty(const void *, const void *) noexcept { /* nothing to assign */ }
};
template <class T, bool nothrow> struct strong_swap_impl
{
constexpr strong_swap_impl(bool &allgood, T &a, T &b)
{
allgood = true;
using std::swap;
swap(a, b);
}
};
template <class T, bool nothrow> struct strong_placement_impl
{
template <class F> constexpr strong_placement_impl(bool &allgood, T *a, T *b, F &&f)
{
allgood = true;
new(a) T(static_cast<T &&>(*b));
b->~T();
f();
}
};
#ifdef __cpp_exceptions
template <class T> struct strong_swap_impl<T, false>
{
strong_swap_impl(bool &allgood, T &a, T &b)
{
allgood = true;
T v(static_cast<T &&>(a));
try
{
a = static_cast<T &&>(b);
}
catch(...)
{
// Try to put back a
try
{
a = static_cast<T &&>(v);
// fall through as all good
}
catch(...)
{
// failed to completely restore
allgood = false;
// throw away second exception
}
throw; // rethrow original exception
}
// b has been moved to a, try to move v to b
try
{
b = static_cast<T &&>(v);
}
catch(...)
{
// Try to restore a to b, and v to a
try
{
b = static_cast<T &&>(a);
a = static_cast<T &&>(v);
// fall through as all good
}
catch(...)
{
// failed to completely restore
allgood = false;
// throw away second exception
}
throw; // rethrow original exception
}
}
};
template <class T> struct strong_placement_impl<T, false>
{
template <class F> strong_placement_impl(bool &allgood, T *a, T *b, F &&f)
{
new(a) T(static_cast<T &&>(*b));
try
{
b->~T();
f();
}
catch(...)
{
// Try to put back a, but only if we are still good
if(allgood)
{
try
{
new(b) T(static_cast<T &&>(*a));
// fall through as all good
}
catch(...)
{
// failed to completely restore
allgood = false;
// throw away second exception
}
throw; // rethrow original exception
}
}
}
};
#endif
} // namespace detail
/*!
*/
OUTCOME_TEMPLATE(class T)
OUTCOME_TREQUIRES(OUTCOME_TPRED(std::is_move_constructible<T>::value &&std::is_move_assignable<T>::value))
constexpr inline void strong_swap(bool &allgood, T &a, T &b) noexcept(detail::is_nothrow_swappable<T>::value)
{
detail::strong_swap_impl<T, detail::is_nothrow_swappable<T>::value>(allgood, a, b);
}
/*!
*/
OUTCOME_TEMPLATE(class T, class F)
OUTCOME_TREQUIRES(OUTCOME_TPRED(std::is_move_constructible<T>::value &&std::is_move_assignable<T>::value))
constexpr inline void strong_placement(bool &allgood, T *a, T *b, F &&f) noexcept(std::is_nothrow_move_constructible<T>::value)
{
detail::strong_placement_impl<T, std::is_nothrow_move_constructible<T>::value>(allgood, a, b, static_cast<F &&>(f));
}
namespace detail
{
template <class T>
constexpr
#ifdef _MSC_VER
__declspec(noreturn)
#elif defined(__GNUC__) || defined(__clang__)
__attribute__((noreturn))
#endif
void
make_ub(T && /*unused*/)
{
OUTCOME_ASSERT(false); // NOLINT
#if defined(__GNUC__) || defined(__clang__)
__builtin_unreachable();
#elif defined(_MSC_VER)
__assume(0);
#endif
}
/* Outcome v1 used a C bitfield whose values were tracked by compiler optimisers nicely,
but that produces ICEs when used in constexpr.
Outcome v2.0-v2.1 used a 32 bit integer and manually set and cleared bits. Unfortunately
only GCC's optimiser tracks bit values during constant folding, and only per byte, and
even then unreliably. https://wg21.link/P1886 "Error speed benchmarking" showed just how
poorly clang and MSVC fails to optimise outcome-using code, if you manually set bits.
Outcome v2.2 therefore uses an enum with fixed values, and constexpr manipulation functions
to change the value to one of the enum's values. This is stupid to look at in source code,
but it make clang's optimiser do the right thing, so it's worth it.
*/
#define OUTCOME_USE_CONSTEXPR_ENUM_STATUS 0
enum class status : uint16_t
{
// WARNING: These bits are not tracked by abi-dumper, but changing them will break ABI!
none = 0,
have_value = (1U << 0U),
have_error = (1U << 1U),
have_exception = (2U << 1U),
have_error_exception = (3U << 1U),
// failed to complete a strong swap
have_lost_consistency = (1U << 3U),
have_value_lost_consistency = (1U << 0U) | (1U << 3U),
have_error_lost_consistency = (1U << 1U) | (1U << 3U),
have_exception_lost_consistency = (2U << 1U) | (1U << 3U),
have_error_exception_lost_consistency = (3U << 1U) | (1U << 3U),
// can errno be set from this error?
have_error_is_errno = (1U << 4U),
have_error_error_is_errno = (1U << 1U) | (1U << 4U),
have_error_exception_error_is_errno = (3U << 1U) | (1U << 4U),
have_error_lost_consistency_error_is_errno = (1U << 1U) | (1U << 3U) | (1U << 4U),
have_error_exception_lost_consistency_error_is_errno = (3U << 1U) | (1U << 3U) | (1U << 4U),
// value has been moved from
have_moved_from = (1U << 5U)
};
struct status_bitfield_type
{
status status_value{status::none};
uint16_t spare_storage_value{0}; // hooks::spare_storage()
constexpr status_bitfield_type() = default;
constexpr status_bitfield_type(status v) noexcept
: status_value(v)
{
} // NOLINT
constexpr status_bitfield_type(status v, uint16_t s) noexcept
: status_value(v)
, spare_storage_value(s)
{
}
constexpr status_bitfield_type(const status_bitfield_type &) = default;
constexpr status_bitfield_type(status_bitfield_type &&) = default;
constexpr status_bitfield_type &operator=(const status_bitfield_type &) = default;
constexpr status_bitfield_type &operator=(status_bitfield_type &&) = default;
//~status_bitfield_type() = default; // Do NOT uncomment this, it breaks older clangs!
constexpr bool have_value() const noexcept
{
return (static_cast<uint16_t>(status_value) & static_cast<uint16_t>(status::have_value)) != 0;
}
constexpr bool have_error() const noexcept
{
return (static_cast<uint16_t>(status_value) & static_cast<uint16_t>(status::have_error)) != 0;
}
constexpr bool have_exception() const noexcept
{
return (static_cast<uint16_t>(status_value) & static_cast<uint16_t>(status::have_exception)) != 0;
}
constexpr bool have_lost_consistency() const noexcept
{
return (static_cast<uint16_t>(status_value) & static_cast<uint16_t>(status::have_lost_consistency)) != 0;
}
constexpr bool have_error_is_errno() const noexcept
{
return (static_cast<uint16_t>(status_value) & static_cast<uint16_t>(status::have_error_is_errno)) != 0;
}
constexpr bool have_moved_from() const noexcept
{
return (static_cast<uint16_t>(status_value) & static_cast<uint16_t>(status::have_moved_from)) != 0;
}
constexpr status_bitfield_type &set_have_value(bool v) noexcept
{
status_value = static_cast<status>(v ? (static_cast<uint16_t>(status_value) | static_cast<uint16_t>(status::have_value)) :
(static_cast<uint16_t>(status_value) & ~static_cast<uint16_t>(status::have_value)));
return *this;
}
constexpr status_bitfield_type &set_have_error(bool v) noexcept
{
status_value = static_cast<status>(v ? (static_cast<uint16_t>(status_value) | static_cast<uint16_t>(status::have_error)) :
(static_cast<uint16_t>(status_value) & ~static_cast<uint16_t>(status::have_error)));
return *this;
}
constexpr status_bitfield_type &set_have_exception(bool v) noexcept
{
status_value = static_cast<status>(v ? (static_cast<uint16_t>(status_value) | static_cast<uint16_t>(status::have_exception)) :
(static_cast<uint16_t>(status_value) & ~static_cast<uint16_t>(status::have_exception)));
return *this;
}
constexpr status_bitfield_type &set_have_error_is_errno(bool v) noexcept
{
status_value = static_cast<status>(v ? (static_cast<uint16_t>(status_value) | static_cast<uint16_t>(status::have_error_is_errno)) :
(static_cast<uint16_t>(status_value) & ~static_cast<uint16_t>(status::have_error_is_errno)));
return *this;
}
constexpr status_bitfield_type &set_have_lost_consistency(bool v) noexcept
{
status_value = static_cast<status>(v ? (static_cast<uint16_t>(status_value) | static_cast<uint16_t>(status::have_lost_consistency)) :
(static_cast<uint16_t>(status_value) & ~static_cast<uint16_t>(status::have_lost_consistency)));
return *this;
}
constexpr status_bitfield_type &set_have_moved_from(bool v) noexcept
{
status_value = static_cast<status>(v ? (static_cast<uint16_t>(status_value) | static_cast<uint16_t>(status::have_moved_from)) :
(static_cast<uint16_t>(status_value) & ~static_cast<uint16_t>(status::have_moved_from)));
return *this;
}
};
#if !defined(NDEBUG)
// Check is trivial in all ways except default constructibility
static_assert(sizeof(status_bitfield_type) == 4, "status_bitfield_type is not sized 4 bytes!");
static_assert(std::is_trivially_copyable<status_bitfield_type>::value, "status_bitfield_type is not trivially copyable!");
static_assert(std::is_trivially_assignable<status_bitfield_type, status_bitfield_type>::value, "status_bitfield_type is not trivially assignable!");
static_assert(std::is_trivially_destructible<status_bitfield_type>::value, "status_bitfield_type is not trivially destructible!");
static_assert(std::is_trivially_copy_constructible<status_bitfield_type>::value, "status_bitfield_type is not trivially copy constructible!");
static_assert(std::is_trivially_move_constructible<status_bitfield_type>::value, "status_bitfield_type is not trivially move constructible!");
static_assert(std::is_trivially_copy_assignable<status_bitfield_type>::value, "status_bitfield_type is not trivially copy assignable!");
static_assert(std::is_trivially_move_assignable<status_bitfield_type>::value, "status_bitfield_type is not trivially move assignable!");
// Also check is standard layout
static_assert(std::is_standard_layout<status_bitfield_type>::value, "status_bitfield_type is not a standard layout type!");
#endif
template <class State> constexpr inline void _set_error_is_errno(State & /*unused*/) {}
#ifdef _MSC_VER
#pragma warning(push)
#pragma warning(disable : 4127) // conditional expression is constant
#pragma warning(disable : 4624) // destructor was implicitly defined as deleted
#endif
// Used if both T and E are trivial
template <class T, class E> struct value_storage_trivial
{
using value_type = T;
using error_type = E;
// Disable in place construction if they are the same type
struct disable_in_place_value_type
{
};
struct disable_in_place_error_type
{
};
using _value_type = std::conditional_t<std::is_same<value_type, error_type>::value, disable_in_place_value_type, value_type>;
using _error_type = std::conditional_t<std::is_same<value_type, error_type>::value, disable_in_place_error_type, error_type>;
using _value_type_ = devoid<value_type>;
using _error_type_ = devoid<error_type>;
union
{
empty_type _empty;
_value_type_ _value;
_error_type_ _error;
};
status_bitfield_type _status;
constexpr value_storage_trivial() noexcept
: _empty{}
{
}
value_storage_trivial(const value_storage_trivial &) = default; // NOLINT
value_storage_trivial(value_storage_trivial &&) = default; // NOLINT
value_storage_trivial &operator=(const value_storage_trivial &) = default; // NOLINT
value_storage_trivial &operator=(value_storage_trivial &&) = default; // NOLINT
~value_storage_trivial() = default;
constexpr explicit value_storage_trivial(status_bitfield_type status)
: _empty()
, _status(status)
{
}
template <class... Args>
constexpr explicit value_storage_trivial(in_place_type_t<_value_type> /*unused*/,
Args &&...args) noexcept(detail::is_nothrow_constructible<_value_type_, Args...>)
: _value(static_cast<Args &&>(args)...)
, _status(status::have_value)
{
}
template <class U, class... Args>
constexpr value_storage_trivial(in_place_type_t<_value_type> /*unused*/, std::initializer_list<U> il,
Args &&...args) noexcept(detail::is_nothrow_constructible<_value_type_, std::initializer_list<U>, Args...>)
: _value(il, static_cast<Args &&>(args)...)
, _status(status::have_value)
{
}
template <class... Args>
constexpr explicit value_storage_trivial(in_place_type_t<_error_type> /*unused*/,
Args &&...args) noexcept(detail::is_nothrow_constructible<_error_type_, Args...>)
: _error(static_cast<Args &&>(args)...)
, _status(status::have_error)
{
_set_error_is_errno(*this);
}
template <class U, class... Args>
constexpr value_storage_trivial(in_place_type_t<_error_type> /*unused*/, std::initializer_list<U> il,
Args &&...args) noexcept(detail::is_nothrow_constructible<_error_type_, std::initializer_list<U>, Args...>)
: _error(il, static_cast<Args &&>(args)...)
, _status(status::have_error)
{
_set_error_is_errno(*this);
}
struct nonvoid_converting_constructor_tag
{
};
template <class U, class V>
static constexpr bool enable_nonvoid_converting_constructor =
!(std::is_same<std::decay_t<U>, value_type>::value && std::is_same<std::decay_t<V>, error_type>::value) //
&& detail::is_constructible<value_type, U> && detail::is_constructible<error_type, V>;
OUTCOME_TEMPLATE(class U, class V)
OUTCOME_TREQUIRES(OUTCOME_TPRED(enable_nonvoid_converting_constructor<U, V>))
constexpr explicit value_storage_trivial(const value_storage_trivial<U, V> &o,
nonvoid_converting_constructor_tag /*unused*/ = {}) noexcept(detail::is_nothrow_constructible<_value_type_, U> &&
detail::is_nothrow_constructible<_error_type_, V>)
: value_storage_trivial(o._status.have_value() ?
value_storage_trivial(in_place_type<value_type>, o._value) :
(o._status.have_error() ? value_storage_trivial(in_place_type<error_type>, o._error) : value_storage_trivial())) // NOLINT
{
_status = o._status;
}
OUTCOME_TEMPLATE(class U, class V)
OUTCOME_TREQUIRES(OUTCOME_TPRED(enable_nonvoid_converting_constructor<U, V>))
constexpr explicit value_storage_trivial(value_storage_trivial<U, V> &&o,
nonvoid_converting_constructor_tag /*unused*/ = {}) noexcept(detail::is_nothrow_constructible<_value_type_, U> &&
detail::is_nothrow_constructible<_error_type_, V>)
: value_storage_trivial(
o._status.have_value() ?
value_storage_trivial(in_place_type<value_type>, static_cast<U &&>(o._value)) :
(o._status.have_error() ? value_storage_trivial(in_place_type<error_type>, static_cast<V &&>(o._error)) : value_storage_trivial())) // NOLINT
{
_status = o._status;
}
struct void_value_converting_constructor_tag
{
};
template <class V>
static constexpr bool enable_void_value_converting_constructor =
std::is_default_constructible<value_type>::value && detail::is_constructible<error_type, V>;
OUTCOME_TEMPLATE(class V)
OUTCOME_TREQUIRES(OUTCOME_TPRED(enable_void_value_converting_constructor<V>))
constexpr explicit value_storage_trivial(const value_storage_trivial<void, V> &o, void_value_converting_constructor_tag /*unused*/ = {}) noexcept(
std::is_nothrow_default_constructible<_value_type_>::value && detail::is_nothrow_constructible<_error_type_, V>)
: value_storage_trivial(o._status.have_value() ?
value_storage_trivial(in_place_type<value_type>) :
(o._status.have_error() ? value_storage_trivial(in_place_type<error_type>, o._error) : value_storage_trivial())) // NOLINT
{
_status = o._status;
}
OUTCOME_TEMPLATE(class V)
OUTCOME_TREQUIRES(OUTCOME_TPRED(enable_void_value_converting_constructor<V>))
constexpr explicit value_storage_trivial(value_storage_trivial<void, V> &&o, void_value_converting_constructor_tag /*unused*/ = {}) noexcept(
std::is_nothrow_default_constructible<_value_type_>::value && detail::is_nothrow_constructible<_error_type_, V>)
: value_storage_trivial(
o._status.have_value() ?
value_storage_trivial(in_place_type<value_type>) :
(o._status.have_error() ? value_storage_trivial(in_place_type<error_type>, static_cast<V &&>(o._error)) : value_storage_trivial())) // NOLINT
{
_status = o._status;
}
struct void_error_converting_constructor_tag
{
};
template <class U>
static constexpr bool enable_void_error_converting_constructor =
std::is_default_constructible<error_type>::value && detail::is_constructible<value_type, U>;
OUTCOME_TEMPLATE(class U)
OUTCOME_TREQUIRES(OUTCOME_TPRED(enable_void_error_converting_constructor<U>))
constexpr explicit value_storage_trivial(const value_storage_trivial<U, void> &o, void_error_converting_constructor_tag /*unused*/ = {}) noexcept(
detail::is_nothrow_constructible<_value_type_, U> && std::is_nothrow_default_constructible<_error_type_>::value)
: value_storage_trivial(o._status.have_value() ?
value_storage_trivial(in_place_type<value_type>, o._value) :
(o._status.have_error() ? value_storage_trivial(in_place_type<error_type>) : value_storage_trivial())) // NOLINT
{
_status = o._status;
}
OUTCOME_TEMPLATE(class U)
OUTCOME_TREQUIRES(OUTCOME_TPRED(enable_void_error_converting_constructor<U>))
constexpr explicit value_storage_trivial(value_storage_trivial<U, void> &&o, void_error_converting_constructor_tag /*unused*/ = {}) noexcept(
detail::is_nothrow_constructible<_value_type_, U> && std::is_nothrow_default_constructible<_error_type_>::value)
: value_storage_trivial(o._status.have_value() ?
value_storage_trivial(in_place_type<value_type>, static_cast<U &&>(o._value)) :
(o._status.have_error() ? value_storage_trivial(in_place_type<error_type>) : value_storage_trivial())) // NOLINT
{
_status = o._status;
}
constexpr void swap(value_storage_trivial &o) noexcept
{
// storage is trivial, so just use assignment
auto temp = static_cast<value_storage_trivial &&>(*this);
*this = static_cast<value_storage_trivial &&>(o);
o = static_cast<value_storage_trivial &&>(temp);
}
};
/* Used if T or E is non-trivial. The additional constexpr is injected in C++ 20 to enable Outcome to
work in constexpr evaluation contexts in C++ 20 where non-trivial constexpr destructors are now allowed.
*/
template <class T, class E> struct value_storage_nontrivial
{
using value_type = T;
using error_type = E;
struct disable_in_place_value_type
{
};
struct disable_in_place_error_type
{
};
using _value_type = std::conditional_t<std::is_same<value_type, error_type>::value, disable_in_place_value_type, value_type>;
using _error_type = std::conditional_t<std::is_same<value_type, error_type>::value, disable_in_place_error_type, error_type>;
using _value_type_ = devoid<value_type>;
using _error_type_ = devoid<error_type>;
union
{
empty_type _empty1;
_value_type_ _value;
};
status_bitfield_type _status;
union
{
empty_type _empty2;
_error_type_ _error;
};
#if __cplusplus >= 202000L || _HAS_CXX20
constexpr
#endif
value_storage_nontrivial() noexcept
: _empty1{}
, _empty2{}
{
}
value_storage_nontrivial &operator=(const value_storage_nontrivial &) = default; // if reaches here, copy assignment is trivial
value_storage_nontrivial &operator=(value_storage_nontrivial &&) = default; // NOLINT if reaches here, move assignment is trivial
#if __cplusplus >= 202000L || _HAS_CXX20
constexpr
#endif
value_storage_nontrivial(value_storage_nontrivial &&o) noexcept(std::is_nothrow_move_constructible<_value_type_>::value &&
std::is_nothrow_move_constructible<_error_type_>::value) // NOLINT
{
if(o._status.have_value())
{
new(OUTCOME_ADDRESS_OF(_value)) _value_type_(static_cast<_value_type_ &&>(o._value)); // NOLINT
}
else if(o._status.have_error())
{
new(OUTCOME_ADDRESS_OF(_error)) _error_type_(static_cast<_error_type_ &&>(o._error)); // NOLINT
}
_status = o._status;
o._status.set_have_moved_from(true);
}
#if __cplusplus >= 202000L || _HAS_CXX20
constexpr
#endif
value_storage_nontrivial(const value_storage_nontrivial &o) noexcept(std::is_nothrow_copy_constructible<_value_type_>::value &&
std::is_nothrow_copy_constructible<_error_type_>::value)
{
if(o._status.have_value())
{
new(OUTCOME_ADDRESS_OF(_value)) _value_type_(o._value); // NOLINT
}
else if(o._status.have_error())
{
new(OUTCOME_ADDRESS_OF(_error)) _error_type_(o._error); // NOLINT
}
_status = o._status;
}
#if __cplusplus >= 202000L || _HAS_CXX20
constexpr
#endif
explicit value_storage_nontrivial(status_bitfield_type status)
: _empty1()
, _status(status)
, _empty2()
{
}
template <class... Args>
constexpr explicit value_storage_nontrivial(in_place_type_t<_value_type> /*unused*/,
Args &&...args) noexcept(detail::is_nothrow_constructible<_value_type_, Args...>)
: _value(static_cast<Args &&>(args)...) // NOLINT
, _status(status::have_value)
{
}
template <class U, class... Args>
constexpr value_storage_nontrivial(in_place_type_t<_value_type> /*unused*/, std::initializer_list<U> il,
Args &&...args) noexcept(detail::is_nothrow_constructible<_value_type_, std::initializer_list<U>, Args...>)
: _value(il, static_cast<Args &&>(args)...)
, _status(status::have_value)
{
}
template <class... Args>
constexpr explicit value_storage_nontrivial(in_place_type_t<_error_type> /*unused*/,
Args &&...args) noexcept(detail::is_nothrow_constructible<_error_type_, Args...>)
: _status(status::have_error)
, _error(static_cast<Args &&>(args)...) // NOLINT
{
_set_error_is_errno(*this);
}
template <class U, class... Args>
constexpr value_storage_nontrivial(in_place_type_t<_error_type> /*unused*/, std::initializer_list<U> il,
Args &&...args) noexcept(detail::is_nothrow_constructible<_error_type_, std::initializer_list<U>, Args...>)
: _status(status::have_error)
, _error(il, static_cast<Args &&>(args)...)
{
_set_error_is_errno(*this);
}
struct nonvoid_converting_constructor_tag
{
};
template <class U, class V>
static constexpr bool enable_nonvoid_converting_constructor =
!(std::is_same<std::decay_t<U>, value_type>::value && std::is_same<std::decay_t<V>, error_type>::value) //
&& detail::is_constructible<value_type, U> && detail::is_constructible<error_type, V>;
OUTCOME_TEMPLATE(class U, class V)
OUTCOME_TREQUIRES(OUTCOME_TPRED(enable_nonvoid_converting_constructor<U, V>))
constexpr explicit value_storage_nontrivial(const value_storage_trivial<U, V> &o, nonvoid_converting_constructor_tag /*unused*/ = {}) noexcept(
detail::is_nothrow_constructible<_value_type_, U> && detail::is_nothrow_constructible<_error_type_, V>)
: value_storage_nontrivial(o._status.have_value() ?
value_storage_nontrivial(in_place_type<value_type>, o._value) :
(o._status.have_error() ? value_storage_nontrivial(in_place_type<error_type>, o._error) : value_storage_nontrivial()))
{
_status = o._status;
}
OUTCOME_TEMPLATE(class U, class V)
OUTCOME_TREQUIRES(OUTCOME_TPRED(enable_nonvoid_converting_constructor<U, V>))
constexpr explicit value_storage_nontrivial(value_storage_trivial<U, V> &&o, nonvoid_converting_constructor_tag /*unused*/ = {}) noexcept(
detail::is_nothrow_constructible<_value_type_, U> && detail::is_nothrow_constructible<_error_type_, V>)
: value_storage_nontrivial(
o._status.have_value() ?
value_storage_nontrivial(in_place_type<value_type>, static_cast<U &&>(o._value)) :
(o._status.have_error() ? value_storage_nontrivial(in_place_type<error_type>, static_cast<V &&>(o._error)) : value_storage_nontrivial()))
{
_status = o._status;
}
OUTCOME_TEMPLATE(class U, class V)
OUTCOME_TREQUIRES(OUTCOME_TPRED(enable_nonvoid_converting_constructor<U, V>))
constexpr explicit value_storage_nontrivial(const value_storage_nontrivial<U, V> &o, nonvoid_converting_constructor_tag /*unused*/ = {}) noexcept(
detail::is_nothrow_constructible<_value_type_, U> && detail::is_nothrow_constructible<_error_type_, V>)
: value_storage_nontrivial(o._status.have_value() ?
value_storage_nontrivial(in_place_type<value_type>, o._value) :
(o._status.have_error() ? value_storage_nontrivial(in_place_type<error_type>, o._error) : value_storage_nontrivial()))
{
_status = o._status;
}
OUTCOME_TEMPLATE(class U, class V)
OUTCOME_TREQUIRES(OUTCOME_TPRED(enable_nonvoid_converting_constructor<U, V>))
constexpr explicit value_storage_nontrivial(value_storage_nontrivial<U, V> &&o, nonvoid_converting_constructor_tag /*unused*/ = {}) noexcept(
detail::is_nothrow_constructible<_value_type_, U> && detail::is_nothrow_constructible<_error_type_, V>)
: value_storage_nontrivial(
o._status.have_value() ?
value_storage_nontrivial(in_place_type<value_type>, static_cast<U &&>(o._value)) :
(o._status.have_error() ? value_storage_nontrivial(in_place_type<error_type>, static_cast<V &&>(o._error)) : value_storage_nontrivial()))
{
_status = o._status;
}
struct void_value_converting_constructor_tag
{
};
template <class V>
static constexpr bool enable_void_value_converting_constructor =
std::is_default_constructible<value_type>::value && detail::is_constructible<error_type, V>;
OUTCOME_TEMPLATE(class V)
OUTCOME_TREQUIRES(OUTCOME_TPRED(enable_void_value_converting_constructor<V>))
constexpr explicit value_storage_nontrivial(const value_storage_trivial<void, V> &o, void_value_converting_constructor_tag /*unused*/ = {}) noexcept(
std::is_nothrow_default_constructible<_value_type_>::value && detail::is_nothrow_constructible<_error_type_, V>)
{
if(o._status.have_value())
{
new(OUTCOME_ADDRESS_OF(_value)) _value_type_(); // NOLINT
}
else if(o._status.have_error())
{
new(OUTCOME_ADDRESS_OF(_error)) _error_type_(o._error); // NOLINT
}
_status = o._status;
}
OUTCOME_TEMPLATE(class V)
OUTCOME_TREQUIRES(OUTCOME_TPRED(enable_void_value_converting_constructor<V>))
constexpr explicit value_storage_nontrivial(value_storage_trivial<void, V> &&o, void_value_converting_constructor_tag /*unused*/ = {}) noexcept(
std::is_nothrow_default_constructible<_value_type_>::value && detail::is_nothrow_constructible<_error_type_, V>)
{
if(o._status.have_value())
{
new(OUTCOME_ADDRESS_OF(_value)) _value_type_(); // NOLINT
}
else if(o._status.have_error())
{
new(OUTCOME_ADDRESS_OF(_error)) _error_type_(static_cast<_error_type_ &&>(o._error)); // NOLINT
}
_status = o._status;
o._status.set_have_moved_from(true);
}
struct void_error_converting_constructor_tag
{
};
template <class U>
static constexpr bool enable_void_error_converting_constructor =
std::is_default_constructible<error_type>::value && detail::is_constructible<value_type, U>;
OUTCOME_TEMPLATE(class U)
OUTCOME_TREQUIRES(OUTCOME_TPRED(enable_void_error_converting_constructor<U>))
constexpr explicit value_storage_nontrivial(const value_storage_trivial<U, void> &o, void_error_converting_constructor_tag /*unused*/ = {}) noexcept(
detail::is_nothrow_constructible<_value_type_, U> && std::is_nothrow_default_constructible<_error_type_>::value)
{
if(o._status.have_value())
{
new(OUTCOME_ADDRESS_OF(_value)) _value_type_(o._value); // NOLINT
}
else if(o._status.have_error())
{
new(OUTCOME_ADDRESS_OF(_error)) _error_type_(); // NOLINT
}
_status = o._status;
}
OUTCOME_TEMPLATE(class U)
OUTCOME_TREQUIRES(OUTCOME_TPRED(enable_void_error_converting_constructor<U>))
constexpr explicit value_storage_nontrivial(value_storage_trivial<U, void> &&o, void_error_converting_constructor_tag /*unused*/ = {}) noexcept(
detail::is_nothrow_constructible<_value_type_, U> && std::is_nothrow_default_constructible<_error_type_>::value)
{
if(o._status.have_value())
{
new(OUTCOME_ADDRESS_OF(_value)) _value_type_(static_cast<_value_type_ &&>(o._value)); // NOLINT
}
else if(o._status.have_error())
{
new(OUTCOME_ADDRESS_OF(_error)) _error_type_(); // NOLINT
}
_status = o._status;
o._status.set_have_moved_from(true);
}
#if __cplusplus >= 202000L || _HAS_CXX20
constexpr
#endif
~value_storage_nontrivial() noexcept(std::is_nothrow_destructible<_value_type_>::value && std::is_nothrow_destructible<_error_type_>::value)
{
if(this->_status.have_value())
{
if(!trait::is_move_bitcopying<value_type>::value || !this->_status.have_moved_from())
{
this->_value.~_value_type_(); // NOLINT
}
this->_status.set_have_value(false);
}
else if(this->_status.have_error())
{
if(!trait::is_move_bitcopying<error_type>::value || !this->_status.have_moved_from())
{
this->_error.~_error_type_(); // NOLINT
}
this->_status.set_have_error(false);
}
}
#if __cplusplus >= 202000L || _HAS_CXX20
constexpr
#endif
void
swap(value_storage_nontrivial &o) noexcept(detail::is_nothrow_swappable<_value_type_>::value && detail::is_nothrow_swappable<_error_type_>::value)
{
using std::swap;
// empty/empty
if(!_status.have_value() && !o._status.have_value() && !_status.have_error() && !o._status.have_error())
{
swap(_status, o._status);
return;
}
// value/value
if(_status.have_value() && o._status.have_value())
{
struct some_type
{
status_bitfield_type &a, &b;
bool all_good{false};
~some_type()
{
if(!this->all_good)
{
// We lost one of the values
this->a.set_have_lost_consistency(true);
this->b.set_have_lost_consistency(true);
}
}
} some_type_value{_status, o._status};
strong_swap(some_type_value.all_good, _value, o._value);
swap(_status, o._status);
return;
}
// error/error
if(_status.have_error() && o._status.have_error())
{
struct some_type
{
status_bitfield_type &a, &b;
bool all_good{false};
~some_type()
{
if(!this->all_good)
{
// We lost one of the values
this->a.set_have_lost_consistency(true);
this->b.set_have_lost_consistency(true);
}
}
} some_type_value{_status, o._status};
strong_swap(some_type_value.all_good, _error, o._error);
swap(_status, o._status);
return;
}
// Could be value/empty, error/empty, etc
if(_status.have_value() && !o._status.have_error())
{
// Move construct me into other
new(OUTCOME_ADDRESS_OF(o._value)) _value_type_(static_cast<_value_type_ &&>(_value)); // NOLINT
if(!trait::is_move_bitcopying<value_type>::value)
{
this->_value.~value_type(); // NOLINT
}
swap(_status, o._status);
return;
}
if(o._status.have_value() && !_status.have_error())
{
// Move construct other into me
new(OUTCOME_ADDRESS_OF(_value)) _value_type_(static_cast<_value_type_ &&>(o._value)); // NOLINT
if(!trait::is_move_bitcopying<value_type>::value)
{
o._value.~value_type(); // NOLINT
}
swap(_status, o._status);
return;
}
if(_status.have_error() && !o._status.have_value())
{
// Move construct me into other
new(OUTCOME_ADDRESS_OF(o._error)) _error_type_(static_cast<_error_type_ &&>(_error)); // NOLINT
if(!trait::is_move_bitcopying<error_type>::value)
{
this->_error.~error_type(); // NOLINT
}
swap(_status, o._status);
return;
}
if(o._status.have_error() && !_status.have_value())
{
// Move construct other into me
new(OUTCOME_ADDRESS_OF(_error)) _error_type_(static_cast<_error_type_ &&>(o._error)); // NOLINT
if(!trait::is_move_bitcopying<error_type>::value)
{
o._error.~error_type(); // NOLINT
}
swap(_status, o._status);
return;
}
// It can now only be value/error, or error/value
struct some_type
{
status_bitfield_type &a, &b;
_value_type_ *value, *o_value;
_error_type_ *error, *o_error;
bool all_good{true};
~some_type()
{
if(!this->all_good)
{
// We lost one of the values
this->a.set_have_lost_consistency(true);
this->b.set_have_lost_consistency(true);
}
}
} some_type_value{_status, o._status, OUTCOME_ADDRESS_OF(_value), OUTCOME_ADDRESS_OF(o._value), OUTCOME_ADDRESS_OF(_error), OUTCOME_ADDRESS_OF(o._error)};
if(_status.have_value() && o._status.have_error())
{
strong_placement(some_type_value.all_good, some_type_value.o_value, some_type_value.value, [&some_type_value] { //
strong_placement(some_type_value.all_good, some_type_value.error, some_type_value.o_error, [&some_type_value] { //
swap(some_type_value.a, some_type_value.b); //
});
});
return;
}
if(_status.have_error() && o._status.have_value())
{
strong_placement(some_type_value.all_good, some_type_value.o_error, some_type_value.error, [&some_type_value] { //
strong_placement(some_type_value.all_good, some_type_value.value, some_type_value.o_value, [&some_type_value] { //
swap(some_type_value.a, some_type_value.b); //
});
});
return;
}
// Should never reach here
make_ub(_value);
}
};
template <class Base> struct value_storage_delete_copy_constructor : Base // NOLINT
{
using Base::Base;
using value_type = typename Base::value_type;
using error_type = typename Base::error_type;
value_storage_delete_copy_constructor() = default;
value_storage_delete_copy_constructor(const value_storage_delete_copy_constructor &) = delete;
value_storage_delete_copy_constructor(value_storage_delete_copy_constructor &&) = default; // NOLINT
value_storage_delete_copy_constructor &operator=(const value_storage_delete_copy_constructor &o) = default;
value_storage_delete_copy_constructor &operator=(value_storage_delete_copy_constructor &&o) = default; // NOLINT
~value_storage_delete_copy_constructor() = default;
};
template <class Base> struct value_storage_delete_copy_assignment : Base // NOLINT
{
using Base::Base;
using value_type = typename Base::value_type;
using error_type = typename Base::error_type;
value_storage_delete_copy_assignment() = default;
value_storage_delete_copy_assignment(const value_storage_delete_copy_assignment &) = default;
value_storage_delete_copy_assignment(value_storage_delete_copy_assignment &&) = default; // NOLINT
value_storage_delete_copy_assignment &operator=(const value_storage_delete_copy_assignment &o) = delete;
value_storage_delete_copy_assignment &operator=(value_storage_delete_copy_assignment &&o) = default; // NOLINT
~value_storage_delete_copy_assignment() = default;
};
template <class Base> struct value_storage_delete_move_assignment : Base // NOLINT
{
using Base::Base;
using value_type = typename Base::value_type;
using error_type = typename Base::error_type;
value_storage_delete_move_assignment() = default;
value_storage_delete_move_assignment(const value_storage_delete_move_assignment &) = default;
value_storage_delete_move_assignment(value_storage_delete_move_assignment &&) = default; // NOLINT
value_storage_delete_move_assignment &operator=(const value_storage_delete_move_assignment &o) = default;
value_storage_delete_move_assignment &operator=(value_storage_delete_move_assignment &&o) = delete;
~value_storage_delete_move_assignment() = default;
};
template <class Base> struct value_storage_delete_move_constructor : Base // NOLINT
{
using Base::Base;
using value_type = typename Base::value_type;
using error_type = typename Base::error_type;
value_storage_delete_move_constructor() = default;
value_storage_delete_move_constructor(const value_storage_delete_move_constructor &) = default;
value_storage_delete_move_constructor(value_storage_delete_move_constructor &&) = delete;
value_storage_delete_move_constructor &operator=(const value_storage_delete_move_constructor &o) = default;
value_storage_delete_move_constructor &operator=(value_storage_delete_move_constructor &&o) = default;
~value_storage_delete_move_constructor() = default;
};
template <class Base> struct value_storage_nontrivial_move_assignment : Base // NOLINT
{
using Base::Base;
using value_type = typename Base::value_type;
using error_type = typename Base::error_type;
value_storage_nontrivial_move_assignment() = default;
value_storage_nontrivial_move_assignment(const value_storage_nontrivial_move_assignment &) = default;
value_storage_nontrivial_move_assignment(value_storage_nontrivial_move_assignment &&) = default; // NOLINT
value_storage_nontrivial_move_assignment &operator=(const value_storage_nontrivial_move_assignment &o) = default;
~value_storage_nontrivial_move_assignment() = default;
#if __cplusplus >= 202000L || _HAS_CXX20
constexpr
#endif
value_storage_nontrivial_move_assignment &
operator=(value_storage_nontrivial_move_assignment &&o) noexcept(std::is_nothrow_move_assignable<value_type>::value &&
std::is_nothrow_move_assignable<error_type>::value &&
noexcept(move_assign_to_empty<value_type>(static_cast<value_type *>(nullptr),
static_cast<value_type *>(nullptr))) &&
noexcept(move_assign_to_empty<error_type>(static_cast<error_type *>(nullptr),
static_cast<error_type *>(nullptr)))) // NOLINT
{
using _value_type_ = typename Base::_value_type_;
using _error_type_ = typename Base::_error_type_;
if(!this->_status.have_value() && !this->_status.have_error() && !o._status.have_value() && !o._status.have_error())
{
this->_status = o._status;
o._status.set_have_moved_from(true);
return *this;
}
if(this->_status.have_value() && o._status.have_value())
{
this->_value = static_cast<_value_type_ &&>(o._value); // NOLINT
this->_status = o._status;
o._status.set_have_moved_from(true);
return *this;
}
if(this->_status.have_error() && o._status.have_error())
{
this->_error = static_cast<_error_type_ &&>(o._error); // NOLINT
this->_status = o._status;
o._status.set_have_moved_from(true);
return *this;
}
if(this->_status.have_value() && !o._status.have_value() && !o._status.have_error())
{
if(!trait::is_move_bitcopying<value_type>::value || this->_status.have_moved_from())
{
this->_value.~_value_type_(); // NOLINT
}
this->_status = o._status;
o._status.set_have_moved_from(true);
return *this;
}
if(!this->_status.have_value() && !this->_status.have_error() && o._status.have_value())
{
move_assign_to_empty<_value_type_>(OUTCOME_ADDRESS_OF(this->_value), OUTCOME_ADDRESS_OF(o._value));
this->_status = o._status;
o._status.set_have_moved_from(true);
return *this;
}
if(this->_status.have_error() && !o._status.have_value() && !o._status.have_error())
{
if(!trait::is_move_bitcopying<error_type>::value || this->_status.have_moved_from())
{
this->_error.~_error_type_(); // NOLINT
}
this->_status = o._status;
o._status.set_have_moved_from(true);
return *this;
}
if(!this->_status.have_value() && !this->_status.have_error() && o._status.have_error())
{
move_assign_to_empty<_error_type_>(OUTCOME_ADDRESS_OF(this->_error), OUTCOME_ADDRESS_OF(o._error));
this->_status = o._status;
o._status.set_have_moved_from(true);
return *this;
}
if(this->_status.have_value() && o._status.have_error())
{
if(!trait::is_move_bitcopying<value_type>::value || this->_status.have_moved_from())
{
this->_value.~_value_type_(); // NOLINT
}
move_assign_to_empty<_error_type_>(OUTCOME_ADDRESS_OF(this->_error), OUTCOME_ADDRESS_OF(o._error));
this->_status = o._status;
o._status.set_have_moved_from(true);
return *this;
}
if(this->_status.have_error() && o._status.have_value())
{
if(!trait::is_move_bitcopying<error_type>::value || this->_status.have_moved_from())
{
this->_error.~_error_type_(); // NOLINT
}
move_assign_to_empty<_value_type_>(OUTCOME_ADDRESS_OF(this->_value), OUTCOME_ADDRESS_OF(o._value));
this->_status = o._status;
o._status.set_have_moved_from(true);
return *this;
}
// Should never reach here
make_ub(this->_value);
}
};
template <class Base> struct value_storage_nontrivial_copy_assignment : Base // NOLINT
{
using Base::Base;
using value_type = typename Base::value_type;
using error_type = typename Base::error_type;
value_storage_nontrivial_copy_assignment() = default;
value_storage_nontrivial_copy_assignment(const value_storage_nontrivial_copy_assignment &) = default;
value_storage_nontrivial_copy_assignment(value_storage_nontrivial_copy_assignment &&) = default; // NOLINT
value_storage_nontrivial_copy_assignment &operator=(value_storage_nontrivial_copy_assignment &&o) = default; // NOLINT
~value_storage_nontrivial_copy_assignment() = default;
#if __cplusplus >= 202000L || _HAS_CXX20
constexpr
#endif
value_storage_nontrivial_copy_assignment &
operator=(const value_storage_nontrivial_copy_assignment &o) noexcept(
std::is_nothrow_copy_assignable<value_type>::value && std::is_nothrow_copy_assignable<error_type>::value &&
noexcept(copy_assign_to_empty<value_type>(static_cast<value_type *>(nullptr), static_cast<value_type *>(nullptr))) &&
noexcept(copy_assign_to_empty<error_type>(static_cast<error_type *>(nullptr), static_cast<error_type *>(nullptr))))
{
using _value_type_ = typename Base::_value_type_;
using _error_type_ = typename Base::_error_type_;
if(!this->_status.have_value() && !this->_status.have_error() && !o._status.have_value() && !o._status.have_error())
{
this->_status = o._status;
return *this;
}
if(this->_status.have_value() && o._status.have_value())
{
this->_value = o._value; // NOLINT
this->_status = o._status;
return *this;
}
if(this->_status.have_error() && o._status.have_error())
{
this->_error = o._error; // NOLINT
this->_status = o._status;
return *this;
}
if(this->_status.have_value() && !o._status.have_value() && !o._status.have_error())
{
if(!trait::is_move_bitcopying<value_type>::value || this->_status.have_moved_from())
{
this->_value.~_value_type_(); // NOLINT
}
this->_status = o._status;
return *this;
}
if(!this->_status.have_value() && !this->_status.have_error() && o._status.have_value())
{
copy_assign_to_empty<_value_type_>(OUTCOME_ADDRESS_OF(this->_value), OUTCOME_ADDRESS_OF(o._value));
this->_status = o._status;
return *this;
}
if(this->_status.have_error() && !o._status.have_value() && !o._status.have_error())
{
if(!trait::is_move_bitcopying<error_type>::value || this->_status.have_moved_from())
{
this->_error.~_error_type_(); // NOLINT
}
this->_status = o._status;
return *this;
}
if(!this->_status.have_value() && !this->_status.have_error() && o._status.have_error())
{
copy_assign_to_empty<_error_type_>(OUTCOME_ADDRESS_OF(this->_error), OUTCOME_ADDRESS_OF(o._error));
this->_status = o._status;
return *this;
}
if(this->_status.have_value() && o._status.have_error())
{
if(!trait::is_move_bitcopying<value_type>::value || this->_status.have_moved_from())
{
this->_value.~_value_type_(); // NOLINT
}
copy_assign_to_empty<_error_type_>(OUTCOME_ADDRESS_OF(this->_error), OUTCOME_ADDRESS_OF(o._error));
this->_status = o._status;
return *this;
}
if(this->_status.have_error() && o._status.have_value())
{
if(!trait::is_move_bitcopying<error_type>::value || this->_status.have_moved_from())
{
this->_error.~_error_type_(); // NOLINT
}
copy_assign_to_empty<_value_type_>(OUTCOME_ADDRESS_OF(this->_value), OUTCOME_ADDRESS_OF(o._value));
this->_status = o._status;
return *this;
}
// Should never reach here
make_ub(this->_value);
}
};
#ifdef _MSC_VER
#pragma warning(pop)
#endif
// is_trivially_copyable is true even if type is not copyable, so handle that here
template <class T> struct is_storage_trivial
{
static constexpr bool value = std::is_void<T>::value || (std::is_trivially_copy_constructible<T>::value && std::is_trivially_copyable<T>::value);
};
// work around libstdc++ 7 bug
template <> struct is_storage_trivial<void>
{
static constexpr bool value = true;
};
template <> struct is_storage_trivial<const void>
{
static constexpr bool value = true;
};
// Ability to do copy assigns needs more than just copy assignment
template <class T> struct is_copy_assignable
{
static constexpr bool value = std::is_copy_assignable<T>::value && (std::is_copy_constructible<T>::value || std::is_default_constructible<T>::value);
};
// Ability to do move assigns needs more than just move assignment
template <class T> struct is_move_assignable
{
static constexpr bool value = std::is_move_assignable<T>::value && (std::is_move_constructible<T>::value || std::is_default_constructible<T>::value);
};
template <class T, class E>
using value_storage_select_trivality =
std::conditional_t<is_storage_trivial<T>::value && is_storage_trivial<E>::value, value_storage_trivial<T, E>, value_storage_nontrivial<T, E>>;
template <class T, class E>
using value_storage_select_move_constructor =
std::conditional_t<std::is_move_constructible<devoid<T>>::value && std::is_move_constructible<devoid<E>>::value, value_storage_select_trivality<T, E>,
value_storage_delete_move_constructor<value_storage_select_trivality<T, E>>>;
template <class T, class E>
using value_storage_select_copy_constructor =
std::conditional_t<std::is_copy_constructible<devoid<T>>::value && std::is_copy_constructible<devoid<E>>::value, value_storage_select_move_constructor<T, E>,
value_storage_delete_copy_constructor<value_storage_select_move_constructor<T, E>>>;
template <class T, class E>
using value_storage_select_move_assignment =
std::conditional_t<std::is_trivially_move_assignable<devoid<T>>::value && std::is_trivially_move_assignable<devoid<E>>::value,
value_storage_select_copy_constructor<T, E>,
std::conditional_t<is_move_assignable<devoid<T>>::value && is_move_assignable<devoid<E>>::value,
value_storage_nontrivial_move_assignment<value_storage_select_copy_constructor<T, E>>,
value_storage_delete_move_assignment<value_storage_select_copy_constructor<T, E>>>>;
template <class T, class E>
using value_storage_select_copy_assignment =
std::conditional_t<std::is_trivially_copy_assignable<devoid<T>>::value && std::is_trivially_copy_assignable<devoid<E>>::value,
value_storage_select_move_assignment<T, E>,
std::conditional_t<is_copy_assignable<devoid<T>>::value && is_copy_assignable<devoid<E>>::value,
value_storage_nontrivial_copy_assignment<value_storage_select_move_assignment<T, E>>,
value_storage_delete_copy_assignment<value_storage_select_move_assignment<T, E>>>>;
template <class T, class E> using value_storage_select_impl = value_storage_select_copy_assignment<T, E>;
#ifndef NDEBUG
// Check is trivial in all ways except default constructibility
// static_assert(std::is_trivial<value_storage_select_impl<int, long>>::value, "value_storage_select_impl<int, long> is not trivial!");
// static_assert(std::is_trivially_default_constructible<value_storage_select_impl<int, long>>::value, "value_storage_select_impl<int, long> is not
// trivially default constructible!");
static_assert(std::is_trivially_copyable<value_storage_select_impl<int, long>>::value, "value_storage_select_impl<int, long> is not trivially copyable!");
static_assert(std::is_trivially_assignable<value_storage_select_impl<int, long>, value_storage_select_impl<int, long>>::value,
"value_storage_select_impl<int, long> is not trivially assignable!");
static_assert(std::is_trivially_destructible<value_storage_select_impl<int, long>>::value,
"value_storage_select_impl<int, long> is not trivially destructible!");
static_assert(std::is_trivially_copy_constructible<value_storage_select_impl<int, long>>::value,
"value_storage_select_impl<int, long> is not trivially copy constructible!");
static_assert(std::is_trivially_move_constructible<value_storage_select_impl<int, long>>::value,
"value_storage_select_impl<int, long> is not trivially move constructible!");
static_assert(std::is_trivially_copy_assignable<value_storage_select_impl<int, long>>::value,
"value_storage_select_impl<int, long> is not trivially copy assignable!");
static_assert(std::is_trivially_move_assignable<value_storage_select_impl<int, long>>::value,
"value_storage_select_impl<int, long> is not trivially move assignable!");
// Also check is standard layout
static_assert(std::is_standard_layout<value_storage_select_impl<int, long>>::value, "value_storage_select_impl<int, long> is not a standard layout type!");
#endif
} // namespace detail
OUTCOME_V2_NAMESPACE_END
#endif
OUTCOME_V2_NAMESPACE_EXPORT_BEGIN
namespace detail
{
template <class R, class EC, class NoValuePolicy> class basic_result_storage;
} // namespace detail
namespace hooks
{
template <class R, class S, class NoValuePolicy> constexpr inline uint16_t spare_storage(const detail::basic_result_storage<R, S, NoValuePolicy> *r) noexcept;
template <class R, class S, class NoValuePolicy>
constexpr inline void set_spare_storage(detail::basic_result_storage<R, S, NoValuePolicy> *r, uint16_t v) noexcept;
} // namespace hooks
namespace policy
{
struct base;
} // namespace policy
namespace detail
{
template <class R, class EC, class NoValuePolicy> //
class basic_result_storage
{
static_assert(trait::type_can_be_used_in_basic_result<R>, "The type R cannot be used in a basic_result");
static_assert(trait::type_can_be_used_in_basic_result<EC>, "The type S cannot be used in a basic_result");
friend struct policy::base;
template <class T, class U, class V> //
friend class basic_result_storage;
template <class T, class U, class V> friend class basic_result_final;
template <class T, class U, class V>
friend constexpr inline uint16_t hooks::spare_storage(const detail::basic_result_storage<T, U, V> *r) noexcept; // NOLINT
template <class T, class U, class V>
friend constexpr inline void hooks::set_spare_storage(detail::basic_result_storage<T, U, V> *r, uint16_t v) noexcept; // NOLINT
struct disable_in_place_value_type
{
};
struct disable_in_place_error_type
{
};
protected:
using _value_type = std::conditional_t<std::is_same<R, EC>::value, disable_in_place_value_type, R>;
using _error_type = std::conditional_t<std::is_same<R, EC>::value, disable_in_place_error_type, EC>;
using _state_type = value_storage_select_impl<_value_type, _error_type>;
_state_type _state;
public:
// Used by iostream support to access state
_state_type &_iostreams_state() { return _state; }
const _state_type &_iostreams_state() const { return _state; }
protected:
basic_result_storage() = default;
basic_result_storage(const basic_result_storage &) = default; // NOLINT
basic_result_storage(basic_result_storage &&) = default; // NOLINT
basic_result_storage &operator=(const basic_result_storage &) = default; // NOLINT
basic_result_storage &operator=(basic_result_storage &&) = default; // NOLINT
~basic_result_storage() = default;
template <class... Args>
constexpr explicit basic_result_storage(in_place_type_t<_value_type> _,
Args &&... args) noexcept(detail::is_nothrow_constructible<_value_type, Args...>)
: _state{_, static_cast<Args &&>(args)...}
{
}
template <class U, class... Args>
constexpr basic_result_storage(in_place_type_t<_value_type> _, std::initializer_list<U> il,
Args &&... args) noexcept(detail::is_nothrow_constructible<_value_type, std::initializer_list<U>, Args...>)
: _state{_, il, static_cast<Args &&>(args)...}
{
}
template <class... Args>
constexpr explicit basic_result_storage(in_place_type_t<_error_type> _,
Args &&... args) noexcept(detail::is_nothrow_constructible<_error_type, Args...>)
: _state{_, static_cast<Args &&>(args)...}
{
}
template <class U, class... Args>
constexpr basic_result_storage(in_place_type_t<_error_type> _, std::initializer_list<U> il,
Args &&... args) noexcept(detail::is_nothrow_constructible<_error_type, std::initializer_list<U>, Args...>)
: _state{_, il, static_cast<Args &&>(args)...}
{
}
struct compatible_conversion_tag
{
};
template <class T, class U, class V>
constexpr basic_result_storage(compatible_conversion_tag /*unused*/, const basic_result_storage<T, U, V> &o) noexcept(
detail::is_nothrow_constructible<_value_type, T> &&detail::is_nothrow_constructible<_error_type, U>)
: _state(o._state)
{
}
template <class T, class U, class V>
constexpr basic_result_storage(compatible_conversion_tag /*unused*/, basic_result_storage<T, U, V> &&o) noexcept(
detail::is_nothrow_constructible<_value_type, T> &&detail::is_nothrow_constructible<_error_type, U>)
: _state(static_cast<decltype(o._state) &&>(o._state))
{
}
struct make_error_code_compatible_conversion_tag
{
};
template <class T, class U, class V>
constexpr basic_result_storage(make_error_code_compatible_conversion_tag /*unused*/, const basic_result_storage<T, U, V> &o) noexcept(
detail::is_nothrow_constructible<_value_type, T> &&noexcept(make_error_code(std::declval<U>())))
: _state(o._state._status.have_value() ? _state_type(in_place_type<_value_type>, o._state._value) :
_state_type(in_place_type<_error_type>, make_error_code(o._state._error)))
{
}
template <class T, class U, class V>
constexpr basic_result_storage(make_error_code_compatible_conversion_tag /*unused*/, basic_result_storage<T, U, V> &&o) noexcept(
detail::is_nothrow_constructible<_value_type, T> &&noexcept(make_error_code(std::declval<U>())))
: _state(o._state._status.have_value() ? _state_type(in_place_type<_value_type>, static_cast<T &&>(o._state._value)) :
_state_type(in_place_type<_error_type>, make_error_code(static_cast<U &&>(o._state._error))))
{
}
struct make_exception_ptr_compatible_conversion_tag
{
};
template <class T, class U, class V>
constexpr basic_result_storage(make_exception_ptr_compatible_conversion_tag /*unused*/, const basic_result_storage<T, U, V> &o) noexcept(
detail::is_nothrow_constructible<_value_type, T> &&noexcept(make_exception_ptr(std::declval<U>())))
: _state(o._state._status.have_value() ? _state_type(in_place_type<_value_type>, o._state._value) :
_state_type(in_place_type<_error_type>, make_exception_ptr(o._state._error)))
{
}
template <class T, class U, class V>
constexpr basic_result_storage(make_exception_ptr_compatible_conversion_tag /*unused*/, basic_result_storage<T, U, V> &&o) noexcept(
detail::is_nothrow_constructible<_value_type, T> &&noexcept(make_exception_ptr(std::declval<U>())))
: _state(o._state._status.have_value() ? _state_type(in_place_type<_value_type>, static_cast<T &&>(o._state._value)) :
_state_type(in_place_type<_error_type>, make_exception_ptr(static_cast<U &&>(o._state._error))))
{
}
};
} // namespace detail
OUTCOME_V2_NAMESPACE_END
#endif
OUTCOME_V2_NAMESPACE_EXPORT_BEGIN
namespace concepts
{
#if defined(__cpp_concepts)
#if (defined(_MSC_VER) || defined(__clang__) || (defined(__GNUC__) && __cpp_concepts >= 201707) || OUTCOME_FORCE_STD_CXX_CONCEPTS) && !OUTCOME_FORCE_LEGACY_GCC_CXX_CONCEPTS
#define OUTCOME_GCC6_CONCEPT_BOOL
#else
#ifndef OUTCOME_SUPPRESS_LEGACY_CONCEPTS_WARNING
#warning "WARNING: Legacy GCC concepts are known to fail to compile in a number of important situations!"
#endif
#define OUTCOME_GCC6_CONCEPT_BOOL bool
#endif
namespace detail
{
template <class T, class U>
concept OUTCOME_GCC6_CONCEPT_BOOL SameHelper = std::is_same<T, U>::value;
template <class T, class U>
concept OUTCOME_GCC6_CONCEPT_BOOL same_as = detail::SameHelper<T, U> && detail::SameHelper<U, T>;
template <class T, class U>
concept OUTCOME_GCC6_CONCEPT_BOOL convertible = std::is_convertible<T, U>::value;
template <class T, class U>
concept OUTCOME_GCC6_CONCEPT_BOOL base_of = std::is_base_of<T, U>::value;
} // namespace detail
/* The `value_or_none` concept.
\requires That `U::value_type` exists and that `std::declval<U>().has_value()` returns a `bool` and `std::declval<U>().value()` exists.
*/
template <class U>
concept OUTCOME_GCC6_CONCEPT_BOOL value_or_none = requires(U a) {
{
a.has_value()
} -> detail::same_as<bool>;
{
a.value()
};
};
/* The `value_or_error` concept.
\requires That `U::value_type` and `U::error_type` exist;
that `std::declval<U>().has_value()` returns a `bool`, `std::declval<U>().value()` and `std::declval<U>().error()` exists.
*/
template <class U>
concept OUTCOME_GCC6_CONCEPT_BOOL value_or_error = requires(U a) {
{
a.has_value()
} -> detail::same_as<bool>;
{
a.value()
};
{
a.error()
};
};
#else
namespace detail
{
struct no_match
{
};
inline no_match match_value_or_none(...);
inline no_match match_value_or_error(...);
OUTCOME_TEMPLATE(class U)
OUTCOME_TREQUIRES(OUTCOME_TEXPR(std::declval<U>().has_value()), OUTCOME_TEXPR(std::declval<U>().value()))
inline U match_value_or_none(U &&);
OUTCOME_TEMPLATE(class U)
OUTCOME_TREQUIRES(OUTCOME_TEXPR(std::declval<U>().has_value()), OUTCOME_TEXPR(std::declval<U>().value()), OUTCOME_TEXPR(std::declval<U>().error()))
inline U match_value_or_error(U &&);
template <class U>
static constexpr bool value_or_none =
!std::is_same<no_match, decltype(match_value_or_none(std::declval<OUTCOME_V2_NAMESPACE::detail::devoid<U>>()))>::value;
template <class U>
static constexpr bool value_or_error =
!std::is_same<no_match, decltype(match_value_or_error(std::declval<OUTCOME_V2_NAMESPACE::detail::devoid<U>>()))>::value;
} // namespace detail
/* The `value_or_none` concept.
\requires That `U::value_type` exists and that `std::declval<U>().has_value()` returns a `bool` and `std::declval<U>().value()` exists.
*/
template <class U> static constexpr bool value_or_none = detail::value_or_none<U>;
/* The `value_or_error` concept.
\requires That `U::value_type` and `U::error_type` exist;
that `std::declval<U>().has_value()` returns a `bool`, `std::declval<U>().value()` and `std::declval<U>().error()` exists.
*/
template <class U> static constexpr bool value_or_error = detail::value_or_error<U>;
#endif
} // namespace concepts
namespace convert
{
#if OUTCOME_ENABLE_LEGACY_SUPPORT_FOR < 220
#if defined(__cpp_concepts)
template <class U>
concept OUTCOME_GCC6_CONCEPT_BOOL ValueOrNone = concepts::value_or_none<U>;
template <class U>
concept OUTCOME_GCC6_CONCEPT_BOOL ValueOrError = concepts::value_or_error<U>;
#else
template <class U> static constexpr bool ValueOrNone = concepts::value_or_none<U>;
template <class U> static constexpr bool ValueOrError = concepts::value_or_error<U>;
#endif
#endif
namespace detail
{
template <class T, class X> struct make_type
{
template <class U> static constexpr T value(U &&v) { return T{in_place_type<typename T::value_type>, static_cast<U &&>(v).value()}; }
template <class U> static constexpr T error(U &&v) { return T{in_place_type<typename T::error_type>, static_cast<U &&>(v).error()}; }
static constexpr T error() { return T{in_place_type<typename T::error_type>}; }
};
template <class T> struct make_type<T, void>
{
template <class U> static constexpr T value(U && /*unused*/) { return T{in_place_type<typename T::value_type>}; }
template <class U> static constexpr T error(U && /*unused*/) { return T{in_place_type<typename T::error_type>}; }
static constexpr T error() { return T{in_place_type<typename T::error_type>}; }
};
} // namespace detail
/*! AWAITING HUGO JSON CONVERSION TOOL
type definition value_or_error. Potential doc page: NOT FOUND
*/
template <class T, class U> struct value_or_error
{
static constexpr bool enable_result_inputs = false;
static constexpr bool enable_outcome_inputs = false;
OUTCOME_TEMPLATE(class X)
OUTCOME_TREQUIRES(
OUTCOME_TPRED(std::is_same<U, std::decay_t<X>>::value //
&&concepts::value_or_error<U> //
&& (std::is_void<typename std::decay_t<X>::value_type>::value ||
OUTCOME_V2_NAMESPACE::detail::is_explicitly_constructible<typename T::value_type, typename std::decay_t<X>::value_type>) //
&&(std::is_void<typename std::decay_t<X>::error_type>::value ||
OUTCOME_V2_NAMESPACE::detail::is_explicitly_constructible<typename T::error_type, typename std::decay_t<X>::error_type>) ))
constexpr T operator()(X &&v)
{
return v.has_value() ? detail::make_type<T, typename T::value_type>::value(static_cast<X &&>(v)) :
detail::make_type<T, typename U::error_type>::error(static_cast<X &&>(v));
}
};
} // namespace convert
OUTCOME_V2_NAMESPACE_END
#endif
/* Finaliser for a very simple result type
(C) 2017-2019 Niall Douglas <http://www.nedproductions.biz/> (5 commits)
File Created: Oct 2017
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License in the accompanying file
Licence.txt or at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Distributed under the Boost Software License, Version 1.0.
(See accompanying file Licence.txt or copy at
http://www.boost.org/LICENSE_1_0.txt)
*/
#ifndef OUTCOME_BASIC_RESULT_FINAL_HPP
#define OUTCOME_BASIC_RESULT_FINAL_HPP
/* Error observers for a very simple basic_result type
(C) 2017-2019 Niall Douglas <http://www.nedproductions.biz/> (2 commits)
File Created: Oct 2017
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License in the accompanying file
Licence.txt or at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Distributed under the Boost Software License, Version 1.0.
(See accompanying file Licence.txt or copy at
http://www.boost.org/LICENSE_1_0.txt)
*/
#ifndef OUTCOME_BASIC_RESULT_ERROR_OBSERVERS_HPP
#define OUTCOME_BASIC_RESULT_ERROR_OBSERVERS_HPP
OUTCOME_V2_NAMESPACE_EXPORT_BEGIN
namespace detail
{
template <class Base, class EC, class NoValuePolicy> class basic_result_error_observers : public Base
{
public:
using error_type = EC;
using Base::Base;
constexpr error_type &assume_error() & noexcept
{
NoValuePolicy::narrow_error_check(static_cast<basic_result_error_observers &>(*this));
return this->_state._error;
}
constexpr const error_type &assume_error() const & noexcept
{
NoValuePolicy::narrow_error_check(static_cast<const basic_result_error_observers &>(*this));
return this->_state._error;
}
constexpr error_type &&assume_error() && noexcept
{
NoValuePolicy::narrow_error_check(static_cast<basic_result_error_observers &&>(*this));
return static_cast<error_type &&>(this->_state._error);
}
constexpr const error_type &&assume_error() const && noexcept
{
NoValuePolicy::narrow_error_check(static_cast<const basic_result_error_observers &&>(*this));
return static_cast<const error_type &&>(this->_state._error);
}
constexpr error_type &error() &
{
NoValuePolicy::wide_error_check(static_cast<basic_result_error_observers &>(*this));
return this->_state._error;
}
constexpr const error_type &error() const &
{
NoValuePolicy::wide_error_check(static_cast<const basic_result_error_observers &>(*this));
return this->_state._error;
}
constexpr error_type &&error() &&
{
NoValuePolicy::wide_error_check(static_cast<basic_result_error_observers &&>(*this));
return static_cast<error_type &&>(this->_state._error);
}
constexpr const error_type &&error() const &&
{
NoValuePolicy::wide_error_check(static_cast<const basic_result_error_observers &&>(*this));
return static_cast<const error_type &&>(this->_state._error);
}
};
template <class Base, class NoValuePolicy> class basic_result_error_observers<Base, void, NoValuePolicy> : public Base
{
public:
using Base::Base;
constexpr void assume_error() & noexcept { NoValuePolicy::narrow_error_check(static_cast<basic_result_error_observers &>(*this)); }
constexpr void assume_error() const & noexcept { NoValuePolicy::narrow_error_check(static_cast<const basic_result_error_observers &>(*this)); }
constexpr void assume_error() && noexcept { NoValuePolicy::narrow_error_check(static_cast<basic_result_error_observers &&>(*this)); }
constexpr void assume_error() const && noexcept { NoValuePolicy::narrow_error_check(static_cast<const basic_result_error_observers &&>(*this)); }
constexpr void error() & { NoValuePolicy::wide_error_check(static_cast<basic_result_error_observers &>(*this)); }
constexpr void error() const & { NoValuePolicy::wide_error_check(static_cast<const basic_result_error_observers &>(*this)); }
constexpr void error() && { NoValuePolicy::wide_error_check(static_cast<basic_result_error_observers &&>(*this)); }
constexpr void error() const && { NoValuePolicy::wide_error_check(static_cast<const basic_result_error_observers &&>(*this)); }
};
} // namespace detail
OUTCOME_V2_NAMESPACE_END
#endif
/* Value observers for a very simple basic_result type
(C) 2017-2019 Niall Douglas <http://www.nedproductions.biz/> (2 commits)
File Created: Oct 2017
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License in the accompanying file
Licence.txt or at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Distributed under the Boost Software License, Version 1.0.
(See accompanying file Licence.txt or copy at
http://www.boost.org/LICENSE_1_0.txt)
*/
#ifndef OUTCOME_RESULT_VALUE_OBSERVERS_HPP
#define OUTCOME_RESULT_VALUE_OBSERVERS_HPP
OUTCOME_V2_NAMESPACE_EXPORT_BEGIN
namespace detail
{
template <class Base, class R, class NoValuePolicy> class basic_result_value_observers : public Base
{
public:
using value_type = R;
using Base::Base;
constexpr value_type &assume_value() & noexcept
{
NoValuePolicy::narrow_value_check(static_cast<basic_result_value_observers &>(*this));
return this->_state._value; // NOLINT
}
constexpr const value_type &assume_value() const & noexcept
{
NoValuePolicy::narrow_value_check(static_cast<const basic_result_value_observers &>(*this));
return this->_state._value; // NOLINT
}
constexpr value_type &&assume_value() && noexcept
{
NoValuePolicy::narrow_value_check(static_cast<basic_result_value_observers &&>(*this));
return static_cast<value_type &&>(this->_state._value); // NOLINT
}
constexpr const value_type &&assume_value() const && noexcept
{
NoValuePolicy::narrow_value_check(static_cast<const basic_result_value_observers &&>(*this));
return static_cast<const value_type &&>(this->_state._value); // NOLINT
}
constexpr value_type &value() &
{
NoValuePolicy::wide_value_check(static_cast<basic_result_value_observers &>(*this));
return this->_state._value; // NOLINT
}
constexpr const value_type &value() const &
{
NoValuePolicy::wide_value_check(static_cast<const basic_result_value_observers &>(*this));
return this->_state._value; // NOLINT
}
constexpr value_type &&value() &&
{
NoValuePolicy::wide_value_check(static_cast<basic_result_value_observers &&>(*this));
return static_cast<value_type &&>(this->_state._value); // NOLINT
}
constexpr const value_type &&value() const &&
{
NoValuePolicy::wide_value_check(static_cast<const basic_result_value_observers &&>(*this));
return static_cast<const value_type &&>(this->_state._value); // NOLINT
}
};
template <class Base, class NoValuePolicy> class basic_result_value_observers<Base, void, NoValuePolicy> : public Base
{
public:
using Base::Base;
constexpr void assume_value() & noexcept { NoValuePolicy::narrow_value_check(static_cast<basic_result_value_observers &>(*this)); }
constexpr void assume_value() const & noexcept { NoValuePolicy::narrow_value_check(static_cast<const basic_result_value_observers &>(*this)); }
constexpr void assume_value() && noexcept { NoValuePolicy::narrow_value_check(static_cast<basic_result_value_observers &&>(*this)); }
constexpr void assume_value() const && noexcept { NoValuePolicy::narrow_value_check(static_cast<const basic_result_value_observers &&>(*this)); }
constexpr void value() & { NoValuePolicy::wide_value_check(static_cast<basic_result_value_observers &>(*this)); }
constexpr void value() const & { NoValuePolicy::wide_value_check(static_cast<const basic_result_value_observers &>(*this)); }
constexpr void value() && { NoValuePolicy::wide_value_check(static_cast<basic_result_value_observers &&>(*this)); }
constexpr void value() const && { NoValuePolicy::wide_value_check(static_cast<const basic_result_value_observers &&>(*this)); }
};
} // namespace detail
OUTCOME_V2_NAMESPACE_END
#endif
OUTCOME_V2_NAMESPACE_EXPORT_BEGIN
namespace detail
{
template <class R, class EC, class NoValuePolicy> using select_basic_result_impl = basic_result_error_observers<basic_result_value_observers<basic_result_storage<R, EC, NoValuePolicy>, R, NoValuePolicy>, EC, NoValuePolicy>;
template <class R, class S, class NoValuePolicy>
class basic_result_final
: public select_basic_result_impl<R, S, NoValuePolicy>
{
using base = select_basic_result_impl<R, S, NoValuePolicy>;
public:
using base::base;
constexpr explicit operator bool() const noexcept { return this->_state._status.have_value(); }
constexpr bool has_value() const noexcept { return this->_state._status.have_value(); }
constexpr bool has_error() const noexcept { return this->_state._status.have_error(); }
constexpr bool has_exception() const noexcept { return this->_state._status.have_exception(); }
constexpr bool has_lost_consistency() const noexcept { return this->_state._status.have_lost_consistency(); }
constexpr bool has_failure() const noexcept { return this->_state._status.have_error() || this->_state._status.have_exception(); }
OUTCOME_TEMPLATE(class T, class U, class V)
OUTCOME_TREQUIRES(OUTCOME_TEXPR(std::declval<detail::devoid<R>>() == std::declval<detail::devoid<T>>()), //
OUTCOME_TEXPR(std::declval<detail::devoid<S>>() == std::declval<detail::devoid<U>>()))
constexpr bool operator==(const basic_result_final<T, U, V> &o) const noexcept( //
noexcept(std::declval<detail::devoid<R>>() == std::declval<detail::devoid<T>>()) && noexcept(std::declval<detail::devoid<S>>() == std::declval<detail::devoid<U>>()))
{
if(this->_state._status.have_value() && o._state._status.have_value())
{
return this->_state._value == o._state._value; // NOLINT
}
if(this->_state._status.have_error() && o._state._status.have_error())
{
return this->_state._error == o._state._error;
}
return false;
}
OUTCOME_TEMPLATE(class T)
OUTCOME_TREQUIRES(OUTCOME_TEXPR(std::declval<R>() == std::declval<T>()))
constexpr bool operator==(const success_type<T> &o) const noexcept( //
noexcept(std::declval<R>() == std::declval<T>()))
{
if(this->_state._status.have_value())
{
return this->_state._value == o.value();
}
return false;
}
constexpr bool operator==(const success_type<void> &o) const noexcept
{
(void) o;
return this->_state._status.have_value();
}
OUTCOME_TEMPLATE(class T)
OUTCOME_TREQUIRES(OUTCOME_TEXPR(std::declval<S>() == std::declval<T>()))
constexpr bool operator==(const failure_type<T, void> &o) const noexcept( //
noexcept(std::declval<S>() == std::declval<T>()))
{
if(this->_state._status.have_error())
{
return this->_state._error == o.error();
}
return false;
}
OUTCOME_TEMPLATE(class T, class U, class V)
OUTCOME_TREQUIRES(OUTCOME_TEXPR(std::declval<detail::devoid<R>>() != std::declval<detail::devoid<T>>()), //
OUTCOME_TEXPR(std::declval<detail::devoid<S>>() != std::declval<detail::devoid<U>>()))
constexpr bool operator!=(const basic_result_final<T, U, V> &o) const noexcept( //
noexcept(std::declval<detail::devoid<R>>() != std::declval<detail::devoid<T>>()) && noexcept(std::declval<detail::devoid<S>>() != std::declval<detail::devoid<U>>()))
{
if(this->_state._status.have_value() && o._state._status.have_value())
{
return this->_state._value != o._state._value;
}
if(this->_state._status.have_error() && o._state._status.have_error())
{
return this->_state._error != o._state._error;
}
return true;
}
OUTCOME_TEMPLATE(class T)
OUTCOME_TREQUIRES(OUTCOME_TEXPR(std::declval<R>() != std::declval<T>()))
constexpr bool operator!=(const success_type<T> &o) const noexcept( //
noexcept(std::declval<R>() != std::declval<T>()))
{
if(this->_state._status.have_value())
{
return this->_state._value != o.value();
}
return false;
}
constexpr bool operator!=(const success_type<void> &o) const noexcept
{
(void) o;
return !this->_state._status.have_value();
}
OUTCOME_TEMPLATE(class T)
OUTCOME_TREQUIRES(OUTCOME_TEXPR(std::declval<S>() != std::declval<T>()))
constexpr bool operator!=(const failure_type<T, void> &o) const noexcept( //
noexcept(std::declval<S>() != std::declval<T>()))
{
if(this->_state._status.have_error())
{
return this->_state._error != o.error();
}
return true;
}
};
template <class T, class U, class V, class W> constexpr inline bool operator==(const success_type<W> &a, const basic_result_final<T, U, V> &b) noexcept(noexcept(b == a)) { return b == a; }
template <class T, class U, class V, class W> constexpr inline bool operator==(const failure_type<W, void> &a, const basic_result_final<T, U, V> &b) noexcept(noexcept(b == a)) { return b == a; }
template <class T, class U, class V, class W> constexpr inline bool operator!=(const success_type<W> &a, const basic_result_final<T, U, V> &b) noexcept(noexcept(b == a)) { return b != a; }
template <class T, class U, class V, class W> constexpr inline bool operator!=(const failure_type<W, void> &a, const basic_result_final<T, U, V> &b) noexcept(noexcept(b == a)) { return b != a; }
} // namespace detail
OUTCOME_V2_NAMESPACE_END
#endif
/* Inline GDB pretty printer for result
(C) 2024 Niall Douglas <http://www.nedproductions.biz/> (6 commits)
File Created: Jun 2024
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License in the accompanying file
Licence.txt or at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Distributed under the Boost Software License, Version 1.0.
(See accompanying file Licence.txt or copy at
http://www.boost.org/LICENSE_1_0.txt)
*/
#ifndef OUTCOME_INLINE_GDB_PRETTY_PRINTER_H
#define OUTCOME_INLINE_GDB_PRETTY_PRINTER_H
#ifndef OUTCOME_DISABLE_INLINE_GDB_PRETTY_PRINTERS
#if defined(__ELF__)
#ifdef __clang__
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Woverlength-strings"
#endif
__asm__(".pushsection \".debug_gdb_scripts\", \"MS\",@progbits,1\n"
".byte 4 /* Python Text */\n"
".ascii \"gdb.inlined-script\\n\"\n"
".ascii \"import gdb.printing\\n\"\n"
".ascii \"import os\\n\"\n"
".ascii \"def synthesise_gdb_value_from_string(s):\\n\"\n"
".ascii \" '''For when you want to return a synthetic string from children()'''\\n\"\n"
".ascii \" return gdb.Value(s + '\\0').cast(gdb.lookup_type('char').pointer())\\n\"\n"
".ascii \"class OutcomeBasicOutcomePrinter(object):\\n\"\n"
".ascii \" '''Print an outcome::basic_outcome<T> and outcome::basic_result<T>'''\\n\"\n"
".ascii \" def __init__(self, val):\\n\"\n"
".ascii \" self.val = val\\n\"\n"
".ascii \" def children(self):\\n\"\n"
".ascii \" if self.val['_state']['_status']['status_value'] & 1 == 1:\\n\"\n"
".ascii \" yield ('value', self.val['_state']['_value'])\\n\"\n"
".ascii \" if self.val['_state']['_status']['status_value'] & 2 == 2:\\n\"\n"
".ascii \" yield ('error', self.val['_state']['_error'])\\n\"\n"
".ascii \" if self.val['_state']['_status']['status_value'] & 4 == 4:\\n\"\n"
".ascii \" yield ('exception', self.val['_ptr'])\\n\"\n"
".ascii \" def display_hint(self):\\n\"\n"
".ascii \" return None\\n\"\n"
".ascii \" def to_string(self):\\n\"\n"
".ascii \" if self.val['_state']['_status']['status_value'] & 54 == 54:\\n\"\n"
".ascii \" return 'errored (errno, moved from) + exceptioned'\\n\"\n"
".ascii \" if self.val['_state']['_status']['status_value'] & 50 == 50:\\n\"\n"
".ascii \" return 'errored (errno, moved from)'\\n\"\n"
".ascii \" if self.val['_state']['_status']['status_value'] & 38 == 38:\\n\"\n"
".ascii \" return 'errored + exceptioned (moved from)'\\n\"\n"
".ascii \" if self.val['_state']['_status']['status_value'] & 36 == 36:\\n\"\n"
".ascii \" return 'exceptioned (moved from)'\\n\"\n"
".ascii \" if self.val['_state']['_status']['status_value'] & 35 == 35:\\n\"\n"
".ascii \" return 'errored (moved from)'\\n\"\n"
".ascii \" if self.val['_state']['_status']['status_value'] & 33 == 33:\\n\"\n"
".ascii \" return 'valued (moved from)'\\n\"\n"
".ascii \" if self.val['_state']['_status']['status_value'] & 22 == 22:\\n\"\n"
".ascii \" return 'errored (errno) + exceptioned'\\n\"\n"
".ascii \" if self.val['_state']['_status']['status_value'] & 18 == 18:\\n\"\n"
".ascii \" return 'errored (errno)'\\n\"\n"
".ascii \" if self.val['_state']['_status']['status_value'] & 6 == 6:\\n\"\n"
".ascii \" return 'errored + exceptioned'\\n\"\n"
".ascii \" if self.val['_state']['_status']['status_value'] & 4 == 4:\\n\"\n"
".ascii \" return 'exceptioned'\\n\"\n"
".ascii \" if self.val['_state']['_status']['status_value'] & 2 == 2:\\n\"\n"
".ascii \" return 'errored'\\n\"\n"
".ascii \" if self.val['_state']['_status']['status_value'] & 1 == 1:\\n\"\n"
".ascii \" return 'valued'\\n\"\n"
".ascii \" if self.val['_state']['_status']['status_value'] & 0xff == 0:\\n\"\n"
".ascii \" return 'empty'\\n\"\n"
".ascii \"class OutcomeCResultStatusPrinter(object):\\n\"\n"
".ascii \" '''Print a C result'''\\n\"\n"
".ascii \" def __init__(self, val):\\n\"\n"
".ascii \" self.val = val\\n\"\n"
".ascii \" def children(self):\\n\"\n"
".ascii \" if self.val['flags'] & 1 == 1:\\n\"\n"
".ascii \" yield ('value', self.val['value'])\\n\"\n"
".ascii \" if self.val['flags'] & 2 == 2:\\n\"\n"
".ascii \" yield ('error', self.val['error'])\\n\"\n"
".ascii \" def display_hint(self):\\n\"\n"
".ascii \" return None\\n\"\n"
".ascii \" def to_string(self):\\n\"\n"
".ascii \" if self.val['flags'] & 50 == 50:\\n\"\n"
".ascii \" return 'errored (errno, moved from)'\\n\"\n"
".ascii \" if self.val['flags'] & 35 == 35:\\n\"\n"
".ascii \" return 'errored (moved from)'\\n\"\n"
".ascii \" if self.val['flags'] & 33 == 33:\\n\"\n"
".ascii \" return 'valued (moved from)'\\n\"\n"
".ascii \" if self.val['flags'] & 18 == 18:\\n\"\n"
".ascii \" return 'errored (errno)'\\n\"\n"
".ascii \" if self.val['flags'] & 2 == 2:\\n\"\n"
".ascii \" return 'errored'\\n\"\n"
".ascii \" if self.val['flags'] & 1 == 1:\\n\"\n"
".ascii \" return 'valued'\\n\"\n"
".ascii \" if self.val['flags'] & 0xff == 0:\\n\"\n"
".ascii \" return 'empty'\\n\"\n"
".ascii \"class OutcomeCStatusCodePrinter(object):\\n\"\n"
".ascii \" '''Print a C status code'''\\n\"\n"
".ascii \" def __init__(self, val):\\n\"\n"
".ascii \" self.val = val\\n\"\n"
".ascii \" def children(self):\\n\"\n"
".ascii \" yield ('domain', self.val['domain'])\\n\"\n"
".ascii \" yield ('value', self.val['value'])\\n\"\n"
".ascii \" def display_hint(self):\\n\"\n"
".ascii \" return None\\n\"\n"
".ascii \" def to_string(self):\\n\"\n"
".ascii \" s = str(self.val['domain'])\\n\"\n"
".ascii \" if 'posix_code_domain' in s or 'generic_code_domain' in s:\\n\"\n"
".ascii \" return str(self.val['value']) + ' (' + os.strerror(int(self.val['value'])) + ')'\\n\"\n"
".ascii \" else:\\n\"\n"
".ascii \" return self.val['value']\\n\"\n"
".ascii \"def build_pretty_printer():\\n\"\n"
".ascii \" pp = gdb.printing.RegexpCollectionPrettyPrinter('outcome_v2')\\n\"\n"
".ascii \" pp.add_printer('outcome_v2::basic_result', '^(boost::)?outcome_v2[_0-9a-f]*::basic_result<.*>$', OutcomeBasicOutcomePrinter)\\n\"\n"
".ascii \" pp.add_printer('outcome_v2::basic_outcome', '^(boost::)?outcome_v2[_0-9a-f]*::basic_outcome<.*>$', OutcomeBasicOutcomePrinter)\\n\"\n"
".ascii \" pp.add_printer('cxx_result_status_code_*', '^cxx_result_status_code_.*$', OutcomeCResultStatusPrinter)\\n\"\n"
".ascii \" pp.add_printer('cxx_status_code_*', '^cxx_status_code_.*$', OutcomeCStatusCodePrinter)\\n\"\n"
".ascii \" return pp\\n\"\n"
".ascii \"def register_printers(obj = None):\\n\"\n"
".ascii \" gdb.printing.register_pretty_printer(obj, build_pretty_printer(), replace = True)\\n\"\n"
".ascii \"register_printers(gdb.current_objfile())\\n\"\n"
".byte 0\n"
".popsection\n");
#ifdef __clang__
#pragma clang diagnostic pop
#endif
#endif
#endif
#endif
/* Policies for result and outcome
(C) 2017-2019 Niall Douglas <http://www.nedproductions.biz/> (13 commits)
File Created: Oct 2017
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License in the accompanying file
Licence.txt or at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Distributed under the Boost Software License, Version 1.0.
(See accompanying file Licence.txt or copy at
http://www.boost.org/LICENSE_1_0.txt)
*/
#ifndef OUTCOME_POLICY_ALL_NARROW_HPP
#define OUTCOME_POLICY_ALL_NARROW_HPP
/* Policies for result and outcome
(C) 2017-2020 Niall Douglas <http://www.nedproductions.biz/> (6 commits) and Andrzej Krzemieński <[email protected]> (1 commit)
File Created: Oct 2017
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License in the accompanying file
Licence.txt or at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Distributed under the Boost Software License, Version 1.0.
(See accompanying file Licence.txt or copy at
http://www.boost.org/LICENSE_1_0.txt)
*/
#ifndef OUTCOME_POLICY_BASE_HPP
#define OUTCOME_POLICY_BASE_HPP
OUTCOME_V2_NAMESPACE_EXPORT_BEGIN
#if OUTCOME_ENABLE_LEGACY_SUPPORT_FOR < 220
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
namespace hooks
{
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
template <class T, class U> constexpr inline void hook_result_construction(T * /*unused*/, U && /*unused*/) noexcept {}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
template <class T, class U> constexpr inline void hook_result_copy_construction(T * /*unused*/, U && /*unused*/) noexcept {}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
template <class T, class U> constexpr inline void hook_result_move_construction(T * /*unused*/, U && /*unused*/) noexcept {}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
template <class T, class U, class... Args>
constexpr inline void hook_result_in_place_construction(T * /*unused*/, in_place_type_t<U> /*unused*/, Args &&... /*unused*/) noexcept
{
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
template <class T, class... U> constexpr inline void hook_outcome_construction(T * /*unused*/, U &&... /*unused*/) noexcept {}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
template <class T, class U> constexpr inline void hook_outcome_copy_construction(T * /*unused*/, U && /*unused*/) noexcept {}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
template <class T, class U> constexpr inline void hook_outcome_move_construction(T * /*unused*/, U && /*unused*/) noexcept {}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
template <class T, class U, class... Args>
constexpr inline void hook_outcome_in_place_construction(T * /*unused*/, in_place_type_t<U> /*unused*/, Args &&... /*unused*/) noexcept
{
}
} // namespace hooks
#endif
namespace policy
{
namespace detail
{
using OUTCOME_V2_NAMESPACE::detail::make_ub;
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
struct base
{
template <class... Args> static constexpr void _silence_unused(Args &&... /*unused*/) noexcept {}
protected:
template <class Impl> static constexpr void _make_ub(Impl &&self) noexcept { return detail::make_ub(static_cast<Impl &&>(self)); }
template <class Impl> static constexpr bool _has_value(Impl &&self) noexcept { return self._state._status.have_value(); }
template <class Impl> static constexpr bool _has_error(Impl &&self) noexcept { return self._state._status.have_error(); }
template <class Impl> static constexpr bool _has_exception(Impl &&self) noexcept { return self._state._status.have_exception(); }
template <class Impl> static constexpr bool _has_error_is_errno(Impl &&self) noexcept { return self._state._status.have_error_is_errno(); }
template <class Impl> static constexpr void _set_has_value(Impl &&self, bool v) noexcept { self._state._status.set_have_value(v); }
template <class Impl> static constexpr void _set_has_error(Impl &&self, bool v) noexcept { self._state._status.set_have_error(v); }
template <class Impl> static constexpr void _set_has_exception(Impl &&self, bool v) noexcept { self._state._status.set_have_exception(v); }
template <class Impl> static constexpr void _set_has_error_is_errno(Impl &&self, bool v) noexcept { self._state._status.set_have_error_is_errno(v); }
template <class Impl> static constexpr auto &&_value(Impl &&self) noexcept { return static_cast<Impl &&>(self)._state._value; }
template <class Impl> static constexpr auto &&_error(Impl &&self) noexcept { return static_cast<Impl &&>(self)._state._error; }
public:
template <class R, class S, class P, class NoValuePolicy, class Impl> static inline constexpr auto &&_exception(Impl &&self) noexcept;
template <class T, class U> static constexpr inline void on_result_construction(T *inst, U &&v) noexcept
{
#if OUTCOME_ENABLE_LEGACY_SUPPORT_FOR < 220
using namespace hooks;
hook_result_construction(inst, static_cast<U &&>(v));
#else
(void) inst;
(void) v;
#endif
}
template <class T, class U> static constexpr inline void on_result_copy_construction(T *inst, U &&v) noexcept
{
#if OUTCOME_ENABLE_LEGACY_SUPPORT_FOR < 220
using namespace hooks;
hook_result_copy_construction(inst, static_cast<U &&>(v));
#else
(void) inst;
(void) v;
#endif
}
template <class T, class U> static constexpr inline void on_result_move_construction(T *inst, U &&v) noexcept
{
#if OUTCOME_ENABLE_LEGACY_SUPPORT_FOR < 220
using namespace hooks;
hook_result_move_construction(inst, static_cast<U &&>(v));
#else
(void) inst;
(void) v;
#endif
}
template <class T, class U, class... Args>
static constexpr inline void on_result_in_place_construction(T *inst, in_place_type_t<U> _, Args &&... args) noexcept
{
#if OUTCOME_ENABLE_LEGACY_SUPPORT_FOR < 220
using namespace hooks;
hook_result_in_place_construction(inst, _, static_cast<Args &&>(args)...);
#else
(void) inst;
(void) _;
_silence_unused(static_cast<Args &&>(args)...);
#endif
}
template <class T, class... U> static constexpr inline void on_outcome_construction(T *inst, U &&... args) noexcept
{
#if OUTCOME_ENABLE_LEGACY_SUPPORT_FOR < 220
using namespace hooks;
hook_outcome_construction(inst, static_cast<U &&>(args)...);
#else
(void) inst;
_silence_unused(static_cast<U &&>(args)...);
#endif
}
template <class T, class U> static constexpr inline void on_outcome_copy_construction(T *inst, U &&v) noexcept
{
#if OUTCOME_ENABLE_LEGACY_SUPPORT_FOR < 220
using namespace hooks;
hook_outcome_copy_construction(inst, static_cast<U &&>(v));
#else
(void) inst;
(void) v;
#endif
}
template <class T, class U> static constexpr inline void on_outcome_move_construction(T *inst, U &&v) noexcept
{
#if OUTCOME_ENABLE_LEGACY_SUPPORT_FOR < 220
using namespace hooks;
hook_outcome_move_construction(inst, static_cast<U &&>(v));
#else
(void) inst;
(void) v;
#endif
}
template <class T, class U, class... Args>
static constexpr inline void on_outcome_in_place_construction(T *inst, in_place_type_t<U> _, Args &&... args) noexcept
{
#if OUTCOME_ENABLE_LEGACY_SUPPORT_FOR < 220
using namespace hooks;
hook_outcome_in_place_construction(inst, _, static_cast<Args &&>(args)...);
#else
(void) inst;
(void) _;
_silence_unused(static_cast<Args &&>(args)...);
#endif
}
template <class Impl> static constexpr void narrow_value_check(Impl &&self) noexcept
{
if(!_has_value(self))
{
_make_ub(self);
}
}
template <class Impl> static constexpr void narrow_error_check(Impl &&self) noexcept
{
if(!_has_error(self))
{
_make_ub(self);
}
}
template <class Impl> static constexpr void narrow_exception_check(Impl &&self) noexcept
{
if(!_has_exception(self))
{
_make_ub(self);
}
}
};
} // namespace policy
OUTCOME_V2_NAMESPACE_END
#endif
OUTCOME_V2_NAMESPACE_EXPORT_BEGIN
namespace policy
{
/*! AWAITING HUGO JSON CONVERSION TOOL
type definition all_narrow. Potential doc page: `all_narrow`
*/
struct all_narrow : base
{
template <class Impl> static constexpr void wide_value_check(Impl &&self) { base::narrow_value_check(static_cast<Impl &&>(self)); }
template <class Impl> static constexpr void wide_error_check(Impl &&self) { base::narrow_error_check(static_cast<Impl &&>(self)); }
template <class Impl> static constexpr void wide_exception_check(Impl &&self) { base::narrow_exception_check(static_cast<Impl &&>(self)); }
};
} // namespace policy
OUTCOME_V2_NAMESPACE_END
#endif
/* Policies for result and outcome
(C) 2017-2019 Niall Douglas <http://www.nedproductions.biz/> (12 commits)
File Created: Oct 2017
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License in the accompanying file
Licence.txt or at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Distributed under the Boost Software License, Version 1.0.
(See accompanying file Licence.txt or copy at
http://www.boost.org/LICENSE_1_0.txt)
*/
#ifndef OUTCOME_POLICY_TERMINATE_HPP
#define OUTCOME_POLICY_TERMINATE_HPP
#include <cstdlib>
OUTCOME_V2_NAMESPACE_EXPORT_BEGIN
namespace policy
{
/*! AWAITING HUGO JSON CONVERSION TOOL
type definition terminate. Potential doc page: `terminate`
*/
struct terminate : base
{
template <class Impl> static constexpr void wide_value_check(Impl &&self)
{
if(!base::_has_value(static_cast<Impl &&>(self)))
{
std::abort();
}
}
template <class Impl> static constexpr void wide_error_check(Impl &&self) noexcept
{
if(!base::_has_error(static_cast<Impl &&>(self)))
{
std::abort();
}
}
template <class Impl> static constexpr void wide_exception_check(Impl &&self)
{
if(!base::_has_exception(static_cast<Impl &&>(self)))
{
std::abort();
}
}
};
} // namespace policy
OUTCOME_V2_NAMESPACE_END
#endif
#ifdef __clang__
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdocumentation" // Standardese markup confuses clang
#endif
OUTCOME_V2_NAMESPACE_EXPORT_BEGIN
template <class R, class S, class NoValuePolicy> //
class basic_result;
namespace detail
{
// These are reused by basic_outcome to save load on the compiler
template <class value_type, class error_type> struct result_predicates
{
// Predicate for the implicit constructors to be available. Weakened to allow result<int, C enum>.
static constexpr bool implicit_constructors_enabled = //
!(trait::is_error_type<std::decay_t<value_type>>::value &&
trait::is_error_type<std::decay_t<error_type>>::value) // both value and error types are not whitelisted error types
&& ((!detail::is_implicitly_constructible<value_type, error_type> &&
!detail::is_implicitly_constructible<error_type, value_type>) // if value and error types cannot be constructed into one another
|| (trait::is_error_type<std::decay_t<error_type>>::value // if error type is a whitelisted error type
&& !detail::is_implicitly_constructible<error_type, value_type> // AND which cannot be constructed from the value type
&& std::is_integral<value_type>::value)); // AND the value type is some integral type
// Predicate for the value converting constructor to be available. Weakened to allow result<int, C enum>.
template <class T>
static constexpr bool enable_value_converting_constructor = //
implicit_constructors_enabled //
&& !is_in_place_type_t<std::decay_t<T>>::value // not in place construction
&& !trait::is_error_type_enum<error_type, std::decay_t<T>>::value // not an enum valid for my error type
&& ((detail::is_implicitly_constructible<value_type, T> && !detail::is_implicitly_constructible<error_type, T>) // is unambiguously for value type
|| (std::is_same<value_type, std::decay_t<T>>::value // OR is my value type exactly
&& detail::is_implicitly_constructible<value_type, T>) ); // and my value type is constructible from this ref form of T
// Predicate for the error converting constructor to be available. Weakened to allow result<int, C enum>.
template <class T>
static constexpr bool enable_error_converting_constructor = //
implicit_constructors_enabled //
&& !is_in_place_type_t<std::decay_t<T>>::value // not in place construction
&& !trait::is_error_type_enum<error_type, std::decay_t<T>>::value // not an enum valid for my error type
&& ((!detail::is_implicitly_constructible<value_type, T> && detail::is_implicitly_constructible<error_type, T>) // is unambiguously for error type
|| (std::is_same<error_type, std::decay_t<T>>::value // OR is my error type exactly
&& detail::is_implicitly_constructible<error_type, T>) ); // and my error type is constructible from this ref form of T
// Predicate for the error condition converting constructor to be available.
template <class ErrorCondEnum>
static constexpr bool enable_error_condition_converting_constructor = //
!is_in_place_type_t<std::decay_t<ErrorCondEnum>>::value // not in place construction
&& trait::is_error_type_enum<error_type, std::decay_t<ErrorCondEnum>>::value // is an error condition enum
/*&& !detail::is_implicitly_constructible<value_type, ErrorCondEnum> && !detail::is_implicitly_constructible<error_type, ErrorCondEnum>*/; // not
// constructible
// via any other
// means
// Predicate for the converting constructor from a compatible input to be available.
template <class T, class U, class V>
static constexpr bool enable_compatible_conversion = //
(std::is_void<T>::value ||
detail::is_explicitly_constructible<value_type, typename basic_result<T, U, V>::value_type>) // if our value types are constructible
&&(std::is_void<U>::value ||
detail::is_explicitly_constructible<error_type, typename basic_result<T, U, V>::error_type>) // if our error types are constructible
;
// Predicate for the converting constructor from a make_error_code() of the input to be available.
template <class T, class U, class V>
static constexpr bool enable_make_error_code_compatible_conversion = //
trait::is_error_code_available<std::decay_t<error_type>>::value // if error type has an error code
&& !enable_compatible_conversion<T, U, V> // and the normal compatible conversion is not available
&& (std::is_void<T>::value ||
detail::is_explicitly_constructible<value_type, typename basic_result<T, U, V>::value_type>) // and if our value types are constructible
&&detail::is_explicitly_constructible<error_type,
typename trait::is_error_code_available<U>::type>; // and our error type is constructible from a make_error_code()
// Predicate for the converting constructor from a make_exception_ptr() of the input to be available.
template <class T, class U, class V>
static constexpr bool enable_make_exception_ptr_compatible_conversion = //
trait::is_exception_ptr_available<std::decay_t<error_type>>::value // if error type has an exception ptr
&& !enable_compatible_conversion<T, U, V> // and the normal compatible conversion is not available
&& (std::is_void<T>::value ||
detail::is_explicitly_constructible<value_type, typename basic_result<T, U, V>::value_type>) // and if our value types are constructible
&&detail::is_explicitly_constructible<error_type, typename trait::is_exception_ptr_available<U>::type>; // and our error type is constructible from a
// make_exception_ptr()
// Predicate for the implicit converting inplace constructor from a compatible input to be available.
struct disable_inplace_value_error_constructor;
template <class... Args>
using choose_inplace_value_error_constructor = std::conditional_t< //
detail::is_constructible<value_type, Args...> && detail::is_constructible<error_type, Args...>, //
disable_inplace_value_error_constructor, //
std::conditional_t< //
detail::is_constructible<value_type, Args...>, //
value_type, //
std::conditional_t< //
detail::is_constructible<error_type, Args...>, //
error_type, //
disable_inplace_value_error_constructor>>>;
template <class... Args>
static constexpr bool enable_inplace_value_error_constructor =
implicit_constructors_enabled //
&& !std::is_same<choose_inplace_value_error_constructor<Args...>, disable_inplace_value_error_constructor>::value;
};
template <class T, class U> constexpr inline const U &extract_value_from_success(const success_type<U> &v)
{
return v.value();
}
template <class T, class U> constexpr inline U &&extract_value_from_success(success_type<U> &&v)
{
return static_cast<success_type<U> &&>(v).value();
}
template <class T> constexpr inline T extract_value_from_success(const success_type<void> & /*unused*/)
{
return T{};
}
template <class T, class U, class V> constexpr inline const U &extract_error_from_failure(const failure_type<U, V> &v)
{
return v.error();
}
template <class T, class U, class V> constexpr inline U &&extract_error_from_failure(failure_type<U, V> &&v)
{
return static_cast<failure_type<U, V> &&>(v).error();
}
template <class T, class V> constexpr inline T extract_error_from_failure(const failure_type<void, V> & /*unused*/)
{
return T{};
}
template <class T> struct is_basic_result
{
static constexpr bool value = false;
};
template <class R, class S, class T> struct is_basic_result<basic_result<R, S, T>>
{
static constexpr bool value = true;
};
} // namespace detail
/*! AWAITING HUGO JSON CONVERSION TOOL
type alias template <class T> is_basic_result. Potential doc page: `is_basic_result<T>`
*/
template <class T> using is_basic_result = detail::is_basic_result<std::decay_t<T>>;
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
template <class T> static constexpr bool is_basic_result_v = detail::is_basic_result<std::decay_t<T>>::value;
namespace concepts
{
#if defined(__cpp_concepts)
/* The `basic_result` concept.
\requires That `U` matches a `basic_result`.
*/
template <class U>
concept OUTCOME_GCC6_CONCEPT_BOOL basic_result =
OUTCOME_V2_NAMESPACE::is_basic_result<U>::value ||
(requires(U v) { OUTCOME_V2_NAMESPACE::basic_result<typename U::value_type, typename U::error_type, typename U::no_value_policy_type>(v); } && //
detail::convertible<U, OUTCOME_V2_NAMESPACE::basic_result<typename U::value_type, typename U::error_type, typename U::no_value_policy_type>> && //
detail::base_of<OUTCOME_V2_NAMESPACE::basic_result<typename U::value_type, typename U::error_type, typename U::no_value_policy_type>, U>);
#else
namespace detail
{
inline no_match match_basic_result(...);
template <class R, class S, class NVP, class T, //
typename = typename T::value_type, //
typename = typename T::error_type, //
typename = typename T::no_value_policy_type, //
typename std::enable_if_t<std::is_convertible<T, OUTCOME_V2_NAMESPACE::basic_result<R, S, NVP>>::value && //
std::is_base_of<OUTCOME_V2_NAMESPACE::basic_result<R, S, NVP>, T>::value,
bool> = true>
inline OUTCOME_V2_NAMESPACE::basic_result<R, S, NVP> match_basic_result(OUTCOME_V2_NAMESPACE::basic_result<R, S, NVP> &&, T &&);
template <class U>
static constexpr bool basic_result = OUTCOME_V2_NAMESPACE::is_basic_result<U>::value ||
!std::is_same<no_match, decltype(match_basic_result(std::declval<OUTCOME_V2_NAMESPACE::detail::devoid<U>>(),
std::declval<OUTCOME_V2_NAMESPACE::detail::devoid<U>>()))>::value;
} // namespace detail
/* The `basic_result` concept.
\requires That `U` matches a `basic_result`.
*/
template <class U> static constexpr bool basic_result = detail::basic_result<U>;
#endif
} // namespace concepts
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
namespace hooks
{
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
template <class R, class S, class NoValuePolicy> constexpr inline uint16_t spare_storage(const detail::basic_result_storage<R, S, NoValuePolicy> *r) noexcept
{
return r->_state._status.spare_storage_value;
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
template <class R, class S, class NoValuePolicy>
constexpr inline void set_spare_storage(detail::basic_result_storage<R, S, NoValuePolicy> *r, uint16_t v) noexcept
{
r->_state._status.spare_storage_value = v;
}
} // namespace hooks
/*! AWAITING HUGO JSON CONVERSION TOOL
type definition template <class R, class S, class NoValuePolicy> basic_result. Potential doc page: `basic_result<T, E, NoValuePolicy>`
*/
template <class R, class S, class NoValuePolicy> //
class OUTCOME_NODISCARD basic_result : public detail::basic_result_final<R, S, NoValuePolicy>
{
static_assert(trait::type_can_be_used_in_basic_result<R>, "The type R cannot be used in a basic_result");
static_assert(trait::type_can_be_used_in_basic_result<S>, "The type S cannot be used in a basic_result");
using base = detail::basic_result_final<R, S, NoValuePolicy>;
struct implicit_constructors_disabled_tag
{
};
struct value_converting_constructor_tag
{
};
struct error_converting_constructor_tag
{
};
struct error_condition_converting_constructor_tag
{
};
struct explicit_valueornone_converting_constructor_tag
{
};
struct explicit_valueorerror_converting_constructor_tag
{
};
struct explicit_compatible_copy_conversion_tag
{
};
struct explicit_compatible_move_conversion_tag
{
};
struct explicit_make_error_code_compatible_copy_conversion_tag
{
};
struct explicit_make_error_code_compatible_move_conversion_tag
{
};
struct explicit_make_exception_ptr_compatible_copy_conversion_tag
{
};
struct explicit_make_exception_ptr_compatible_move_conversion_tag
{
};
public:
using value_type = R;
using error_type = S;
using no_value_policy_type = NoValuePolicy;
using value_type_if_enabled = typename base::_value_type;
using error_type_if_enabled = typename base::_error_type;
template <class T, class U = S, class V = NoValuePolicy> using rebind = basic_result<T, U, V>;
protected:
// Requirement predicates for result.
struct predicate
{
using base = detail::result_predicates<value_type, error_type>;
// Predicate for any constructors to be available at all
static constexpr bool constructors_enabled = !std::is_same<std::decay_t<value_type>, std::decay_t<error_type>>::value;
// Predicate for implicit constructors to be available at all
static constexpr bool implicit_constructors_enabled = constructors_enabled && base::implicit_constructors_enabled;
// Predicate for the value converting constructor to be available.
template <class T>
static constexpr bool enable_value_converting_constructor = //
constructors_enabled //
&& !std::is_same<std::decay_t<T>, basic_result>::value // not my type
&& base::template enable_value_converting_constructor<T>;
// Predicate for the error converting constructor to be available.
template <class T>
static constexpr bool enable_error_converting_constructor = //
constructors_enabled //
&& !std::is_same<std::decay_t<T>, basic_result>::value // not my type
&& base::template enable_error_converting_constructor<T>;
// Predicate for the error condition converting constructor to be available.
template <class ErrorCondEnum>
static constexpr bool enable_error_condition_converting_constructor = //
constructors_enabled //
&& !std::is_same<std::decay_t<ErrorCondEnum>, basic_result>::value // not my type
&& base::template enable_error_condition_converting_constructor<ErrorCondEnum>;
// Predicate for the converting constructor from a compatible input to be available.
template <class T, class U, class V>
static constexpr bool enable_compatible_conversion = //
constructors_enabled //
&& !std::is_same<basic_result<T, U, V>, basic_result>::value // not my type
&& base::template enable_compatible_conversion<T, U, V>;
// Predicate for the converting constructor from a make_error_code() of the input to be available.
template <class T, class U, class V>
static constexpr bool enable_make_error_code_compatible_conversion = //
constructors_enabled //
&& !std::is_same<basic_result<T, U, V>, basic_result>::value // not my type
&& base::template enable_make_error_code_compatible_conversion<T, U, V>;
// Predicate for the converting constructor from a make_exception_ptr() of the input to be available.
template <class T, class U, class V>
static constexpr bool enable_make_exception_ptr_compatible_conversion = //
constructors_enabled //
&& !std::is_same<basic_result<T, U, V>, basic_result>::value // not my type
&& base::template enable_make_exception_ptr_compatible_conversion<T, U, V>;
// Predicate for the inplace construction of value to be available.
template <class... Args>
static constexpr bool enable_inplace_value_constructor = //
constructors_enabled //
&& (std::is_void<value_type>::value //
|| detail::is_constructible<value_type, Args...>);
// Predicate for the inplace construction of error to be available.
template <class... Args>
static constexpr bool enable_inplace_error_constructor = //
constructors_enabled //
&& (std::is_void<error_type>::value //
|| detail::is_constructible<error_type, Args...>);
// Predicate for the implicit converting inplace constructor to be available.
template <class... Args>
static constexpr bool enable_inplace_value_error_constructor = //
constructors_enabled //
&& base::template enable_inplace_value_error_constructor<Args...>;
template <class... Args> using choose_inplace_value_error_constructor = typename base::template choose_inplace_value_error_constructor<Args...>;
};
public:
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
basic_result() = delete;
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
basic_result(basic_result && /*unused*/) = default; // NOLINT
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
basic_result(const basic_result & /*unused*/) = default;
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
basic_result &operator=(basic_result && /*unused*/) = default; // NOLINT
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
basic_result &operator=(const basic_result & /*unused*/) = default;
~basic_result() = default;
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class Arg, class... Args)
OUTCOME_TREQUIRES(OUTCOME_TPRED(!predicate::constructors_enabled && (sizeof...(Args) >= 0)))
basic_result(Arg && /*unused*/, Args &&.../*unused*/) = delete; // NOLINT basic_result<T, T> is NOT SUPPORTED, see docs!
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class T)
OUTCOME_TREQUIRES(OUTCOME_TPRED((predicate::constructors_enabled && !predicate::implicit_constructors_enabled //
&& (detail::is_implicitly_constructible<value_type, T> || detail::is_implicitly_constructible<error_type, T>) )))
basic_result(T && /*unused*/, implicit_constructors_disabled_tag /*unused*/ = implicit_constructors_disabled_tag()) =
delete; // NOLINT Implicit constructors disabled, use explicit in_place_type<T>, success() or failure(). see docs!
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class T)
OUTCOME_TREQUIRES(OUTCOME_TPRED(predicate::template enable_value_converting_constructor<T>))
constexpr basic_result(T &&t, value_converting_constructor_tag /*unused*/ = value_converting_constructor_tag()) noexcept(
detail::is_nothrow_constructible<value_type, T>) // NOLINT
: base{in_place_type<typename base::value_type>, static_cast<T &&>(t)}
{
no_value_policy_type::on_result_construction(this, static_cast<T &&>(t));
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class T)
OUTCOME_TREQUIRES(OUTCOME_TPRED(predicate::template enable_error_converting_constructor<T>))
constexpr basic_result(T &&t, error_converting_constructor_tag /*unused*/ = error_converting_constructor_tag()) noexcept(
detail::is_nothrow_constructible<error_type, T>) // NOLINT
: base{in_place_type<typename base::error_type>, static_cast<T &&>(t)}
{
no_value_policy_type::on_result_construction(this, static_cast<T &&>(t));
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class ErrorCondEnum)
OUTCOME_TREQUIRES(OUTCOME_TEXPR(error_type(make_error_code(ErrorCondEnum()))), //
OUTCOME_TPRED(predicate::template enable_error_condition_converting_constructor<ErrorCondEnum>))
constexpr basic_result(ErrorCondEnum &&t, error_condition_converting_constructor_tag /*unused*/ = error_condition_converting_constructor_tag()) noexcept(
noexcept(error_type(make_error_code(static_cast<ErrorCondEnum &&>(t))))) // NOLINT
: base{in_place_type<typename base::error_type>, make_error_code(t)}
{
no_value_policy_type::on_result_construction(this, static_cast<ErrorCondEnum &&>(t));
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class T)
OUTCOME_TREQUIRES(OUTCOME_TPRED(convert::value_or_error<basic_result, std::decay_t<T>>::enable_result_inputs || !concepts::basic_result<T>), //
OUTCOME_TEXPR(convert::value_or_error<basic_result, std::decay_t<T>>{}(std::declval<T>())))
constexpr explicit basic_result(T &&o,
explicit_valueorerror_converting_constructor_tag /*unused*/ = explicit_valueorerror_converting_constructor_tag()) // NOLINT
: basic_result{convert::value_or_error<basic_result, std::decay_t<T>>{}(static_cast<T &&>(o))}
{
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class T, class U, class V)
OUTCOME_TREQUIRES(OUTCOME_TPRED(predicate::template enable_compatible_conversion<T, U, V>))
constexpr explicit basic_result(
const basic_result<T, U, V> &o,
explicit_compatible_copy_conversion_tag /*unused*/ = explicit_compatible_copy_conversion_tag()) noexcept(detail::is_nothrow_constructible<value_type, T> &&
detail::is_nothrow_constructible<error_type, U>)
: base{typename base::compatible_conversion_tag(), o}
{
no_value_policy_type::on_result_copy_construction(this, o);
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class T, class U, class V)
OUTCOME_TREQUIRES(OUTCOME_TPRED(predicate::template enable_compatible_conversion<T, U, V>))
constexpr explicit basic_result(
basic_result<T, U, V> &&o,
explicit_compatible_move_conversion_tag /*unused*/ = explicit_compatible_move_conversion_tag()) noexcept(detail::is_nothrow_constructible<value_type, T> &&
detail::is_nothrow_constructible<error_type, U>)
: base{typename base::compatible_conversion_tag(), static_cast<basic_result<T, U, V> &&>(o)}
{
no_value_policy_type::on_result_move_construction(this, static_cast<basic_result<T, U, V> &&>(o));
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class T, class U, class V)
OUTCOME_TREQUIRES(OUTCOME_TPRED(predicate::template enable_make_error_code_compatible_conversion<T, U, V>))
constexpr explicit basic_result(const basic_result<T, U, V> &o,
explicit_make_error_code_compatible_copy_conversion_tag /*unused*/ =
explicit_make_error_code_compatible_copy_conversion_tag()) noexcept(detail::is_nothrow_constructible<value_type, T> &&
noexcept(make_error_code(std::declval<U>())))
: base{typename base::make_error_code_compatible_conversion_tag(), o}
{
no_value_policy_type::on_result_copy_construction(this, o);
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class T, class U, class V)
OUTCOME_TREQUIRES(OUTCOME_TPRED(predicate::template enable_make_error_code_compatible_conversion<T, U, V>))
constexpr explicit basic_result(basic_result<T, U, V> &&o,
explicit_make_error_code_compatible_move_conversion_tag /*unused*/ =
explicit_make_error_code_compatible_move_conversion_tag()) noexcept(detail::is_nothrow_constructible<value_type, T> &&
noexcept(make_error_code(std::declval<U>())))
: base{typename base::make_error_code_compatible_conversion_tag(), static_cast<basic_result<T, U, V> &&>(o)}
{
no_value_policy_type::on_result_move_construction(this, static_cast<basic_result<T, U, V> &&>(o));
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class T, class U, class V)
OUTCOME_TREQUIRES(OUTCOME_TPRED(predicate::template enable_make_exception_ptr_compatible_conversion<T, U, V>))
constexpr explicit basic_result(const basic_result<T, U, V> &o,
explicit_make_exception_ptr_compatible_copy_conversion_tag /*unused*/ =
explicit_make_exception_ptr_compatible_copy_conversion_tag()) noexcept(detail::is_nothrow_constructible<value_type, T> &&
noexcept(make_exception_ptr(std::declval<U>())))
: base{typename base::make_exception_ptr_compatible_conversion_tag(), o}
{
no_value_policy_type::on_result_copy_construction(this, o);
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class T, class U, class V)
OUTCOME_TREQUIRES(OUTCOME_TPRED(predicate::template enable_make_exception_ptr_compatible_conversion<T, U, V>))
constexpr explicit basic_result(basic_result<T, U, V> &&o,
explicit_make_exception_ptr_compatible_move_conversion_tag /*unused*/ =
explicit_make_exception_ptr_compatible_move_conversion_tag()) noexcept(detail::is_nothrow_constructible<value_type, T> &&
noexcept(make_exception_ptr(std::declval<U>())))
: base{typename base::make_exception_ptr_compatible_conversion_tag(), static_cast<basic_result<T, U, V> &&>(o)}
{
no_value_policy_type::on_result_move_construction(this, static_cast<basic_result<T, U, V> &&>(o));
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class... Args)
OUTCOME_TREQUIRES(OUTCOME_TPRED(predicate::template enable_inplace_value_constructor<Args...>))
constexpr explicit basic_result(in_place_type_t<value_type_if_enabled> _, Args &&...args) noexcept(detail::is_nothrow_constructible<value_type, Args...>)
: base{_, static_cast<Args &&>(args)...}
{
no_value_policy_type::on_result_in_place_construction(this, in_place_type<value_type>, static_cast<Args &&>(args)...);
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class U, class... Args)
OUTCOME_TREQUIRES(OUTCOME_TPRED(predicate::template enable_inplace_value_constructor<std::initializer_list<U>, Args...>))
constexpr explicit basic_result(in_place_type_t<value_type_if_enabled> _, std::initializer_list<U> il,
Args &&...args) noexcept(detail::is_nothrow_constructible<value_type, std::initializer_list<U>, Args...>)
: base{_, il, static_cast<Args &&>(args)...}
{
no_value_policy_type::on_result_in_place_construction(this, in_place_type<value_type>, il, static_cast<Args &&>(args)...);
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class... Args)
OUTCOME_TREQUIRES(OUTCOME_TPRED(predicate::template enable_inplace_error_constructor<Args...>))
constexpr explicit basic_result(in_place_type_t<error_type_if_enabled> _, Args &&...args) noexcept(detail::is_nothrow_constructible<error_type, Args...>)
: base{_, static_cast<Args &&>(args)...}
{
no_value_policy_type::on_result_in_place_construction(this, in_place_type<error_type>, static_cast<Args &&>(args)...);
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class U, class... Args)
OUTCOME_TREQUIRES(OUTCOME_TPRED(predicate::template enable_inplace_error_constructor<std::initializer_list<U>, Args...>))
constexpr explicit basic_result(in_place_type_t<error_type_if_enabled> _, std::initializer_list<U> il,
Args &&...args) noexcept(detail::is_nothrow_constructible<error_type, std::initializer_list<U>, Args...>)
: base{_, il, static_cast<Args &&>(args)...}
{
no_value_policy_type::on_result_in_place_construction(this, in_place_type<error_type>, il, static_cast<Args &&>(args)...);
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class A1, class A2, class... Args)
OUTCOME_TREQUIRES(OUTCOME_TPRED(predicate::template enable_inplace_value_error_constructor<A1, A2, Args...>))
constexpr basic_result(A1 &&a1, A2 &&a2, Args &&...args) noexcept(noexcept(
typename predicate::template choose_inplace_value_error_constructor<A1, A2, Args...>(std::declval<A1>(), std::declval<A2>(), std::declval<Args>()...)))
: basic_result(in_place_type<typename predicate::template choose_inplace_value_error_constructor<A1, A2, Args...>>, static_cast<A1 &&>(a1),
static_cast<A2 &&>(a2), static_cast<Args &&>(args)...)
{
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
constexpr basic_result(const success_type<void> &o) noexcept(std::is_nothrow_default_constructible<value_type>::value) // NOLINT
: base{in_place_type<value_type_if_enabled>}
{
hooks::set_spare_storage(this, o.spare_storage());
no_value_policy_type::on_result_copy_construction(this, o);
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class T)
OUTCOME_TREQUIRES(OUTCOME_TPRED(predicate::template enable_compatible_conversion<T, void, void>))
constexpr basic_result(const success_type<T> &o) noexcept(detail::is_nothrow_constructible<value_type, T>) // NOLINT
: base{in_place_type<value_type_if_enabled>, detail::extract_value_from_success<value_type>(o)}
{
hooks::set_spare_storage(this, o.spare_storage());
no_value_policy_type::on_result_copy_construction(this, o);
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class T)
OUTCOME_TREQUIRES(OUTCOME_TPRED(!std::is_void<T>::value && predicate::template enable_compatible_conversion<T, void, void>))
constexpr basic_result(success_type<T> &&o) noexcept(detail::is_nothrow_constructible<value_type, T>) // NOLINT
: base{in_place_type<value_type_if_enabled>, detail::extract_value_from_success<value_type>(static_cast<success_type<T> &&>(o))}
{
hooks::set_spare_storage(this, o.spare_storage());
no_value_policy_type::on_result_move_construction(this, static_cast<success_type<T> &&>(o));
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class T)
OUTCOME_TREQUIRES(OUTCOME_TPRED(predicate::template enable_compatible_conversion<void, T, void>))
constexpr basic_result(const failure_type<T> &o, explicit_compatible_copy_conversion_tag /*unused*/ = explicit_compatible_copy_conversion_tag()) noexcept(
detail::is_nothrow_constructible<error_type, T>) // NOLINT
: base{in_place_type<error_type_if_enabled>, detail::extract_error_from_failure<error_type>(o)}
{
hooks::set_spare_storage(this, o.spare_storage());
no_value_policy_type::on_result_copy_construction(this, o);
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class T)
OUTCOME_TREQUIRES(OUTCOME_TPRED(predicate::template enable_compatible_conversion<void, T, void>))
constexpr basic_result(failure_type<T> &&o, explicit_compatible_move_conversion_tag /*unused*/ = explicit_compatible_move_conversion_tag()) noexcept(
detail::is_nothrow_constructible<error_type, T>) // NOLINT
: base{in_place_type<error_type_if_enabled>, detail::extract_error_from_failure<error_type>(static_cast<failure_type<T> &&>(o))}
{
hooks::set_spare_storage(this, o.spare_storage());
no_value_policy_type::on_result_move_construction(this, static_cast<failure_type<T> &&>(o));
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class T)
OUTCOME_TREQUIRES(OUTCOME_TPRED(predicate::template enable_make_error_code_compatible_conversion<void, T, void>))
constexpr basic_result(const failure_type<T> &o,
explicit_make_error_code_compatible_copy_conversion_tag /*unused*/ =
explicit_make_error_code_compatible_copy_conversion_tag()) noexcept(noexcept(make_error_code(std::declval<T>()))) // NOLINT
: base{in_place_type<error_type_if_enabled>, make_error_code(detail::extract_error_from_failure<error_type>(o))}
{
hooks::set_spare_storage(this, o.spare_storage());
no_value_policy_type::on_result_copy_construction(this, o);
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class T)
OUTCOME_TREQUIRES(OUTCOME_TPRED(predicate::template enable_make_error_code_compatible_conversion<void, T, void>))
constexpr basic_result(failure_type<T> &&o,
explicit_make_error_code_compatible_move_conversion_tag /*unused*/ =
explicit_make_error_code_compatible_move_conversion_tag()) noexcept(noexcept(make_error_code(std::declval<T>()))) // NOLINT
: base{in_place_type<error_type_if_enabled>, make_error_code(detail::extract_error_from_failure<error_type>(static_cast<failure_type<T> &&>(o)))}
{
hooks::set_spare_storage(this, o.spare_storage());
no_value_policy_type::on_result_move_construction(this, static_cast<failure_type<T> &&>(o));
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class T)
OUTCOME_TREQUIRES(OUTCOME_TPRED(predicate::template enable_make_exception_ptr_compatible_conversion<void, T, void>))
constexpr basic_result(const failure_type<T> &o,
explicit_make_exception_ptr_compatible_copy_conversion_tag /*unused*/ =
explicit_make_exception_ptr_compatible_copy_conversion_tag()) noexcept(noexcept(make_exception_ptr(std::declval<T>()))) // NOLINT
: base{in_place_type<error_type_if_enabled>, make_exception_ptr(detail::extract_error_from_failure<error_type>(o))}
{
hooks::set_spare_storage(this, o.spare_storage());
no_value_policy_type::on_result_copy_construction(this, o);
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class T)
OUTCOME_TREQUIRES(OUTCOME_TPRED(predicate::template enable_make_exception_ptr_compatible_conversion<void, T, void>))
constexpr basic_result(failure_type<T> &&o,
explicit_make_exception_ptr_compatible_move_conversion_tag /*unused*/ =
explicit_make_exception_ptr_compatible_move_conversion_tag()) noexcept(noexcept(make_exception_ptr(std::declval<T>()))) // NOLINT
: base{in_place_type<error_type_if_enabled>, make_exception_ptr(detail::extract_error_from_failure<error_type>(static_cast<failure_type<T> &&>(o)))}
{
hooks::set_spare_storage(this, o.spare_storage());
no_value_policy_type::on_result_move_construction(this, static_cast<failure_type<T> &&>(o));
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
constexpr void swap(basic_result &o) noexcept((std::is_void<value_type>::value || detail::is_nothrow_swappable<value_type>::value) //
&& (std::is_void<error_type>::value || detail::is_nothrow_swappable<error_type>::value))
{
this->_state.swap(o._state);
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
auto as_failure() const & { return failure(this->assume_error(), hooks::spare_storage(this)); }
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
auto as_failure() &&
{
this->_state._status.set_have_moved_from(true);
return failure(static_cast<basic_result &&>(*this).assume_error(), hooks::spare_storage(this));
}
#ifdef __APPLE__
failure_type<error_type> _xcode_workaround_as_failure() &&;
#endif
};
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
template <class R, class S, class P> inline void swap(basic_result<R, S, P> &a, basic_result<R, S, P> &b) noexcept(noexcept(a.swap(b)))
{
a.swap(b);
}
#if !defined(NDEBUG)
// Check is trivial in all ways except default constructibility
// static_assert(std::is_trivial<basic_result<int, long, policy::all_narrow>>::value, "result<int> is not trivial!");
// static_assert(std::is_trivially_default_constructible<basic_result<int, long, policy::all_narrow>>::value, "result<int> is not trivially default
// constructible!");
static_assert(std::is_trivially_copyable<basic_result<int, long, policy::all_narrow>>::value, "result<int> is not trivially copyable!");
static_assert(std::is_trivially_assignable<basic_result<int, long, policy::all_narrow>, basic_result<int, long, policy::all_narrow>>::value,
"result<int> is not trivially assignable!");
static_assert(std::is_trivially_destructible<basic_result<int, long, policy::all_narrow>>::value, "result<int> is not trivially destructible!");
static_assert(std::is_trivially_copy_constructible<basic_result<int, long, policy::all_narrow>>::value, "result<int> is not trivially copy constructible!");
static_assert(std::is_trivially_move_constructible<basic_result<int, long, policy::all_narrow>>::value, "result<int> is not trivially move constructible!");
static_assert(std::is_trivially_copy_assignable<basic_result<int, long, policy::all_narrow>>::value, "result<int> is not trivially copy assignable!");
static_assert(std::is_trivially_move_assignable<basic_result<int, long, policy::all_narrow>>::value, "result<int> is not trivially move assignable!");
// Also check is standard layout
static_assert(std::is_standard_layout<basic_result<int, long, policy::all_narrow>>::value, "result<int> is not a standard layout type!");
#endif
OUTCOME_V2_NAMESPACE_END
#ifdef __clang__
#pragma clang diagnostic pop
#endif
#endif
/* Exception observers for outcome type
(C) 2017-2019 Niall Douglas <http://www.nedproductions.biz/> (3 commits)
File Created: Oct 2017
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License in the accompanying file
Licence.txt or at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Distributed under the Boost Software License, Version 1.0.
(See accompanying file Licence.txt or copy at
http://www.boost.org/LICENSE_1_0.txt)
*/
#ifndef OUTCOME_BASIC_OUTCOME_EXCEPTION_OBSERVERS_HPP
#define OUTCOME_BASIC_OUTCOME_EXCEPTION_OBSERVERS_HPP
OUTCOME_V2_NAMESPACE_EXPORT_BEGIN
namespace detail
{
template <class Base, class R, class S, class P, class NoValuePolicy> class basic_outcome_exception_observers : public Base
{
public:
using exception_type = P;
using Base::Base;
constexpr inline exception_type &assume_exception() & noexcept;
constexpr inline const exception_type &assume_exception() const & noexcept;
constexpr inline exception_type &&assume_exception() && noexcept;
constexpr inline const exception_type &&assume_exception() const && noexcept;
constexpr inline exception_type &exception() &;
constexpr inline const exception_type &exception() const &;
constexpr inline exception_type &&exception() &&;
constexpr inline const exception_type &&exception() const &&;
};
// Exception observers not present
template <class Base, class R, class S, class NoValuePolicy> class basic_outcome_exception_observers<Base, R, S, void, NoValuePolicy> : public Base
{
public:
using Base::Base;
constexpr void assume_exception() & noexcept { NoValuePolicy::narrow_exception_check(*this); }
constexpr void assume_exception() const & noexcept { NoValuePolicy::narrow_exception_check(*this); }
constexpr void assume_exception() && noexcept { NoValuePolicy::narrow_exception_check(std::move(*this)); }
constexpr void assume_exception() const && noexcept { NoValuePolicy::narrow_exception_check(std::move(*this)); }
constexpr void exception() & { NoValuePolicy::wide_exception_check(*this); }
constexpr void exception() const & { NoValuePolicy::wide_exception_check(*this); }
constexpr void exception() && { NoValuePolicy::wide_exception_check(std::move(*this)); }
constexpr void exception() const && { NoValuePolicy::wide_exception_check(std::move(*this)); }
};
} // namespace detail
OUTCOME_V2_NAMESPACE_END
#endif
/* Failure observers for outcome type
(C) 2017-2019 Niall Douglas <http://www.nedproductions.biz/> (7 commits)
File Created: Oct 2017
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License in the accompanying file
Licence.txt or at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Distributed under the Boost Software License, Version 1.0.
(See accompanying file Licence.txt or copy at
http://www.boost.org/LICENSE_1_0.txt)
*/
#ifndef OUTCOME_BASIC_OUTCOME_FAILURE_OBSERVERS_HPP
#define OUTCOME_BASIC_OUTCOME_FAILURE_OBSERVERS_HPP
#include <exception>
OUTCOME_V2_NAMESPACE_EXPORT_BEGIN
namespace detail
{
namespace adl
{
struct search_detail_adl
{
};
// Do NOT use template requirements here!
template <class S, typename = decltype(basic_outcome_failure_exception_from_error(std::declval<S>()))>
inline auto _delayed_lookup_basic_outcome_failure_exception_from_error(const S &ec, search_detail_adl /*unused*/)
{
// ADL discovered
return basic_outcome_failure_exception_from_error(ec);
}
} // namespace adl
#if defined(_MSC_VER) && _MSC_VER <= 1923 // VS2019
// VS2017 and VS2019 with /permissive- chokes on the correct form due to over eager early instantiation.
template <class S, class P> inline void _delayed_lookup_basic_outcome_failure_exception_from_error(...) { static_assert(sizeof(S) == 0, "No specialisation for these error and exception types available!"); }
#else
template <class S, class P> inline void _delayed_lookup_basic_outcome_failure_exception_from_error(...) = delete; // NOLINT No specialisation for these error and exception types available!
#endif
template <class exception_type> inline exception_type current_exception_or_fatal(std::exception_ptr e) { std::rethrow_exception(e); }
template <> inline std::exception_ptr current_exception_or_fatal<std::exception_ptr>(std::exception_ptr e) { return e; }
template <class Base, class R, class S, class P, class NoValuePolicy> class basic_outcome_failure_observers : public Base
{
public:
using exception_type = P;
using Base::Base;
exception_type failure() const noexcept
{
#ifdef __cpp_exceptions
try
#endif
{
if(this->_state._status.have_exception())
{
return this->assume_exception();
}
if(this->_state._status.have_error())
{
return _delayed_lookup_basic_outcome_failure_exception_from_error(this->assume_error(), adl::search_detail_adl());
}
return exception_type();
}
#ifdef __cpp_exceptions
catch(...)
{
// Return the failure if exception_type is std::exception_ptr,
// otherwise terminate same as throwing an exception inside noexcept
return current_exception_or_fatal<exception_type>(std::current_exception());
}
#endif
}
};
} // namespace detail
OUTCOME_V2_NAMESPACE_END
#endif
#ifdef __clang__
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdocumentation" // Standardese markup confuses clang
#endif
OUTCOME_V2_NAMESPACE_EXPORT_BEGIN
template <class R, class S, class P, class NoValuePolicy> //
class basic_outcome;
namespace detail
{
// May be reused by basic_outcome subclasses to save load on the compiler
template <class value_type, class error_type, class exception_type> struct outcome_predicates
{
using result = result_predicates<value_type, error_type>;
// Predicate for the implicit constructors to be available
static constexpr bool implicit_constructors_enabled = //
result::implicit_constructors_enabled //
&& !detail::is_implicitly_constructible<value_type, exception_type> //
&& !detail::is_implicitly_constructible<error_type, exception_type> //
&& !detail::is_implicitly_constructible<exception_type, value_type> //
&& !detail::is_implicitly_constructible<exception_type, error_type>;
// Predicate for the value converting constructor to be available.
template <class T>
static constexpr bool enable_value_converting_constructor = //
implicit_constructors_enabled //
&& result::template enable_value_converting_constructor<T> //
&& !detail::is_implicitly_constructible<exception_type, T>; // deliberately less tolerant of ambiguity than result's edition
// Predicate for the error converting constructor to be available.
template <class T>
static constexpr bool enable_error_converting_constructor = //
implicit_constructors_enabled //
&& result::template enable_error_converting_constructor<T> //
&& !detail::is_implicitly_constructible<exception_type, T>; // deliberately less tolerant of ambiguity than result's edition
// Predicate for the error condition converting constructor to be available.
template <class ErrorCondEnum>
static constexpr bool enable_error_condition_converting_constructor = result::template enable_error_condition_converting_constructor<ErrorCondEnum> //
&& !detail::is_implicitly_constructible<exception_type, ErrorCondEnum>;
// Predicate for the exception converting constructor to be available.
template <class T>
static constexpr bool enable_exception_converting_constructor = //
implicit_constructors_enabled //
&& !is_in_place_type_t<std::decay_t<T>>::value // not in place construction
&& !detail::is_implicitly_constructible<value_type, T> && !detail::is_implicitly_constructible<error_type, T> &&
detail::is_implicitly_constructible<exception_type, T>;
// Predicate for the error + exception converting constructor to be available.
template <class T, class U>
static constexpr bool enable_error_exception_converting_constructor = //
implicit_constructors_enabled //
&& !is_in_place_type_t<std::decay_t<T>>::value // not in place construction
&& !detail::is_implicitly_constructible<value_type, T> && detail::is_implicitly_constructible<error_type, T> //
&& !detail::is_implicitly_constructible<value_type, U> && detail::is_implicitly_constructible<exception_type, U>;
// Predicate for the converting copy constructor from a compatible outcome to be available.
template <class T, class U, class V, class W>
static constexpr bool enable_compatible_conversion = //
(std::is_void<T>::value ||
detail::is_explicitly_constructible<value_type, typename basic_outcome<T, U, V, W>::value_type>) // if our value types are constructible
&&(std::is_void<U>::value ||
detail::is_explicitly_constructible<error_type, typename basic_outcome<T, U, V, W>::error_type>) // if our error types are constructible
&&(std::is_void<V>::value ||
detail::is_explicitly_constructible<exception_type, typename basic_outcome<T, U, V, W>::exception_type>) // if our exception types are constructible
;
// Predicate for the converting constructor from a make_error_code() of the input to be available.
template <class T, class U, class V, class W>
static constexpr bool enable_make_error_code_compatible_conversion = //
trait::is_error_code_available<std::decay_t<error_type>>::value // if error type has an error code
&& !enable_compatible_conversion<T, U, V, W> // and the normal compatible conversion is not available
&& (std::is_void<T>::value ||
detail::is_explicitly_constructible<value_type, typename basic_outcome<T, U, V, W>::value_type>) // and if our value types are constructible
&&detail::is_explicitly_constructible<error_type,
typename trait::is_error_code_available<U>::type> // and our error type is constructible from a make_error_code()
&& (std::is_void<V>::value ||
detail::is_explicitly_constructible<exception_type, typename basic_outcome<T, U, V, W>::exception_type>); // and our exception types are constructible
// Predicate for the implicit converting inplace constructor from a compatible input to be available.
struct disable_inplace_value_error_exception_constructor;
template <class... Args>
using choose_inplace_value_error_exception_constructor = std::conditional_t< //
((static_cast<int>(detail::is_constructible<value_type, Args...>) + static_cast<int>(detail::is_constructible<error_type, Args...>) +
static_cast<int>(detail::is_constructible<exception_type, Args...>)) > 1), //
disable_inplace_value_error_exception_constructor, //
std::conditional_t< //
detail::is_constructible<value_type, Args...>, //
value_type, //
std::conditional_t< //
detail::is_constructible<error_type, Args...>, //
error_type, //
std::conditional_t< //
detail::is_constructible<exception_type, Args...>, //
exception_type, //
disable_inplace_value_error_exception_constructor>>>>;
template <class... Args>
static constexpr bool enable_inplace_value_error_exception_constructor = //
implicit_constructors_enabled &&
!std::is_same<choose_inplace_value_error_exception_constructor<Args...>, disable_inplace_value_error_exception_constructor>::value;
};
// Select whether to use basic_outcome_failure_observers or not
template <class Base, class R, class S, class P, class NoValuePolicy>
using select_basic_outcome_failure_observers = //
std::conditional_t<trait::is_error_code_available<S>::value && trait::is_exception_ptr_available<P>::value,
basic_outcome_failure_observers<Base, R, S, P, NoValuePolicy>, Base>;
template <class T, class U, class V> constexpr inline const V &extract_exception_from_failure(const failure_type<U, V> &v)
{
return v.exception();
}
template <class T, class U, class V> constexpr inline V &&extract_exception_from_failure(failure_type<U, V> &&v)
{
return static_cast<failure_type<U, V> &&>(v).exception();
}
template <class T, class U> constexpr inline const U &extract_exception_from_failure(const failure_type<U, void> &v)
{
return v.error();
}
template <class T, class U> constexpr inline U &&extract_exception_from_failure(failure_type<U, void> &&v)
{
return static_cast<failure_type<U, void> &&>(v).error();
}
template <class T> struct is_basic_outcome
{
static constexpr bool value = false;
};
template <class R, class S, class T, class N> struct is_basic_outcome<basic_outcome<R, S, T, N>>
{
static constexpr bool value = true;
};
} // namespace detail
/*! AWAITING HUGO JSON CONVERSION TOOL
type alias template <class T> is_basic_outcome. Potential doc page: `is_basic_outcome<T>`
*/
template <class T> using is_basic_outcome = detail::is_basic_outcome<std::decay_t<T>>;
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
template <class T> static constexpr bool is_basic_outcome_v = detail::is_basic_outcome<std::decay_t<T>>::value;
namespace concepts
{
#if defined(__cpp_concepts)
/* The `basic_outcome` concept.
\requires That `U` matches a `basic_outcome`.
*/
template <class U>
concept OUTCOME_GCC6_CONCEPT_BOOL basic_outcome =
OUTCOME_V2_NAMESPACE::is_basic_outcome<U>::value ||
(requires(U v) {
OUTCOME_V2_NAMESPACE::basic_outcome<typename U::value_type, typename U::error_type, typename U::exception_type, typename U::no_value_policy_type>(v);
} && //
detail::convertible<
U, OUTCOME_V2_NAMESPACE::basic_outcome<typename U::value_type, typename U::error_type, typename U::exception_type, typename U::no_value_policy_type>> && //
detail::base_of<
OUTCOME_V2_NAMESPACE::basic_outcome<typename U::value_type, typename U::error_type, typename U::exception_type, typename U::no_value_policy_type>, U>);
#else
namespace detail
{
inline no_match match_basic_outcome(...);
template <class R, class S, class P, class NVP, class T, //
typename = typename T::value_type, //
typename = typename T::error_type, //
typename = typename T::exception_type, //
typename = typename T::no_value_policy_type, //
typename std::enable_if_t<std::is_convertible<T, OUTCOME_V2_NAMESPACE::basic_outcome<R, S, P, NVP>>::value && //
std::is_base_of<OUTCOME_V2_NAMESPACE::basic_outcome<R, S, P, NVP>, T>::value,
bool> = true>
inline OUTCOME_V2_NAMESPACE::basic_outcome<R, S, P, NVP> match_basic_outcome(OUTCOME_V2_NAMESPACE::basic_outcome<R, S, P, NVP> &&, T &&);
template <class U>
static constexpr bool basic_outcome =
OUTCOME_V2_NAMESPACE::is_basic_outcome<U>::value ||
!std::is_same<no_match, decltype(match_basic_outcome(std::declval<OUTCOME_V2_NAMESPACE::detail::devoid<U>>(),
std::declval<OUTCOME_V2_NAMESPACE::detail::devoid<U>>()))>::value;
} // namespace detail
/* The `basic_outcome` concept.
\requires That `U` matches a `basic_outcome`.
*/
template <class U> static constexpr bool basic_outcome = detail::basic_outcome<U>;
#endif
} // namespace concepts
namespace hooks
{
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
template <class R, class S, class P, class NoValuePolicy, class U>
constexpr inline void override_outcome_exception(basic_outcome<R, S, P, NoValuePolicy> *o, U &&v) noexcept;
} // namespace hooks
/*! AWAITING HUGO JSON CONVERSION TOOL
type definition template <class R, class S, class P, class NoValuePolicy> basic_outcome. Potential doc page: `basic_outcome<T, EC, EP, NoValuePolicy>`
*/
template <class R, class S, class P, class NoValuePolicy> //
class OUTCOME_NODISCARD basic_outcome
: public detail::select_basic_outcome_failure_observers<
detail::basic_outcome_exception_observers<detail::basic_result_final<R, S, NoValuePolicy>, R, S, P, NoValuePolicy>, R, S, P, NoValuePolicy>
{
static_assert(trait::type_can_be_used_in_basic_result<P>, "The exception_type cannot be used");
static_assert(std::is_void<P>::value || std::is_default_constructible<P>::value, "exception_type must be void or default constructible");
using base = detail::select_basic_outcome_failure_observers<
detail::basic_outcome_exception_observers<detail::basic_result_final<R, S, NoValuePolicy>, R, S, P, NoValuePolicy>, R, S, P, NoValuePolicy>;
friend struct policy::base;
template <class T, class U, class V, class W> //
friend class basic_outcome;
template <class T, class U, class V, class W, class X>
friend constexpr inline void hooks::override_outcome_exception(basic_outcome<T, U, V, W> *o, X &&v) noexcept; // NOLINT
struct implicit_constructors_disabled_tag
{
};
struct value_converting_constructor_tag
{
};
struct error_converting_constructor_tag
{
};
struct error_condition_converting_constructor_tag
{
};
struct exception_converting_constructor_tag
{
};
struct error_exception_converting_constructor_tag
{
};
struct explicit_valueorerror_converting_constructor_tag
{
};
struct explicit_compatible_copy_conversion_tag
{
};
struct explicit_compatible_move_conversion_tag
{
};
struct explicit_make_error_code_compatible_copy_conversion_tag
{
};
struct explicit_make_error_code_compatible_move_conversion_tag
{
};
struct error_failure_tag
{
};
struct exception_failure_tag
{
};
struct disable_in_place_value_type
{
};
struct disable_in_place_error_type
{
};
struct disable_in_place_exception_type
{
};
public:
using value_type = R;
using error_type = S;
using exception_type = P;
using no_value_policy_type = NoValuePolicy;
template <class T, class U = S, class V = P, class W = NoValuePolicy> using rebind = basic_outcome<T, U, V, W>;
protected:
// Requirement predicates for outcome.
struct predicate
{
using base = detail::outcome_predicates<value_type, error_type, exception_type>;
// Predicate for any constructors to be available at all
static constexpr bool constructors_enabled =
(!std::is_same<std::decay_t<value_type>, std::decay_t<error_type>>::value || (std::is_void<value_type>::value && std::is_void<error_type>::value)) //
&& (!std::is_same<std::decay_t<value_type>, std::decay_t<exception_type>>::value ||
(std::is_void<value_type>::value && std::is_void<exception_type>::value)) //
&& (!std::is_same<std::decay_t<error_type>, std::decay_t<exception_type>>::value ||
(std::is_void<error_type>::value && std::is_void<exception_type>::value)) //
;
// Predicate for implicit constructors to be available at all
static constexpr bool implicit_constructors_enabled = constructors_enabled && base::implicit_constructors_enabled;
// Predicate for the value converting constructor to be available.
template <class T>
static constexpr bool enable_value_converting_constructor = //
constructors_enabled //
&& !std::is_same<std::decay_t<T>, basic_outcome>::value // not my type
&& base::template enable_value_converting_constructor<T>;
// Predicate for the error converting constructor to be available.
template <class T>
static constexpr bool enable_error_converting_constructor = //
constructors_enabled //
&& !std::is_same<std::decay_t<T>, basic_outcome>::value // not my type
&& base::template enable_error_converting_constructor<T>;
// Predicate for the error condition converting constructor to be available.
template <class ErrorCondEnum>
static constexpr bool enable_error_condition_converting_constructor = //
constructors_enabled //
&& !std::is_same<std::decay_t<ErrorCondEnum>, basic_outcome>::value // not my type
&& base::template enable_error_condition_converting_constructor<ErrorCondEnum>;
// Predicate for the exception converting constructor to be available.
template <class T>
static constexpr bool enable_exception_converting_constructor = //
constructors_enabled //
&& !std::is_same<std::decay_t<T>, basic_outcome>::value // not my type
&& base::template enable_exception_converting_constructor<T>;
// Predicate for the error + exception converting constructor to be available.
template <class T, class U>
static constexpr bool enable_error_exception_converting_constructor = //
constructors_enabled //
&& !std::is_same<std::decay_t<T>, basic_outcome>::value // not my type
&& base::template enable_error_exception_converting_constructor<T, U>;
// Predicate for the converting constructor from a compatible input to be available.
template <class T, class U, class V, class W>
static constexpr bool enable_compatible_conversion = //
constructors_enabled //
&& !std::is_same<basic_outcome<T, U, V, W>, basic_outcome>::value // not my type
&& base::template enable_compatible_conversion<T, U, V, W>;
// Predicate for the converting constructor from a make_error_code() of the input to be available.
template <class T, class U, class V, class W>
static constexpr bool enable_make_error_code_compatible_conversion = //
constructors_enabled //
&& !std::is_same<basic_outcome<T, U, V, W>, basic_outcome>::value // not my type
&& base::template enable_make_error_code_compatible_conversion<T, U, V, W>;
// Predicate for the inplace construction of value to be available.
template <class... Args>
static constexpr bool enable_inplace_value_constructor = //
constructors_enabled //
&& (std::is_void<value_type>::value //
|| detail::is_constructible<value_type, Args...>);
// Predicate for the inplace construction of error to be available.
template <class... Args>
static constexpr bool enable_inplace_error_constructor = //
constructors_enabled //
&& (std::is_void<error_type>::value //
|| detail::is_constructible<error_type, Args...>);
// Predicate for the inplace construction of exception to be available.
template <class... Args>
static constexpr bool enable_inplace_exception_constructor = //
constructors_enabled //
&& (std::is_void<exception_type>::value //
|| detail::is_constructible<exception_type, Args...>);
// Predicate for the implicit converting inplace constructor to be available.
template <class... Args>
static constexpr bool enable_inplace_value_error_exception_constructor = //
constructors_enabled //
&& base::template enable_inplace_value_error_exception_constructor<Args...>;
template <class... Args>
using choose_inplace_value_error_exception_constructor = typename base::template choose_inplace_value_error_exception_constructor<Args...>;
};
public:
using value_type_if_enabled =
std::conditional_t<std::is_same<value_type, error_type>::value || std::is_same<value_type, exception_type>::value, disable_in_place_value_type, value_type>;
using error_type_if_enabled =
std::conditional_t<std::is_same<error_type, value_type>::value || std::is_same<error_type, exception_type>::value, disable_in_place_error_type, error_type>;
using exception_type_if_enabled = std::conditional_t<std::is_same<exception_type, value_type>::value || std::is_same<exception_type, error_type>::value,
disable_in_place_exception_type, exception_type>;
protected:
detail::devoid<exception_type> _ptr;
public:
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class Arg, class... Args)
OUTCOME_TREQUIRES(OUTCOME_TPRED((!predicate::constructors_enabled && sizeof...(Args) >= 0)))
basic_outcome(Arg && /*unused*/, Args &&.../*unused*/) = delete; // NOLINT basic_outcome<> with any of the same type is NOT SUPPORTED, see docs!
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class T)
OUTCOME_TREQUIRES(OUTCOME_TPRED((predicate::constructors_enabled && !predicate::implicit_constructors_enabled //
&& (detail::is_implicitly_constructible<value_type, T> || detail::is_implicitly_constructible<error_type, T> ||
detail::is_implicitly_constructible<exception_type, T>) )))
basic_outcome(T && /*unused*/, implicit_constructors_disabled_tag /*unused*/ = implicit_constructors_disabled_tag()) =
delete; // NOLINT Implicit constructors disabled, use explicit in_place_type<T>, success() or failure(). see docs!
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class T)
OUTCOME_TREQUIRES(OUTCOME_TPRED(predicate::template enable_value_converting_constructor<T>))
constexpr basic_outcome(T &&t, value_converting_constructor_tag /*unused*/ = value_converting_constructor_tag()) noexcept(
detail::is_nothrow_constructible<value_type, T>) // NOLINT
: base{in_place_type<typename base::_value_type>, static_cast<T &&>(t)}
, _ptr()
{
no_value_policy_type::on_outcome_construction(this, static_cast<T &&>(t));
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class T)
OUTCOME_TREQUIRES(OUTCOME_TPRED(predicate::template enable_error_converting_constructor<T>))
constexpr basic_outcome(T &&t, error_converting_constructor_tag /*unused*/ = error_converting_constructor_tag()) noexcept(
detail::is_nothrow_constructible<error_type, T>) // NOLINT
: base{in_place_type<typename base::_error_type>, static_cast<T &&>(t)}
, _ptr()
{
no_value_policy_type::on_outcome_construction(this, static_cast<T &&>(t));
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class ErrorCondEnum)
OUTCOME_TREQUIRES(OUTCOME_TEXPR(error_type(make_error_code(ErrorCondEnum()))), //
OUTCOME_TPRED(predicate::template enable_error_condition_converting_constructor<ErrorCondEnum>))
constexpr basic_outcome(ErrorCondEnum &&t, error_condition_converting_constructor_tag /*unused*/ = error_condition_converting_constructor_tag()) noexcept(
noexcept(error_type(make_error_code(static_cast<ErrorCondEnum &&>(t))))) // NOLINT
: base{in_place_type<typename base::_error_type>, make_error_code(t)}
{
no_value_policy_type::on_outcome_construction(this, static_cast<ErrorCondEnum &&>(t));
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class T)
OUTCOME_TREQUIRES(OUTCOME_TPRED(predicate::template enable_exception_converting_constructor<T>))
constexpr basic_outcome(T &&t, exception_converting_constructor_tag /*unused*/ = exception_converting_constructor_tag()) noexcept(
detail::is_nothrow_constructible<exception_type, T>) // NOLINT
: base()
, _ptr(static_cast<T &&>(t))
{
this->_state._status.set_have_exception(true);
no_value_policy_type::on_outcome_construction(this, static_cast<T &&>(t));
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class T, class U)
OUTCOME_TREQUIRES(OUTCOME_TPRED(predicate::template enable_error_exception_converting_constructor<T, U>))
constexpr basic_outcome(T &&a, U &&b, error_exception_converting_constructor_tag /*unused*/ = error_exception_converting_constructor_tag()) noexcept(
detail::is_nothrow_constructible<error_type, T> && detail::is_nothrow_constructible<exception_type, U>) // NOLINT
: base{in_place_type<typename base::_error_type>, static_cast<T &&>(a)}
, _ptr(static_cast<U &&>(b))
{
this->_state._status.set_have_exception(true);
no_value_policy_type::on_outcome_construction(this, static_cast<T &&>(a), static_cast<U &&>(b));
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class T)
OUTCOME_TREQUIRES(OUTCOME_TPRED(convert::value_or_error<basic_outcome, std::decay_t<T>>::enable_result_inputs || !concepts::basic_result<T>), //
OUTCOME_TPRED(convert::value_or_error<basic_outcome, std::decay_t<T>>::enable_outcome_inputs || !concepts::basic_outcome<T>), //
OUTCOME_TEXPR(convert::value_or_error<basic_outcome, std::decay_t<T>>{}(std::declval<T>())))
constexpr explicit basic_outcome(T &&o,
explicit_valueorerror_converting_constructor_tag /*unused*/ = explicit_valueorerror_converting_constructor_tag()) // NOLINT
: basic_outcome{convert::value_or_error<basic_outcome, std::decay_t<T>>{}(static_cast<T &&>(o))}
{
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class T, class U, class V, class W)
OUTCOME_TREQUIRES(OUTCOME_TPRED(predicate::template enable_compatible_conversion<T, U, V, W>))
constexpr explicit basic_outcome(
const basic_outcome<T, U, V, W> &o,
explicit_compatible_copy_conversion_tag /*unused*/ = explicit_compatible_copy_conversion_tag()) noexcept(detail::is_nothrow_constructible<value_type, T> &&
detail::is_nothrow_constructible<error_type, U> &&
detail::is_nothrow_constructible<exception_type, V>)
: base{typename base::compatible_conversion_tag(), o}
, _ptr(o._ptr)
{
no_value_policy_type::on_outcome_copy_construction(this, o);
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class T, class U, class V, class W)
OUTCOME_TREQUIRES(OUTCOME_TPRED(predicate::template enable_compatible_conversion<T, U, V, W>))
constexpr explicit basic_outcome(
basic_outcome<T, U, V, W> &&o,
explicit_compatible_move_conversion_tag /*unused*/ = explicit_compatible_move_conversion_tag()) noexcept(detail::is_nothrow_constructible<value_type, T> &&
detail::is_nothrow_constructible<error_type, U> &&
detail::is_nothrow_constructible<exception_type, V>)
: base{typename base::compatible_conversion_tag(), static_cast<basic_outcome<T, U, V, W> &&>(o)}
, _ptr(static_cast<typename basic_outcome<T, U, V, W>::exception_type &&>(o._ptr))
{
no_value_policy_type::on_outcome_move_construction(this, static_cast<basic_outcome<T, U, V, W> &&>(o));
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class T, class U, class V)
OUTCOME_TREQUIRES(OUTCOME_TPRED(detail::result_predicates<value_type, error_type>::template enable_compatible_conversion<T, U, V>))
constexpr explicit basic_outcome(
const basic_result<T, U, V> &o,
explicit_compatible_copy_conversion_tag /*unused*/ = explicit_compatible_copy_conversion_tag()) noexcept(detail::is_nothrow_constructible<value_type, T> &&
detail::is_nothrow_constructible<error_type, U> &&
detail::is_nothrow_constructible<exception_type>)
: base{typename base::compatible_conversion_tag(), o}
, _ptr()
{
no_value_policy_type::on_outcome_copy_construction(this, o);
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class T, class U, class V)
OUTCOME_TREQUIRES(OUTCOME_TPRED(detail::result_predicates<value_type, error_type>::template enable_compatible_conversion<T, U, V>))
constexpr explicit basic_outcome(
basic_result<T, U, V> &&o,
explicit_compatible_move_conversion_tag /*unused*/ = explicit_compatible_move_conversion_tag()) noexcept(detail::is_nothrow_constructible<value_type, T> &&
detail::is_nothrow_constructible<error_type, U> &&
detail::is_nothrow_constructible<exception_type>)
: base{typename base::compatible_conversion_tag(), static_cast<basic_result<T, U, V> &&>(o)}
, _ptr()
{
no_value_policy_type::on_outcome_move_construction(this, static_cast<basic_result<T, U, V> &&>(o));
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class T, class U, class V)
OUTCOME_TREQUIRES(OUTCOME_TPRED(detail::result_predicates<value_type, error_type>::template enable_make_error_code_compatible_conversion<T, U, V>))
constexpr explicit basic_outcome(const basic_result<T, U, V> &o,
explicit_make_error_code_compatible_copy_conversion_tag /*unused*/ =
explicit_make_error_code_compatible_copy_conversion_tag()) noexcept(detail::is_nothrow_constructible<value_type, T> &&
noexcept(make_error_code(std::declval<U>())) &&
detail::is_nothrow_constructible<exception_type>)
: base{typename base::make_error_code_compatible_conversion_tag(), o}
, _ptr()
{
no_value_policy_type::on_outcome_copy_construction(this, o);
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class T, class U, class V)
OUTCOME_TREQUIRES(OUTCOME_TPRED(detail::result_predicates<value_type, error_type>::template enable_make_error_code_compatible_conversion<T, U, V>))
constexpr explicit basic_outcome(basic_result<T, U, V> &&o,
explicit_make_error_code_compatible_move_conversion_tag /*unused*/ =
explicit_make_error_code_compatible_move_conversion_tag()) noexcept(detail::is_nothrow_constructible<value_type, T> &&
noexcept(make_error_code(std::declval<U>())) &&
detail::is_nothrow_constructible<exception_type>)
: base{typename base::make_error_code_compatible_conversion_tag(), static_cast<basic_result<T, U, V> &&>(o)}
, _ptr()
{
no_value_policy_type::on_outcome_move_construction(this, static_cast<basic_result<T, U, V> &&>(o));
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class... Args)
OUTCOME_TREQUIRES(OUTCOME_TPRED(predicate::template enable_inplace_value_constructor<Args...>))
constexpr explicit basic_outcome(in_place_type_t<value_type_if_enabled> _, Args &&...args) noexcept(detail::is_nothrow_constructible<value_type, Args...>)
: base{_, static_cast<Args &&>(args)...}
, _ptr()
{
no_value_policy_type::on_outcome_in_place_construction(this, in_place_type<value_type>, static_cast<Args &&>(args)...);
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class U, class... Args)
OUTCOME_TREQUIRES(OUTCOME_TPRED(predicate::template enable_inplace_value_constructor<std::initializer_list<U>, Args...>))
constexpr explicit basic_outcome(in_place_type_t<value_type_if_enabled> _, std::initializer_list<U> il,
Args &&...args) noexcept(detail::is_nothrow_constructible<value_type, std::initializer_list<U>, Args...>)
: base{_, il, static_cast<Args &&>(args)...}
, _ptr()
{
no_value_policy_type::on_outcome_in_place_construction(this, in_place_type<value_type>, il, static_cast<Args &&>(args)...);
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class... Args)
OUTCOME_TREQUIRES(OUTCOME_TPRED(predicate::template enable_inplace_error_constructor<Args...>))
constexpr explicit basic_outcome(in_place_type_t<error_type_if_enabled> _, Args &&...args) noexcept(detail::is_nothrow_constructible<error_type, Args...>)
: base{_, static_cast<Args &&>(args)...}
, _ptr()
{
no_value_policy_type::on_outcome_in_place_construction(this, in_place_type<error_type>, static_cast<Args &&>(args)...);
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class U, class... Args)
OUTCOME_TREQUIRES(OUTCOME_TPRED(predicate::template enable_inplace_error_constructor<std::initializer_list<U>, Args...>))
constexpr explicit basic_outcome(in_place_type_t<error_type_if_enabled> _, std::initializer_list<U> il,
Args &&...args) noexcept(detail::is_nothrow_constructible<error_type, std::initializer_list<U>, Args...>)
: base{_, il, static_cast<Args &&>(args)...}
, _ptr()
{
no_value_policy_type::on_outcome_in_place_construction(this, in_place_type<error_type>, il, static_cast<Args &&>(args)...);
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class... Args)
OUTCOME_TREQUIRES(OUTCOME_TPRED(predicate::template enable_inplace_exception_constructor<Args...>))
constexpr explicit basic_outcome(in_place_type_t<exception_type_if_enabled> /*unused*/,
Args &&...args) noexcept(detail::is_nothrow_constructible<exception_type, Args...>)
: base()
, _ptr(static_cast<Args &&>(args)...)
{
this->_state._status.set_have_exception(true);
no_value_policy_type::on_outcome_in_place_construction(this, in_place_type<exception_type>, static_cast<Args &&>(args)...);
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class U, class... Args)
OUTCOME_TREQUIRES(OUTCOME_TPRED(predicate::template enable_inplace_exception_constructor<std::initializer_list<U>, Args...>))
constexpr explicit basic_outcome(in_place_type_t<exception_type_if_enabled> /*unused*/, std::initializer_list<U> il,
Args &&...args) noexcept(detail::is_nothrow_constructible<exception_type, std::initializer_list<U>, Args...>)
: base()
, _ptr(il, static_cast<Args &&>(args)...)
{
this->_state._status.set_have_exception(true);
no_value_policy_type::on_outcome_in_place_construction(this, in_place_type<exception_type>, il, static_cast<Args &&>(args)...);
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class A1, class A2, class... Args)
OUTCOME_TREQUIRES(OUTCOME_TPRED(predicate::template enable_inplace_value_error_exception_constructor<A1, A2, Args...>))
constexpr basic_outcome(A1 &&a1, A2 &&a2, Args &&...args) noexcept(
noexcept(typename predicate::template choose_inplace_value_error_exception_constructor<A1, A2, Args...>(std::declval<A1>(), std::declval<A2>(),
std::declval<Args>()...)))
: basic_outcome(in_place_type<typename predicate::template choose_inplace_value_error_exception_constructor<A1, A2, Args...>>, static_cast<A1 &&>(a1),
static_cast<A2 &&>(a2), static_cast<Args &&>(args)...)
{
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
constexpr basic_outcome(const success_type<void> &o) noexcept(std::is_nothrow_default_constructible<value_type>::value) // NOLINT
: base{in_place_type<typename base::_value_type>}
{
hooks::set_spare_storage(this, o.spare_storage());
no_value_policy_type::on_outcome_copy_construction(this, o);
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class T)
OUTCOME_TREQUIRES(OUTCOME_TPRED(!std::is_void<T>::value && predicate::template enable_compatible_conversion<T, void, void, void>))
constexpr basic_outcome(const success_type<T> &o) noexcept(detail::is_nothrow_constructible<value_type, T>) // NOLINT
: base{in_place_type<typename base::_value_type>, detail::extract_value_from_success<value_type>(o)}
{
hooks::set_spare_storage(this, o.spare_storage());
no_value_policy_type::on_outcome_copy_construction(this, o);
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class T)
OUTCOME_TREQUIRES(OUTCOME_TPRED(!std::is_void<T>::value && predicate::template enable_compatible_conversion<T, void, void, void>))
constexpr basic_outcome(success_type<T> &&o) noexcept(detail::is_nothrow_constructible<value_type, T>) // NOLINT
: base{in_place_type<typename base::_value_type>, detail::extract_value_from_success<value_type>(static_cast<success_type<T> &&>(o))}
{
hooks::set_spare_storage(this, o.spare_storage());
no_value_policy_type::on_outcome_move_construction(this, static_cast<success_type<T> &&>(o));
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class T)
OUTCOME_TREQUIRES(OUTCOME_TPRED(!std::is_void<T>::value && predicate::template enable_compatible_conversion<void, T, void, void>))
constexpr basic_outcome(const failure_type<T> &o,
error_failure_tag /*unused*/ = error_failure_tag()) noexcept(detail::is_nothrow_constructible<error_type, T>) // NOLINT
: base{in_place_type<typename base::_error_type>, detail::extract_error_from_failure<error_type>(o)}
, _ptr()
{
hooks::set_spare_storage(this, o.spare_storage());
no_value_policy_type::on_outcome_copy_construction(this, o);
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class T)
OUTCOME_TREQUIRES(OUTCOME_TPRED(!std::is_void<T>::value && predicate::template enable_compatible_conversion<void, void, T, void>))
constexpr basic_outcome(const failure_type<T> &o,
exception_failure_tag /*unused*/ = exception_failure_tag()) noexcept(detail::is_nothrow_constructible<exception_type, T>) // NOLINT
: base()
, _ptr(detail::extract_exception_from_failure<exception_type>(o))
{
this->_state._status.set_have_exception(true);
hooks::set_spare_storage(this, o.spare_storage());
no_value_policy_type::on_outcome_copy_construction(this, o);
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class T)
OUTCOME_TREQUIRES(OUTCOME_TPRED(!std::is_void<T>::value && predicate::template enable_make_error_code_compatible_conversion<void, T, void, void>))
constexpr basic_outcome(const failure_type<T> &o,
explicit_make_error_code_compatible_copy_conversion_tag /*unused*/ =
explicit_make_error_code_compatible_copy_conversion_tag()) noexcept(noexcept(make_error_code(std::declval<T>()))) // NOLINT
: base{in_place_type<typename base::_error_type>, make_error_code(detail::extract_error_from_failure<error_type>(o))}
, _ptr()
{
hooks::set_spare_storage(this, o.spare_storage());
no_value_policy_type::on_outcome_copy_construction(this, o);
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class T, class U)
OUTCOME_TREQUIRES(OUTCOME_TPRED(!std::is_void<U>::value && predicate::template enable_compatible_conversion<void, T, U, void>))
constexpr basic_outcome(const failure_type<T, U> &o, explicit_compatible_copy_conversion_tag /*unused*/ = explicit_compatible_copy_conversion_tag()) noexcept(
detail::is_nothrow_constructible<error_type, T> && detail::is_nothrow_constructible<exception_type, U>) // NOLINT
: base{in_place_type<typename base::_error_type>, detail::extract_error_from_failure<error_type>(o)}
, _ptr(detail::extract_exception_from_failure<exception_type>(o))
{
if(!o.has_error())
{
this->_state._status.set_have_error(false);
}
if(o.has_exception())
{
this->_state._status.set_have_exception(true);
}
hooks::set_spare_storage(this, o.spare_storage());
no_value_policy_type::on_outcome_copy_construction(this, o);
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class T)
OUTCOME_TREQUIRES(OUTCOME_TPRED(!std::is_void<T>::value && predicate::template enable_compatible_conversion<void, T, void, void>))
constexpr basic_outcome(failure_type<T> &&o,
error_failure_tag /*unused*/ = error_failure_tag()) noexcept(detail::is_nothrow_constructible<error_type, T>) // NOLINT
: base{in_place_type<typename base::_error_type>, detail::extract_error_from_failure<error_type>(static_cast<failure_type<T> &&>(o))}
, _ptr()
{
hooks::set_spare_storage(this, o.spare_storage());
no_value_policy_type::on_outcome_copy_construction(this, o);
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class T)
OUTCOME_TREQUIRES(OUTCOME_TPRED(!std::is_void<T>::value && predicate::template enable_compatible_conversion<void, void, T, void>))
constexpr basic_outcome(failure_type<T> &&o,
exception_failure_tag /*unused*/ = exception_failure_tag()) noexcept(detail::is_nothrow_constructible<exception_type, T>) // NOLINT
: base()
, _ptr(detail::extract_exception_from_failure<exception_type>(static_cast<failure_type<T> &&>(o)))
{
this->_state._status.set_have_exception(true);
hooks::set_spare_storage(this, o.spare_storage());
no_value_policy_type::on_outcome_copy_construction(this, o);
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class T)
OUTCOME_TREQUIRES(OUTCOME_TPRED(!std::is_void<T>::value && predicate::template enable_make_error_code_compatible_conversion<void, T, void, void>))
constexpr basic_outcome(failure_type<T> &&o,
explicit_make_error_code_compatible_move_conversion_tag /*unused*/ =
explicit_make_error_code_compatible_move_conversion_tag()) noexcept(noexcept(make_error_code(std::declval<T>()))) // NOLINT
: base{in_place_type<typename base::_error_type>, make_error_code(detail::extract_error_from_failure<error_type>(static_cast<failure_type<T> &&>(o)))}
, _ptr()
{
hooks::set_spare_storage(this, o.spare_storage());
no_value_policy_type::on_outcome_copy_construction(this, o);
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class T, class U)
OUTCOME_TREQUIRES(OUTCOME_TPRED(!std::is_void<U>::value && predicate::template enable_compatible_conversion<void, T, U, void>))
constexpr basic_outcome(failure_type<T, U> &&o, explicit_compatible_move_conversion_tag /*unused*/ = explicit_compatible_move_conversion_tag()) noexcept(
detail::is_nothrow_constructible<error_type, T> && detail::is_nothrow_constructible<exception_type, U>) // NOLINT
: base{in_place_type<typename base::_error_type>, detail::extract_error_from_failure<error_type>(static_cast<failure_type<T, U> &&>(o))}
, _ptr(detail::extract_exception_from_failure<exception_type>(static_cast<failure_type<T, U> &&>(o)))
{
if(!o.has_error())
{
this->_state._status.set_have_error(false);
}
if(o.has_exception())
{
this->_state._status.set_have_exception(true);
}
hooks::set_spare_storage(this, o.spare_storage());
no_value_policy_type::on_outcome_move_construction(this, static_cast<failure_type<T, U> &&>(o));
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
using base::operator==;
using base::operator!=;
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class T, class U, class V, class W)
OUTCOME_TREQUIRES(OUTCOME_TEXPR(std::declval<detail::devoid<value_type>>() == std::declval<detail::devoid<T>>()), //
OUTCOME_TEXPR(std::declval<detail::devoid<error_type>>() == std::declval<detail::devoid<U>>()), //
OUTCOME_TEXPR(std::declval<detail::devoid<exception_type>>() == std::declval<detail::devoid<V>>()))
constexpr bool operator==(const basic_outcome<T, U, V, W> &o) const noexcept( //
noexcept(std::declval<detail::devoid<value_type>>() == std::declval<detail::devoid<T>>()) //
&& noexcept(std::declval<detail::devoid<error_type>>() == std::declval<detail::devoid<U>>()) //
&& noexcept(std::declval<detail::devoid<exception_type>>() == std::declval<detail::devoid<V>>()))
{
if(this->_state._status.have_value() && o._state._status.have_value())
{
return this->_state._value == o._state._value; // NOLINT
}
if(this->_state._status.have_error() && o._state._status.have_error() //
&& this->_state._status.have_exception() && o._state._status.have_exception())
{
return this->_state._error == o._state._error && this->_ptr == o._ptr;
}
if(this->_state._status.have_error() && o._state._status.have_error())
{
return this->_state._error == o._state._error;
}
if(this->_state._status.have_exception() && o._state._status.have_exception())
{
return this->_ptr == o._ptr;
}
return false;
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class T, class U)
OUTCOME_TREQUIRES(OUTCOME_TEXPR(std::declval<error_type>() == std::declval<T>()), //
OUTCOME_TEXPR(std::declval<exception_type>() == std::declval<U>()))
constexpr bool operator==(const failure_type<T, U> &o) const noexcept( //
noexcept(std::declval<error_type>() == std::declval<T>()) && noexcept(std::declval<exception_type>() == std::declval<U>()))
{
if(this->_state._status.have_error() && o._state._status.have_error() //
&& this->_state._status.have_exception() && o._state._status.have_exception())
{
return this->_state._error == o.error() && this->_ptr == o.exception();
}
if(this->_state._status.have_error() && o._state._status.have_error())
{
return this->_state._error == o.error();
}
if(this->_state._status.have_exception() && o._state._status.have_exception())
{
return this->_ptr == o.exception();
}
return false;
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class T, class U, class V, class W)
OUTCOME_TREQUIRES(OUTCOME_TEXPR(std::declval<detail::devoid<value_type>>() != std::declval<detail::devoid<T>>()), //
OUTCOME_TEXPR(std::declval<detail::devoid<error_type>>() != std::declval<detail::devoid<U>>()), //
OUTCOME_TEXPR(std::declval<detail::devoid<exception_type>>() != std::declval<detail::devoid<V>>()))
constexpr bool operator!=(const basic_outcome<T, U, V, W> &o) const noexcept( //
noexcept(std::declval<detail::devoid<value_type>>() != std::declval<detail::devoid<T>>()) //
&& noexcept(std::declval<detail::devoid<error_type>>() != std::declval<detail::devoid<U>>()) //
&& noexcept(std::declval<detail::devoid<exception_type>>() != std::declval<detail::devoid<V>>()))
{
if(this->_state._status.have_value() && o._state._status.have_value())
{
return this->_state._value != o._state._value; // NOLINT
}
if(this->_state._status.have_error() && o._state._status.have_error() //
&& this->_state._status.have_exception() && o._state._status.have_exception())
{
return this->_state._error != o._state._error || this->_ptr != o._ptr;
}
if(this->_state._status.have_error() && o._state._status.have_error())
{
return this->_state._error != o._state._error;
}
if(this->_state._status.have_exception() && o._state._status.have_exception())
{
return this->_ptr != o._ptr;
}
return true;
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class T, class U)
OUTCOME_TREQUIRES(OUTCOME_TEXPR(std::declval<error_type>() != std::declval<T>()), //
OUTCOME_TEXPR(std::declval<exception_type>() != std::declval<U>()))
constexpr bool operator!=(const failure_type<T, U> &o) const noexcept( //
noexcept(std::declval<error_type>() == std::declval<T>()) && noexcept(std::declval<exception_type>() == std::declval<U>()))
{
if(this->_state._status.have_error() && o._state._status.have_error() //
&& this->_state._status.have_exception() && o._state._status.have_exception())
{
return this->_state._error != o.error() || this->_ptr != o.exception();
}
if(this->_state._status.have_error() && o._state._status.have_error())
{
return this->_state._error != o.error();
}
if(this->_state._status.have_exception() && o._state._status.have_exception())
{
return this->_ptr != o.exception();
}
return true;
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
constexpr void swap(basic_outcome &o) noexcept((std::is_void<value_type>::value || detail::is_nothrow_swappable<value_type>::value) //
&& (std::is_void<error_type>::value || detail::is_nothrow_swappable<error_type>::value) //
&& (std::is_void<exception_type>::value || detail::is_nothrow_swappable<exception_type>::value))
{
#ifdef __cpp_exceptions
constexpr bool value_throws = !std::is_void<value_type>::value && !detail::is_nothrow_swappable<value_type>::value;
constexpr bool error_throws = !std::is_void<error_type>::value && !detail::is_nothrow_swappable<error_type>::value;
constexpr bool exception_throws = !std::is_void<exception_type>::value && !detail::is_nothrow_swappable<exception_type>::value;
#ifdef _MSC_VER
#pragma warning(push)
#pragma warning(disable : 4127) // conditional expression is constant
#endif
if(!exception_throws && !value_throws && !error_throws)
{
// Simples
this->_state.swap(o._state);
using std::swap;
swap(this->_ptr, o._ptr);
return;
}
struct some_type
{
basic_outcome &a, &b;
bool exceptioned{false};
bool all_good{false};
~some_type()
{
if(!this->all_good)
{
// We lost one of the values
this->a._state._status.set_have_lost_consistency(true);
this->b._state._status.set_have_lost_consistency(true);
return;
}
if(this->exceptioned)
{
// The value + error swap threw an exception. Try to swap back _ptr
try
{
strong_swap(this->all_good, this->a._ptr, this->b._ptr);
}
catch(...)
{
// We lost one of the values
this->a._state._status.set_have_lost_consistency(true);
this->b._state._status.set_have_lost_consistency(true);
// throw away second exception
}
// Prevent has_value() == has_error() or has_value() == has_exception()
auto check = [](basic_outcome *t)
{
if(t->has_value() && (t->has_error() || t->has_exception()))
{
t->_state._status.set_have_error(false).set_have_exception(false);
t->_state._status.set_have_lost_consistency(true);
}
if(!t->has_value() && !(t->has_error() || t->has_exception()))
{
// Choose error, for no particular reason
t->_state._status.set_have_error(true).set_have_lost_consistency(true);
}
};
check(&this->a);
check(&this->b);
}
}
} some_type_value{*this, o};
strong_swap(some_type_value.all_good, this->_ptr, o._ptr);
some_type_value.exceptioned = true;
this->_state.swap(o._state);
some_type_value.exceptioned = false;
#ifdef _MSC_VER
#pragma warning(pop)
#endif
#else
this->_state.swap(o._state);
using std::swap;
swap(this->_ptr, o._ptr);
#endif
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
failure_type<error_type, exception_type> as_failure() const &
{
if(this->has_error() && this->has_exception())
{
return failure_type<error_type, exception_type>(this->assume_error(), this->assume_exception(), hooks::spare_storage(this));
}
if(this->has_exception())
{
return failure_type<error_type, exception_type>(in_place_type<exception_type>, this->assume_exception(), hooks::spare_storage(this));
}
return failure_type<error_type, exception_type>(in_place_type<error_type>, this->assume_error(), hooks::spare_storage(this));
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
failure_type<error_type, exception_type> as_failure() &&
{
this->_state._status.set_have_moved_from(true);
if(this->has_error() && this->has_exception())
{
return failure_type<error_type, exception_type>(static_cast<S &&>(this->assume_error()), static_cast<P &&>(this->assume_exception()),
hooks::spare_storage(this));
}
if(this->has_exception())
{
return failure_type<error_type, exception_type>(in_place_type<exception_type>, static_cast<P &&>(this->assume_exception()), hooks::spare_storage(this));
}
return failure_type<error_type, exception_type>(in_place_type<error_type>, static_cast<S &&>(this->assume_error()), hooks::spare_storage(this));
}
#ifdef __APPLE__
failure_type<error_type, exception_type> _xcode_workaround_as_failure() &&;
#endif
};
// C++ 20 operator== rewriting should take care of this for us, indeed
// if we don't disable it, we cause Concept recursion to infinity!
#if __cplusplus < 202000L && !_HAS_CXX20
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class T, class U, class V, //
class R, class S, class P, class N)
OUTCOME_TREQUIRES(OUTCOME_TEXPR(std::declval<basic_outcome<R, S, P, N>>() == std::declval<basic_result<T, U, V>>()))
constexpr inline bool operator==(const basic_result<T, U, V> &a, const basic_outcome<R, S, P, N> &b) noexcept( //
noexcept(std::declval<basic_outcome<R, S, P, N>>() == std::declval<basic_result<T, U, V>>()))
{
return b == a;
}
#endif
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class T, class U, class V, //
class R, class S, class P, class N)
OUTCOME_TREQUIRES(OUTCOME_TEXPR(std::declval<basic_outcome<R, S, P, N>>() != std::declval<basic_result<T, U, V>>()))
constexpr inline bool operator!=(const basic_result<T, U, V> &a, const basic_outcome<R, S, P, N> &b) noexcept( //
noexcept(std::declval<basic_outcome<R, S, P, N>>() != std::declval<basic_result<T, U, V>>()))
{
return b != a;
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
template <class R, class S, class P, class N> inline void swap(basic_outcome<R, S, P, N> &a, basic_outcome<R, S, P, N> &b) noexcept(noexcept(a.swap(b)))
{
a.swap(b);
}
namespace hooks
{
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
template <class R, class S, class P, class NoValuePolicy, class U>
constexpr inline void override_outcome_exception(basic_outcome<R, S, P, NoValuePolicy> *o, U &&v) noexcept
{
o->_ptr = static_cast<U &&>(v); // NOLINT
o->_state._status.set_have_exception(true);
}
} // namespace hooks
OUTCOME_V2_NAMESPACE_END
#ifdef __clang__
#pragma clang diagnostic pop
#endif
/* Exception observers for outcome type
(C) 2017-2019 Niall Douglas <http://www.nedproductions.biz/> (6 commits)
File Created: Oct 2017
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License in the accompanying file
Licence.txt or at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Distributed under the Boost Software License, Version 1.0.
(See accompanying file Licence.txt or copy at
http://www.boost.org/LICENSE_1_0.txt)
*/
#ifndef OUTCOME_BASIC_OUTCOME_EXCEPTION_OBSERVERS_IMPL_HPP
#define OUTCOME_BASIC_OUTCOME_EXCEPTION_OBSERVERS_IMPL_HPP
OUTCOME_V2_NAMESPACE_EXPORT_BEGIN
namespace policy
{
template <class R, class S, class P, class NoValuePolicy, class Impl> inline constexpr auto &&base::_exception(Impl &&self) noexcept
{
// Impl will be some internal implementation class which has no knowledge of the _ptr stored
// beneath it. So statically cast, preserving rvalue and constness, to the derived class.
using Outcome = OUTCOME_V2_NAMESPACE::detail::rebind_type<basic_outcome<R, S, P, NoValuePolicy>, decltype(self)>;
#if defined(_MSC_VER) && _MSC_VER < 1920
// VS2017 tries a copy construction in the correct implementation despite that Outcome is always a rvalue or lvalue ref! :(
basic_outcome<R, S, P, NoValuePolicy> &_self = (basic_outcome<R, S, P, NoValuePolicy> &) (self); // NOLINT
#else
Outcome _self = static_cast<Outcome>(self); // NOLINT
#endif
return static_cast<Outcome>(_self)._ptr;
}
} // namespace policy
namespace detail
{
template <class Base, class R, class S, class P, class NoValuePolicy> inline constexpr typename basic_outcome_exception_observers<Base, R, S, P, NoValuePolicy>::exception_type &basic_outcome_exception_observers<Base, R, S, P, NoValuePolicy>::assume_exception() & noexcept
{
NoValuePolicy::narrow_exception_check(*this);
return NoValuePolicy::template _exception<R, S, P, NoValuePolicy>(*this);
}
template <class Base, class R, class S, class P, class NoValuePolicy> inline constexpr const typename basic_outcome_exception_observers<Base, R, S, P, NoValuePolicy>::exception_type &basic_outcome_exception_observers<Base, R, S, P, NoValuePolicy>::assume_exception() const &noexcept
{
NoValuePolicy::narrow_exception_check(*this);
return NoValuePolicy::template _exception<R, S, P, NoValuePolicy>(*this);
}
template <class Base, class R, class S, class P, class NoValuePolicy> inline constexpr typename basic_outcome_exception_observers<Base, R, S, P, NoValuePolicy>::exception_type &&basic_outcome_exception_observers<Base, R, S, P, NoValuePolicy>::assume_exception() && noexcept
{
NoValuePolicy::narrow_exception_check(std::move(*this));
return NoValuePolicy::template _exception<R, S, P, NoValuePolicy>(std::move(*this));
}
template <class Base, class R, class S, class P, class NoValuePolicy> inline constexpr const typename basic_outcome_exception_observers<Base, R, S, P, NoValuePolicy>::exception_type &&basic_outcome_exception_observers<Base, R, S, P, NoValuePolicy>::assume_exception() const &&noexcept
{
NoValuePolicy::narrow_exception_check(std::move(*this));
return NoValuePolicy::template _exception<R, S, P, NoValuePolicy>(std::move(*this));
}
template <class Base, class R, class S, class P, class NoValuePolicy> inline constexpr typename basic_outcome_exception_observers<Base, R, S, P, NoValuePolicy>::exception_type &basic_outcome_exception_observers<Base, R, S, P, NoValuePolicy>::exception() &
{
NoValuePolicy::wide_exception_check(*this);
return NoValuePolicy::template _exception<R, S, P, NoValuePolicy>(*this);
}
template <class Base, class R, class S, class P, class NoValuePolicy> inline constexpr const typename basic_outcome_exception_observers<Base, R, S, P, NoValuePolicy>::exception_type &basic_outcome_exception_observers<Base, R, S, P, NoValuePolicy>::exception() const &
{
NoValuePolicy::wide_exception_check(*this);
return NoValuePolicy::template _exception<R, S, P, NoValuePolicy>(*this);
}
template <class Base, class R, class S, class P, class NoValuePolicy> inline constexpr typename basic_outcome_exception_observers<Base, R, S, P, NoValuePolicy>::exception_type &&basic_outcome_exception_observers<Base, R, S, P, NoValuePolicy>::exception() &&
{
NoValuePolicy::wide_exception_check(std::move(*this));
return NoValuePolicy::template _exception<R, S, P, NoValuePolicy>(std::move(*this));
}
template <class Base, class R, class S, class P, class NoValuePolicy> inline constexpr const typename basic_outcome_exception_observers<Base, R, S, P, NoValuePolicy>::exception_type &&basic_outcome_exception_observers<Base, R, S, P, NoValuePolicy>::exception() const &&
{
NoValuePolicy::wide_exception_check(std::move(*this));
return NoValuePolicy::template _exception<R, S, P, NoValuePolicy>(std::move(*this));
}
} // namespace detail
OUTCOME_V2_NAMESPACE_END
#endif
#if !defined(NDEBUG)
OUTCOME_V2_NAMESPACE_BEGIN
// Check is trivial in all ways except default constructibility and standard layout
// static_assert(std::is_trivial<basic_outcome<int, long, double, policy::all_narrow>>::value, "outcome<int> is not trivial!");
// static_assert(std::is_trivially_default_constructible<basic_outcome<int, long, double, policy::all_narrow>>::value, "outcome<int> is not trivially default
// constructible!");
static_assert(std::is_trivially_copyable<basic_outcome<int, long, double, policy::all_narrow>>::value, "outcome<int> is not trivially copyable!");
static_assert(std::is_trivially_assignable<basic_outcome<int, long, double, policy::all_narrow>, basic_outcome<int, long, double, policy::all_narrow>>::value,
"outcome<int> is not trivially assignable!");
static_assert(std::is_trivially_destructible<basic_outcome<int, long, double, policy::all_narrow>>::value, "outcome<int> is not trivially destructible!");
static_assert(std::is_trivially_copy_constructible<basic_outcome<int, long, double, policy::all_narrow>>::value,
"outcome<int> is not trivially copy constructible!");
static_assert(std::is_trivially_move_constructible<basic_outcome<int, long, double, policy::all_narrow>>::value,
"outcome<int> is not trivially move constructible!");
static_assert(std::is_trivially_copy_assignable<basic_outcome<int, long, double, policy::all_narrow>>::value, "outcome<int> is not trivially copy assignable!");
static_assert(std::is_trivially_move_assignable<basic_outcome<int, long, double, policy::all_narrow>>::value, "outcome<int> is not trivially move assignable!");
// Can't be standard layout as non-static member data is defined in more than one inherited class
// static_assert(std::is_standard_layout<basic_outcome<int, long, double, policy::all_narrow>>::value, "outcome<int> is not a standard layout type!");
OUTCOME_V2_NAMESPACE_END
#endif
#endif
/* Try operation macros
(C) 2017-2021 Niall Douglas <http://www.nedproductions.biz/> (20 commits)
File Created: July 2017
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License in the accompanying file
Licence.txt or at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Distributed under the Boost Software License, Version 1.0.
(See accompanying file Licence.txt or copy at
http://www.boost.org/LICENSE_1_0.txt)
*/
#ifndef OUTCOME_TRY_HPP
#define OUTCOME_TRY_HPP
/* Try operation macros
(C) 2017-2024 Niall Douglas <http://www.nedproductions.biz/> (20 commits)
File Created: July 2017
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License in the accompanying file
Licence.txt or at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Distributed under the Boost Software License, Version 1.0.
(See accompanying file Licence.txt or copy at
http://www.boost.org/LICENSE_1_0.txt)
*/
#ifndef OUTCOME_TRY_H
#define OUTCOME_TRY_H
#if !defined(__clang__) && defined(__GNUC__) && __GNUC__ >= 8
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wparentheses"
#endif
#define OUTCOME_TRY_GLUE2(x, y) x##y
#define OUTCOME_TRY_GLUE(x, y) OUTCOME_TRY_GLUE2(x, y)
#define OUTCOME_TRY_UNIQUE_NAME OUTCOME_TRY_GLUE(_outcome_try_unique_name_temporary, __COUNTER__)
#define OUTCOME_TRY_RETURN_ARG_COUNT(_1_, _2_, _3_, _4_, _5_, _6_, _7_, _8_, count, ...) count
#define OUTCOME_TRY_EXPAND_ARGS(args) OUTCOME_TRY_RETURN_ARG_COUNT args
#define OUTCOME_TRY_COUNT_ARGS_MAX8(...) OUTCOME_TRY_EXPAND_ARGS((__VA_ARGS__, 8, 7, 6, 5, 4, 3, 2, 1, 0))
#define OUTCOME_TRY_OVERLOAD_MACRO2(name, count) name##count
#define OUTCOME_TRY_OVERLOAD_MACRO1(name, count) OUTCOME_TRY_OVERLOAD_MACRO2(name, count)
#define OUTCOME_TRY_OVERLOAD_MACRO(name, count) OUTCOME_TRY_OVERLOAD_MACRO1(name, count)
#define OUTCOME_TRY_OVERLOAD_GLUE(x, y) x y
#define OUTCOME_TRY_CALL_OVERLOAD(name, ...) OUTCOME_TRY_OVERLOAD_GLUE(OUTCOME_TRY_OVERLOAD_MACRO(name, OUTCOME_TRY_COUNT_ARGS_MAX8(__VA_ARGS__)), (__VA_ARGS__))
#define _OUTCOME_TRY_RETURN_ARG_COUNT(_1_, _2_, _3_, _4_, _5_, _6_, _7_, _8_, count, ...) count
#define _OUTCOME_TRY_EXPAND_ARGS(args) _OUTCOME_TRY_RETURN_ARG_COUNT args
#define _OUTCOME_TRY_COUNT_ARGS_MAX8(...) _OUTCOME_TRY_EXPAND_ARGS((__VA_ARGS__, 8, 7, 6, 5, 4, 3, 2, 1, 0))
#define _OUTCOME_TRY_OVERLOAD_MACRO2(name, count) name##count
#define _OUTCOME_TRY_OVERLOAD_MACRO1(name, count) _OUTCOME_TRY_OVERLOAD_MACRO2(name, count)
#define _OUTCOME_TRY_OVERLOAD_MACRO(name, count) _OUTCOME_TRY_OVERLOAD_MACRO1(name, count)
#define _OUTCOME_TRY_OVERLOAD_GLUE(x, y) x y
#define _OUTCOME_TRY_CALL_OVERLOAD(name, ...) _OUTCOME_TRY_OVERLOAD_GLUE(_OUTCOME_TRY_OVERLOAD_MACRO(name, _OUTCOME_TRY_COUNT_ARGS_MAX8(__VA_ARGS__)), (__VA_ARGS__))
#if !defined(OUTCOME_TRY_LIKELY_IF) && defined(__has_cpp_attribute)
#if __has_cpp_attribute(likely)
#define OUTCOME_TRY_LIKELY_IF(...) if(__VA_ARGS__) [[likely]]
#endif
#endif
#ifndef OUTCOME_TRY_LIKELY_IF
#if defined(__clang__) || defined(__GNUC__)
#define OUTCOME_TRY_LIKELY_IF(...) if(__builtin_expect(!!(__VA_ARGS__), 1))
#else
#define OUTCOME_TRY_LIKELY_IF(...) if(__VA_ARGS__)
#endif
#endif
#ifdef __cplusplus
#define OUTCOME_TRYV2_UNIQUE_STORAGE_AUTO(...) auto
#else
#define OUTCOME_TRYV2_UNIQUE_STORAGE_AUTO(...) __typeof__(__VA_ARGS__)
#endif
#define OUTCOME_TRYV2_UNIQUE_STORAGE_UNPACK(...) __VA_ARGS__
#define OUTCOME_TRYV2_UNIQUE_STORAGE_DEDUCE3(unique, ...) OUTCOME_TRYV2_UNIQUE_STORAGE_AUTO(__VA_ARGS__) unique = (__VA_ARGS__)
#define OUTCOME_TRYV2_UNIQUE_STORAGE_DEDUCE2(x) x
#define OUTCOME_TRYV2_UNIQUE_STORAGE_DEDUCE(unique, x, ...) OUTCOME_TRYV2_UNIQUE_STORAGE_DEDUCE2(OUTCOME_TRYV2_UNIQUE_STORAGE_DEDUCE3(unique, __VA_ARGS__))
#define OUTCOME_TRYV2_UNIQUE_STORAGE_SPECIFIED3(unique, x, y, ...) x unique = (__VA_ARGS__)
#define OUTCOME_TRYV2_UNIQUE_STORAGE_SPECIFIED2(x) x
#define OUTCOME_TRYV2_UNIQUE_STORAGE_SPECIFIED(unique, ...) OUTCOME_TRYV2_UNIQUE_STORAGE_SPECIFIED2(OUTCOME_TRYV2_UNIQUE_STORAGE_SPECIFIED3(unique, __VA_ARGS__))
#define OUTCOME_TRYV2_UNIQUE_STORAGE1(...) OUTCOME_TRYV2_UNIQUE_STORAGE_DEDUCE
#define OUTCOME_TRYV2_UNIQUE_STORAGE2(...) OUTCOME_TRYV2_UNIQUE_STORAGE_SPECIFIED
#define OUTCOME_TRYV2_UNIQUE_STORAGE(unique, spec, ...) _OUTCOME_TRY_CALL_OVERLOAD(OUTCOME_TRYV2_UNIQUE_STORAGE, OUTCOME_TRYV2_UNIQUE_STORAGE_UNPACK spec) (unique, OUTCOME_TRYV2_UNIQUE_STORAGE_UNPACK spec, __VA_ARGS__)
#define OUTCOME_TRY2_VAR_SECOND2(x, var) var
#define OUTCOME_TRY2_VAR_SECOND3(x, y, ...) x y
#define OUTCOME_TRY2_VAR(spec) _OUTCOME_TRY_CALL_OVERLOAD(OUTCOME_TRY2_VAR_SECOND, OUTCOME_TRYV2_UNIQUE_STORAGE_UNPACK spec, spec)
#if !defined(__clang__) && defined(__GNUC__) && __GNUC__ >= 8
#pragma GCC diagnostic pop
#endif
#endif
OUTCOME_V2_NAMESPACE_BEGIN
namespace detail
{
struct has_value_overload
{
};
struct as_failure_overload
{
};
struct assume_error_overload
{
};
struct error_overload
{
};
struct assume_value_overload
{
};
struct value_overload
{
};
// #ifdef __APPLE__
// OUTCOME_TEMPLATE(class T, class R = decltype(std::declval<T>()._xcode_workaround_as_failure()))
// #else
OUTCOME_TEMPLATE(class T, class R = decltype(std::declval<T>().as_failure()))
// #endif
OUTCOME_TREQUIRES(OUTCOME_TPRED(OUTCOME_V2_NAMESPACE::is_failure_type<R>))
constexpr inline bool has_as_failure(int /*unused */)
{
return true;
}
template <class T> constexpr inline bool has_as_failure(...)
{
return false;
}
OUTCOME_TEMPLATE(class T)
OUTCOME_TREQUIRES(OUTCOME_TEXPR(std::declval<T>().assume_error()))
constexpr inline bool has_assume_error(int /*unused */)
{
return true;
}
template <class T> constexpr inline bool has_assume_error(...)
{
return false;
}
OUTCOME_TEMPLATE(class T)
OUTCOME_TREQUIRES(OUTCOME_TEXPR(std::declval<T>().error()))
constexpr inline bool has_error(int /*unused */)
{
return true;
}
template <class T> constexpr inline bool has_error(...)
{
return false;
}
OUTCOME_TEMPLATE(class T)
OUTCOME_TREQUIRES(OUTCOME_TEXPR(std::declval<T>().assume_value()))
constexpr inline bool has_assume_value(int /*unused */)
{
return true;
}
template <class T> constexpr inline bool has_assume_value(...)
{
return false;
}
OUTCOME_TEMPLATE(class T)
OUTCOME_TREQUIRES(OUTCOME_TEXPR(std::declval<T>().value()))
constexpr inline bool has_value(int /*unused */)
{
return true;
}
template <class T> constexpr inline bool has_value(...)
{
return false;
}
} // namespace detail
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class T)
OUTCOME_TREQUIRES(OUTCOME_TEXPR(std::declval<T>().has_value()))
constexpr inline bool try_operation_has_value(T &&v, detail::has_value_overload = {})
{
return v.has_value();
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class T)
OUTCOME_TREQUIRES(OUTCOME_TPRED(detail::has_as_failure<T>(5)))
constexpr inline decltype(auto) try_operation_return_as(T &&v, detail::as_failure_overload = {})
{
return static_cast<T &&>(v).as_failure();
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class T)
OUTCOME_TREQUIRES(OUTCOME_TPRED(!detail::has_as_failure<T>(5) && detail::has_assume_error<T>(5)))
constexpr inline decltype(auto) try_operation_return_as(T &&v, detail::assume_error_overload = {})
{
return failure(static_cast<T &&>(v).assume_error());
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class T)
OUTCOME_TREQUIRES(OUTCOME_TPRED(!detail::has_as_failure<T>(5) && !detail::has_assume_error<T>(5) && detail::has_error<T>(5)))
constexpr inline decltype(auto) try_operation_return_as(T &&v, detail::error_overload = {})
{
return failure(static_cast<T &&>(v).error());
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class T)
OUTCOME_TREQUIRES(OUTCOME_TPRED(detail::has_assume_value<T>(5)))
constexpr inline decltype(auto) try_operation_extract_value(T &&v, detail::assume_value_overload = {})
{
return static_cast<T &&>(v).assume_value();
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class T)
OUTCOME_TREQUIRES(OUTCOME_TPRED(!detail::has_assume_value<T>(5) && detail::has_value<T>(5)))
constexpr inline decltype(auto) try_operation_extract_value(T &&v, detail::value_overload = {})
{
return static_cast<T &&>(v).value();
}
OUTCOME_V2_NAMESPACE_END
#if !defined(__clang__) && defined(__GNUC__) && __GNUC__ >= 8
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wparentheses"
#endif
// Use if(!expr); else as some compilers assume else clauses are always unlikely
#define OUTCOME_TRYV2_SUCCESS_LIKELY(unique, retstmt, spec, ...) OUTCOME_TRYV2_UNIQUE_STORAGE(unique, spec, __VA_ARGS__); OUTCOME_TRY_LIKELY_IF(::OUTCOME_V2_NAMESPACE::try_operation_has_value(unique)); else { /* works around ICE in GCC's coroutines implementation */ auto unique##_f(::OUTCOME_V2_NAMESPACE::try_operation_return_as(static_cast<decltype(unique) &&>(unique))); retstmt unique##_f; }
#define OUTCOME_TRYV3_FAILURE_LIKELY(unique, retstmt, spec, ...) OUTCOME_TRYV2_UNIQUE_STORAGE(unique, spec, __VA_ARGS__); OUTCOME_TRY_LIKELY_IF(!OUTCOME_V2_NAMESPACE::try_operation_has_value(unique)) { /* works around ICE in GCC's coroutines implementation */ auto unique##_f(::OUTCOME_V2_NAMESPACE::try_operation_return_as(static_cast<decltype(unique) &&>(unique))); retstmt unique##_f; }
#define OUTCOME_TRY2_SUCCESS_LIKELY(unique, retstmt, var, ...) OUTCOME_TRYV2_SUCCESS_LIKELY(unique, retstmt, var, __VA_ARGS__); OUTCOME_TRY2_VAR(var) = ::OUTCOME_V2_NAMESPACE::try_operation_extract_value(static_cast<decltype(unique) &&>(unique))
#define OUTCOME_TRY2_FAILURE_LIKELY(unique, retstmt, var, ...) OUTCOME_TRYV3_FAILURE_LIKELY(unique, retstmt, var, __VA_ARGS__); OUTCOME_TRY2_VAR(var) = ::OUTCOME_V2_NAMESPACE::try_operation_extract_value(static_cast<decltype(unique) &&>(unique))
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
#define OUTCOME_TRYV(...) OUTCOME_TRYV2_SUCCESS_LIKELY(OUTCOME_TRY_UNIQUE_NAME, return, deduce, __VA_ARGS__)
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
#define OUTCOME_TRYV_FAILURE_LIKELY(...) OUTCOME_TRYV3_FAILURE_LIKELY(OUTCOME_TRY_UNIQUE_NAME, return, deduce, __VA_ARGS__)
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
#define OUTCOME_CO_TRYV(...) OUTCOME_TRYV2_SUCCESS_LIKELY(OUTCOME_TRY_UNIQUE_NAME, co_return, deduce, __VA_ARGS__)
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
#define OUTCOME_CO_TRYV_FAILURE_LIKELY(...) OUTCOME_TRYV3_FAILURE_LIKELY(OUTCOME_TRY_UNIQUE_NAME, co_return, deduce, __VA_ARGS__)
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
#define OUTCOME_TRYV2(s, ...) OUTCOME_TRYV2_SUCCESS_LIKELY(OUTCOME_TRY_UNIQUE_NAME, return, (s, ), __VA_ARGS__)
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
#define OUTCOME_TRYV2_FAILURE_LIKELY(s, ...) OUTCOME_TRYV3_FAILURE_LIKELY(OUTCOME_TRY_UNIQUE_NAME, return, (s, ), __VA_ARGS__)
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
#define OUTCOME_CO_TRYV2(s, ...) OUTCOME_TRYV2_SUCCESS_LIKELY(OUTCOME_TRY_UNIQUE_NAME, co_return, (s, ), __VA_ARGS__)
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
#define OUTCOME_CO_TRYV2_FAILURE_LIKELY(s, ...) OUTCOME_TRYV3_FAILURE_LIKELY(OUTCOME_TRY_UNIQUE_NAME, co_return, s(, ), __VA_ARGS__)
#if defined(__GNUC__) || defined(__clang__)
#define OUTCOME_TRYX2(unique, retstmt, ...) ({ OUTCOME_TRYV2_SUCCESS_LIKELY(unique, retstmt, deduce, __VA_ARGS__); ::OUTCOME_V2_NAMESPACE::try_operation_extract_value(static_cast<decltype(unique) &&>(unique)); })
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
#define OUTCOME_TRYX(...) OUTCOME_TRYX2(OUTCOME_TRY_UNIQUE_NAME, return, __VA_ARGS__)
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
#define OUTCOME_CO_TRYX(...) OUTCOME_TRYX2(OUTCOME_TRY_UNIQUE_NAME, co_return, __VA_ARGS__)
#endif
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
#define OUTCOME_TRYA(v, ...) OUTCOME_TRY2_SUCCESS_LIKELY(OUTCOME_TRY_UNIQUE_NAME, return, v, __VA_ARGS__)
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
#define OUTCOME_TRYA_FAILURE_LIKELY(v, ...) OUTCOME_TRY2_FAILURE_LIKELY(OUTCOME_TRY_UNIQUE_NAME, return, v, __VA_ARGS__)
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
#define OUTCOME_CO_TRYA(v, ...) OUTCOME_TRY2_SUCCESS_LIKELY(OUTCOME_TRY_UNIQUE_NAME, co_return, v, __VA_ARGS__)
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
#define OUTCOME_CO_TRYA_FAILURE_LIKELY(v, ...) OUTCOME_TRY2_FAILURE_LIKELY(OUTCOME_TRY_UNIQUE_NAME, co_return, v, __VA_ARGS__)
#define OUTCOME_TRY_INVOKE_TRY8(a, b, c, d, e, f, g, h) OUTCOME_TRYA(a, b, c, d, e, f, g, h)
#define OUTCOME_TRY_INVOKE_TRY7(a, b, c, d, e, f, g) OUTCOME_TRYA(a, b, c, d, e, f, g)
#define OUTCOME_TRY_INVOKE_TRY6(a, b, c, d, e, f) OUTCOME_TRYA(a, b, c, d, e, f)
#define OUTCOME_TRY_INVOKE_TRY5(a, b, c, d, e) OUTCOME_TRYA(a, b, c, d, e)
#define OUTCOME_TRY_INVOKE_TRY4(a, b, c, d) OUTCOME_TRYA(a, b, c, d)
#define OUTCOME_TRY_INVOKE_TRY3(a, b, c) OUTCOME_TRYA(a, b, c)
#define OUTCOME_TRY_INVOKE_TRY2(a, b) OUTCOME_TRYA(a, b)
#define OUTCOME_TRY_INVOKE_TRY1(a) OUTCOME_TRYV(a)
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
#define OUTCOME_TRY(...) OUTCOME_TRY_CALL_OVERLOAD(OUTCOME_TRY_INVOKE_TRY, __VA_ARGS__)
#define OUTCOME_TRY_FAILURE_LIKELY_INVOKE_TRY8(a, b, c, d, e, f, g, h) OUTCOME_TRYA_FAILURE_LIKELY(a, b, c, d, e, f, g, h)
#define OUTCOME_TRY_FAILURE_LIKELY_INVOKE_TRY7(a, b, c, d, e, f, g) OUTCOME_TRYA_FAILURE_LIKELY(a, b, c, d, e, f, g)
#define OUTCOME_TRY_FAILURE_LIKELY_INVOKE_TRY6(a, b, c, d, e, f) OUTCOME_TRYA_FAILURE_LIKELY(a, b, c, d, e, f)
#define OUTCOME_TRY_FAILURE_LIKELY_INVOKE_TRY5(a, b, c, d, e) OUTCOME_TRYA_FAILURE_LIKELY(a, b, c, d, e)
#define OUTCOME_TRY_FAILURE_LIKELY_INVOKE_TRY4(a, b, c, d) OUTCOME_TRYA_FAILURE_LIKELY(a, b, c, d)
#define OUTCOME_TRY_FAILURE_LIKELY_INVOKE_TRY3(a, b, c) OUTCOME_TRYA_FAILURE_LIKELY(a, b, c)
#define OUTCOME_TRY_FAILURE_LIKELY_INVOKE_TRY2(a, b) OUTCOME_TRYA_FAILURE_LIKELY(a, b)
#define OUTCOME_TRY_FAILURE_LIKELY_INVOKE_TRY1(a) OUTCOME_TRYV_FAILURE_LIKELY(a)
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
#define OUTCOME_TRY_FAILURE_LIKELY(...) OUTCOME_TRY_CALL_OVERLOAD(OUTCOME_TRY_FAILURE_LIKELY_INVOKE_TRY, __VA_ARGS__)
#define OUTCOME_CO_TRY_INVOKE_TRY8(a, b, c, d, e, f, g, h) OUTCOME_CO_TRYA(a, b, c, d, e, f, g, h)
#define OUTCOME_CO_TRY_INVOKE_TRY7(a, b, c, d, e, f, g) OUTCOME_CO_TRYA(a, b, c, d, e, f, g)
#define OUTCOME_CO_TRY_INVOKE_TRY6(a, b, c, d, e, f) OUTCOME_CO_TRYA(a, b, c, d, e, f)
#define OUTCOME_CO_TRY_INVOKE_TRY5(a, b, c, d, e) OUTCOME_CO_TRYA(a, b, c, d, e)
#define OUTCOME_CO_TRY_INVOKE_TRY4(a, b, c, d) OUTCOME_CO_TRYA(a, b, c, d)
#define OUTCOME_CO_TRY_INVOKE_TRY3(a, b, c) OUTCOME_CO_TRYA(a, b, c)
#define OUTCOME_CO_TRY_INVOKE_TRY2(a, b) OUTCOME_CO_TRYA(a, b)
#define OUTCOME_CO_TRY_INVOKE_TRY1(a) OUTCOME_CO_TRYV(a)
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
#define OUTCOME_CO_TRY(...) OUTCOME_TRY_CALL_OVERLOAD(OUTCOME_CO_TRY_INVOKE_TRY, __VA_ARGS__)
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
#define OUTCOME_TRY(...) OUTCOME_TRY_CALL_OVERLOAD(OUTCOME_TRY_INVOKE_TRY, __VA_ARGS__)
#define OUTCOME_CO_TRY_FAILURE_LIKELY_INVOKE_TRY8(a, b, c, d, e, f, g, h) OUTCOME_CO_TRYA_FAILURE_LIKELY(a, b, c, d, e, f, g, h)
#define OUTCOME_CO_TRY_FAILURE_LIKELY_INVOKE_TRY7(a, b, c, d, e, f, g) OUTCOME_CO_TRYA_FAILURE_LIKELY(a, b, c, d, e, f, g)
#define OUTCOME_CO_TRY_FAILURE_LIKELY_INVOKE_TRY6(a, b, c, d, e, f) OUTCOME_CO_TRYA_FAILURE_LIKELY(a, b, c, d, e, f)
#define OUTCOME_CO_TRY_FAILURE_LIKELY_INVOKE_TRY5(a, b, c, d, e) OUTCOME_CO_TRYA_FAILURE_LIKELY(a, b, c, d, e)
#define OUTCOME_CO_TRY_FAILURE_LIKELY_INVOKE_TRY4(a, b, c, d) OUTCOME_CO_TRYA_FAILURE_LIKELY(a, b, c, d)
#define OUTCOME_CO_TRY_FAILURE_LIKELY_INVOKE_TRY3(a, b, c) OUTCOME_CO_TRYA_FAILURE_LIKELY(a, b, c)
#define OUTCOME_CO_TRY_FAILURE_LIKELY_INVOKE_TRY2(a, b) OUTCOME_CO_TRYA_FAILURE_LIKELY(a, b)
#define OUTCOME_CO_TRY_FAILURE_LIKELY_INVOKE_TRY1(a) OUTCOME_CO_TRYV_FAILURE_LIKELY(a)
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
#define OUTCOME_CO_TRY_FAILURE_LIKELY(...) OUTCOME_TRY_CALL_OVERLOAD(OUTCOME_CO_TRY_FAILURE_LIKELY_INVOKE_TRY, __VA_ARGS__)
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
#define OUTCOME21_TRYA(v, ...) OUTCOME_TRY2_SUCCESS_LIKELY(OUTCOME_TRY_UNIQUE_NAME, return, deduce, auto &&v, __VA_ARGS__)
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
#define OUTCOME21_TRYA_FAILURE_LIKELY(v, ...) OUTCOME_TRY2_FAILURE_LIKELY(OUTCOME_TRY_UNIQUE_NAME, return, deduce, auto &&v, __VA_ARGS__)
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
#define OUTCOME21_CO_TRYA(v, ...) OUTCOME_TRY2_FAILURE_LIKELY(OUTCOME_TRY_UNIQUE_NAME, co_return, deduce, auto &&v, __VA_ARGS__)
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
#define OUTCOME21_CO_TRYA_FAILURE_LIKELY(v, ...) OUTCOME_TRY2_FAILURE_LIKELY(OUTCOME_TRY_UNIQUE_NAME, co_retrn, deduce, auto &&v, __VA_ARGS__)
#define OUTCOME21_TRY_INVOKE_TRY8(a, b, c, d, e, f, g, h) OUTCOME21_TRYA(a, b, c, d, e, f, g, h)
#define OUTCOME21_TRY_INVOKE_TRY7(a, b, c, d, e, f, g) OUTCOME21_TRYA(a, b, c, d, e, f, g)
#define OUTCOME21_TRY_INVOKE_TRY6(a, b, c, d, e, f) OUTCOME21_TRYA(a, b, c, d, e, f)
#define OUTCOME21_TRY_INVOKE_TRY5(a, b, c, d, e) OUTCOME21_TRYA(a, b, c, d, e)
#define OUTCOME21_TRY_INVOKE_TRY4(a, b, c, d) OUTCOME21_TRYA(a, b, c, d)
#define OUTCOME21_TRY_INVOKE_TRY3(a, b, c) OUTCOME21_TRYA(a, b, c)
#define OUTCOME21_TRY_INVOKE_TRY2(a, b) OUTCOME21_TRYA(a, b)
#define OUTCOME21_TRY_INVOKE_TRY1(a) OUTCOME_TRYV(a)
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
#define OUTCOME21_TRY(...) OUTCOME_TRY_CALL_OVERLOAD(OUTCOME21_TRY_INVOKE_TRY, __VA_ARGS__)
#define OUTCOME21_TRY_FAILURE_LIKELY_INVOKE_TRY8(a, b, c, d, e, f, g, h) OUTCOME21_TRYA_FAILURE_LIKELY(a, b, c, d, e, f, g, h)
#define OUTCOME21_TRY_FAILURE_LIKELY_INVOKE_TRY7(a, b, c, d, e, f, g) OUTCOME21_TRYA_FAILURE_LIKELY(a, b, c, d, e, f, g)
#define OUTCOME21_TRY_FAILURE_LIKELY_INVOKE_TRY6(a, b, c, d, e, f) OUTCOME21_TRYA_FAILURE_LIKELY(a, b, c, d, e, f)
#define OUTCOME21_TRY_FAILURE_LIKELY_INVOKE_TRY5(a, b, c, d, e) OUTCOME21_TRYA_FAILURE_LIKELY(a, b, c, d, e)
#define OUTCOME21_TRY_FAILURE_LIKELY_INVOKE_TRY4(a, b, c, d) OUTCOME21_TRYA_FAILURE_LIKELY(a, b, c, d)
#define OUTCOME21_TRY_FAILURE_LIKELY_INVOKE_TRY3(a, b, c) OUTCOME21_TRYA_FAILURE_LIKELY(a, b, c)
#define OUTCOME21_TRY_FAILURE_LIKELY_INVOKE_TRY2(a, b) OUTCOME21_TRYA_FAILURE_LIKELY(a, b)
#define OUTCOME21_TRY_FAILURE_LIKELY_INVOKE_TRY1(a) OUTCOME_TRYV_FAILURE_LIKELY(a)
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
#define OUTCOME21_TRY_FAILURE_LIKELY(...) OUTCOME_TRY_CALL_OVERLOAD(OUTCOME21_TRY_FAILURE_LIKELY_INVOKE_TRY, __VA_ARGS__)
#define OUTCOME21_CO_TRY_INVOKE_TRY8(a, b, c, d, e, f, g, h) OUTCOME21_CO_TRYA(a, b, c, d, e, f, g, h)
#define OUTCOME21_CO_TRY_INVOKE_TRY7(a, b, c, d, e, f, g) OUTCOME21_CO_TRYA(a, b, c, d, e, f, g)
#define OUTCOME21_CO_TRY_INVOKE_TRY6(a, b, c, d, e, f) OUTCOME21_CO_TRYA(a, b, c, d, e, f)
#define OUTCOME21_CO_TRY_INVOKE_TRY5(a, b, c, d, e) OUTCOME21_CO_TRYA(a, b, c, d, e)
#define OUTCOME21_CO_TRY_INVOKE_TRY4(a, b, c, d) OUTCOME21_CO_TRYA(a, b, c, d)
#define OUTCOME21_CO_TRY_INVOKE_TRY3(a, b, c) OUTCOME21_CO_TRYA(a, b, c)
#define OUTCOME21_CO_TRY_INVOKE_TRY2(a, b) OUTCOME21_CO_TRYA(a, b)
#define OUTCOME21_CO_TRY_INVOKE_TRY1(a) OUTCOME_CO_TRYV(a)
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
#define OUTCOME21_CO_TRY(...) OUTCOME_TRY_CALL_OVERLOAD(OUTCOME21_CO_TRY_INVOKE_TRY, __VA_ARGS__)
#define OUTCOME21_CO_TRY_FAILURE_LIKELY_INVOKE_TRY8(a, b, c, d, e, f, g, h) OUTCOME21_CO_TRYA_FAILURE_LIKELY(a, b, c, d, e, f, g, h)
#define OUTCOME21_CO_TRY_FAILURE_LIKELY_INVOKE_TRY7(a, b, c, d, e, f, g) OUTCOME21_CO_TRYA_FAILURE_LIKELY(a, b, c, d, e, f, g)
#define OUTCOME21_CO_TRY_FAILURE_LIKELY_INVOKE_TRY6(a, b, c, d, e, f) OUTCOME21_CO_TRYA_FAILURE_LIKELY(a, b, c, d, e, f)
#define OUTCOME21_CO_TRY_FAILURE_LIKELY_INVOKE_TRY5(a, b, c, d, e) OUTCOME21_CO_TRYA_FAILURE_LIKELY(a, b, c, d, e)
#define OUTCOME21_CO_TRY_FAILURE_LIKELY_INVOKE_TRY4(a, b, c, d) OUTCOME21_CO_TRYA_FAILURE_LIKELY(a, b, c, d)
#define OUTCOME21_CO_TRY_FAILURE_LIKELY_INVOKE_TRY3(a, b, c) OUTCOME21_CO_TRYA_FAILURE_LIKELY(a, b, c)
#define OUTCOME21_CO_TRY_FAILURE_LIKELY_INVOKE_TRY2(a, b) OUTCOME21_CO_TRYA_FAILURE_LIKELY(a, b)
#define OUTCOME21_CO_TRY_FAILURE_LIKELY_INVOKE_TRY1(a) OUTCOME_CO_TRYV_FAILURE_LIKELY(a)
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
#define OUTCOME21_CO_TRY_FAILURE_LIKELY(...) OUTCOME_TRY_CALL_OVERLOAD(OUTCOME21_CO_TRY_FAILURE_LIKELY_INVOKE_TRY, __VA_ARGS__)
#if !defined(__clang__) && defined(__GNUC__) && __GNUC__ >= 8
#pragma GCC diagnostic pop
#endif
#endif
|
0 | repos/outcome | repos/outcome/single-header/Readme.md | Herein lie multiple single header editions of Outcome:
<dl>
<dt><code><outcome-basic.hpp></code></dt>
<dd>An inclusion of <code>basic_outcome.hpp</code> + <code>try.hpp</code> which includes as few
system headers as possible in order to give an absolute minimum compile time
impact edition of Outcome. See <a href="https://github.com/ned14/stl-header-heft">https://github.com/ned14/stl-header-heft</a>.
</dd>
<dt><code><outcome-experimental.hpp></code></dt>
<dd>An inclusion of <code>experimental/status_outcome.hpp</code> + <code>try.hpp</code> which
is the low compile time impact of the basic edition combined with
<code>status_code</code> from <a href="https://ned14.github.io/status-code/">https://ned14.github.io/status-code/</a>. If you are on an
embedded system where binary bloat must be absolutely avoided, and don't
mind the potentially unstable <code>status_code</code>, this is definitely the edition
for you.
</dd>
<dt><code><outcome.hpp></code></dt>
<dd>An inclusion of <code>outcome.hpp</code> which brings in all the specialisations
for the <code>std</code> STL types, the utilities header, plus iostreams and coroutines
support. If you don't know which edition to use, you should use this one, it ought to
"just work".</dd>
</dl>
|
0 | repos/outcome | repos/outcome/single-header/outcome.hpp | /* Include the default amount of outcome
(C) 2018-2021 Niall Douglas <http://www.nedproductions.biz/> (4 commits)
File Created: Mar 2018
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License in the accompanying file
Licence.txt or at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Distributed under the Boost Software License, Version 1.0.
(See accompanying file Licence.txt or copy at
http://www.boost.org/LICENSE_1_0.txt)
*/
#if !OUTCOME_ENABLE_CXX_MODULES || !0L || defined(GENERATING_OUTCOME_MODULE_INTERFACE) || OUTCOME_DISABLE_CXX_MODULES
/* Tells C++ coroutines about Outcome's result
(C) 2019 Niall Douglas <http://www.nedproductions.biz/> (12 commits)
File Created: Oct 2019
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License in the accompanying file
Licence.txt or at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Distributed under the Boost Software License, Version 1.0.
(See accompanying file Licence.txt or copy at
http://www.boost.org/LICENSE_1_0.txt)
*/
#ifndef OUTCOME_COROUTINE_SUPPORT_HPP
#define OUTCOME_COROUTINE_SUPPORT_HPP
/* Configure Outcome with QuickCppLib
(C) 2015-2021 Niall Douglas <http://www.nedproductions.biz/> (24 commits)
File Created: August 2015
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License in the accompanying file
Licence.txt or at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Distributed under the Boost Software License, Version 1.0.
(See accompanying file Licence.txt or copy at
http://www.boost.org/LICENSE_1_0.txt)
*/
#ifndef OUTCOME_V2_CONFIG_HPP
#define OUTCOME_V2_CONFIG_HPP
/* Sets Outcome version
(C) 2017-2023 Niall Douglas <http://www.nedproductions.biz/> (4 commits)
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License in the accompanying file
Licence.txt or at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Distributed under the Boost Software License, Version 1.0.
(See accompanying file Licence.txt or copy at
http://www.boost.org/LICENSE_1_0.txt)
*/
/*! AWAITING HUGO JSON CONVERSION TOOL */
#define OUTCOME_VERSION_MAJOR 2
/*! AWAITING HUGO JSON CONVERSION TOOL */
#define OUTCOME_VERSION_MINOR 2
/*! AWAITING HUGO JSON CONVERSION TOOL */
#define OUTCOME_VERSION_PATCH 9
/*! AWAITING HUGO JSON CONVERSION TOOL */
#define OUTCOME_VERSION_REVISION 0 // Revision version for cmake and DLL version stamping
/*! AWAITING HUGO JSON CONVERSION TOOL */
// Pull in detection of __MINGW64_VERSION_MAJOR
#if defined(__MINGW32__) && !0L
#include <_mingw.h>
#endif
/* Configure QuickCppLib
(C) 2016-2021 Niall Douglas <http://www.nedproductions.biz/> (8 commits)
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License in the accompanying file
Licence.txt or at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Distributed under the Boost Software License, Version 1.0.
(See accompanying file Licence.txt or copy at
http://www.boost.org/LICENSE_1_0.txt)
*/
#ifndef QUICKCPPLIB_CONFIG_HPP
#define QUICKCPPLIB_CONFIG_HPP
/* Provides SG-10 feature checking for all C++ compilers
(C) 2014-2017 Niall Douglas <http://www.nedproductions.biz/> (13 commits)
File Created: Nov 2014
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License in the accompanying file
Licence.txt or at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Distributed under the Boost Software License, Version 1.0.
(See accompanying file Licence.txt or copy at
http://www.boost.org/LICENSE_1_0.txt)
*/
#ifndef QUICKCPPLIB_HAS_FEATURE_H
#define QUICKCPPLIB_HAS_FEATURE_H
#if __cplusplus >= 201103L
// Some of these macros ended up getting removed by ISO standards,
// they are prefixed with ////
////#if !defined(__cpp_alignas)
////#define __cpp_alignas 190000
////#endif
////#if !defined(__cpp_default_function_template_args)
////#define __cpp_default_function_template_args 190000
////#endif
////#if !defined(__cpp_defaulted_functions)
////#define __cpp_defaulted_functions 190000
////#endif
////#if !defined(__cpp_deleted_functions)
////#define __cpp_deleted_functions 190000
////#endif
////#if !defined(__cpp_generalized_initializers)
////#define __cpp_generalized_initializers 190000
////#endif
////#if !defined(__cpp_implicit_moves)
////#define __cpp_implicit_moves 190000
////#endif
////#if !defined(__cpp_inline_namespaces)
////#define __cpp_inline_namespaces 190000
////#endif
////#if !defined(__cpp_local_type_template_args)
////#define __cpp_local_type_template_args 190000
////#endif
////#if !defined(__cpp_noexcept)
////#define __cpp_noexcept 190000
////#endif
////#if !defined(__cpp_nonstatic_member_init)
////#define __cpp_nonstatic_member_init 190000
////#endif
////#if !defined(__cpp_nullptr)
////#define __cpp_nullptr 190000
////#endif
////#if !defined(__cpp_override_control)
////#define __cpp_override_control 190000
////#endif
////#if !defined(__cpp_thread_local)
////#define __cpp_thread_local 190000
////#endif
////#if !defined(__cpp_auto_type)
////#define __cpp_auto_type 190000
////#endif
////#if !defined(__cpp_strong_enums)
////#define __cpp_strong_enums 190000
////#endif
////#if !defined(__cpp_trailing_return)
////#define __cpp_trailing_return 190000
////#endif
////#if !defined(__cpp_unrestricted_unions)
////#define __cpp_unrestricted_unions 190000
////#endif
#if !defined(__cpp_alias_templates)
#define __cpp_alias_templates 190000
#endif
#if !defined(__cpp_attributes)
#define __cpp_attributes 190000
#endif
#if !defined(__cpp_constexpr)
#if __cplusplus >= 201402L
#define __cpp_constexpr 201304 // relaxed constexpr
#else
#define __cpp_constexpr 190000
#endif
#endif
#if !defined(__cpp_decltype)
#define __cpp_decltype 190000
#endif
#if !defined(__cpp_delegating_constructors)
#define __cpp_delegating_constructors 190000
#endif
#if !defined(__cpp_explicit_conversion) //// renamed from __cpp_explicit_conversions
#define __cpp_explicit_conversion 190000
#endif
#if !defined(__cpp_inheriting_constructors)
#define __cpp_inheriting_constructors 190000
#endif
#if !defined(__cpp_initializer_lists) //// NEW
#define __cpp_initializer_lists 190000
#endif
#if !defined(__cpp_lambdas)
#define __cpp_lambdas 190000
#endif
#if !defined(__cpp_nsdmi)
#define __cpp_nsdmi 190000 //// NEW
#endif
#if !defined(__cpp_range_based_for) //// renamed from __cpp_range_for
#define __cpp_range_based_for 190000
#endif
#if !defined(__cpp_raw_strings)
#define __cpp_raw_strings 190000
#endif
#if !defined(__cpp_ref_qualifiers) //// renamed from __cpp_reference_qualified_functions
#define __cpp_ref_qualifiers 190000
#endif
#if !defined(__cpp_rvalue_references)
#define __cpp_rvalue_references 190000
#endif
#if !defined(__cpp_static_assert)
#define __cpp_static_assert 190000
#endif
#if !defined(__cpp_unicode_characters) //// NEW
#define __cpp_unicode_characters 190000
#endif
#if !defined(__cpp_unicode_literals)
#define __cpp_unicode_literals 190000
#endif
#if !defined(__cpp_user_defined_literals)
#define __cpp_user_defined_literals 190000
#endif
#if !defined(__cpp_variadic_templates)
#define __cpp_variadic_templates 190000
#endif
#endif
#if __cplusplus >= 201402L
// Some of these macros ended up getting removed by ISO standards,
// they are prefixed with ////
////#if !defined(__cpp_contextual_conversions)
////#define __cpp_contextual_conversions 190000
////#endif
////#if !defined(__cpp_digit_separators)
////#define __cpp_digit_separators 190000
////#endif
////#if !defined(__cpp_relaxed_constexpr)
////#define __cpp_relaxed_constexpr 190000
////#endif
////#if !defined(__cpp_runtime_arrays)
////# define __cpp_runtime_arrays 190000
////#endif
#if !defined(__cpp_aggregate_nsdmi)
#define __cpp_aggregate_nsdmi 190000
#endif
#if !defined(__cpp_binary_literals)
#define __cpp_binary_literals 190000
#endif
#if !defined(__cpp_decltype_auto)
#define __cpp_decltype_auto 190000
#endif
#if !defined(__cpp_generic_lambdas)
#define __cpp_generic_lambdas 190000
#endif
#if !defined(__cpp_init_captures)
#define __cpp_init_captures 190000
#endif
#if !defined(__cpp_return_type_deduction)
#define __cpp_return_type_deduction 190000
#endif
#if !defined(__cpp_sized_deallocation)
#define __cpp_sized_deallocation 190000
#endif
#if !defined(__cpp_variable_templates)
#define __cpp_variable_templates 190000
#endif
#endif
// VS2010: _MSC_VER=1600
// VS2012: _MSC_VER=1700
// VS2013: _MSC_VER=1800
// VS2015: _MSC_VER=1900
// VS2017: _MSC_VER=1910
#if defined(_MSC_VER) && !defined(__clang__)
#if !defined(__cpp_exceptions) && defined(_CPPUNWIND)
#define __cpp_exceptions 190000
#endif
#if !defined(__cpp_rtti) && defined(_CPPRTTI)
#define __cpp_rtti 190000
#endif
// C++ 11
#if !defined(__cpp_alias_templates) && _MSC_VER >= 1800
#define __cpp_alias_templates 190000
#endif
#if !defined(__cpp_attributes)
#define __cpp_attributes 190000
#endif
#if !defined(__cpp_constexpr) && _MSC_FULL_VER >= 190023506 /* VS2015 */
#define __cpp_constexpr 190000
#endif
#if !defined(__cpp_decltype) && _MSC_VER >= 1600
#define __cpp_decltype 190000
#endif
#if !defined(__cpp_delegating_constructors) && _MSC_VER >= 1800
#define __cpp_delegating_constructors 190000
#endif
#if !defined(__cpp_explicit_conversion) && _MSC_VER >= 1800
#define __cpp_explicit_conversion 190000
#endif
#if !defined(__cpp_inheriting_constructors) && _MSC_VER >= 1900
#define __cpp_inheriting_constructors 190000
#endif
#if !defined(__cpp_initializer_lists) && _MSC_VER >= 1900
#define __cpp_initializer_lists 190000
#endif
#if !defined(__cpp_lambdas) && _MSC_VER >= 1600
#define __cpp_lambdas 190000
#endif
#if !defined(__cpp_nsdmi) && _MSC_VER >= 1900
#define __cpp_nsdmi 190000
#endif
#if !defined(__cpp_range_based_for) && _MSC_VER >= 1700
#define __cpp_range_based_for 190000
#endif
#if !defined(__cpp_raw_strings) && _MSC_VER >= 1800
#define __cpp_raw_strings 190000
#endif
#if !defined(__cpp_ref_qualifiers) && _MSC_VER >= 1900
#define __cpp_ref_qualifiers 190000
#endif
#if !defined(__cpp_rvalue_references) && _MSC_VER >= 1600
#define __cpp_rvalue_references 190000
#endif
#if !defined(__cpp_static_assert) && _MSC_VER >= 1600
#define __cpp_static_assert 190000
#endif
//#if !defined(__cpp_unicode_literals)
//# define __cpp_unicode_literals 190000
//#endif
#if !defined(__cpp_user_defined_literals) && _MSC_VER >= 1900
#define __cpp_user_defined_literals 190000
#endif
#if !defined(__cpp_variadic_templates) && _MSC_VER >= 1800
#define __cpp_variadic_templates 190000
#endif
// C++ 14
//#if !defined(__cpp_aggregate_nsdmi)
//#define __cpp_aggregate_nsdmi 190000
//#endif
#if !defined(__cpp_binary_literals) && _MSC_VER >= 1900
#define __cpp_binary_literals 190000
#endif
#if !defined(__cpp_decltype_auto) && _MSC_VER >= 1900
#define __cpp_decltype_auto 190000
#endif
#if !defined(__cpp_generic_lambdas) && _MSC_VER >= 1900
#define __cpp_generic_lambdas 190000
#endif
#if !defined(__cpp_init_captures) && _MSC_VER >= 1900
#define __cpp_init_captures 190000
#endif
#if !defined(__cpp_return_type_deduction) && _MSC_VER >= 1900
#define __cpp_return_type_deduction 190000
#endif
#if !defined(__cpp_sized_deallocation) && _MSC_VER >= 1900
#define __cpp_sized_deallocation 190000
#endif
#if !defined(__cpp_variable_templates) && _MSC_FULL_VER >= 190023506
#define __cpp_variable_templates 190000
#endif
#endif // _MSC_VER
// Much to my surprise, GCC's support of these is actually incomplete, so fill in the gaps
#if (defined(__GNUC__) && !defined(__clang__))
#define QUICKCPPLIB_GCC (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__)
#if !defined(__cpp_exceptions) && defined(__EXCEPTIONS)
#define __cpp_exceptions 190000
#endif
#if !defined(__cpp_rtti) && defined(__GXX_RTTI)
#define __cpp_rtti 190000
#endif
// C++ 11
#if defined(__GXX_EXPERIMENTAL_CXX0X__)
#if !defined(__cpp_alias_templates) && (QUICKCPPLIB_GCC >= 40700)
#define __cpp_alias_templates 190000
#endif
#if !defined(__cpp_attributes) && (QUICKCPPLIB_GCC >= 40800)
#define __cpp_attributes 190000
#endif
#if !defined(__cpp_constexpr) && (QUICKCPPLIB_GCC >= 40600)
#define __cpp_constexpr 190000
#endif
#if !defined(__cpp_decltype) && (QUICKCPPLIB_GCC >= 40300)
#define __cpp_decltype 190000
#endif
#if !defined(__cpp_delegating_constructors) && (QUICKCPPLIB_GCC >= 40700)
#define __cpp_delegating_constructors 190000
#endif
#if !defined(__cpp_explicit_conversion) && (QUICKCPPLIB_GCC >= 40500)
#define __cpp_explicit_conversion 190000
#endif
#if !defined(__cpp_inheriting_constructors) && (QUICKCPPLIB_GCC >= 40800)
#define __cpp_inheriting_constructors 190000
#endif
#if !defined(__cpp_initializer_lists) && (QUICKCPPLIB_GCC >= 40800)
#define __cpp_initializer_lists 190000
#endif
#if !defined(__cpp_lambdas) && (QUICKCPPLIB_GCC >= 40500)
#define __cpp_lambdas 190000
#endif
#if !defined(__cpp_nsdmi) && (QUICKCPPLIB_GCC >= 40700)
#define __cpp_nsdmi 190000
#endif
#if !defined(__cpp_range_based_for) && (QUICKCPPLIB_GCC >= 40600)
#define __cpp_range_based_for 190000
#endif
#if !defined(__cpp_raw_strings) && (QUICKCPPLIB_GCC >= 40500)
#define __cpp_raw_strings 190000
#endif
#if !defined(__cpp_ref_qualifiers) && (QUICKCPPLIB_GCC >= 40801)
#define __cpp_ref_qualifiers 190000
#endif
// __cpp_rvalue_reference deviation
#if !defined(__cpp_rvalue_references) && defined(__cpp_rvalue_reference)
#define __cpp_rvalue_references __cpp_rvalue_reference
#endif
#if !defined(__cpp_static_assert) && (QUICKCPPLIB_GCC >= 40300)
#define __cpp_static_assert 190000
#endif
#if !defined(__cpp_unicode_characters) && (QUICKCPPLIB_GCC >= 40500)
#define __cpp_unicode_characters 190000
#endif
#if !defined(__cpp_unicode_literals) && (QUICKCPPLIB_GCC >= 40500)
#define __cpp_unicode_literals 190000
#endif
#if !defined(__cpp_user_defined_literals) && (QUICKCPPLIB_GCC >= 40700)
#define __cpp_user_defined_literals 190000
#endif
#if !defined(__cpp_variadic_templates) && (QUICKCPPLIB_GCC >= 40400)
#define __cpp_variadic_templates 190000
#endif
// C++ 14
// Every C++ 14 supporting GCC does the right thing here
#endif // __GXX_EXPERIMENTAL_CXX0X__
#endif // GCC
// clang deviates in some places from the present SG-10 draft, plus older
// clangs are quite incomplete
#if defined(__clang__)
#define QUICKCPPLIB_CLANG (__clang_major__ * 10000 + __clang_minor__ * 100 + __clang_patchlevel__)
#if !defined(__cpp_exceptions) && (defined(__EXCEPTIONS) || defined(_CPPUNWIND))
#define __cpp_exceptions 190000
#endif
#if !defined(__cpp_rtti) && (defined(__GXX_RTTI) || defined(_CPPRTTI))
#define __cpp_rtti 190000
#endif
// C++ 11
#if defined(__GXX_EXPERIMENTAL_CXX0X__)
#if !defined(__cpp_alias_templates) && (QUICKCPPLIB_CLANG >= 30000)
#define __cpp_alias_templates 190000
#endif
#if !defined(__cpp_attributes) && (QUICKCPPLIB_CLANG >= 30300)
#define __cpp_attributes 190000
#endif
#if !defined(__cpp_constexpr) && (QUICKCPPLIB_CLANG >= 30100)
#define __cpp_constexpr 190000
#endif
#if !defined(__cpp_decltype) && (QUICKCPPLIB_CLANG >= 20900)
#define __cpp_decltype 190000
#endif
#if !defined(__cpp_delegating_constructors) && (QUICKCPPLIB_CLANG >= 30000)
#define __cpp_delegating_constructors 190000
#endif
#if !defined(__cpp_explicit_conversion) && (QUICKCPPLIB_CLANG >= 30000)
#define __cpp_explicit_conversion 190000
#endif
#if !defined(__cpp_inheriting_constructors) && (QUICKCPPLIB_CLANG >= 30300)
#define __cpp_inheriting_constructors 190000
#endif
#if !defined(__cpp_initializer_lists) && (QUICKCPPLIB_CLANG >= 30100)
#define __cpp_initializer_lists 190000
#endif
#if !defined(__cpp_lambdas) && (QUICKCPPLIB_CLANG >= 30100)
#define __cpp_lambdas 190000
#endif
#if !defined(__cpp_nsdmi) && (QUICKCPPLIB_CLANG >= 30000)
#define __cpp_nsdmi 190000
#endif
#if !defined(__cpp_range_based_for) && (QUICKCPPLIB_CLANG >= 30000)
#define __cpp_range_based_for 190000
#endif
// __cpp_raw_string_literals deviation
#if !defined(__cpp_raw_strings) && defined(__cpp_raw_string_literals)
#define __cpp_raw_strings __cpp_raw_string_literals
#endif
#if !defined(__cpp_raw_strings) && (QUICKCPPLIB_CLANG >= 30000)
#define __cpp_raw_strings 190000
#endif
#if !defined(__cpp_ref_qualifiers) && (QUICKCPPLIB_CLANG >= 20900)
#define __cpp_ref_qualifiers 190000
#endif
// __cpp_rvalue_reference deviation
#if !defined(__cpp_rvalue_references) && defined(__cpp_rvalue_reference)
#define __cpp_rvalue_references __cpp_rvalue_reference
#endif
#if !defined(__cpp_rvalue_references) && (QUICKCPPLIB_CLANG >= 20900)
#define __cpp_rvalue_references 190000
#endif
#if !defined(__cpp_static_assert) && (QUICKCPPLIB_CLANG >= 20900)
#define __cpp_static_assert 190000
#endif
#if !defined(__cpp_unicode_characters) && (QUICKCPPLIB_CLANG >= 30000)
#define __cpp_unicode_characters 190000
#endif
#if !defined(__cpp_unicode_literals) && (QUICKCPPLIB_CLANG >= 30000)
#define __cpp_unicode_literals 190000
#endif
// __cpp_user_literals deviation
#if !defined(__cpp_user_defined_literals) && defined(__cpp_user_literals)
#define __cpp_user_defined_literals __cpp_user_literals
#endif
#if !defined(__cpp_user_defined_literals) && (QUICKCPPLIB_CLANG >= 30100)
#define __cpp_user_defined_literals 190000
#endif
#if !defined(__cpp_variadic_templates) && (QUICKCPPLIB_CLANG >= 20900)
#define __cpp_variadic_templates 190000
#endif
// C++ 14
// Every C++ 14 supporting clang does the right thing here
#endif // __GXX_EXPERIMENTAL_CXX0X__
#endif // clang
#endif
/*
This is a dummy header file which is a placeholder for the real config.hpp which
gets generated by the build system. This file is here to allow the library to be
used without the build system.
*/
#if defined(min)
#error "You must not define min() as a macro, because this is unsupported and known to break e.g. LLFIO"
#elif defined(max)
#error "You must not define max() as a macro, because this is unsupported and known to break e.g. LLFIO"
#endif
#define QUICKCPPLIB_VERSION_GLUE2(a, b) a##b
#define QUICKCPPLIB_VERSION_GLUE(a, b) QUICKCPPLIB_VERSION_GLUE2(a, b)
// clang-format off
#define QUICKCPPLIB_NAMESPACE quickcpplib
#define QUICKCPPLIB_NAMESPACE_BEGIN namespace quickcpplib {
#define QUICKCPPLIB_NAMESPACE_END }
// clang-format on
#ifdef _MSC_VER
#define QUICKCPPLIB_BIND_MESSAGE_PRAGMA2(x) __pragma(message(x))
#define QUICKCPPLIB_BIND_MESSAGE_PRAGMA(x) QUICKCPPLIB_BIND_MESSAGE_PRAGMA2(x)
#define QUICKCPPLIB_BIND_MESSAGE_PREFIX(type) __FILE__ "(" QUICKCPPLIB_BIND_STRINGIZE2(__LINE__) "): " type ": "
#define QUICKCPPLIB_BIND_MESSAGE_(type, prefix, msg) QUICKCPPLIB_BIND_MESSAGE_PRAGMA(prefix msg)
#else
#define QUICKCPPLIB_BIND_MESSAGE_PRAGMA2(x) _Pragma(#x)
#define QUICKCPPLIB_BIND_MESSAGE_PRAGMA(type, x) QUICKCPPLIB_BIND_MESSAGE_PRAGMA2(type x)
#define QUICKCPPLIB_BIND_MESSAGE_(type, prefix, msg) QUICKCPPLIB_BIND_MESSAGE_PRAGMA(type, msg)
#endif
//! Have the compiler output a message
#define QUICKCPPLIB_MESSAGE(msg) QUICKCPPLIB_BIND_MESSAGE_(message, QUICKCPPLIB_BIND_MESSAGE_PREFIX("message"), msg)
//! Have the compiler output a note
#define QUICKCPPLIB_NOTE(msg) QUICKCPPLIB_BIND_MESSAGE_(message, QUICKCPPLIB_BIND_MESSAGE_PREFIX("note"), msg)
//! Have the compiler output a warning
#define QUICKCPPLIB_WARNING(msg) QUICKCPPLIB_BIND_MESSAGE_(GCC warning, QUICKCPPLIB_BIND_MESSAGE_PREFIX("warning"), msg)
//! Have the compiler output an error
#define QUICKCPPLIB_ERROR(msg) QUICKCPPLIB_BIND_MESSAGE_(GCC error, QUICKCPPLIB_BIND_MESSAGE_PREFIX("error"), msg)
#define QUICKCPPLIB_ANNOTATE_RWLOCK_CREATE(p)
#define QUICKCPPLIB_ANNOTATE_RWLOCK_DESTROY(p)
#define QUICKCPPLIB_ANNOTATE_RWLOCK_ACQUIRED(p, s)
#define QUICKCPPLIB_ANNOTATE_RWLOCK_RELEASED(p, s)
#define QUICKCPPLIB_ANNOTATE_IGNORE_READS_BEGIN()
#define QUICKCPPLIB_ANNOTATE_IGNORE_READS_END()
#define QUICKCPPLIB_ANNOTATE_IGNORE_WRITES_BEGIN()
#define QUICKCPPLIB_ANNOTATE_IGNORE_WRITES_END()
#define QUICKCPPLIB_DRD_IGNORE_VAR(x)
#define QUICKCPPLIB_DRD_STOP_IGNORING_VAR(x)
#define QUICKCPPLIB_RUNNING_ON_VALGRIND (0)
#ifndef QUICKCPPLIB_IN_ADDRESS_SANITIZER
#if defined(__has_feature)
#if __has_feature(address_sanitizer) || defined(__SANITIZE_ADDRESS__)
#define QUICKCPPLIB_IN_ADDRESS_SANITIZER 1
#endif
#elif defined(__SANITIZE_ADDRESS__)
#define QUICKCPPLIB_IN_ADDRESS_SANITIZER 1
#endif
#endif
#ifndef QUICKCPPLIB_IN_ADDRESS_SANITIZER
#define QUICKCPPLIB_IN_ADDRESS_SANITIZER 0
#endif
#ifndef QUICKCPPLIB_IN_THREAD_SANITIZER
#if defined(__has_feature)
#if __has_feature(thread_sanitizer) || defined(__SANITIZE_THREAD__)
#define QUICKCPPLIB_IN_THREAD_SANITIZER 1
#endif
#elif defined(__SANITIZE_THREAD__)
#define QUICKCPPLIB_IN_THREAD_SANITIZER 1
#endif
#endif
#ifndef QUICKCPPLIB_IN_THREAD_SANITIZER
#define QUICKCPPLIB_IN_THREAD_SANITIZER 0
#endif
#ifndef QUICKCPPLIB_IN_UNDEFINED_SANITIZER
#if defined(__has_feature)
#if __has_feature(undefined_behavior_sanitizer) || defined(__SANITIZE_UNDEFINED__) || (__GNUC__ <= 9 && defined(__SANITIZE_ADDRESS__))
#define QUICKCPPLIB_IN_UNDEFINED_SANITIZER 1
#endif
#elif defined(__SANITIZE_UNDEFINED__) || (__GNUC__ <= 9 && defined(__SANITIZE_ADDRESS__))
#define QUICKCPPLIB_IN_UNDEFINED_SANITIZER 1
#endif
#endif
#ifndef QUICKCPPLIB_IN_UNDEFINED_SANITIZER
#define QUICKCPPLIB_IN_UNDEFINED_SANITIZER 0
#endif
#if QUICKCPPLIB_IN_THREAD_SANITIZER
#define QUICKCPPLIB_DISABLE_THREAD_SANITIZE __attribute__((no_sanitize_thread))
#else
#define QUICKCPPLIB_DISABLE_THREAD_SANITIZE
#endif
#if QUICKCPPLIB_IN_THREAD_SANITIZER
#define QUICKCPPLIB_DISABLE_THREAD_SANITIZE __attribute__((no_sanitize_thread))
#else
#define QUICKCPPLIB_DISABLE_THREAD_SANITIZE
#endif
#if QUICKCPPLIB_IN_UNDEFINED_SANITIZER
#define QUICKCPPLIB_DISABLE_UNDEFINED_SANITIZE __attribute__((no_sanitize_undefined))
#else
#define QUICKCPPLIB_DISABLE_UNDEFINED_SANITIZE
#endif
#ifndef QUICKCPPLIB_SMT_PAUSE
#if !defined(__clang__) && defined(_MSC_VER) && _MSC_VER >= 1310 && (defined(_M_IX86) || defined(_M_X64))
extern "C" void _mm_pause();
#if !defined(_M_ARM64EC)
#pragma intrinsic(_mm_pause)
#endif
#define QUICKCPPLIB_SMT_PAUSE _mm_pause();
#elif !defined(__c2__) && defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
#define QUICKCPPLIB_SMT_PAUSE __asm__ __volatile__("rep; nop" : : : "memory");
#endif
#endif
#ifndef QUICKCPPLIB_FORCEINLINE
#if defined(_MSC_VER)
#define QUICKCPPLIB_FORCEINLINE __forceinline
#elif defined(__GNUC__)
#define QUICKCPPLIB_FORCEINLINE __attribute__((always_inline))
#else
#define QUICKCPPLIB_FORCEINLINE
#endif
#endif
#ifndef QUICKCPPLIB_NOINLINE
#if defined(_MSC_VER)
#define QUICKCPPLIB_NOINLINE __declspec(noinline)
#elif defined(__GNUC__)
#define QUICKCPPLIB_NOINLINE __attribute__((noinline))
#else
#define QUICKCPPLIB_NOINLINE
#endif
#endif
#if defined(QUICKCPPLIB_REQUIRE_CXX_STANDARD)
#define QUICKCPPLIB_REQUIRE_CXX17 (QUICKCPPLIB_REQUIRE_CXX_STANDARD >= 201703L)
#define QUICKCPPLIB_REQUIRE_CXX20 (QUICKCPPLIB_REQUIRE_CXX_STANDARD >= 202002L)
#define QUICKCPPLIB_USE_STD_BYTE QUICKCPPLIB_REQUIRE_CXX17
#define QUICKCPPLIB_USE_STD_OPTIONAL QUICKCPPLIB_REQUIRE_CXX17
#define QUICKCPPLIB_USE_STD_SPAN QUICKCPPLIB_REQUIRE_CXX20
#endif // ^^^ defined QUICKCPPLIB_REQUIRE_CXX_STANDARD ^^^
#if !defined(QUICKCPPLIB_USE_SYSTEM_BYTE_LITE)
#define QUICKCPPLIB_USE_SYSTEM_BYTE_LITE 0
#endif
#if !defined(QUICKCPPLIB_USE_SYSTEM_SPAN_LITE)
#define QUICKCPPLIB_USE_SYSTEM_SPAN_LITE 0
#endif
#ifdef __has_cpp_attribute
#define QUICKCPPLIB_HAS_CPP_ATTRIBUTE(attr, edition) (__has_cpp_attribute(attr) >= (edition) && __cplusplus >= (edition))
#else
#define QUICKCPPLIB_HAS_CPP_ATTRIBUTE(attr, edition) (0)
#endif
#if !defined(QUICKCPPLIB_NORETURN)
#if QUICKCPPLIB_HAS_CPP_ATTRIBUTE(noreturn, 201100)
#define QUICKCPPLIB_NORETURN [[noreturn]]
#elif defined(_MSC_VER)
#define QUICKCPPLIB_NORETURN __declspec(noreturn)
#elif defined(__GNUC__)
#define QUICKCPPLIB_NORETURN __attribute__((__noreturn__))
#else
#define QUICKCPPLIB_NORETURN
#endif
#endif
#ifndef QUICKCPPLIB_NODISCARD
#if 0L || (_HAS_CXX17 && _MSC_VER >= 1911 /* VS2017.3 */)
#define QUICKCPPLIB_NODISCARD [[nodiscard]]
#endif
#endif
#ifndef QUICKCPPLIB_NODISCARD
#if QUICKCPPLIB_HAS_CPP_ATTRIBUTE(nodiscard, 201700) && (!defined(__GNUC__) || !defined(__cpp_concepts) || __cpp_concepts >= 202000L /* -fconcepts-ts and [[nodiscard]] don't mix on GCC \
*/)
#define QUICKCPPLIB_NODISCARD [[nodiscard]]
#elif defined(__clang__) // deliberately not GCC
#define QUICKCPPLIB_NODISCARD __attribute__((warn_unused_result))
#elif defined(_MSC_VER)
// _Must_inspect_result_ expands into this
#define QUICKCPPLIB_NODISCARD __declspec( "SAL_name" "(" "\"_Must_inspect_result_\"" "," "\"\"" "," "\"2\"" ")") __declspec("SAL_begin") __declspec("SAL_post") __declspec("SAL_mustInspect") __declspec("SAL_post") __declspec("SAL_checkReturn") __declspec("SAL_end")
#endif
#endif
#ifndef QUICKCPPLIB_NODISCARD
#define QUICKCPPLIB_NODISCARD
#endif
#ifndef QUICKCPPLIB_SYMBOL_VISIBLE
#if defined(_MSC_VER)
#define QUICKCPPLIB_SYMBOL_VISIBLE
#elif defined(__GNUC__)
#define QUICKCPPLIB_SYMBOL_VISIBLE __attribute__((visibility("default")))
#else
#define QUICKCPPLIB_SYMBOL_VISIBLE
#endif
#endif
#ifndef QUICKCPPLIB_SYMBOL_EXPORT
#if defined(_MSC_VER)
#define QUICKCPPLIB_SYMBOL_EXPORT __declspec(dllexport)
#elif defined(__GNUC__)
#define QUICKCPPLIB_SYMBOL_EXPORT __attribute__((visibility("default")))
#else
#define QUICKCPPLIB_SYMBOL_EXPORT
#endif
#endif
#ifndef QUICKCPPLIB_SYMBOL_IMPORT
#if defined(_MSC_VER)
#define QUICKCPPLIB_SYMBOL_IMPORT __declspec(dllimport)
#elif defined(__GNUC__)
#define QUICKCPPLIB_SYMBOL_IMPORT
#else
#define QUICKCPPLIB_SYMBOL_IMPORT
#endif
#endif
#ifndef QUICKCPPLIB_THREAD_LOCAL
#if _MSC_VER >= 1800
#define QUICKCPPLIB_THREAD_LOCAL_IS_CXX11 1
#elif __cplusplus >= 201103L
#if __GNUC__ >= 5 && !defined(__clang__)
#define QUICKCPPLIB_THREAD_LOCAL_IS_CXX11 1
#elif defined(__has_feature)
#if __has_feature(cxx_thread_local)
#define QUICKCPPLIB_THREAD_LOCAL_IS_CXX11 1
#endif
#endif
#endif
#ifdef QUICKCPPLIB_THREAD_LOCAL_IS_CXX11
#define QUICKCPPLIB_THREAD_LOCAL thread_local
#endif
#ifndef QUICKCPPLIB_THREAD_LOCAL
#if defined(_MSC_VER)
#define QUICKCPPLIB_THREAD_LOCAL __declspec(thread)
#elif defined(__GNUC__)
#define QUICKCPPLIB_THREAD_LOCAL __thread
#else
#error Unknown compiler, cannot set QUICKCPPLIB_THREAD_LOCAL
#endif
#endif
#endif
#ifndef QUICKCPPLIB_DISABLE_EXECINFO
#if defined(__EMSCRIPTEN__)
#define QUICKCPPLIB_DISABLE_EXECINFO 1
#endif
#endif
#ifndef QUICKCPPLIB_PLATFORM_NATIVE_BITLENGTH
#if defined(__SIZEOF_POINTER__)
#define QUICKCPPLIB_PLATFORM_NATIVE_BITLENGTH (__SIZEOF_POINTER__ * __CHAR_BIT__)
#elif defined(_WIN64) || defined(__x86_64__) || defined(_M_X64) || defined(__aarch64__) || defined(_M_ARM64) || defined(__ia64__) || defined(_M_IA64) || defined(__ppc64__)
#define QUICKCPPLIB_PLATFORM_NATIVE_BITLENGTH (64)
#else
#define QUICKCPPLIB_PLATFORM_NATIVE_BITLENGTH (32)
#endif
#endif
/* MSVC capable preprocessor macro overloading
(C) 2014-2017 Niall Douglas <http://www.nedproductions.biz/> (3 commits)
File Created: Aug 2014
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License in the accompanying file
Licence.txt or at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Distributed under the Boost Software License, Version 1.0.
(See accompanying file Licence.txt or copy at
http://www.boost.org/LICENSE_1_0.txt)
*/
#ifndef QUICKCPPLIB_PREPROCESSOR_MACRO_OVERLOAD_H
#define QUICKCPPLIB_PREPROCESSOR_MACRO_OVERLOAD_H
#define QUICKCPPLIB_GLUE(x, y) x y
#define QUICKCPPLIB_RETURN_ARG_COUNT(_1_, _2_, _3_, _4_, _5_, _6_, _7_, _8_, count, ...) count
#define QUICKCPPLIB_EXPAND_ARGS(args) QUICKCPPLIB_RETURN_ARG_COUNT args
#define QUICKCPPLIB_COUNT_ARGS_MAX8(...) QUICKCPPLIB_EXPAND_ARGS((__VA_ARGS__, 8, 7, 6, 5, 4, 3, 2, 1, 0))
#define QUICKCPPLIB_OVERLOAD_MACRO2(name, count) name##count
#define QUICKCPPLIB_OVERLOAD_MACRO1(name, count) QUICKCPPLIB_OVERLOAD_MACRO2(name, count)
#define QUICKCPPLIB_OVERLOAD_MACRO(name, count) QUICKCPPLIB_OVERLOAD_MACRO1(name, count)
#define QUICKCPPLIB_CALL_OVERLOAD(name, ...) QUICKCPPLIB_GLUE(QUICKCPPLIB_OVERLOAD_MACRO(name, QUICKCPPLIB_COUNT_ARGS_MAX8(__VA_ARGS__)), (__VA_ARGS__))
#define QUICKCPPLIB_GLUE_(x, y) x y
#define QUICKCPPLIB_RETURN_ARG_COUNT_(_1_, _2_, _3_, _4_, _5_, _6_, _7_, _8_, count, ...) count
#define QUICKCPPLIB_EXPAND_ARGS_(args) QUICKCPPLIB_RETURN_ARG_COUNT_ args
#define QUICKCPPLIB_COUNT_ARGS_MAX8_(...) QUICKCPPLIB_EXPAND_ARGS_((__VA_ARGS__, 8, 7, 6, 5, 4, 3, 2, 1, 0))
#define QUICKCPPLIB_OVERLOAD_MACRO2_(name, count) name##count
#define QUICKCPPLIB_OVERLOAD_MACRO1_(name, count) QUICKCPPLIB_OVERLOAD_MACRO2_(name, count)
#define QUICKCPPLIB_OVERLOAD_MACRO_(name, count) QUICKCPPLIB_OVERLOAD_MACRO1_(name, count)
#define QUICKCPPLIB_CALL_OVERLOAD_(name, ...) QUICKCPPLIB_GLUE_(QUICKCPPLIB_OVERLOAD_MACRO_(name, QUICKCPPLIB_COUNT_ARGS_MAX8_(__VA_ARGS__)), (__VA_ARGS__))
#endif
#if defined(__cpp_concepts) && !defined(QUICKCPPLIB_DISABLE_CONCEPTS_SUPPORT)
#define QUICKCPPLIB_TREQUIRES_EXPAND8(a, b, c, d, e, f, g, h) a &&QUICKCPPLIB_TREQUIRES_EXPAND7(b, c, d, e, f, g, h)
#define QUICKCPPLIB_TREQUIRES_EXPAND7(a, b, c, d, e, f, g) a &&QUICKCPPLIB_TREQUIRES_EXPAND6(b, c, d, e, f, g)
#define QUICKCPPLIB_TREQUIRES_EXPAND6(a, b, c, d, e, f) a &&QUICKCPPLIB_TREQUIRES_EXPAND5(b, c, d, e, f)
#define QUICKCPPLIB_TREQUIRES_EXPAND5(a, b, c, d, e) a &&QUICKCPPLIB_TREQUIRES_EXPAND4(b, c, d, e)
#define QUICKCPPLIB_TREQUIRES_EXPAND4(a, b, c, d) a &&QUICKCPPLIB_TREQUIRES_EXPAND3(b, c, d)
#define QUICKCPPLIB_TREQUIRES_EXPAND3(a, b, c) a &&QUICKCPPLIB_TREQUIRES_EXPAND2(b, c)
#define QUICKCPPLIB_TREQUIRES_EXPAND2(a, b) a &&QUICKCPPLIB_TREQUIRES_EXPAND1(b)
#define QUICKCPPLIB_TREQUIRES_EXPAND1(a) a
//! Expands into a && b && c && ...
#define QUICKCPPLIB_TREQUIRES(...) requires QUICKCPPLIB_CALL_OVERLOAD(QUICKCPPLIB_TREQUIRES_EXPAND, __VA_ARGS__)
#define QUICKCPPLIB_TEMPLATE(...) template <__VA_ARGS__>
#define QUICKCPPLIB_TEXPR(...) requires { (__VA_ARGS__); }
#define QUICKCPPLIB_TPRED(...) (__VA_ARGS__)
#if !defined(_MSC_VER) || _MSC_FULL_VER >= 192400000 // VS 2019 16.3 is broken here
#define QUICKCPPLIB_REQUIRES(...) requires(__VA_ARGS__)
#else
#define QUICKCPPLIB_REQUIRES(...)
#endif
#else
#define QUICKCPPLIB_TEMPLATE(...) template <__VA_ARGS__
#define QUICKCPPLIB_TREQUIRES(...) , __VA_ARGS__ >
#define QUICKCPPLIB_TEXPR(...) typename = decltype(__VA_ARGS__)
#ifdef _MSC_VER
// MSVC gives an error if every specialisation of a template is always ill-formed, so
// the more powerful SFINAE form below causes pukeage :(
#define QUICKCPPLIB_TPRED(...) typename = typename std::enable_if<(__VA_ARGS__)>::type
#else
#define QUICKCPPLIB_TPRED(...) typename std::enable_if<(__VA_ARGS__), bool>::type = true
#endif
#define QUICKCPPLIB_REQUIRES(...)
#endif
#endif
#ifndef __cpp_variadic_templates
#error Outcome needs variadic template support in the compiler
#endif
#if __cpp_constexpr < 201304 && _MSC_FULL_VER < 191100000
#error Outcome needs constexpr (C++ 14) support in the compiler
#endif
#ifndef __cpp_variable_templates
#error Outcome needs variable template support in the compiler
#endif
#if !defined(__clang__) && defined(__GNUC__) && __GNUC__ < 6
#error Due to a bug in nested template variables parsing, Outcome does not work on GCCs earlier than v6.
#endif
#ifndef OUTCOME_SYMBOL_VISIBLE
#define OUTCOME_SYMBOL_VISIBLE QUICKCPPLIB_SYMBOL_VISIBLE
#endif
#ifndef OUTCOME_FORCEINLINE
#define OUTCOME_FORCEINLINE QUICKCPPLIB_FORCEINLINE
#endif
#ifndef OUTCOME_NODISCARD
#define OUTCOME_NODISCARD QUICKCPPLIB_NODISCARD
#endif
#ifndef OUTCOME_THREAD_LOCAL
#define OUTCOME_THREAD_LOCAL QUICKCPPLIB_THREAD_LOCAL
#endif
#ifndef OUTCOME_TEMPLATE
#define OUTCOME_TEMPLATE(...) QUICKCPPLIB_TEMPLATE(__VA_ARGS__)
#endif
#ifndef OUTCOME_TREQUIRES
#define OUTCOME_TREQUIRES(...) QUICKCPPLIB_TREQUIRES(__VA_ARGS__)
#endif
#ifndef OUTCOME_TEXPR
#define OUTCOME_TEXPR(...) QUICKCPPLIB_TEXPR(__VA_ARGS__)
#endif
#ifndef OUTCOME_TPRED
#define OUTCOME_TPRED(...) QUICKCPPLIB_TPRED(__VA_ARGS__)
#endif
#ifndef OUTCOME_REQUIRES
#define OUTCOME_REQUIRES(...) QUICKCPPLIB_REQUIRES(__VA_ARGS__)
#endif
/* Convenience macros for importing local namespace binds
(C) 2014-2017 Niall Douglas <http://www.nedproductions.biz/> (9 commits)
File Created: Aug 2014
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License in the accompanying file
Licence.txt or at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Distributed under the Boost Software License, Version 1.0.
(See accompanying file Licence.txt or copy at
http://www.boost.org/LICENSE_1_0.txt)
*/
#ifndef QUICKCPPLIB_BIND_IMPORT_HPP
#define QUICKCPPLIB_BIND_IMPORT_HPP
/* 2014-10-9 ned: I lost today figuring out the below. I really hate the C preprocessor now.
*
* Anyway, infinity = 8. It's easy to expand below if needed.
*/
#define QUICKCPPLIB_BIND_STRINGIZE(a) #a
#define QUICKCPPLIB_BIND_STRINGIZE2(a) QUICKCPPLIB_BIND_STRINGIZE(a)
#define QUICKCPPLIB_BIND_NAMESPACE_VERSION8(a, b, c, d, e, f, g, h) a##_##b##_##c##_##d##_##e##_##f##_##g##_##h
#define QUICKCPPLIB_BIND_NAMESPACE_VERSION7(a, b, c, d, e, f, g) a##_##b##_##c##_##d##_##e##_##f##_##g
#define QUICKCPPLIB_BIND_NAMESPACE_VERSION6(a, b, c, d, e, f) a##_##b##_##c##_##d##_##e##_##f
#define QUICKCPPLIB_BIND_NAMESPACE_VERSION5(a, b, c, d, e) a##_##b##_##c##_##d##_##e
#define QUICKCPPLIB_BIND_NAMESPACE_VERSION4(a, b, c, d) a##_##b##_##c##_##d
#define QUICKCPPLIB_BIND_NAMESPACE_VERSION3(a, b, c) a##_##b##_##c
#define QUICKCPPLIB_BIND_NAMESPACE_VERSION2(a, b) a##_##b
#define QUICKCPPLIB_BIND_NAMESPACE_VERSION1(a) a
//! Concatenates each parameter with _
#define QUICKCPPLIB_BIND_NAMESPACE_VERSION(...) QUICKCPPLIB_CALL_OVERLOAD(QUICKCPPLIB_BIND_NAMESPACE_VERSION, __VA_ARGS__)
#define QUICKCPPLIB_BIND_NAMESPACE_SELECT_2(name, modifier) name
#define QUICKCPPLIB_BIND_NAMESPACE_SELECT2(name, modifier) ::name
#define QUICKCPPLIB_BIND_NAMESPACE_SELECT_1(name) name
#define QUICKCPPLIB_BIND_NAMESPACE_SELECT1(name) ::name
#define QUICKCPPLIB_BIND_NAMESPACE_SELECT_(...) QUICKCPPLIB_CALL_OVERLOAD_(QUICKCPPLIB_BIND_NAMESPACE_SELECT_, __VA_ARGS__)
#define QUICKCPPLIB_BIND_NAMESPACE_SELECT(...) QUICKCPPLIB_CALL_OVERLOAD_(QUICKCPPLIB_BIND_NAMESPACE_SELECT, __VA_ARGS__)
#define QUICKCPPLIB_BIND_NAMESPACE_EXPAND8(a, b, c, d, e, f, g, h) QUICKCPPLIB_BIND_NAMESPACE_SELECT_ a QUICKCPPLIB_BIND_NAMESPACE_SELECT b QUICKCPPLIB_BIND_NAMESPACE_SELECT c QUICKCPPLIB_BIND_NAMESPACE_SELECT d QUICKCPPLIB_BIND_NAMESPACE_SELECT e QUICKCPPLIB_BIND_NAMESPACE_SELECT f QUICKCPPLIB_BIND_NAMESPACE_SELECT g QUICKCPPLIB_BIND_NAMESPACE_SELECT h
#define QUICKCPPLIB_BIND_NAMESPACE_EXPAND7(a, b, c, d, e, f, g) QUICKCPPLIB_BIND_NAMESPACE_SELECT_ a QUICKCPPLIB_BIND_NAMESPACE_SELECT b QUICKCPPLIB_BIND_NAMESPACE_SELECT c QUICKCPPLIB_BIND_NAMESPACE_SELECT d QUICKCPPLIB_BIND_NAMESPACE_SELECT e QUICKCPPLIB_BIND_NAMESPACE_SELECT f QUICKCPPLIB_BIND_NAMESPACE_SELECT g
#define QUICKCPPLIB_BIND_NAMESPACE_EXPAND6(a, b, c, d, e, f) QUICKCPPLIB_BIND_NAMESPACE_SELECT_ a QUICKCPPLIB_BIND_NAMESPACE_SELECT b QUICKCPPLIB_BIND_NAMESPACE_SELECT c QUICKCPPLIB_BIND_NAMESPACE_SELECT d QUICKCPPLIB_BIND_NAMESPACE_SELECT e QUICKCPPLIB_BIND_NAMESPACE_SELECT f
#define QUICKCPPLIB_BIND_NAMESPACE_EXPAND5(a, b, c, d, e) QUICKCPPLIB_BIND_NAMESPACE_SELECT_ a QUICKCPPLIB_BIND_NAMESPACE_SELECT b QUICKCPPLIB_BIND_NAMESPACE_SELECT c QUICKCPPLIB_BIND_NAMESPACE_SELECT d QUICKCPPLIB_BIND_NAMESPACE_SELECT e
#define QUICKCPPLIB_BIND_NAMESPACE_EXPAND4(a, b, c, d) QUICKCPPLIB_BIND_NAMESPACE_SELECT_ a QUICKCPPLIB_BIND_NAMESPACE_SELECT b QUICKCPPLIB_BIND_NAMESPACE_SELECT c QUICKCPPLIB_BIND_NAMESPACE_SELECT d
#define QUICKCPPLIB_BIND_NAMESPACE_EXPAND3(a, b, c) QUICKCPPLIB_BIND_NAMESPACE_SELECT_ a QUICKCPPLIB_BIND_NAMESPACE_SELECT b QUICKCPPLIB_BIND_NAMESPACE_SELECT c
#define QUICKCPPLIB_BIND_NAMESPACE_EXPAND2(a, b) QUICKCPPLIB_BIND_NAMESPACE_SELECT_ a QUICKCPPLIB_BIND_NAMESPACE_SELECT b
#define QUICKCPPLIB_BIND_NAMESPACE_EXPAND1(a) QUICKCPPLIB_BIND_NAMESPACE_SELECT_ a
//! Expands into a::b::c:: ...
#define QUICKCPPLIB_BIND_NAMESPACE(...) QUICKCPPLIB_CALL_OVERLOAD(QUICKCPPLIB_BIND_NAMESPACE_EXPAND, __VA_ARGS__)
#define QUICKCPPLIB_BIND_NAMESPACE_BEGIN_NAMESPACE_SELECT2(name, modifier) modifier namespace name {
#define QUICKCPPLIB_BIND_NAMESPACE_BEGIN_NAMESPACE_SELECT1(name) namespace name {
#define QUICKCPPLIB_BIND_NAMESPACE_BEGIN_NAMESPACE_SELECT(...) QUICKCPPLIB_CALL_OVERLOAD_(QUICKCPPLIB_BIND_NAMESPACE_BEGIN_NAMESPACE_SELECT, __VA_ARGS__)
#define QUICKCPPLIB_BIND_NAMESPACE_BEGIN_EXPAND8(a, b, c, d, e, f, g, h) QUICKCPPLIB_BIND_NAMESPACE_BEGIN_NAMESPACE_SELECT a QUICKCPPLIB_BIND_NAMESPACE_BEGIN_EXPAND7(b, c, d, e, f, g, h)
#define QUICKCPPLIB_BIND_NAMESPACE_BEGIN_EXPAND7(a, b, c, d, e, f, g) QUICKCPPLIB_BIND_NAMESPACE_BEGIN_NAMESPACE_SELECT a QUICKCPPLIB_BIND_NAMESPACE_BEGIN_EXPAND6(b, c, d, e, f, g)
#define QUICKCPPLIB_BIND_NAMESPACE_BEGIN_EXPAND6(a, b, c, d, e, f) QUICKCPPLIB_BIND_NAMESPACE_BEGIN_NAMESPACE_SELECT a QUICKCPPLIB_BIND_NAMESPACE_BEGIN_EXPAND5(b, c, d, e, f)
#define QUICKCPPLIB_BIND_NAMESPACE_BEGIN_EXPAND5(a, b, c, d, e) QUICKCPPLIB_BIND_NAMESPACE_BEGIN_NAMESPACE_SELECT a QUICKCPPLIB_BIND_NAMESPACE_BEGIN_EXPAND4(b, c, d, e)
#define QUICKCPPLIB_BIND_NAMESPACE_BEGIN_EXPAND4(a, b, c, d) QUICKCPPLIB_BIND_NAMESPACE_BEGIN_NAMESPACE_SELECT a QUICKCPPLIB_BIND_NAMESPACE_BEGIN_EXPAND3(b, c, d)
#define QUICKCPPLIB_BIND_NAMESPACE_BEGIN_EXPAND3(a, b, c) QUICKCPPLIB_BIND_NAMESPACE_BEGIN_NAMESPACE_SELECT a QUICKCPPLIB_BIND_NAMESPACE_BEGIN_EXPAND2(b, c)
#define QUICKCPPLIB_BIND_NAMESPACE_BEGIN_EXPAND2(a, b) QUICKCPPLIB_BIND_NAMESPACE_BEGIN_NAMESPACE_SELECT a QUICKCPPLIB_BIND_NAMESPACE_BEGIN_EXPAND1(b)
#define QUICKCPPLIB_BIND_NAMESPACE_BEGIN_EXPAND1(a) QUICKCPPLIB_BIND_NAMESPACE_BEGIN_NAMESPACE_SELECT a
//! Expands into namespace a { namespace b { namespace c ...
#define QUICKCPPLIB_BIND_NAMESPACE_BEGIN(...) QUICKCPPLIB_CALL_OVERLOAD(QUICKCPPLIB_BIND_NAMESPACE_BEGIN_EXPAND, __VA_ARGS__)
#define QUICKCPPLIB_BIND_NAMESPACE_EXPORT_BEGIN_NAMESPACE_SELECT2(name, modifier) modifier namespace name {
#define QUICKCPPLIB_BIND_NAMESPACE_EXPORT_BEGIN_NAMESPACE_SELECT1(name) export namespace name {
#define QUICKCPPLIB_BIND_NAMESPACE_EXPORT_BEGIN_NAMESPACE_SELECT(...) QUICKCPPLIB_CALL_OVERLOAD_(QUICKCPPLIB_BIND_NAMESPACE_EXPORT_BEGIN_NAMESPACE_SELECT, __VA_ARGS__)
#define QUICKCPPLIB_BIND_NAMESPACE_EXPORT_BEGIN_EXPAND8(a, b, c, d, e, f, g, h) QUICKCPPLIB_BIND_NAMESPACE_EXPORT_BEGIN_NAMESPACE_SELECT a QUICKCPPLIB_BIND_NAMESPACE_EXPORT_BEGIN_EXPAND7(b, c, d, e, f, g, h)
#define QUICKCPPLIB_BIND_NAMESPACE_EXPORT_BEGIN_EXPAND7(a, b, c, d, e, f, g) QUICKCPPLIB_BIND_NAMESPACE_EXPORT_BEGIN_NAMESPACE_SELECT a QUICKCPPLIB_BIND_NAMESPACE_EXPORT_BEGIN_EXPAND6(b, c, d, e, f, g)
#define QUICKCPPLIB_BIND_NAMESPACE_EXPORT_BEGIN_EXPAND6(a, b, c, d, e, f) QUICKCPPLIB_BIND_NAMESPACE_EXPORT_BEGIN_NAMESPACE_SELECT a QUICKCPPLIB_BIND_NAMESPACE_EXPORT_BEGIN_EXPAND5(b, c, d, e, f)
#define QUICKCPPLIB_BIND_NAMESPACE_EXPORT_BEGIN_EXPAND5(a, b, c, d, e) QUICKCPPLIB_BIND_NAMESPACE_EXPORT_BEGIN_NAMESPACE_SELECT a QUICKCPPLIB_BIND_NAMESPACE_EXPORT_BEGIN_EXPAND4(b, c, d, e)
#define QUICKCPPLIB_BIND_NAMESPACE_EXPORT_BEGIN_EXPAND4(a, b, c, d) QUICKCPPLIB_BIND_NAMESPACE_EXPORT_BEGIN_NAMESPACE_SELECT a QUICKCPPLIB_BIND_NAMESPACE_EXPORT_BEGIN_EXPAND3(b, c, d)
#define QUICKCPPLIB_BIND_NAMESPACE_EXPORT_BEGIN_EXPAND3(a, b, c) QUICKCPPLIB_BIND_NAMESPACE_EXPORT_BEGIN_NAMESPACE_SELECT a QUICKCPPLIB_BIND_NAMESPACE_EXPORT_BEGIN_EXPAND2(b, c)
#define QUICKCPPLIB_BIND_NAMESPACE_EXPORT_BEGIN_EXPAND2(a, b) QUICKCPPLIB_BIND_NAMESPACE_EXPORT_BEGIN_NAMESPACE_SELECT a QUICKCPPLIB_BIND_NAMESPACE_EXPORT_BEGIN_EXPAND1(b)
#define QUICKCPPLIB_BIND_NAMESPACE_EXPORT_BEGIN_EXPAND1(a) QUICKCPPLIB_BIND_NAMESPACE_EXPORT_BEGIN_NAMESPACE_SELECT a
//! Expands into export namespace a { namespace b { namespace c ...
#define QUICKCPPLIB_BIND_NAMESPACE_EXPORT_BEGIN(...) QUICKCPPLIB_CALL_OVERLOAD(QUICKCPPLIB_BIND_NAMESPACE_EXPORT_BEGIN_EXPAND, __VA_ARGS__)
#define QUICKCPPLIB_BIND_NAMESPACE_END_NAMESPACE_SELECT2(name, modifier) }
#define QUICKCPPLIB_BIND_NAMESPACE_END_NAMESPACE_SELECT1(name) }
#define QUICKCPPLIB_BIND_NAMESPACE_END_NAMESPACE_SELECT(...) QUICKCPPLIB_CALL_OVERLOAD_(QUICKCPPLIB_BIND_NAMESPACE_END_NAMESPACE_SELECT, __VA_ARGS__)
#define QUICKCPPLIB_BIND_NAMESPACE_END_EXPAND8(a, b, c, d, e, f, g, h) QUICKCPPLIB_BIND_NAMESPACE_END_NAMESPACE_SELECT a QUICKCPPLIB_BIND_NAMESPACE_END_EXPAND7(b, c, d, e, f, g, h)
#define QUICKCPPLIB_BIND_NAMESPACE_END_EXPAND7(a, b, c, d, e, f, g) QUICKCPPLIB_BIND_NAMESPACE_END_NAMESPACE_SELECT a QUICKCPPLIB_BIND_NAMESPACE_END_EXPAND6(b, c, d, e, f, g)
#define QUICKCPPLIB_BIND_NAMESPACE_END_EXPAND6(a, b, c, d, e, f) QUICKCPPLIB_BIND_NAMESPACE_END_NAMESPACE_SELECT a QUICKCPPLIB_BIND_NAMESPACE_END_EXPAND5(b, c, d, e, f)
#define QUICKCPPLIB_BIND_NAMESPACE_END_EXPAND5(a, b, c, d, e) QUICKCPPLIB_BIND_NAMESPACE_END_NAMESPACE_SELECT a QUICKCPPLIB_BIND_NAMESPACE_END_EXPAND4(b, c, d, e)
#define QUICKCPPLIB_BIND_NAMESPACE_END_EXPAND4(a, b, c, d) QUICKCPPLIB_BIND_NAMESPACE_END_NAMESPACE_SELECT a QUICKCPPLIB_BIND_NAMESPACE_END_EXPAND3(b, c, d)
#define QUICKCPPLIB_BIND_NAMESPACE_END_EXPAND3(a, b, c) QUICKCPPLIB_BIND_NAMESPACE_END_NAMESPACE_SELECT a QUICKCPPLIB_BIND_NAMESPACE_END_EXPAND2(b, c)
#define QUICKCPPLIB_BIND_NAMESPACE_END_EXPAND2(a, b) QUICKCPPLIB_BIND_NAMESPACE_END_NAMESPACE_SELECT a QUICKCPPLIB_BIND_NAMESPACE_END_EXPAND1(b)
#define QUICKCPPLIB_BIND_NAMESPACE_END_EXPAND1(a) QUICKCPPLIB_BIND_NAMESPACE_END_NAMESPACE_SELECT a
//! Expands into } } ...
#define QUICKCPPLIB_BIND_NAMESPACE_END(...) QUICKCPPLIB_CALL_OVERLOAD(QUICKCPPLIB_BIND_NAMESPACE_END_EXPAND, __VA_ARGS__)
//! Expands into a static const char string array used to mark BindLib compatible namespaces
#define QUICKCPPLIB_BIND_DECLARE(decl, desc) static const char *quickcpplib_out[] = {#decl, desc};
#endif
#ifndef OUTCOME_ENABLE_LEGACY_SUPPORT_FOR
#define OUTCOME_ENABLE_LEGACY_SUPPORT_FOR 220 // the v2.2 Outcome release
#endif
/* UPDATED BY SCRIPT
(C) 2017-2019 Niall Douglas <http://www.nedproductions.biz/> (225 commits)
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License in the accompanying file
Licence.txt or at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Distributed under the Boost Software License, Version 1.0.
(See accompanying file Licence.txt or copy at
http://www.boost.org/LICENSE_1_0.txt)
*/
// Note the second line of this file must ALWAYS be the git SHA, third line ALWAYS the git SHA update time
#define OUTCOME_PREVIOUS_COMMIT_REF b01ac71096775daf18d9a57a69be5e129f421a67
#define OUTCOME_PREVIOUS_COMMIT_DATE "2024-07-17 20:54:50 +00:00"
#define OUTCOME_PREVIOUS_COMMIT_UNIQUE b01ac710
#define OUTCOME_V2 (QUICKCPPLIB_BIND_NAMESPACE_VERSION(outcome_v2))
#ifdef _DEBUG
#define OUTCOME_V2_CXX_MODULE_NAME QUICKCPPLIB_BIND_NAMESPACE((QUICKCPPLIB_BIND_NAMESPACE_VERSION(outcome_v2d)))
#else
#define OUTCOME_V2_CXX_MODULE_NAME QUICKCPPLIB_BIND_NAMESPACE((QUICKCPPLIB_BIND_NAMESPACE_VERSION(outcome_v2)))
#endif
#if defined(GENERATING_OUTCOME_MODULE_INTERFACE)
#define OUTCOME_V2_NAMESPACE QUICKCPPLIB_BIND_NAMESPACE(OUTCOME_V2)
#define OUTCOME_V2_NAMESPACE_BEGIN QUICKCPPLIB_BIND_NAMESPACE_BEGIN(OUTCOME_V2)
#define OUTCOME_V2_NAMESPACE_EXPORT_BEGIN QUICKCPPLIB_BIND_NAMESPACE_EXPORT_BEGIN(OUTCOME_V2)
#define OUTCOME_V2_NAMESPACE_END QUICKCPPLIB_BIND_NAMESPACE_END(OUTCOME_V2)
#else
#define OUTCOME_V2_NAMESPACE QUICKCPPLIB_BIND_NAMESPACE(OUTCOME_V2)
#define OUTCOME_V2_NAMESPACE_BEGIN QUICKCPPLIB_BIND_NAMESPACE_BEGIN(OUTCOME_V2)
#define OUTCOME_V2_NAMESPACE_EXPORT_BEGIN QUICKCPPLIB_BIND_NAMESPACE_BEGIN(OUTCOME_V2)
#define OUTCOME_V2_NAMESPACE_END QUICKCPPLIB_BIND_NAMESPACE_END(OUTCOME_V2)
#endif
#include <cstdint> // for uint32_t etc
#include <initializer_list>
#include <iosfwd> // for future serialisation
#include <new> // for placement in moves etc
#include <type_traits>
#ifndef OUTCOME_USE_STD_IN_PLACE_TYPE
#if defined(_MSC_VER) && _HAS_CXX17
#define OUTCOME_USE_STD_IN_PLACE_TYPE 1 // MSVC always has std::in_place_type
#elif __cplusplus >= 201700
// libstdc++ before GCC 6 doesn't have it, despite claiming C++ 17 support
#ifdef __has_include
#if !__has_include(<variant>)
#define OUTCOME_USE_STD_IN_PLACE_TYPE 0 // must have it if <variant> is present
#endif
#endif
#ifndef OUTCOME_USE_STD_IN_PLACE_TYPE
#define OUTCOME_USE_STD_IN_PLACE_TYPE 1
#endif
#else
#define OUTCOME_USE_STD_IN_PLACE_TYPE 0
#endif
#endif
#if OUTCOME_USE_STD_IN_PLACE_TYPE
#include <utility> // for in_place_type_t
OUTCOME_V2_NAMESPACE_BEGIN
template <class T> using in_place_type_t = std::in_place_type_t<T>;
using std::in_place_type;
OUTCOME_V2_NAMESPACE_END
#else
OUTCOME_V2_NAMESPACE_BEGIN
/*! AWAITING HUGO JSON CONVERSION TOOL
type definition template <class T> in_place_type_t. Potential doc page: `in_place_type_t<T>`
*/
template <class T> struct in_place_type_t
{
explicit in_place_type_t() = default;
};
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
template <class T> constexpr in_place_type_t<T> in_place_type{};
OUTCOME_V2_NAMESPACE_END
#endif
#if OUTCOME_USE_STD_ADDRESSOF
#include <memory> // for std::addressof
#define OUTCOME_ADDRESS_OF(...) std::addressof(__VA_ARGS__)
#else
#define OUTCOME_ADDRESS_OF(...) (&__VA_ARGS__)
#endif
#ifndef OUTCOME_ASSERT
#include <cassert>
#define OUTCOME_ASSERT(...) assert(__VA_ARGS__)
#endif
#ifndef OUTCOME_TRIVIAL_ABI
#if 0L || __clang_major__ >= 7
//! Defined to be `[[clang::trivial_abi]]` when on a new enough clang compiler. Usually automatic, can be overriden.
#define OUTCOME_TRIVIAL_ABI [[clang::trivial_abi]]
#else
#define OUTCOME_TRIVIAL_ABI
#endif
#endif
OUTCOME_V2_NAMESPACE_BEGIN
namespace detail
{
// Test if type is an in_place_type_t
template <class T> struct is_in_place_type_t
{
static constexpr bool value = false;
};
template <class U> struct is_in_place_type_t<in_place_type_t<U>>
{
static constexpr bool value = true;
};
// Replace void with constructible void_type
struct empty_type
{
};
struct void_type
{
// We always compare true to another instance of me
constexpr bool operator==(void_type /*unused*/) const noexcept { return true; }
constexpr bool operator!=(void_type /*unused*/) const noexcept { return false; }
};
template <class T> using devoid = std::conditional_t<std::is_void<T>::value, void_type, T>;
template <class Output, class Input> using rebind_type5 = Output;
template <class Output, class Input>
using rebind_type4 = std::conditional_t< //
std::is_volatile<Input>::value, //
std::add_volatile_t<rebind_type5<Output, std::remove_volatile_t<Input>>>, //
rebind_type5<Output, Input>>;
template <class Output, class Input>
using rebind_type3 = std::conditional_t< //
std::is_const<Input>::value, //
std::add_const_t<rebind_type4<Output, std::remove_const_t<Input>>>, //
rebind_type4<Output, Input>>;
template <class Output, class Input>
using rebind_type2 = std::conditional_t< //
std::is_lvalue_reference<Input>::value, //
std::add_lvalue_reference_t<rebind_type3<Output, std::remove_reference_t<Input>>>, //
rebind_type3<Output, Input>>;
template <class Output, class Input>
using rebind_type = std::conditional_t< //
std::is_rvalue_reference<Input>::value, //
std::add_rvalue_reference_t<rebind_type2<Output, std::remove_reference_t<Input>>>, //
rebind_type2<Output, Input>>;
// static_assert(std::is_same_v<rebind_type<int, volatile const double &&>, volatile const int &&>, "");
/* True if type is the same or constructible. Works around a bug where clang + libstdc++
pukes on std::is_constructible<filesystem::path, void> (this bug is fixed upstream).
*/
template <class T, class U> struct _is_explicitly_constructible
{
static constexpr bool value = std::is_constructible<T, U>::value;
};
template <class T> struct _is_explicitly_constructible<T, void>
{
static constexpr bool value = false;
};
template <> struct _is_explicitly_constructible<void, void>
{
static constexpr bool value = false;
};
template <class T, class U> static constexpr bool is_explicitly_constructible = _is_explicitly_constructible<T, U>::value;
template <class T, class U> struct _is_implicitly_constructible
{
static constexpr bool value = std::is_convertible<U, T>::value;
};
template <class T> struct _is_implicitly_constructible<T, void>
{
static constexpr bool value = false;
};
template <> struct _is_implicitly_constructible<void, void>
{
static constexpr bool value = false;
};
template <class T, class U> static constexpr bool is_implicitly_constructible = _is_implicitly_constructible<T, U>::value;
template <class T, class... Args> struct _is_nothrow_constructible
{
static constexpr bool value = std::is_nothrow_constructible<T, Args...>::value;
};
template <class T> struct _is_nothrow_constructible<T, void>
{
static constexpr bool value = false;
};
template <> struct _is_nothrow_constructible<void, void>
{
static constexpr bool value = false;
};
template <class T, class... Args> static constexpr bool is_nothrow_constructible = _is_nothrow_constructible<T, Args...>::value;
template <class T, class... Args> struct _is_constructible
{
static constexpr bool value = std::is_constructible<T, Args...>::value;
};
template <class T> struct _is_constructible<T, void>
{
static constexpr bool value = false;
};
template <> struct _is_constructible<void, void>
{
static constexpr bool value = false;
};
template <class T, class... Args> static constexpr bool is_constructible = _is_constructible<T, Args...>::value;
#ifndef OUTCOME_USE_STD_IS_NOTHROW_SWAPPABLE
#if defined(_MSC_VER) && _HAS_CXX17
#define OUTCOME_USE_STD_IS_NOTHROW_SWAPPABLE 1 // MSVC always has std::is_nothrow_swappable
#elif __cplusplus >= 201700
// libstdc++ before GCC 6 doesn't have it, despite claiming C++ 17 support
#ifdef __has_include
#if !__has_include(<variant>)
#define OUTCOME_USE_STD_IS_NOTHROW_SWAPPABLE 0
#endif
#endif
#ifndef OUTCOME_USE_STD_IS_NOTHROW_SWAPPABLE
#define OUTCOME_USE_STD_IS_NOTHROW_SWAPPABLE 1
#endif
#else
#define OUTCOME_USE_STD_IS_NOTHROW_SWAPPABLE 0
#endif
#endif
// True if type is nothrow swappable
#if !0L && OUTCOME_USE_STD_IS_NOTHROW_SWAPPABLE
template <class T> using is_nothrow_swappable = std::is_nothrow_swappable<T>;
#else
template <class T> struct is_nothrow_swappable
{
static constexpr bool value = std::is_nothrow_move_constructible<T>::value && std::is_nothrow_move_assignable<T>::value;
};
#endif
} // namespace detail
OUTCOME_V2_NAMESPACE_END
#ifndef OUTCOME_THROW_EXCEPTION
#ifdef __cpp_exceptions
#define OUTCOME_THROW_EXCEPTION(expr) throw expr
#else
#ifdef __ANDROID__
#define OUTCOME_DISABLE_EXECINFO
#endif
#ifndef OUTCOME_DISABLE_EXECINFO
#ifdef _WIN32
/* Implements backtrace() et al from glibc on win64
(C) 2016-2017 Niall Douglas <http://www.nedproductions.biz/> (4 commits)
File Created: Mar 2016
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License in the accompanying file
Licence.txt or at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Distributed under the Boost Software License, Version 1.0.
(See accompanying file Licence.txt or copy at
http://www.boost.org/LICENSE_1_0.txt)
*/
#ifndef BOOST_BINDLIB_EXECINFO_WIN64_H
#define BOOST_BINDLIB_EXECINFO_WIN64_H
#ifndef _WIN32
#error Can only be included on Windows
#endif
#include <sal.h>
#include <stddef.h>
#ifdef QUICKCPPLIB_EXPORTS
#define EXECINFO_DECL extern __declspec(dllexport)
#else
#if defined(__cplusplus) && (!defined(QUICKCPPLIB_HEADERS_ONLY) || QUICKCPPLIB_HEADERS_ONLY == 1) && !0L
#define EXECINFO_DECL inline
#elif defined(QUICKCPPLIB_DYN_LINK) && !defined(QUICKCPPLIB_STATIC_LINK)
#define EXECINFO_DECL extern __declspec(dllimport)
#else
#define EXECINFO_DECL extern
#endif
#endif
#ifdef __cplusplus
extern "C" {
#endif
//! Fill the array of void * at bt with up to len entries, returning entries filled.
EXECINFO_DECL _Check_return_ size_t backtrace(_Out_writes_(len) void **bt, _In_ size_t len);
//! Returns a malloced block of string representations of the input backtrace.
EXECINFO_DECL _Check_return_ _Ret_writes_maybenull_(len) char **backtrace_symbols(_In_reads_(len) void *const *bt, _In_ size_t len);
// extern void backtrace_symbols_fd(void *const *bt, size_t len, int fd);
#ifdef __cplusplus
}
#if (!defined(QUICKCPPLIB_HEADERS_ONLY) || QUICKCPPLIB_HEADERS_ONLY == 1) && !0L
#define QUICKCPPLIB_INCLUDED_BY_HEADER 1
/* Implements backtrace() et al from glibc on win64
(C) 2016-2017 Niall Douglas <http://www.nedproductions.biz/> (14 commits)
File Created: Mar 2016
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License in the accompanying file
Licence.txt or at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Distributed under the Boost Software License, Version 1.0.
(See accompanying file Licence.txt or copy at
http://www.boost.org/LICENSE_1_0.txt)
*/
/* Implements backtrace() et al from glibc on win64
(C) 2016-2017 Niall Douglas <http://www.nedproductions.biz/> (4 commits)
File Created: Mar 2016
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License in the accompanying file
Licence.txt or at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Distributed under the Boost Software License, Version 1.0.
(See accompanying file Licence.txt or copy at
http://www.boost.org/LICENSE_1_0.txt)
*/
#include <atomic>
#include <stdlib.h> // for abort
#include <string.h>
// To avoid including windows.h, this source has been macro expanded and win32 function shimmed for C++ only
#if defined(__cplusplus) && !defined(__clang__)
namespace win32
{
extern _Ret_maybenull_ void *__stdcall LoadLibraryA(_In_ const char *lpLibFileName);
typedef int(__stdcall *GetProcAddress_returntype)();
extern GetProcAddress_returntype __stdcall GetProcAddress(_In_ void *hModule, _In_ const char *lpProcName);
extern _Success_(return != 0) unsigned short __stdcall RtlCaptureStackBackTrace(_In_ unsigned long FramesToSkip, _In_ unsigned long FramesToCapture,
_Out_writes_to_(FramesToCapture, return ) void **BackTrace,
_Out_opt_ unsigned long *BackTraceHash);
extern _Success_(return != 0)
_When_((cchWideChar == -1) && (cbMultiByte != 0),
_Post_equal_to_(_String_length_(lpMultiByteStr) +
1)) int __stdcall WideCharToMultiByte(_In_ unsigned int CodePage, _In_ unsigned long dwFlags, const wchar_t *lpWideCharStr,
_In_ int cchWideChar, _Out_writes_bytes_to_opt_(cbMultiByte, return ) char *lpMultiByteStr,
_In_ int cbMultiByte, _In_opt_ const char *lpDefaultChar, _Out_opt_ int *lpUsedDefaultChar);
#pragma comment(lib, "kernel32.lib")
#if (defined(__x86_64__) || defined(_M_X64)) || (defined(__aarch64__) || defined(_M_ARM64))
#pragma comment(linker, "/alternatename:?LoadLibraryA@win32@@YAPEAXPEBD@Z=LoadLibraryA")
#pragma comment(linker, "/alternatename:?GetProcAddress@win32@@YAP6AHXZPEAXPEBD@Z=GetProcAddress")
#pragma comment(linker, "/alternatename:?RtlCaptureStackBackTrace@win32@@YAGKKPEAPEAXPEAK@Z=RtlCaptureStackBackTrace")
#pragma comment(linker, "/alternatename:?WideCharToMultiByte@win32@@YAHIKPEB_WHPEADHPEBDPEAH@Z=WideCharToMultiByte")
#elif defined(__x86__) || defined(_M_IX86) || defined(__i386__)
#pragma comment(linker, "/alternatename:?LoadLibraryA@win32@@YGPAXPBD@Z=__imp__LoadLibraryA@4")
#pragma comment(linker, "/alternatename:?GetProcAddress@win32@@YGP6GHXZPAXPBD@Z=__imp__GetProcAddress@8")
#pragma comment(linker, "/alternatename:?RtlCaptureStackBackTrace@win32@@YGGKKPAPAXPAK@Z=__imp__RtlCaptureStackBackTrace@16")
#pragma comment(linker, "/alternatename:?WideCharToMultiByte@win32@@YGHIKPB_WHPADHPBDPAH@Z=__imp__WideCharToMultiByte@32")
#elif defined(__arm__) || defined(_M_ARM)
#pragma comment(linker, "/alternatename:?LoadLibraryA@win32@@YAPAXPBD@Z=LoadLibraryA")
#pragma comment(linker, "/alternatename:?GetProcAddress@win32@@YAP6AHXZPAXPBD@Z=GetProcAddress")
#pragma comment(linker, "/alternatename:?RtlCaptureStackBackTrace@win32@@YAGKKPAPAXPAK@Z=RtlCaptureStackBackTrace")
#pragma comment(linker, "/alternatename:?WideCharToMultiByte@win32@@YAHIKPB_WHPADHPBDPAH@Z=WideCharToMultiByte")
#else
#error Unknown architecture
#endif
} // namespace win32
#else
#ifndef WIN32_LEAN_AND_MEAN
#define WIN32_LEAN_AND_MEAN
#endif
#ifndef NOMINMAX
#define NOMINMAX
#endif
#include <Windows.h>
#endif
#ifdef __cplusplus
namespace
{
#endif
typedef struct _IMAGEHLP_LINE64
{
unsigned long SizeOfStruct;
void *Key;
unsigned long LineNumber;
wchar_t *FileName;
unsigned long long int Address;
} IMAGEHLP_LINE64, *PIMAGEHLP_LINE64;
typedef int(__stdcall *SymInitialize_t)(_In_ void *hProcess, _In_opt_ const wchar_t *UserSearchPath, _In_ int fInvadeProcess);
typedef int(__stdcall *SymGetLineFromAddr64_t)(_In_ void *hProcess, _In_ unsigned long long int dwAddr, _Out_ unsigned long *pdwDisplacement,
_Out_ PIMAGEHLP_LINE64 Line);
static std::atomic<unsigned> dbghelp_init_lock;
#if defined(__cplusplus) && !defined(__clang__)
static void *dbghelp;
#else
static HMODULE dbghelp;
#endif
static SymInitialize_t SymInitialize;
static SymGetLineFromAddr64_t SymGetLineFromAddr64;
static void load_dbghelp()
{
#if defined(__cplusplus) && !defined(__clang__)
using win32::GetProcAddress;
using win32::LoadLibraryA;
#endif
while(dbghelp_init_lock.exchange(1, std::memory_order_acq_rel))
;
if(dbghelp)
{
dbghelp_init_lock.store(0, std::memory_order_release);
return;
}
dbghelp = LoadLibraryA("DBGHELP.DLL");
if(dbghelp)
{
SymInitialize = (SymInitialize_t) GetProcAddress(dbghelp, "SymInitializeW");
if(!SymInitialize)
abort();
if(!SymInitialize((void *) (size_t) -1 /*GetCurrentProcess()*/, NULL, 1))
abort();
SymGetLineFromAddr64 = (SymGetLineFromAddr64_t) GetProcAddress(dbghelp, "SymGetLineFromAddrW64");
if(!SymGetLineFromAddr64)
abort();
}
dbghelp_init_lock.store(0, std::memory_order_release);
}
#ifdef __cplusplus
}
#endif
#ifdef __cplusplus
extern "C"
{
#endif
_Check_return_ size_t backtrace(_Out_writes_(len) void **bt, _In_ size_t len)
{
#if defined(__cplusplus) && !defined(__clang__)
using win32::RtlCaptureStackBackTrace;
#endif
return RtlCaptureStackBackTrace(1, (unsigned long) len, bt, NULL);
}
#ifdef _MSC_VER
#pragma warning(push)
#pragma warning(disable : 6385 6386) // MSVC static analyser can't grok this function. clang's analyser gives it thumbs up.
#endif
_Check_return_ _Ret_writes_maybenull_(len) char **backtrace_symbols(_In_reads_(len) void *const *bt, _In_ size_t len)
{
#if defined(__cplusplus) && !defined(__clang__)
using win32::WideCharToMultiByte;
#endif
size_t bytes = (len + 1) * sizeof(void *) + 256, n;
if(!len)
return NULL;
else
{
char **ret = (char **) malloc(bytes);
char *p = (char *) (ret + len + 1), *end = (char *) ret + bytes;
if(!ret)
return NULL;
for(n = 0; n < len + 1; n++)
ret[n] = NULL;
load_dbghelp();
for(n = 0; n < len; n++)
{
unsigned long displ;
IMAGEHLP_LINE64 ihl;
memset(&ihl, 0, sizeof(ihl));
ihl.SizeOfStruct = sizeof(IMAGEHLP_LINE64);
int please_realloc = 0;
if(!bt[n])
{
ret[n] = NULL;
}
else
{
// Keep offset till later
ret[n] = (char *) ((char *) p - (char *) ret);
{
static std::atomic<unsigned> symlock(0);
while(symlock.exchange(1, std::memory_order_acq_rel))
;
if(!SymGetLineFromAddr64 || !SymGetLineFromAddr64((void *) (size_t) -1 /*GetCurrentProcess()*/, (size_t) bt[n], &displ, &ihl))
{
symlock.store(0, std::memory_order_release);
if(n == 0)
{
free(ret);
return NULL;
}
ihl.FileName = (wchar_t *) L"unknown";
ihl.LineNumber = 0;
}
else
{
symlock.store(0, std::memory_order_release);
}
}
retry:
if(please_realloc)
{
char **temp = (char **) realloc(ret, bytes + 256);
if(!temp)
{
free(ret);
return NULL;
}
p = (char *) temp + (p - (char *) ret);
ret = temp;
bytes += 256;
end = (char *) ret + bytes;
}
if(ihl.FileName && ihl.FileName[0])
{
int plen = WideCharToMultiByte(65001 /*CP_UTF8*/, 0, ihl.FileName, -1, p, (int) (end - p), NULL, NULL);
if(!plen)
{
please_realloc = 1;
goto retry;
}
p[plen - 1] = 0;
p += plen - 1;
}
else
{
if(end - p < 16)
{
please_realloc = 1;
goto retry;
}
_ui64toa_s((size_t) bt[n], p, end - p, 16);
p = strchr(p, 0);
}
if(end - p < 16)
{
please_realloc = 1;
goto retry;
}
*p++ = ':';
_itoa_s(ihl.LineNumber, p, end - p, 10);
p = strchr(p, 0) + 1;
}
}
for(n = 0; n < len; n++)
{
if(ret[n])
ret[n] = (char *) ret + (size_t) ret[n];
}
return ret;
}
}
#ifdef _MSC_VER
#pragma warning(pop)
#endif
// extern void backtrace_symbols_fd(void *const *bt, size_t len, int fd);
#ifdef __cplusplus
}
#endif
#undef QUICKCPPLIB_INCLUDED_BY_HEADER
#endif
#endif
#endif
#else
#include <execinfo.h>
#endif
#endif // OUTCOME_DISABLE_EXECINFO
#include <cstdio>
#include <cstdlib>
OUTCOME_V2_NAMESPACE_BEGIN
namespace detail
{
QUICKCPPLIB_NORETURN inline void do_fatal_exit(const char *expr)
{
#if !defined(OUTCOME_DISABLE_EXECINFO)
void *bt[16];
size_t btlen = backtrace(bt, sizeof(bt) / sizeof(bt[0])); // NOLINT
#endif
fprintf(stderr, "FATAL: Outcome throws exception %s with exceptions disabled\n", expr); // NOLINT
#if !defined(OUTCOME_DISABLE_EXECINFO)
char **bts = backtrace_symbols(bt, btlen); // NOLINT
if(bts != nullptr)
{
for(size_t n = 0; n < btlen; n++)
{
fprintf(stderr, " %s\n", bts[n]); // NOLINT
}
free(bts); // NOLINT
}
#endif
abort();
}
} // namespace detail
OUTCOME_V2_NAMESPACE_END
#define OUTCOME_THROW_EXCEPTION(expr) OUTCOME_V2_NAMESPACE::detail::do_fatal_exit(#expr), (void) (expr)
#endif
#endif
#ifndef BOOST_OUTCOME_AUTO_TEST_CASE
#define BOOST_OUTCOME_AUTO_TEST_CASE(a, b) BOOST_AUTO_TEST_CASE(a, b)
#endif
#endif
#define OUTCOME_COROUTINE_SUPPORT_NAMESPACE_BEGIN OUTCOME_V2_NAMESPACE_BEGIN namespace awaitables {
//
#define OUTCOME_COROUTINE_SUPPORT_NAMESPACE_EXPORT_BEGIN OUTCOME_V2_NAMESPACE_EXPORT_BEGIN namespace awaitables {
//
#define OUTCOME_COROUTINE_SUPPORT_NAMESPACE_END } OUTCOME_V2_NAMESPACE_END
#ifdef __cpp_exceptions
/* Tries to convert an exception ptr into its equivalent error code
(C) 2017-2019 Niall Douglas <http://www.nedproductions.biz/> (11 commits)
File Created: July 2017
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License in the accompanying file
Licence.txt or at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Distributed under the Boost Software License, Version 1.0.
(See accompanying file Licence.txt or copy at
http://www.boost.org/LICENSE_1_0.txt)
*/
#ifndef OUTCOME_UTILS_HPP
#define OUTCOME_UTILS_HPP
#include <exception>
#include <string>
#include <system_error>
OUTCOME_V2_NAMESPACE_BEGIN
#ifdef __cpp_exceptions
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
inline std::error_code error_from_exception(std::exception_ptr &&ep = std::current_exception(), std::error_code not_matched = std::make_error_code(std::errc::resource_unavailable_try_again)) noexcept
{
if(!ep)
{
return {};
}
try
{
std::rethrow_exception(ep);
}
catch(const std::invalid_argument & /*unused*/)
{
ep = std::exception_ptr();
return std::make_error_code(std::errc::invalid_argument);
}
catch(const std::domain_error & /*unused*/)
{
ep = std::exception_ptr();
return std::make_error_code(std::errc::argument_out_of_domain);
}
catch(const std::length_error & /*unused*/)
{
ep = std::exception_ptr();
return std::make_error_code(std::errc::argument_list_too_long);
}
catch(const std::out_of_range & /*unused*/)
{
ep = std::exception_ptr();
return std::make_error_code(std::errc::result_out_of_range);
}
catch(const std::logic_error & /*unused*/) /* base class for this group */
{
ep = std::exception_ptr();
return std::make_error_code(std::errc::invalid_argument);
}
catch(const std::system_error &e) /* also catches ios::failure */
{
ep = std::exception_ptr();
return e.code();
}
catch(const std::overflow_error & /*unused*/)
{
ep = std::exception_ptr();
return std::make_error_code(std::errc::value_too_large);
}
catch(const std::range_error & /*unused*/)
{
ep = std::exception_ptr();
return std::make_error_code(std::errc::result_out_of_range);
}
catch(const std::runtime_error & /*unused*/) /* base class for this group */
{
ep = std::exception_ptr();
return std::make_error_code(std::errc::resource_unavailable_try_again);
}
catch(const std::bad_alloc & /*unused*/)
{
ep = std::exception_ptr();
return std::make_error_code(std::errc::not_enough_memory);
}
catch(...)
{
}
return not_matched;
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
inline void try_throw_std_exception_from_error(std::error_code ec, const std::string &msg = std::string{})
{
if(!ec || (ec.category() != std::generic_category()
#ifndef _WIN32
&& ec.category() != std::system_category()
#endif
))
{
return;
}
switch(ec.value())
{
case EINVAL:
throw msg.empty() ? std::invalid_argument("invalid argument") : std::invalid_argument(msg);
case EDOM:
throw msg.empty() ? std::domain_error("domain error") : std::domain_error(msg);
case E2BIG:
throw msg.empty() ? std::length_error("length error") : std::length_error(msg);
case ERANGE:
throw msg.empty() ? std::out_of_range("out of range") : std::out_of_range(msg);
case EOVERFLOW:
throw msg.empty() ? std::overflow_error("overflow error") : std::overflow_error(msg);
case ENOMEM:
throw std::bad_alloc();
}
}
#endif
OUTCOME_V2_NAMESPACE_END
#endif
OUTCOME_V2_NAMESPACE_BEGIN
namespace awaitables
{
namespace detail
{
inline bool error_is_set(std::error_code ec) noexcept { return !!ec; }
inline std::error_code error_from_exception(std::exception_ptr &&ep, std::error_code not_matched) noexcept { return OUTCOME_V2_NAMESPACE::error_from_exception(static_cast<std::exception_ptr &&>(ep), not_matched); }
} // namespace detail
} // namespace awaitables
OUTCOME_V2_NAMESPACE_END
#endif
/* Tells C++ coroutines about Outcome's result
(C) 2019-2023 Niall Douglas <http://www.nedproductions.biz/> (12 commits)
File Created: Oct 2019
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License in the accompanying file
Licence.txt or at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Distributed under the Boost Software License, Version 1.0.
(See accompanying file Licence.txt or copy at
http://www.boost.org/LICENSE_1_0.txt)
*/
#ifndef OUTCOME_DETAIL_COROUTINE_SUPPORT_HPP
#define OUTCOME_DETAIL_COROUTINE_SUPPORT_HPP
#include <atomic>
#include <exception>
#ifndef OUTCOME_COROUTINE_HEADER_TYPE
#if __has_include(<coroutine>)
#define OUTCOME_COROUTINE_HEADER_TYPE 1
#elif __has_include(<experimental/coroutine>)
#define OUTCOME_COROUTINE_HEADER_TYPE 2
#else
#define OUTCOME_COROUTINE_HEADER_TYPE 0
#endif
#endif
#if OUTCOME_COROUTINE_HEADER_TYPE && (__cpp_impl_coroutine || (defined(_MSC_VER) && __cpp_coroutines))
#ifndef OUTCOME_HAVE_NOOP_COROUTINE
#if defined(__has_builtin)
#if __has_builtin(__builtin_coro_noop) || (!defined(__clang__) && __GNUC__ >= 10)
#define OUTCOME_HAVE_NOOP_COROUTINE 1
#endif
#endif
#endif
#ifndef OUTCOME_HAVE_NOOP_COROUTINE
#if _MSC_VER >= 1928 || (!defined(__clang__) && __GNUC__ >= 10)
#define OUTCOME_HAVE_NOOP_COROUTINE 1
#else
#define OUTCOME_HAVE_NOOP_COROUTINE 0
#endif
#endif
#if OUTCOME_COROUTINE_HEADER_TYPE == 1
#include <coroutine>
OUTCOME_V2_NAMESPACE_BEGIN
namespace awaitables
{
template <class Promise = void> using coroutine_handle = std::coroutine_handle<Promise>;
template <class... Args> using coroutine_traits = std::coroutine_traits<Args...>;
using std::suspend_always;
using std::suspend_never;
#if OUTCOME_HAVE_NOOP_COROUTINE
using std::noop_coroutine;
#endif
} // namespace awaitables
OUTCOME_V2_NAMESPACE_END
#define OUTCOME_FOUND_COROUTINE_HEADER 1
#elif OUTCOME_COROUTINE_HEADER_TYPE == 2
#include <experimental/coroutine>
OUTCOME_V2_NAMESPACE_BEGIN
namespace awaitables
{
template <class Promise = void> using coroutine_handle = std::experimental::coroutine_handle<Promise>;
template <class... Args> using coroutine_traits = std::experimental::coroutine_traits<Args...>;
using std::experimental::suspend_always;
using std::experimental::suspend_never;
#if OUTCOME_HAVE_NOOP_COROUTINE
using std::experimental::noop_coroutine;
#endif
} // namespace awaitables
OUTCOME_V2_NAMESPACE_END
#define OUTCOME_FOUND_COROUTINE_HEADER 1
#endif
#endif
#ifndef OUTCOME_V2_AWAITABLES_DEBUG_PRINTER
// #include <iostream>
// #define OUTCOME_V2_AWAITABLES_DEBUG_PRINTER(...) std::cout << __VA_ARGS__ << std::endl;
#define OUTCOME_V2_AWAITABLES_DEBUG_PRINTER(...)
#endif
OUTCOME_V2_NAMESPACE_EXPORT_BEGIN
namespace awaitables
{
namespace detail
{
struct error_type_not_found
{
};
struct exception_type_not_found
{
};
template <class T> struct type_found
{
using type = T;
};
template <class T, class U = typename T::error_type> constexpr inline type_found<U> extract_error_type(int /*unused*/)
{
return {};
}
template <class T> constexpr inline type_found<error_type_not_found> extract_error_type(...)
{
return {};
}
template <class T, class U = typename T::exception_type> constexpr inline type_found<U> extract_exception_type(int /*unused*/)
{
return {};
}
template <class T> constexpr inline type_found<exception_type_not_found> extract_exception_type(...)
{
return {};
}
OUTCOME_TEMPLATE(class T, class U)
OUTCOME_TREQUIRES(OUTCOME_TPRED(OUTCOME_V2_NAMESPACE::detail::is_constructible<U, T>))
inline bool try_set_error(T &&e, U *result)
{
new(result) U(static_cast<T &&>(e));
return true;
}
template <class T> inline bool try_set_error(T && /*unused*/, ...)
{
return false;
}
OUTCOME_TEMPLATE(class T, class U)
OUTCOME_TREQUIRES(OUTCOME_TPRED(OUTCOME_V2_NAMESPACE::detail::is_constructible<U, T>))
inline void set_or_rethrow(T &e, U *result)
{
new(result) U(e);
}
template <class T> inline void set_or_rethrow(T &e, ...)
{
rethrow_exception(e);
}
template <class T> class fake_atomic
{
T _v;
public:
constexpr fake_atomic(T v)
: _v(v)
{
}
T load(std::memory_order /*unused*/) { return _v; }
void store(T v, std::memory_order /*unused*/) { _v = v; }
bool compare_exchange_strong(T &expected, T v, std::memory_order /*unused*/, std::memory_order /*unused*/)
{
if(_v == expected)
{
_v = v;
return true;
}
return false;
}
};
#ifdef OUTCOME_FOUND_COROUTINE_HEADER
template <class Awaitable, bool suspend_initial, bool use_atomic, bool is_void> struct outcome_promise_type
{
using container_type = typename Awaitable::container_type;
using result_set_type = std::conditional_t<use_atomic, std::atomic<bool>, fake_atomic<bool>>;
union
{
OUTCOME_V2_NAMESPACE::detail::empty_type _default{};
container_type result;
};
result_set_type result_set{false}, pending_first_resumption{is_initially_suspended};
coroutine_handle<> continuation;
static constexpr bool is_initially_suspended = suspend_initial;
static constexpr bool is_using_atomics = use_atomic;
outcome_promise_type() noexcept { OUTCOME_V2_AWAITABLES_DEBUG_PRINTER(this << " promise constructed"); }
outcome_promise_type(const outcome_promise_type &) = delete;
outcome_promise_type(outcome_promise_type &&) = delete;
outcome_promise_type &operator=(const outcome_promise_type &) = delete;
outcome_promise_type &operator=(outcome_promise_type &&) = delete;
~outcome_promise_type()
{
OUTCOME_V2_AWAITABLES_DEBUG_PRINTER(this << " promise destructs");
if(result_set.load(std::memory_order_acquire))
{
result.~container_type(); // could throw
}
}
auto get_return_object()
{
OUTCOME_V2_AWAITABLES_DEBUG_PRINTER(this << " promise returns awaitable");
return Awaitable{*this}; // could throw bad_alloc
}
void return_value(container_type &&value)
{
OUTCOME_V2_AWAITABLES_DEBUG_PRINTER(this << " promise returns value");
OUTCOME_ASSERT(!result_set.load(std::memory_order_acquire));
if(result_set.load(std::memory_order_acquire))
{
result.~container_type(); // could throw
}
new(&result) container_type(static_cast<container_type &&>(value)); // could throw
result_set.store(true, std::memory_order_release);
}
void return_value(const container_type &value)
{
OUTCOME_V2_AWAITABLES_DEBUG_PRINTER(this << " promise returns value");
OUTCOME_ASSERT(!result_set.load(std::memory_order_acquire));
if(result_set.load(std::memory_order_acquire))
{
result.~container_type(); // could throw
}
new(&result) container_type(value); // could throw
result_set.store(true, std::memory_order_release);
}
void unhandled_exception()
{
OUTCOME_V2_AWAITABLES_DEBUG_PRINTER(this << " promise unhandled exception");
OUTCOME_ASSERT(!result_set.load(std::memory_order_acquire));
if(result_set.load(std::memory_order_acquire))
{
result.~container_type();
}
#ifdef __cpp_exceptions
auto e = std::current_exception();
auto ec = detail::error_from_exception(static_cast<decltype(e) &&>(e), {});
// Try to set error code first
if(!detail::error_is_set(ec) || !detail::try_set_error(static_cast<decltype(ec) &&>(ec), &result))
{
detail::set_or_rethrow(e, &result); // could throw
}
#else
std::terminate();
#endif
result_set.store(true, std::memory_order_release);
}
auto initial_suspend() noexcept
{
OUTCOME_V2_AWAITABLES_DEBUG_PRINTER(this << " promise initial suspend = " << suspend_initial);
struct awaiter
{
constexpr bool await_ready() noexcept { return !suspend_initial; }
void await_resume() noexcept {}
void await_suspend(coroutine_handle<> /*unused*/) noexcept {}
};
return awaiter{};
}
auto final_suspend() noexcept
{
struct awaiter
{
// If we don't force a final suspend, promise will get deleted before awaitable
// TODO: Implement detachable awaitables
constexpr bool await_ready() noexcept { return false; }
void await_resume() noexcept {}
#if OUTCOME_HAVE_NOOP_COROUTINE
coroutine_handle<> await_suspend(coroutine_handle<outcome_promise_type> self) noexcept
{
if(self.promise().continuation)
{
OUTCOME_V2_AWAITABLES_DEBUG_PRINTER(&self.promise() << " promise final suspend will resume coroutine " << self.promise().continuation.address());
}
else
{
OUTCOME_V2_AWAITABLES_DEBUG_PRINTER(&self.promise() << " promise final suspend will exit");
}
return self.promise().continuation ? self.promise().continuation : noop_coroutine();
}
#else
void await_suspend(coroutine_handle<outcome_promise_type> self)
{
if(self.promise().continuation)
{
OUTCOME_V2_AWAITABLES_DEBUG_PRINTER(&self.promise() << " promise final suspend will resume coroutine " << self.promise().continuation.address());
return self.promise().continuation.resume();
}
else
{
OUTCOME_V2_AWAITABLES_DEBUG_PRINTER(&self.promise() << " promise final suspend will exit");
}
}
#endif
};
return awaiter{};
}
};
template <class Awaitable, bool suspend_initial, bool use_atomic> struct outcome_promise_type<Awaitable, suspend_initial, use_atomic, true>
{
using container_type = void;
using result_set_type = std::conditional_t<use_atomic, std::atomic<bool>, fake_atomic<bool>>;
result_set_type result_set{false}, pending_first_resumption{is_initially_suspended};
coroutine_handle<> continuation;
static constexpr bool is_initially_suspended = suspend_initial;
static constexpr bool is_using_atomics = use_atomic;
outcome_promise_type() { OUTCOME_V2_AWAITABLES_DEBUG_PRINTER(this << " promise constructed"); }
outcome_promise_type(const outcome_promise_type &) = delete;
outcome_promise_type(outcome_promise_type &&) = delete;
outcome_promise_type &operator=(const outcome_promise_type &) = delete;
outcome_promise_type &operator=(outcome_promise_type &&) = delete;
~outcome_promise_type() = default;
auto get_return_object()
{
OUTCOME_V2_AWAITABLES_DEBUG_PRINTER(this << " promise returns awaitable");
return Awaitable{*this}; // could throw bad_alloc
}
void return_void() noexcept
{
OUTCOME_V2_AWAITABLES_DEBUG_PRINTER(this << " promise returns void");
OUTCOME_ASSERT(!result_set.load(std::memory_order_acquire));
result_set.store(true, std::memory_order_release);
}
void unhandled_exception()
{
OUTCOME_V2_AWAITABLES_DEBUG_PRINTER(this << " promise unhandled exception");
OUTCOME_ASSERT(!result_set.load(std::memory_order_acquire));
std::rethrow_exception(std::current_exception()); // throws
}
auto initial_suspend() noexcept
{
OUTCOME_V2_AWAITABLES_DEBUG_PRINTER(this << " promise initial suspend = " << suspend_initial);
struct awaiter
{
constexpr bool await_ready() noexcept { return !suspend_initial; }
void await_resume() noexcept {}
void await_suspend(coroutine_handle<> /*unused*/) noexcept {}
};
return awaiter{};
}
auto final_suspend() noexcept
{
struct awaiter
{
// If we don't force a final suspend, promise will get deleted before awaitable
// TODO: Implement detachable awaitables
constexpr bool await_ready() noexcept { return false; }
void await_resume() noexcept {}
#if OUTCOME_HAVE_NOOP_COROUTINE
coroutine_handle<> await_suspend(coroutine_handle<outcome_promise_type> self) noexcept
{
if(self.promise().continuation)
{
OUTCOME_V2_AWAITABLES_DEBUG_PRINTER(&self.promise() << " promise final suspend will resume coroutine " << self.promise().continuation.address());
}
else
{
OUTCOME_V2_AWAITABLES_DEBUG_PRINTER(&self.promise() << " promise final suspend will exit");
}
return self.promise().continuation ? self.promise().continuation : noop_coroutine();
}
#else
void await_suspend(coroutine_handle<outcome_promise_type> self)
{
if(self.promise().continuation)
{
OUTCOME_V2_AWAITABLES_DEBUG_PRINTER(&self.promise() << " promise final suspend will resume coroutine " << self.promise().continuation.address());
return self.promise().continuation.resume();
}
else
{
OUTCOME_V2_AWAITABLES_DEBUG_PRINTER(&self.promise() << " promise final suspend will exit");
}
}
#endif
};
return awaiter{};
}
};
template <class Awaitable, bool suspend_initial, bool use_atomic>
constexpr inline auto move_result_from_promise_if_not_void(outcome_promise_type<Awaitable, suspend_initial, use_atomic, false> &p)
{
return static_cast<typename Awaitable::container_type &&>(p.result);
}
template <class Awaitable, bool suspend_initial, bool use_atomic>
constexpr inline void move_result_from_promise_if_not_void(outcome_promise_type<Awaitable, suspend_initial, use_atomic, true> & /*unused*/)
{
}
template <class Cont, class Executor, bool suspend_initial, bool use_atomic> struct OUTCOME_NODISCARD awaitable
{
using container_type = Cont;
using value_type = Cont;
using executor_type = Executor;
using promise_type = outcome_promise_type<awaitable, suspend_initial, use_atomic, std::is_void<container_type>::value>;
coroutine_handle<promise_type> _h;
awaitable(awaitable &&o) noexcept
: _h(static_cast<coroutine_handle<promise_type> &&>(o._h))
{
o._h = nullptr;
}
awaitable(const awaitable &o) = delete;
awaitable &operator=(awaitable &&) = delete; // as per P1056
awaitable &operator=(const awaitable &) = delete;
~awaitable()
{
OUTCOME_V2_AWAITABLES_DEBUG_PRINTER(&_h.promise() << " awaitable destructs");
if(_h)
{
_h.destroy();
}
}
explicit awaitable(promise_type &p) // could throw
: _h(coroutine_handle<promise_type>::from_promise(p))
{
OUTCOME_V2_AWAITABLES_DEBUG_PRINTER(&_h.promise() << " awaitable constructs for coroutine " << _h.address()
<< " shall resume on first suspend = " << promise_type::is_initially_suspended);
}
bool valid() const noexcept { return _h != nullptr; }
bool await_ready() noexcept
{
OUTCOME_V2_AWAITABLES_DEBUG_PRINTER(&_h.promise() << " await_ready = " << _h.promise().result_set.load(std::memory_order_acquire));
return _h.promise().result_set.load(std::memory_order_acquire);
}
container_type await_resume()
{
OUTCOME_V2_AWAITABLES_DEBUG_PRINTER(&_h.promise() << " await_resume");
OUTCOME_ASSERT(_h.promise().result_set.load(std::memory_order_acquire));
if(!_h.promise().result_set.load(std::memory_order_acquire))
{
std::terminate();
}
return detail::move_result_from_promise_if_not_void(_h.promise());
}
#if OUTCOME_HAVE_NOOP_COROUTINE
coroutine_handle<> await_suspend(coroutine_handle<> cont) noexcept
{
OUTCOME_V2_AWAITABLES_DEBUG_PRINTER(&_h.promise() << " await_suspend suspends coroutine " << cont.address());
auto &p = _h.promise();
p.continuation = cont;
bool expected = true;
if(p.pending_first_resumption.compare_exchange_strong(expected, false, std::memory_order_acq_rel, std::memory_order_relaxed))
{
OUTCOME_V2_AWAITABLES_DEBUG_PRINTER(&_h.promise()
<< " await_suspend does one time first resumption of initially suspended coroutine " << _h.address());
return _h;
}
return noop_coroutine();
}
#else
void await_suspend(coroutine_handle<> cont)
{
OUTCOME_V2_AWAITABLES_DEBUG_PRINTER(&_h.promise() << " await_suspend suspends coroutine " << cont.address());
auto &p = _h.promise();
p.continuation = cont;
bool expected = true;
if(p.pending_first_resumption.compare_exchange_strong(expected, false, std::memory_order_acq_rel, std::memory_order_relaxed))
{
OUTCOME_V2_AWAITABLES_DEBUG_PRINTER(&_h.promise()
<< " await_suspend does one time first resumption of initially suspended coroutine " << _h.address());
_h.resume();
}
}
#endif
};
template <class ContType, class Executor, bool suspend_initial, bool use_atomic> struct generator
{
using container_type = ContType;
using value_type = ContType;
using executor_type = Executor;
class promise_type
{
friend struct generator;
using result_set_type = std::conditional_t<use_atomic, std::atomic<int8_t>, fake_atomic<int8_t>>;
union
{
OUTCOME_V2_NAMESPACE::detail::empty_type _default{};
container_type result;
};
result_set_type result_set{0};
coroutine_handle<> continuation;
public:
promise_type() {}
promise_type(const promise_type &) = delete;
promise_type(promise_type &&) = delete;
promise_type &operator=(const promise_type &) = delete;
promise_type &operator=(promise_type &&) = delete;
~promise_type()
{
if(result_set.load(std::memory_order_acquire) == 1)
{
result.~container_type(); // could throw
}
}
auto get_return_object()
{
return generator{*this}; // could throw bad_alloc
}
void return_void() noexcept
{
OUTCOME_ASSERT(result_set.load(std::memory_order_acquire) >= 0);
if(result_set.load(std::memory_order_acquire) == 1)
{
result.~container_type(); // could throw
}
result_set.store(-1, std::memory_order_release);
}
suspend_always yield_value(container_type &&value)
{
OUTCOME_ASSERT(result_set.load(std::memory_order_acquire) >= 0);
if(result_set.load(std::memory_order_acquire) == 1)
{
result.~container_type(); // could throw
}
new(&result) container_type(static_cast<container_type &&>(value)); // could throw
result_set.store(1, std::memory_order_release);
return {};
}
suspend_always yield_value(const container_type &value)
{
OUTCOME_ASSERT(result_set.load(std::memory_order_acquire) >= 0);
if(result_set.load(std::memory_order_acquire) == 1)
{
result.~container_type(); // could throw
}
new(&result) container_type(value); // could throw
result_set.store(1, std::memory_order_release);
return {};
}
void unhandled_exception()
{
OUTCOME_ASSERT(result_set.load(std::memory_order_acquire) >= 0);
if(result_set.load(std::memory_order_acquire) == 1)
{
result.~container_type();
}
#ifdef __cpp_exceptions
auto e = std::current_exception();
auto ec = detail::error_from_exception(static_cast<decltype(e) &&>(e), {});
// Try to set error code first
if(!detail::error_is_set(ec) || !detail::try_set_error(static_cast<decltype(ec) &&>(ec), &result))
{
detail::set_or_rethrow(e, &result); // could throw
}
#else
std::terminate();
#endif
result_set.store(1, std::memory_order_release);
}
auto initial_suspend() noexcept
{
struct awaiter
{
bool await_ready() noexcept { return !suspend_initial; }
void await_resume() noexcept {}
void await_suspend(coroutine_handle<> /*unused*/) noexcept {}
};
return awaiter{};
}
auto final_suspend() noexcept
{
struct awaiter
{
bool await_ready() noexcept { return false; }
void await_resume() noexcept {}
#if OUTCOME_HAVE_NOOP_COROUTINE
coroutine_handle<> await_suspend(coroutine_handle<promise_type> self) noexcept
{
return self.promise().continuation ? self.promise().continuation : noop_coroutine();
}
#else
void await_suspend(coroutine_handle<promise_type> self)
{
if(self.promise().continuation)
{
return self.promise().continuation.resume();
}
}
#endif
};
return awaiter{};
}
};
coroutine_handle<promise_type> _h;
generator(generator &&o) noexcept
: _h(static_cast<coroutine_handle<promise_type> &&>(o._h))
{
o._h = nullptr;
}
generator(const generator &o) = delete;
generator &operator=(generator &&) = delete; // as per P1056
generator &operator=(const generator &) = delete;
~generator()
{
if(_h)
{
_h.destroy();
}
}
explicit generator(promise_type &p) // could throw
: _h(coroutine_handle<promise_type>::from_promise(p))
{
}
explicit operator bool() const // could throw
{
return valid();
}
bool valid() const // could throw
{
auto &p = _h.promise();
if(p.result_set.load(std::memory_order_acquire) == 0)
{
const_cast<generator *>(this)->_h();
}
return p.result_set.load(std::memory_order_acquire) >= 0;
}
container_type operator()() // could throw
{
auto &p = _h.promise();
if(p.result_set.load(std::memory_order_acquire) == 0)
{
_h();
}
OUTCOME_ASSERT(p.result_set.load(std::memory_order_acquire) >= 0);
if(p.result_set.load(std::memory_order_acquire) < 0)
{
std::terminate();
}
container_type ret(static_cast<container_type &&>(p.result));
p.result.~container_type(); // could throw
p.result_set.store(0, std::memory_order_release);
return ret;
}
#if OUTCOME_HAVE_NOOP_COROUTINE
coroutine_handle<> await_suspend(coroutine_handle<> cont) noexcept
{
_h.promise().continuation = cont;
return _h;
}
#else
void await_suspend(coroutine_handle<> cont)
{
_h.promise().continuation = cont;
_h.resume();
}
#endif
};
#endif
} // namespace detail
} // namespace awaitables
OUTCOME_V2_NAMESPACE_END
#endif
#ifdef OUTCOME_FOUND_COROUTINE_HEADER
OUTCOME_V2_NAMESPACE_EXPORT_BEGIN namespace awaitables {
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
template <class T, class Executor = void> using eager = OUTCOME_V2_NAMESPACE::awaitables::detail::awaitable<T, Executor, false, false>;
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
template <class T, class Executor = void> using atomic_eager = OUTCOME_V2_NAMESPACE::awaitables::detail::awaitable<T, Executor, false, true>;
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
template <class T, class Executor = void> using lazy = OUTCOME_V2_NAMESPACE::awaitables::detail::awaitable<T, Executor, true, false>;
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
template <class T, class Executor = void> using atomic_lazy = OUTCOME_V2_NAMESPACE::awaitables::detail::awaitable<T, Executor, true, true>;
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
template <class T, class Executor = void> using generator = OUTCOME_V2_NAMESPACE::awaitables::detail::generator<T, Executor, true, false>;
} OUTCOME_V2_NAMESPACE_END
#endif
#undef OUTCOME_COROUTINE_SUPPORT_NAMESPACE_BEGIN
#undef OUTCOME_COROUTINE_SUPPORT_NAMESPACE_EXPORT_BEGIN
#undef OUTCOME_COROUTINE_SUPPORT_NAMESPACE_END
#endif
/* iostream specialisations for result and outcome
(C) 2017-2019 Niall Douglas <http://www.nedproductions.biz/> (21 commits)
File Created: July 2017
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License in the accompanying file
Licence.txt or at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Distributed under the Boost Software License, Version 1.0.
(See accompanying file Licence.txt or copy at
http://www.boost.org/LICENSE_1_0.txt)
*/
#ifndef OUTCOME_IOSTREAM_SUPPORT_HPP
#define OUTCOME_IOSTREAM_SUPPORT_HPP
/* A less simple result type
(C) 2017-2019 Niall Douglas <http://www.nedproductions.biz/> (79 commits)
File Created: June 2017
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License in the accompanying file
Licence.txt or at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Distributed under the Boost Software License, Version 1.0.
(See accompanying file Licence.txt or copy at
http://www.boost.org/LICENSE_1_0.txt)
*/
#ifndef OUTCOME_OUTCOME_HPP
#define OUTCOME_OUTCOME_HPP
/* A very simple result type
(C) 2017-2019 Niall Douglas <http://www.nedproductions.biz/> (99 commits)
File Created: June 2017
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License in the accompanying file
Licence.txt or at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Distributed under the Boost Software License, Version 1.0.
(See accompanying file Licence.txt or copy at
http://www.boost.org/LICENSE_1_0.txt)
*/
#ifndef OUTCOME_RESULT_HPP
#define OUTCOME_RESULT_HPP
/* A very simple result type
(C) 2017-2019 Niall Douglas <http://www.nedproductions.biz/> (8 commits)
File Created: June 2017
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License in the accompanying file
Licence.txt or at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Distributed under the Boost Software License, Version 1.0.
(See accompanying file Licence.txt or copy at
http://www.boost.org/LICENSE_1_0.txt)
*/
#ifndef OUTCOME_STD_RESULT_HPP
#define OUTCOME_STD_RESULT_HPP
/* A very simple result type
(C) 2017-2024 Niall Douglas <http://www.nedproductions.biz/> (14 commits)
File Created: June 2017
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License in the accompanying file
Licence.txt or at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Distributed under the Boost Software License, Version 1.0.
(See accompanying file Licence.txt or copy at
http://www.boost.org/LICENSE_1_0.txt)
*/
#ifndef OUTCOME_BASIC_RESULT_HPP
#define OUTCOME_BASIC_RESULT_HPP
/* Says how to convert value, error and exception types
(C) 2017-2019 Niall Douglas <http://www.nedproductions.biz/> (12 commits)
File Created: Nov 2017
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License in the accompanying file
Licence.txt or at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Distributed under the Boost Software License, Version 1.0.
(See accompanying file Licence.txt or copy at
http://www.boost.org/LICENSE_1_0.txt)
*/
#ifndef OUTCOME_CONVERT_HPP
#define OUTCOME_CONVERT_HPP
/* Storage for a very simple basic_result type
(C) 2017-2019 Niall Douglas <http://www.nedproductions.biz/> (6 commits)
File Created: Oct 2017
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License in the accompanying file
Licence.txt or at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Distributed under the Boost Software License, Version 1.0.
(See accompanying file Licence.txt or copy at
http://www.boost.org/LICENSE_1_0.txt)
*/
#ifndef OUTCOME_BASIC_RESULT_STORAGE_HPP
#define OUTCOME_BASIC_RESULT_STORAGE_HPP
/* Type sugar for success and failure
(C) 2017-2019 Niall Douglas <http://www.nedproductions.biz/> (25 commits)
File Created: July 2017
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License in the accompanying file
Licence.txt or at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Distributed under the Boost Software License, Version 1.0.
(See accompanying file Licence.txt or copy at
http://www.boost.org/LICENSE_1_0.txt)
*/
#ifndef OUTCOME_SUCCESS_FAILURE_HPP
#define OUTCOME_SUCCESS_FAILURE_HPP
OUTCOME_V2_NAMESPACE_BEGIN
/*! AWAITING HUGO JSON CONVERSION TOOL
type definition template <class T> success_type. Potential doc page: `success_type<T>`
*/
template <class T> struct OUTCOME_NODISCARD success_type
{
using value_type = T;
private:
value_type _value;
uint16_t _spare_storage{0};
public:
success_type() = default;
success_type(const success_type &) = default;
success_type(success_type &&) = default; // NOLINT
success_type &operator=(const success_type &) = default;
success_type &operator=(success_type &&) = default; // NOLINT
~success_type() = default;
OUTCOME_TEMPLATE(class U)
OUTCOME_TREQUIRES(OUTCOME_TPRED(!std::is_same<success_type, std::decay_t<U>>::value))
constexpr explicit success_type(U &&v, uint16_t spare_storage = 0)
: _value(static_cast<U &&>(v)) // NOLINT
, _spare_storage(spare_storage)
{
}
constexpr value_type &value() & { return _value; }
constexpr const value_type &value() const & { return _value; }
constexpr value_type &&value() && { return static_cast<value_type &&>(_value); }
constexpr const value_type &&value() const && { return static_cast<value_type &&>(_value); }
constexpr uint16_t spare_storage() const { return _spare_storage; }
};
template <> struct OUTCOME_NODISCARD success_type<void>
{
using value_type = void;
constexpr uint16_t spare_storage() const { return 0; }
};
/*! Returns type sugar for implicitly constructing a `basic_result<T>` with a successful state,
default constructing `T` if necessary.
*/
inline constexpr success_type<void> success() noexcept
{
return success_type<void>{};
}
/*! Returns type sugar for implicitly constructing a `basic_result<T>` with a successful state.
\effects Copies the successful state supplied into the returned type sugar.
*/
OUTCOME_TEMPLATE(class T)
OUTCOME_TREQUIRES(OUTCOME_TPRED(std::is_copy_constructible<T>::value))
inline constexpr success_type<std::decay_t<T>> success(const T &v, uint16_t spare_storage = 0)
{
return success_type<std::decay_t<T>>{v, spare_storage};
}
/*! Returns type sugar for implicitly constructing a `basic_result<T>` with a successful state.
\effects Moves the successful state supplied into the returned type sugar.
*/
OUTCOME_TEMPLATE(class T)
OUTCOME_TREQUIRES(OUTCOME_TPRED(std::is_move_constructible<T>::value))
inline constexpr success_type<std::decay_t<T>> success(T &&v, uint16_t spare_storage = 0)
{
return success_type<std::decay_t<T>>{static_cast<T &&>(v), spare_storage};
}
/*! AWAITING HUGO JSON CONVERSION TOOL
type definition template <class EC, class E = void> failure_type. Potential doc page: `failure_type<EC, EP = void>`
*/
template <class EC, class E = void> struct OUTCOME_NODISCARD failure_type
{
using error_type = EC;
using exception_type = E;
private:
error_type _error;
exception_type _exception;
bool _have_error{false}, _have_exception{false};
uint16_t _spare_storage{0};
struct error_init_tag
{
};
struct exception_init_tag
{
};
public:
failure_type() = default;
failure_type(const failure_type &) = default;
failure_type(failure_type &&) = default; // NOLINT
failure_type &operator=(const failure_type &) = default;
failure_type &operator=(failure_type &&) = default; // NOLINT
~failure_type() = default;
template <class U, class V>
constexpr explicit failure_type(U &&u, V &&v, uint16_t spare_storage = 0)
: _error(static_cast<U &&>(u))
, _exception(static_cast<V &&>(v))
, _have_error(true)
, _have_exception(true)
, _spare_storage(spare_storage)
{
}
template <class U>
constexpr explicit failure_type(in_place_type_t<error_type> /*unused*/, U &&u, uint16_t spare_storage = 0, error_init_tag /*unused*/ = error_init_tag())
: _error(static_cast<U &&>(u))
, _exception()
, _have_error(true)
, _spare_storage(spare_storage)
{
}
template <class U>
constexpr explicit failure_type(in_place_type_t<exception_type> /*unused*/, U &&u, uint16_t spare_storage = 0,
exception_init_tag /*unused*/ = exception_init_tag())
: _error()
, _exception(static_cast<U &&>(u))
, _have_exception(true)
, _spare_storage(spare_storage)
{
}
constexpr bool has_error() const { return _have_error; }
constexpr bool has_exception() const { return _have_exception; }
constexpr error_type &error() & { return _error; }
constexpr const error_type &error() const & { return _error; }
constexpr error_type &&error() && { return static_cast<error_type &&>(_error); }
constexpr const error_type &&error() const && { return static_cast<error_type &&>(_error); }
constexpr exception_type &exception() & { return _exception; }
constexpr const exception_type &exception() const & { return _exception; }
constexpr exception_type &&exception() && { return static_cast<exception_type &&>(_exception); }
constexpr const exception_type &&exception() const && { return static_cast<exception_type &&>(_exception); }
constexpr uint16_t spare_storage() const { return _spare_storage; }
};
template <class EC> struct OUTCOME_NODISCARD failure_type<EC, void>
{
using error_type = EC;
using exception_type = void;
private:
error_type _error;
uint16_t _spare_storage{0};
public:
failure_type() = default;
failure_type(const failure_type &) = default;
failure_type(failure_type &&) = default; // NOLINT
failure_type &operator=(const failure_type &) = default;
failure_type &operator=(failure_type &&) = default; // NOLINT
~failure_type() = default;
OUTCOME_TEMPLATE(class U)
OUTCOME_TREQUIRES(OUTCOME_TPRED(!std::is_same<failure_type, std::decay_t<U>>::value))
constexpr explicit failure_type(U &&u, uint16_t spare_storage = 0)
: _error(static_cast<U &&>(u)) // NOLINT
, _spare_storage(spare_storage)
{
}
constexpr error_type &error() & { return _error; }
constexpr const error_type &error() const & { return _error; }
constexpr error_type &&error() && { return static_cast<error_type &&>(_error); }
constexpr const error_type &&error() const && { return static_cast<error_type &&>(_error); }
constexpr uint16_t spare_storage() const { return _spare_storage; }
};
template <class E> struct OUTCOME_NODISCARD failure_type<void, E>
{
using error_type = void;
using exception_type = E;
private:
exception_type _exception;
uint16_t _spare_storage{0};
public:
failure_type() = default;
failure_type(const failure_type &) = default;
failure_type(failure_type &&) = default; // NOLINT
failure_type &operator=(const failure_type &) = default;
failure_type &operator=(failure_type &&) = default; // NOLINT
~failure_type() = default;
OUTCOME_TEMPLATE(class V)
OUTCOME_TREQUIRES(OUTCOME_TPRED(!std::is_same<failure_type, std::decay_t<V>>::value))
constexpr explicit failure_type(V &&v, uint16_t spare_storage = 0)
: _exception(static_cast<V &&>(v)) // NOLINT
, _spare_storage(spare_storage)
{
}
constexpr exception_type &exception() & { return _exception; }
constexpr const exception_type &exception() const & { return _exception; }
constexpr exception_type &&exception() && { return static_cast<exception_type &&>(_exception); }
constexpr const exception_type &&exception() const && { return static_cast<exception_type &&>(_exception); }
constexpr uint16_t spare_storage() const { return _spare_storage; }
};
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class EC)
OUTCOME_TREQUIRES(OUTCOME_TPRED(std::is_copy_constructible<EC>::value))
inline constexpr failure_type<std::decay_t<EC>> failure(const EC &v, uint16_t spare_storage = 0)
{
return failure_type<std::decay_t<EC>>{v, spare_storage};
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class EC)
OUTCOME_TREQUIRES(OUTCOME_TPRED(std::is_move_constructible<EC>::value))
inline constexpr failure_type<std::decay_t<EC>> failure(EC &&v, uint16_t spare_storage = 0)
{
return failure_type<std::decay_t<EC>>{static_cast<EC &&>(v), spare_storage};
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class EC, class E)
OUTCOME_TREQUIRES(OUTCOME_TPRED(std::is_copy_constructible<EC>::value &&std::is_copy_constructible<E>::value))
inline constexpr failure_type<std::decay_t<EC>, std::decay_t<E>> failure(const EC &v, const E &w, uint16_t spare_storage = 0)
{
return failure_type<std::decay_t<EC>, std::decay_t<E>>{v, w, spare_storage};
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class EC, class E)
OUTCOME_TREQUIRES(OUTCOME_TPRED(std::is_copy_constructible<EC>::value &&std::is_move_constructible<E>::value))
inline constexpr failure_type<std::decay_t<EC>, std::decay_t<E>> failure(const EC &v, E &&w, uint16_t spare_storage = 0)
{
return failure_type<std::decay_t<EC>, std::decay_t<E>>{v, static_cast<E &&>(w), spare_storage};
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class EC, class E)
OUTCOME_TREQUIRES(OUTCOME_TPRED(std::is_move_constructible<EC>::value &&std::is_copy_constructible<E>::value))
inline constexpr failure_type<std::decay_t<EC>, std::decay_t<E>> failure(EC &&v, const E &w, uint16_t spare_storage = 0)
{
return failure_type<std::decay_t<EC>, std::decay_t<E>>{static_cast<EC &&>(v), w, spare_storage};
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class EC, class E)
OUTCOME_TREQUIRES(OUTCOME_TPRED(std::is_move_constructible<EC>::value &&std::is_move_constructible<E>::value))
inline constexpr failure_type<std::decay_t<EC>, std::decay_t<E>> failure(EC &&v, E &&w, uint16_t spare_storage = 0)
{
return failure_type<std::decay_t<EC>, std::decay_t<E>>{static_cast<EC &&>(v), static_cast<E &&>(w), spare_storage};
}
namespace detail
{
template <class T> struct is_success_type
{
static constexpr bool value = false;
};
template <class T> struct is_success_type<success_type<T>>
{
static constexpr bool value = true;
};
template <class T> struct is_failure_type
{
static constexpr bool value = false;
};
template <class EC, class E> struct is_failure_type<failure_type<EC, E>>
{
static constexpr bool value = true;
};
} // namespace detail
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
template <class T> static constexpr bool is_success_type = detail::is_success_type<std::decay_t<T>>::value;
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
template <class T> static constexpr bool is_failure_type = detail::is_failure_type<std::decay_t<T>>::value;
OUTCOME_V2_NAMESPACE_END
#endif
/* Traits for Outcome
(C) 2018-2019 Niall Douglas <http://www.nedproductions.biz/> (8 commits)
File Created: March 2018
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License in the accompanying file
Licence.txt or at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Distributed under the Boost Software License, Version 1.0.
(See accompanying file Licence.txt or copy at
http://www.boost.org/LICENSE_1_0.txt)
*/
#ifndef OUTCOME_TRAIT_HPP
#define OUTCOME_TRAIT_HPP
OUTCOME_V2_NAMESPACE_EXPORT_BEGIN
namespace trait
{
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
template <class R> //
static constexpr bool type_can_be_used_in_basic_result = //
(!std::is_reference<R>::value //
&& !OUTCOME_V2_NAMESPACE::detail::is_in_place_type_t<std::decay_t<R>>::value //
&& !is_success_type<R> //
&& !is_failure_type<R> //
&& !std::is_array<R>::value //
&& (std::is_void<R>::value || (std::is_object<R>::value //
&& std::is_destructible<R>::value)) //
);
/*! AWAITING HUGO JSON CONVERSION TOOL
type definition is_error_type. Potential doc page: NOT FOUND
*/
template <class T> struct is_move_bitcopying
{
static constexpr bool value = false;
};
/*! AWAITING HUGO JSON CONVERSION TOOL
type definition is_error_type. Potential doc page: NOT FOUND
*/
template <class E> struct is_error_type
{
static constexpr bool value = false;
};
/*! AWAITING HUGO JSON CONVERSION TOOL
type definition is_error_type_enum. Potential doc page: NOT FOUND
*/
template <class E, class Enum> struct is_error_type_enum
{
static constexpr bool value = false;
};
namespace detail
{
template <class T> using devoid = OUTCOME_V2_NAMESPACE::detail::devoid<T>;
template <class T> std::add_rvalue_reference_t<devoid<T>> declval() noexcept;
// From http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2015/n4436.pdf
namespace detector_impl
{
template <class...> using void_t = void;
template <class Default, class, template <class...> class Op, class... Args> struct detector
{
static constexpr bool value = false;
using type = Default;
};
template <class Default, template <class...> class Op, class... Args> struct detector<Default, void_t<Op<Args...>>, Op, Args...>
{
static constexpr bool value = true;
using type = Op<Args...>;
};
} // namespace detector_impl
template <template <class...> class Op, class... Args> using is_detected = detector_impl::detector<void, void, Op, Args...>;
template <class Arg> using result_of_make_error_code = decltype(make_error_code(declval<Arg>()));
template <class Arg> using introspect_make_error_code = is_detected<result_of_make_error_code, Arg>;
template <class Arg> using result_of_make_exception_ptr = decltype(make_exception_ptr(declval<Arg>()));
template <class Arg> using introspect_make_exception_ptr = is_detected<result_of_make_exception_ptr, Arg>;
template <class T> struct _is_error_code_available
{
static constexpr bool value = detail::introspect_make_error_code<T>::value;
using type = typename detail::introspect_make_error_code<T>::type;
};
template <class T> struct _is_exception_ptr_available
{
static constexpr bool value = detail::introspect_make_exception_ptr<T>::value;
using type = typename detail::introspect_make_exception_ptr<T>::type;
};
} // namespace detail
/*! AWAITING HUGO JSON CONVERSION TOOL
type definition is_error_code_available. Potential doc page: NOT FOUND
*/
template <class T> struct is_error_code_available
{
static constexpr bool value = detail::_is_error_code_available<std::decay_t<T>>::value;
using type = typename detail::_is_error_code_available<std::decay_t<T>>::type;
};
template <class T> constexpr bool is_error_code_available_v = detail::_is_error_code_available<std::decay_t<T>>::value;
/*! AWAITING HUGO JSON CONVERSION TOOL
type definition is_exception_ptr_available. Potential doc page: NOT FOUND
*/
template <class T> struct is_exception_ptr_available
{
static constexpr bool value = detail::_is_exception_ptr_available<std::decay_t<T>>::value;
using type = typename detail::_is_exception_ptr_available<std::decay_t<T>>::type;
};
template <class T> constexpr bool is_exception_ptr_available_v = detail::_is_exception_ptr_available<std::decay_t<T>>::value;
} // namespace trait
OUTCOME_V2_NAMESPACE_END
#endif
/* Essentially an internal optional implementation :)
(C) 2017-2022 Niall Douglas <http://www.nedproductions.biz/> (24 commits)
File Created: June 2017
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License in the accompanying file
Licence.txt or at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Distributed under the Boost Software License, Version 1.0.
(See accompanying file Licence.txt or copy at
http://www.boost.org/LICENSE_1_0.txt)
*/
#ifndef OUTCOME_VALUE_STORAGE_HPP
#define OUTCOME_VALUE_STORAGE_HPP
OUTCOME_V2_NAMESPACE_EXPORT_BEGIN
namespace detail
{
// Helpers for move assigning to empty storage
template <class T, bool isCopyOrMoveConstructible = std::is_copy_constructible<T>::value || std::is_move_constructible<T>::value,
bool isDefaultConstructibleAndCopyOrMoveAssignable =
std::is_default_constructible<T>::value && (std::is_copy_assignable<T>::value || std::is_move_assignable<T>::value)>
struct move_assign_to_empty;
// Prefer to use move or copy construction
template <class T> struct move_assign_to_empty<T, true, false>
{
move_assign_to_empty(T *dest, T *o) noexcept(std::is_nothrow_move_constructible<T>::value) { new(dest) T(static_cast<T &&>(*o)); }
};
template <class T> struct move_assign_to_empty<T, true, true>
{
move_assign_to_empty(T *dest, T *o) noexcept(std::is_nothrow_move_constructible<T>::value) { new(dest) T(static_cast<T &&>(*o)); }
};
// But fall back on default construction and move assign if necessary
template <class T> struct move_assign_to_empty<T, false, true>
{
move_assign_to_empty(T *dest, T *o) noexcept(std::is_nothrow_default_constructible<T>::value && std::is_nothrow_move_assignable<T>::value)
{
new(dest) T;
*dest = static_cast<T &&>(*o);
}
};
// Void does nothing
template <> struct move_assign_to_empty<void, false, false>
{
move_assign_to_empty(void *, void *) noexcept { /* nothing to assign */ }
};
template <> struct move_assign_to_empty<const void, false, false>
{
move_assign_to_empty(const void *, const void *) noexcept { /* nothing to assign */ }
};
// Helpers for copy assigning to empty storage
template <class T, bool isCopyConstructible = std::is_copy_constructible<T>::value,
bool isDefaultConstructibleAndCopyAssignable = std::is_default_constructible<T>::value && std::is_copy_assignable<T>::value>
struct copy_assign_to_empty;
// Prefer to use copy construction
template <class T> struct copy_assign_to_empty<T, true, false>
{
copy_assign_to_empty(T *dest, const T *o) noexcept(std::is_nothrow_copy_constructible<T>::value) { new(dest) T(*o); }
};
template <class T> struct copy_assign_to_empty<T, true, true>
{
copy_assign_to_empty(T *dest, const T *o) noexcept(std::is_nothrow_copy_constructible<T>::value) { new(dest) T(*o); }
};
// But fall back on default construction and copy assign if necessary
template <class T> struct copy_assign_to_empty<T, false, true>
{
copy_assign_to_empty(T *dest, const T *o) noexcept(std::is_nothrow_default_constructible<T>::value && std::is_nothrow_copy_assignable<T>::value)
{
new(dest) T;
*dest = *o;
}
};
// Void does nothing
template <> struct copy_assign_to_empty<void, false, false>
{
copy_assign_to_empty(void *, void *) noexcept { /* nothing to assign */ }
};
template <> struct copy_assign_to_empty<const void, false, false>
{
copy_assign_to_empty(const void *, const void *) noexcept { /* nothing to assign */ }
};
template <class T, bool nothrow> struct strong_swap_impl
{
constexpr strong_swap_impl(bool &allgood, T &a, T &b)
{
allgood = true;
using std::swap;
swap(a, b);
}
};
template <class T, bool nothrow> struct strong_placement_impl
{
template <class F> constexpr strong_placement_impl(bool &allgood, T *a, T *b, F &&f)
{
allgood = true;
new(a) T(static_cast<T &&>(*b));
b->~T();
f();
}
};
#ifdef __cpp_exceptions
template <class T> struct strong_swap_impl<T, false>
{
strong_swap_impl(bool &allgood, T &a, T &b)
{
allgood = true;
T v(static_cast<T &&>(a));
try
{
a = static_cast<T &&>(b);
}
catch(...)
{
// Try to put back a
try
{
a = static_cast<T &&>(v);
// fall through as all good
}
catch(...)
{
// failed to completely restore
allgood = false;
// throw away second exception
}
throw; // rethrow original exception
}
// b has been moved to a, try to move v to b
try
{
b = static_cast<T &&>(v);
}
catch(...)
{
// Try to restore a to b, and v to a
try
{
b = static_cast<T &&>(a);
a = static_cast<T &&>(v);
// fall through as all good
}
catch(...)
{
// failed to completely restore
allgood = false;
// throw away second exception
}
throw; // rethrow original exception
}
}
};
template <class T> struct strong_placement_impl<T, false>
{
template <class F> strong_placement_impl(bool &allgood, T *a, T *b, F &&f)
{
new(a) T(static_cast<T &&>(*b));
try
{
b->~T();
f();
}
catch(...)
{
// Try to put back a, but only if we are still good
if(allgood)
{
try
{
new(b) T(static_cast<T &&>(*a));
// fall through as all good
}
catch(...)
{
// failed to completely restore
allgood = false;
// throw away second exception
}
throw; // rethrow original exception
}
}
}
};
#endif
} // namespace detail
/*!
*/
OUTCOME_TEMPLATE(class T)
OUTCOME_TREQUIRES(OUTCOME_TPRED(std::is_move_constructible<T>::value &&std::is_move_assignable<T>::value))
constexpr inline void strong_swap(bool &allgood, T &a, T &b) noexcept(detail::is_nothrow_swappable<T>::value)
{
detail::strong_swap_impl<T, detail::is_nothrow_swappable<T>::value>(allgood, a, b);
}
/*!
*/
OUTCOME_TEMPLATE(class T, class F)
OUTCOME_TREQUIRES(OUTCOME_TPRED(std::is_move_constructible<T>::value &&std::is_move_assignable<T>::value))
constexpr inline void strong_placement(bool &allgood, T *a, T *b, F &&f) noexcept(std::is_nothrow_move_constructible<T>::value)
{
detail::strong_placement_impl<T, std::is_nothrow_move_constructible<T>::value>(allgood, a, b, static_cast<F &&>(f));
}
namespace detail
{
template <class T>
constexpr
#ifdef _MSC_VER
__declspec(noreturn)
#elif defined(__GNUC__) || defined(__clang__)
__attribute__((noreturn))
#endif
void
make_ub(T && /*unused*/)
{
OUTCOME_ASSERT(false); // NOLINT
#if defined(__GNUC__) || defined(__clang__)
__builtin_unreachable();
#elif defined(_MSC_VER)
__assume(0);
#endif
}
/* Outcome v1 used a C bitfield whose values were tracked by compiler optimisers nicely,
but that produces ICEs when used in constexpr.
Outcome v2.0-v2.1 used a 32 bit integer and manually set and cleared bits. Unfortunately
only GCC's optimiser tracks bit values during constant folding, and only per byte, and
even then unreliably. https://wg21.link/P1886 "Error speed benchmarking" showed just how
poorly clang and MSVC fails to optimise outcome-using code, if you manually set bits.
Outcome v2.2 therefore uses an enum with fixed values, and constexpr manipulation functions
to change the value to one of the enum's values. This is stupid to look at in source code,
but it make clang's optimiser do the right thing, so it's worth it.
*/
#define OUTCOME_USE_CONSTEXPR_ENUM_STATUS 0
enum class status : uint16_t
{
// WARNING: These bits are not tracked by abi-dumper, but changing them will break ABI!
none = 0,
have_value = (1U << 0U),
have_error = (1U << 1U),
have_exception = (2U << 1U),
have_error_exception = (3U << 1U),
// failed to complete a strong swap
have_lost_consistency = (1U << 3U),
have_value_lost_consistency = (1U << 0U) | (1U << 3U),
have_error_lost_consistency = (1U << 1U) | (1U << 3U),
have_exception_lost_consistency = (2U << 1U) | (1U << 3U),
have_error_exception_lost_consistency = (3U << 1U) | (1U << 3U),
// can errno be set from this error?
have_error_is_errno = (1U << 4U),
have_error_error_is_errno = (1U << 1U) | (1U << 4U),
have_error_exception_error_is_errno = (3U << 1U) | (1U << 4U),
have_error_lost_consistency_error_is_errno = (1U << 1U) | (1U << 3U) | (1U << 4U),
have_error_exception_lost_consistency_error_is_errno = (3U << 1U) | (1U << 3U) | (1U << 4U),
// value has been moved from
have_moved_from = (1U << 5U)
};
struct status_bitfield_type
{
status status_value{status::none};
uint16_t spare_storage_value{0}; // hooks::spare_storage()
constexpr status_bitfield_type() = default;
constexpr status_bitfield_type(status v) noexcept
: status_value(v)
{
} // NOLINT
constexpr status_bitfield_type(status v, uint16_t s) noexcept
: status_value(v)
, spare_storage_value(s)
{
}
constexpr status_bitfield_type(const status_bitfield_type &) = default;
constexpr status_bitfield_type(status_bitfield_type &&) = default;
constexpr status_bitfield_type &operator=(const status_bitfield_type &) = default;
constexpr status_bitfield_type &operator=(status_bitfield_type &&) = default;
//~status_bitfield_type() = default; // Do NOT uncomment this, it breaks older clangs!
constexpr bool have_value() const noexcept
{
return (static_cast<uint16_t>(status_value) & static_cast<uint16_t>(status::have_value)) != 0;
}
constexpr bool have_error() const noexcept
{
return (static_cast<uint16_t>(status_value) & static_cast<uint16_t>(status::have_error)) != 0;
}
constexpr bool have_exception() const noexcept
{
return (static_cast<uint16_t>(status_value) & static_cast<uint16_t>(status::have_exception)) != 0;
}
constexpr bool have_lost_consistency() const noexcept
{
return (static_cast<uint16_t>(status_value) & static_cast<uint16_t>(status::have_lost_consistency)) != 0;
}
constexpr bool have_error_is_errno() const noexcept
{
return (static_cast<uint16_t>(status_value) & static_cast<uint16_t>(status::have_error_is_errno)) != 0;
}
constexpr bool have_moved_from() const noexcept
{
return (static_cast<uint16_t>(status_value) & static_cast<uint16_t>(status::have_moved_from)) != 0;
}
constexpr status_bitfield_type &set_have_value(bool v) noexcept
{
status_value = static_cast<status>(v ? (static_cast<uint16_t>(status_value) | static_cast<uint16_t>(status::have_value)) :
(static_cast<uint16_t>(status_value) & ~static_cast<uint16_t>(status::have_value)));
return *this;
}
constexpr status_bitfield_type &set_have_error(bool v) noexcept
{
status_value = static_cast<status>(v ? (static_cast<uint16_t>(status_value) | static_cast<uint16_t>(status::have_error)) :
(static_cast<uint16_t>(status_value) & ~static_cast<uint16_t>(status::have_error)));
return *this;
}
constexpr status_bitfield_type &set_have_exception(bool v) noexcept
{
status_value = static_cast<status>(v ? (static_cast<uint16_t>(status_value) | static_cast<uint16_t>(status::have_exception)) :
(static_cast<uint16_t>(status_value) & ~static_cast<uint16_t>(status::have_exception)));
return *this;
}
constexpr status_bitfield_type &set_have_error_is_errno(bool v) noexcept
{
status_value = static_cast<status>(v ? (static_cast<uint16_t>(status_value) | static_cast<uint16_t>(status::have_error_is_errno)) :
(static_cast<uint16_t>(status_value) & ~static_cast<uint16_t>(status::have_error_is_errno)));
return *this;
}
constexpr status_bitfield_type &set_have_lost_consistency(bool v) noexcept
{
status_value = static_cast<status>(v ? (static_cast<uint16_t>(status_value) | static_cast<uint16_t>(status::have_lost_consistency)) :
(static_cast<uint16_t>(status_value) & ~static_cast<uint16_t>(status::have_lost_consistency)));
return *this;
}
constexpr status_bitfield_type &set_have_moved_from(bool v) noexcept
{
status_value = static_cast<status>(v ? (static_cast<uint16_t>(status_value) | static_cast<uint16_t>(status::have_moved_from)) :
(static_cast<uint16_t>(status_value) & ~static_cast<uint16_t>(status::have_moved_from)));
return *this;
}
};
#if !defined(NDEBUG)
// Check is trivial in all ways except default constructibility
static_assert(sizeof(status_bitfield_type) == 4, "status_bitfield_type is not sized 4 bytes!");
static_assert(std::is_trivially_copyable<status_bitfield_type>::value, "status_bitfield_type is not trivially copyable!");
static_assert(std::is_trivially_assignable<status_bitfield_type, status_bitfield_type>::value, "status_bitfield_type is not trivially assignable!");
static_assert(std::is_trivially_destructible<status_bitfield_type>::value, "status_bitfield_type is not trivially destructible!");
static_assert(std::is_trivially_copy_constructible<status_bitfield_type>::value, "status_bitfield_type is not trivially copy constructible!");
static_assert(std::is_trivially_move_constructible<status_bitfield_type>::value, "status_bitfield_type is not trivially move constructible!");
static_assert(std::is_trivially_copy_assignable<status_bitfield_type>::value, "status_bitfield_type is not trivially copy assignable!");
static_assert(std::is_trivially_move_assignable<status_bitfield_type>::value, "status_bitfield_type is not trivially move assignable!");
// Also check is standard layout
static_assert(std::is_standard_layout<status_bitfield_type>::value, "status_bitfield_type is not a standard layout type!");
#endif
template <class State> constexpr inline void _set_error_is_errno(State & /*unused*/) {}
#ifdef _MSC_VER
#pragma warning(push)
#pragma warning(disable : 4127) // conditional expression is constant
#pragma warning(disable : 4624) // destructor was implicitly defined as deleted
#endif
// Used if both T and E are trivial
template <class T, class E> struct value_storage_trivial
{
using value_type = T;
using error_type = E;
// Disable in place construction if they are the same type
struct disable_in_place_value_type
{
};
struct disable_in_place_error_type
{
};
using _value_type = std::conditional_t<std::is_same<value_type, error_type>::value, disable_in_place_value_type, value_type>;
using _error_type = std::conditional_t<std::is_same<value_type, error_type>::value, disable_in_place_error_type, error_type>;
using _value_type_ = devoid<value_type>;
using _error_type_ = devoid<error_type>;
union
{
empty_type _empty;
_value_type_ _value;
_error_type_ _error;
};
status_bitfield_type _status;
constexpr value_storage_trivial() noexcept
: _empty{}
{
}
value_storage_trivial(const value_storage_trivial &) = default; // NOLINT
value_storage_trivial(value_storage_trivial &&) = default; // NOLINT
value_storage_trivial &operator=(const value_storage_trivial &) = default; // NOLINT
value_storage_trivial &operator=(value_storage_trivial &&) = default; // NOLINT
~value_storage_trivial() = default;
constexpr explicit value_storage_trivial(status_bitfield_type status)
: _empty()
, _status(status)
{
}
template <class... Args>
constexpr explicit value_storage_trivial(in_place_type_t<_value_type> /*unused*/,
Args &&...args) noexcept(detail::is_nothrow_constructible<_value_type_, Args...>)
: _value(static_cast<Args &&>(args)...)
, _status(status::have_value)
{
}
template <class U, class... Args>
constexpr value_storage_trivial(in_place_type_t<_value_type> /*unused*/, std::initializer_list<U> il,
Args &&...args) noexcept(detail::is_nothrow_constructible<_value_type_, std::initializer_list<U>, Args...>)
: _value(il, static_cast<Args &&>(args)...)
, _status(status::have_value)
{
}
template <class... Args>
constexpr explicit value_storage_trivial(in_place_type_t<_error_type> /*unused*/,
Args &&...args) noexcept(detail::is_nothrow_constructible<_error_type_, Args...>)
: _error(static_cast<Args &&>(args)...)
, _status(status::have_error)
{
_set_error_is_errno(*this);
}
template <class U, class... Args>
constexpr value_storage_trivial(in_place_type_t<_error_type> /*unused*/, std::initializer_list<U> il,
Args &&...args) noexcept(detail::is_nothrow_constructible<_error_type_, std::initializer_list<U>, Args...>)
: _error(il, static_cast<Args &&>(args)...)
, _status(status::have_error)
{
_set_error_is_errno(*this);
}
struct nonvoid_converting_constructor_tag
{
};
template <class U, class V>
static constexpr bool enable_nonvoid_converting_constructor =
!(std::is_same<std::decay_t<U>, value_type>::value && std::is_same<std::decay_t<V>, error_type>::value) //
&& detail::is_constructible<value_type, U> && detail::is_constructible<error_type, V>;
OUTCOME_TEMPLATE(class U, class V)
OUTCOME_TREQUIRES(OUTCOME_TPRED(enable_nonvoid_converting_constructor<U, V>))
constexpr explicit value_storage_trivial(const value_storage_trivial<U, V> &o,
nonvoid_converting_constructor_tag /*unused*/ = {}) noexcept(detail::is_nothrow_constructible<_value_type_, U> &&
detail::is_nothrow_constructible<_error_type_, V>)
: value_storage_trivial(o._status.have_value() ?
value_storage_trivial(in_place_type<value_type>, o._value) :
(o._status.have_error() ? value_storage_trivial(in_place_type<error_type>, o._error) : value_storage_trivial())) // NOLINT
{
_status = o._status;
}
OUTCOME_TEMPLATE(class U, class V)
OUTCOME_TREQUIRES(OUTCOME_TPRED(enable_nonvoid_converting_constructor<U, V>))
constexpr explicit value_storage_trivial(value_storage_trivial<U, V> &&o,
nonvoid_converting_constructor_tag /*unused*/ = {}) noexcept(detail::is_nothrow_constructible<_value_type_, U> &&
detail::is_nothrow_constructible<_error_type_, V>)
: value_storage_trivial(
o._status.have_value() ?
value_storage_trivial(in_place_type<value_type>, static_cast<U &&>(o._value)) :
(o._status.have_error() ? value_storage_trivial(in_place_type<error_type>, static_cast<V &&>(o._error)) : value_storage_trivial())) // NOLINT
{
_status = o._status;
}
struct void_value_converting_constructor_tag
{
};
template <class V>
static constexpr bool enable_void_value_converting_constructor =
std::is_default_constructible<value_type>::value && detail::is_constructible<error_type, V>;
OUTCOME_TEMPLATE(class V)
OUTCOME_TREQUIRES(OUTCOME_TPRED(enable_void_value_converting_constructor<V>))
constexpr explicit value_storage_trivial(const value_storage_trivial<void, V> &o, void_value_converting_constructor_tag /*unused*/ = {}) noexcept(
std::is_nothrow_default_constructible<_value_type_>::value && detail::is_nothrow_constructible<_error_type_, V>)
: value_storage_trivial(o._status.have_value() ?
value_storage_trivial(in_place_type<value_type>) :
(o._status.have_error() ? value_storage_trivial(in_place_type<error_type>, o._error) : value_storage_trivial())) // NOLINT
{
_status = o._status;
}
OUTCOME_TEMPLATE(class V)
OUTCOME_TREQUIRES(OUTCOME_TPRED(enable_void_value_converting_constructor<V>))
constexpr explicit value_storage_trivial(value_storage_trivial<void, V> &&o, void_value_converting_constructor_tag /*unused*/ = {}) noexcept(
std::is_nothrow_default_constructible<_value_type_>::value && detail::is_nothrow_constructible<_error_type_, V>)
: value_storage_trivial(
o._status.have_value() ?
value_storage_trivial(in_place_type<value_type>) :
(o._status.have_error() ? value_storage_trivial(in_place_type<error_type>, static_cast<V &&>(o._error)) : value_storage_trivial())) // NOLINT
{
_status = o._status;
}
struct void_error_converting_constructor_tag
{
};
template <class U>
static constexpr bool enable_void_error_converting_constructor =
std::is_default_constructible<error_type>::value && detail::is_constructible<value_type, U>;
OUTCOME_TEMPLATE(class U)
OUTCOME_TREQUIRES(OUTCOME_TPRED(enable_void_error_converting_constructor<U>))
constexpr explicit value_storage_trivial(const value_storage_trivial<U, void> &o, void_error_converting_constructor_tag /*unused*/ = {}) noexcept(
detail::is_nothrow_constructible<_value_type_, U> && std::is_nothrow_default_constructible<_error_type_>::value)
: value_storage_trivial(o._status.have_value() ?
value_storage_trivial(in_place_type<value_type>, o._value) :
(o._status.have_error() ? value_storage_trivial(in_place_type<error_type>) : value_storage_trivial())) // NOLINT
{
_status = o._status;
}
OUTCOME_TEMPLATE(class U)
OUTCOME_TREQUIRES(OUTCOME_TPRED(enable_void_error_converting_constructor<U>))
constexpr explicit value_storage_trivial(value_storage_trivial<U, void> &&o, void_error_converting_constructor_tag /*unused*/ = {}) noexcept(
detail::is_nothrow_constructible<_value_type_, U> && std::is_nothrow_default_constructible<_error_type_>::value)
: value_storage_trivial(o._status.have_value() ?
value_storage_trivial(in_place_type<value_type>, static_cast<U &&>(o._value)) :
(o._status.have_error() ? value_storage_trivial(in_place_type<error_type>) : value_storage_trivial())) // NOLINT
{
_status = o._status;
}
constexpr void swap(value_storage_trivial &o) noexcept
{
// storage is trivial, so just use assignment
auto temp = static_cast<value_storage_trivial &&>(*this);
*this = static_cast<value_storage_trivial &&>(o);
o = static_cast<value_storage_trivial &&>(temp);
}
};
/* Used if T or E is non-trivial. The additional constexpr is injected in C++ 20 to enable Outcome to
work in constexpr evaluation contexts in C++ 20 where non-trivial constexpr destructors are now allowed.
*/
template <class T, class E> struct value_storage_nontrivial
{
using value_type = T;
using error_type = E;
struct disable_in_place_value_type
{
};
struct disable_in_place_error_type
{
};
using _value_type = std::conditional_t<std::is_same<value_type, error_type>::value, disable_in_place_value_type, value_type>;
using _error_type = std::conditional_t<std::is_same<value_type, error_type>::value, disable_in_place_error_type, error_type>;
using _value_type_ = devoid<value_type>;
using _error_type_ = devoid<error_type>;
union
{
empty_type _empty1;
_value_type_ _value;
};
status_bitfield_type _status;
union
{
empty_type _empty2;
_error_type_ _error;
};
#if __cplusplus >= 202000L || _HAS_CXX20
constexpr
#endif
value_storage_nontrivial() noexcept
: _empty1{}
, _empty2{}
{
}
value_storage_nontrivial &operator=(const value_storage_nontrivial &) = default; // if reaches here, copy assignment is trivial
value_storage_nontrivial &operator=(value_storage_nontrivial &&) = default; // NOLINT if reaches here, move assignment is trivial
#if __cplusplus >= 202000L || _HAS_CXX20
constexpr
#endif
value_storage_nontrivial(value_storage_nontrivial &&o) noexcept(std::is_nothrow_move_constructible<_value_type_>::value &&
std::is_nothrow_move_constructible<_error_type_>::value) // NOLINT
{
if(o._status.have_value())
{
new(OUTCOME_ADDRESS_OF(_value)) _value_type_(static_cast<_value_type_ &&>(o._value)); // NOLINT
}
else if(o._status.have_error())
{
new(OUTCOME_ADDRESS_OF(_error)) _error_type_(static_cast<_error_type_ &&>(o._error)); // NOLINT
}
_status = o._status;
o._status.set_have_moved_from(true);
}
#if __cplusplus >= 202000L || _HAS_CXX20
constexpr
#endif
value_storage_nontrivial(const value_storage_nontrivial &o) noexcept(std::is_nothrow_copy_constructible<_value_type_>::value &&
std::is_nothrow_copy_constructible<_error_type_>::value)
{
if(o._status.have_value())
{
new(OUTCOME_ADDRESS_OF(_value)) _value_type_(o._value); // NOLINT
}
else if(o._status.have_error())
{
new(OUTCOME_ADDRESS_OF(_error)) _error_type_(o._error); // NOLINT
}
_status = o._status;
}
#if __cplusplus >= 202000L || _HAS_CXX20
constexpr
#endif
explicit value_storage_nontrivial(status_bitfield_type status)
: _empty1()
, _status(status)
, _empty2()
{
}
template <class... Args>
constexpr explicit value_storage_nontrivial(in_place_type_t<_value_type> /*unused*/,
Args &&...args) noexcept(detail::is_nothrow_constructible<_value_type_, Args...>)
: _value(static_cast<Args &&>(args)...) // NOLINT
, _status(status::have_value)
{
}
template <class U, class... Args>
constexpr value_storage_nontrivial(in_place_type_t<_value_type> /*unused*/, std::initializer_list<U> il,
Args &&...args) noexcept(detail::is_nothrow_constructible<_value_type_, std::initializer_list<U>, Args...>)
: _value(il, static_cast<Args &&>(args)...)
, _status(status::have_value)
{
}
template <class... Args>
constexpr explicit value_storage_nontrivial(in_place_type_t<_error_type> /*unused*/,
Args &&...args) noexcept(detail::is_nothrow_constructible<_error_type_, Args...>)
: _status(status::have_error)
, _error(static_cast<Args &&>(args)...) // NOLINT
{
_set_error_is_errno(*this);
}
template <class U, class... Args>
constexpr value_storage_nontrivial(in_place_type_t<_error_type> /*unused*/, std::initializer_list<U> il,
Args &&...args) noexcept(detail::is_nothrow_constructible<_error_type_, std::initializer_list<U>, Args...>)
: _status(status::have_error)
, _error(il, static_cast<Args &&>(args)...)
{
_set_error_is_errno(*this);
}
struct nonvoid_converting_constructor_tag
{
};
template <class U, class V>
static constexpr bool enable_nonvoid_converting_constructor =
!(std::is_same<std::decay_t<U>, value_type>::value && std::is_same<std::decay_t<V>, error_type>::value) //
&& detail::is_constructible<value_type, U> && detail::is_constructible<error_type, V>;
OUTCOME_TEMPLATE(class U, class V)
OUTCOME_TREQUIRES(OUTCOME_TPRED(enable_nonvoid_converting_constructor<U, V>))
constexpr explicit value_storage_nontrivial(const value_storage_trivial<U, V> &o, nonvoid_converting_constructor_tag /*unused*/ = {}) noexcept(
detail::is_nothrow_constructible<_value_type_, U> && detail::is_nothrow_constructible<_error_type_, V>)
: value_storage_nontrivial(o._status.have_value() ?
value_storage_nontrivial(in_place_type<value_type>, o._value) :
(o._status.have_error() ? value_storage_nontrivial(in_place_type<error_type>, o._error) : value_storage_nontrivial()))
{
_status = o._status;
}
OUTCOME_TEMPLATE(class U, class V)
OUTCOME_TREQUIRES(OUTCOME_TPRED(enable_nonvoid_converting_constructor<U, V>))
constexpr explicit value_storage_nontrivial(value_storage_trivial<U, V> &&o, nonvoid_converting_constructor_tag /*unused*/ = {}) noexcept(
detail::is_nothrow_constructible<_value_type_, U> && detail::is_nothrow_constructible<_error_type_, V>)
: value_storage_nontrivial(
o._status.have_value() ?
value_storage_nontrivial(in_place_type<value_type>, static_cast<U &&>(o._value)) :
(o._status.have_error() ? value_storage_nontrivial(in_place_type<error_type>, static_cast<V &&>(o._error)) : value_storage_nontrivial()))
{
_status = o._status;
}
OUTCOME_TEMPLATE(class U, class V)
OUTCOME_TREQUIRES(OUTCOME_TPRED(enable_nonvoid_converting_constructor<U, V>))
constexpr explicit value_storage_nontrivial(const value_storage_nontrivial<U, V> &o, nonvoid_converting_constructor_tag /*unused*/ = {}) noexcept(
detail::is_nothrow_constructible<_value_type_, U> && detail::is_nothrow_constructible<_error_type_, V>)
: value_storage_nontrivial(o._status.have_value() ?
value_storage_nontrivial(in_place_type<value_type>, o._value) :
(o._status.have_error() ? value_storage_nontrivial(in_place_type<error_type>, o._error) : value_storage_nontrivial()))
{
_status = o._status;
}
OUTCOME_TEMPLATE(class U, class V)
OUTCOME_TREQUIRES(OUTCOME_TPRED(enable_nonvoid_converting_constructor<U, V>))
constexpr explicit value_storage_nontrivial(value_storage_nontrivial<U, V> &&o, nonvoid_converting_constructor_tag /*unused*/ = {}) noexcept(
detail::is_nothrow_constructible<_value_type_, U> && detail::is_nothrow_constructible<_error_type_, V>)
: value_storage_nontrivial(
o._status.have_value() ?
value_storage_nontrivial(in_place_type<value_type>, static_cast<U &&>(o._value)) :
(o._status.have_error() ? value_storage_nontrivial(in_place_type<error_type>, static_cast<V &&>(o._error)) : value_storage_nontrivial()))
{
_status = o._status;
}
struct void_value_converting_constructor_tag
{
};
template <class V>
static constexpr bool enable_void_value_converting_constructor =
std::is_default_constructible<value_type>::value && detail::is_constructible<error_type, V>;
OUTCOME_TEMPLATE(class V)
OUTCOME_TREQUIRES(OUTCOME_TPRED(enable_void_value_converting_constructor<V>))
constexpr explicit value_storage_nontrivial(const value_storage_trivial<void, V> &o, void_value_converting_constructor_tag /*unused*/ = {}) noexcept(
std::is_nothrow_default_constructible<_value_type_>::value && detail::is_nothrow_constructible<_error_type_, V>)
{
if(o._status.have_value())
{
new(OUTCOME_ADDRESS_OF(_value)) _value_type_(); // NOLINT
}
else if(o._status.have_error())
{
new(OUTCOME_ADDRESS_OF(_error)) _error_type_(o._error); // NOLINT
}
_status = o._status;
}
OUTCOME_TEMPLATE(class V)
OUTCOME_TREQUIRES(OUTCOME_TPRED(enable_void_value_converting_constructor<V>))
constexpr explicit value_storage_nontrivial(value_storage_trivial<void, V> &&o, void_value_converting_constructor_tag /*unused*/ = {}) noexcept(
std::is_nothrow_default_constructible<_value_type_>::value && detail::is_nothrow_constructible<_error_type_, V>)
{
if(o._status.have_value())
{
new(OUTCOME_ADDRESS_OF(_value)) _value_type_(); // NOLINT
}
else if(o._status.have_error())
{
new(OUTCOME_ADDRESS_OF(_error)) _error_type_(static_cast<_error_type_ &&>(o._error)); // NOLINT
}
_status = o._status;
o._status.set_have_moved_from(true);
}
struct void_error_converting_constructor_tag
{
};
template <class U>
static constexpr bool enable_void_error_converting_constructor =
std::is_default_constructible<error_type>::value && detail::is_constructible<value_type, U>;
OUTCOME_TEMPLATE(class U)
OUTCOME_TREQUIRES(OUTCOME_TPRED(enable_void_error_converting_constructor<U>))
constexpr explicit value_storage_nontrivial(const value_storage_trivial<U, void> &o, void_error_converting_constructor_tag /*unused*/ = {}) noexcept(
detail::is_nothrow_constructible<_value_type_, U> && std::is_nothrow_default_constructible<_error_type_>::value)
{
if(o._status.have_value())
{
new(OUTCOME_ADDRESS_OF(_value)) _value_type_(o._value); // NOLINT
}
else if(o._status.have_error())
{
new(OUTCOME_ADDRESS_OF(_error)) _error_type_(); // NOLINT
}
_status = o._status;
}
OUTCOME_TEMPLATE(class U)
OUTCOME_TREQUIRES(OUTCOME_TPRED(enable_void_error_converting_constructor<U>))
constexpr explicit value_storage_nontrivial(value_storage_trivial<U, void> &&o, void_error_converting_constructor_tag /*unused*/ = {}) noexcept(
detail::is_nothrow_constructible<_value_type_, U> && std::is_nothrow_default_constructible<_error_type_>::value)
{
if(o._status.have_value())
{
new(OUTCOME_ADDRESS_OF(_value)) _value_type_(static_cast<_value_type_ &&>(o._value)); // NOLINT
}
else if(o._status.have_error())
{
new(OUTCOME_ADDRESS_OF(_error)) _error_type_(); // NOLINT
}
_status = o._status;
o._status.set_have_moved_from(true);
}
#if __cplusplus >= 202000L || _HAS_CXX20
constexpr
#endif
~value_storage_nontrivial() noexcept(std::is_nothrow_destructible<_value_type_>::value && std::is_nothrow_destructible<_error_type_>::value)
{
if(this->_status.have_value())
{
if(!trait::is_move_bitcopying<value_type>::value || !this->_status.have_moved_from())
{
this->_value.~_value_type_(); // NOLINT
}
this->_status.set_have_value(false);
}
else if(this->_status.have_error())
{
if(!trait::is_move_bitcopying<error_type>::value || !this->_status.have_moved_from())
{
this->_error.~_error_type_(); // NOLINT
}
this->_status.set_have_error(false);
}
}
#if __cplusplus >= 202000L || _HAS_CXX20
constexpr
#endif
void
swap(value_storage_nontrivial &o) noexcept(detail::is_nothrow_swappable<_value_type_>::value && detail::is_nothrow_swappable<_error_type_>::value)
{
using std::swap;
// empty/empty
if(!_status.have_value() && !o._status.have_value() && !_status.have_error() && !o._status.have_error())
{
swap(_status, o._status);
return;
}
// value/value
if(_status.have_value() && o._status.have_value())
{
struct some_type
{
status_bitfield_type &a, &b;
bool all_good{false};
~some_type()
{
if(!this->all_good)
{
// We lost one of the values
this->a.set_have_lost_consistency(true);
this->b.set_have_lost_consistency(true);
}
}
} some_type_value{_status, o._status};
strong_swap(some_type_value.all_good, _value, o._value);
swap(_status, o._status);
return;
}
// error/error
if(_status.have_error() && o._status.have_error())
{
struct some_type
{
status_bitfield_type &a, &b;
bool all_good{false};
~some_type()
{
if(!this->all_good)
{
// We lost one of the values
this->a.set_have_lost_consistency(true);
this->b.set_have_lost_consistency(true);
}
}
} some_type_value{_status, o._status};
strong_swap(some_type_value.all_good, _error, o._error);
swap(_status, o._status);
return;
}
// Could be value/empty, error/empty, etc
if(_status.have_value() && !o._status.have_error())
{
// Move construct me into other
new(OUTCOME_ADDRESS_OF(o._value)) _value_type_(static_cast<_value_type_ &&>(_value)); // NOLINT
if(!trait::is_move_bitcopying<value_type>::value)
{
this->_value.~value_type(); // NOLINT
}
swap(_status, o._status);
return;
}
if(o._status.have_value() && !_status.have_error())
{
// Move construct other into me
new(OUTCOME_ADDRESS_OF(_value)) _value_type_(static_cast<_value_type_ &&>(o._value)); // NOLINT
if(!trait::is_move_bitcopying<value_type>::value)
{
o._value.~value_type(); // NOLINT
}
swap(_status, o._status);
return;
}
if(_status.have_error() && !o._status.have_value())
{
// Move construct me into other
new(OUTCOME_ADDRESS_OF(o._error)) _error_type_(static_cast<_error_type_ &&>(_error)); // NOLINT
if(!trait::is_move_bitcopying<error_type>::value)
{
this->_error.~error_type(); // NOLINT
}
swap(_status, o._status);
return;
}
if(o._status.have_error() && !_status.have_value())
{
// Move construct other into me
new(OUTCOME_ADDRESS_OF(_error)) _error_type_(static_cast<_error_type_ &&>(o._error)); // NOLINT
if(!trait::is_move_bitcopying<error_type>::value)
{
o._error.~error_type(); // NOLINT
}
swap(_status, o._status);
return;
}
// It can now only be value/error, or error/value
struct some_type
{
status_bitfield_type &a, &b;
_value_type_ *value, *o_value;
_error_type_ *error, *o_error;
bool all_good{true};
~some_type()
{
if(!this->all_good)
{
// We lost one of the values
this->a.set_have_lost_consistency(true);
this->b.set_have_lost_consistency(true);
}
}
} some_type_value{_status, o._status, OUTCOME_ADDRESS_OF(_value), OUTCOME_ADDRESS_OF(o._value), OUTCOME_ADDRESS_OF(_error), OUTCOME_ADDRESS_OF(o._error)};
if(_status.have_value() && o._status.have_error())
{
strong_placement(some_type_value.all_good, some_type_value.o_value, some_type_value.value, [&some_type_value] { //
strong_placement(some_type_value.all_good, some_type_value.error, some_type_value.o_error, [&some_type_value] { //
swap(some_type_value.a, some_type_value.b); //
});
});
return;
}
if(_status.have_error() && o._status.have_value())
{
strong_placement(some_type_value.all_good, some_type_value.o_error, some_type_value.error, [&some_type_value] { //
strong_placement(some_type_value.all_good, some_type_value.value, some_type_value.o_value, [&some_type_value] { //
swap(some_type_value.a, some_type_value.b); //
});
});
return;
}
// Should never reach here
make_ub(_value);
}
};
template <class Base> struct value_storage_delete_copy_constructor : Base // NOLINT
{
using Base::Base;
using value_type = typename Base::value_type;
using error_type = typename Base::error_type;
value_storage_delete_copy_constructor() = default;
value_storage_delete_copy_constructor(const value_storage_delete_copy_constructor &) = delete;
value_storage_delete_copy_constructor(value_storage_delete_copy_constructor &&) = default; // NOLINT
value_storage_delete_copy_constructor &operator=(const value_storage_delete_copy_constructor &o) = default;
value_storage_delete_copy_constructor &operator=(value_storage_delete_copy_constructor &&o) = default; // NOLINT
~value_storage_delete_copy_constructor() = default;
};
template <class Base> struct value_storage_delete_copy_assignment : Base // NOLINT
{
using Base::Base;
using value_type = typename Base::value_type;
using error_type = typename Base::error_type;
value_storage_delete_copy_assignment() = default;
value_storage_delete_copy_assignment(const value_storage_delete_copy_assignment &) = default;
value_storage_delete_copy_assignment(value_storage_delete_copy_assignment &&) = default; // NOLINT
value_storage_delete_copy_assignment &operator=(const value_storage_delete_copy_assignment &o) = delete;
value_storage_delete_copy_assignment &operator=(value_storage_delete_copy_assignment &&o) = default; // NOLINT
~value_storage_delete_copy_assignment() = default;
};
template <class Base> struct value_storage_delete_move_assignment : Base // NOLINT
{
using Base::Base;
using value_type = typename Base::value_type;
using error_type = typename Base::error_type;
value_storage_delete_move_assignment() = default;
value_storage_delete_move_assignment(const value_storage_delete_move_assignment &) = default;
value_storage_delete_move_assignment(value_storage_delete_move_assignment &&) = default; // NOLINT
value_storage_delete_move_assignment &operator=(const value_storage_delete_move_assignment &o) = default;
value_storage_delete_move_assignment &operator=(value_storage_delete_move_assignment &&o) = delete;
~value_storage_delete_move_assignment() = default;
};
template <class Base> struct value_storage_delete_move_constructor : Base // NOLINT
{
using Base::Base;
using value_type = typename Base::value_type;
using error_type = typename Base::error_type;
value_storage_delete_move_constructor() = default;
value_storage_delete_move_constructor(const value_storage_delete_move_constructor &) = default;
value_storage_delete_move_constructor(value_storage_delete_move_constructor &&) = delete;
value_storage_delete_move_constructor &operator=(const value_storage_delete_move_constructor &o) = default;
value_storage_delete_move_constructor &operator=(value_storage_delete_move_constructor &&o) = default;
~value_storage_delete_move_constructor() = default;
};
template <class Base> struct value_storage_nontrivial_move_assignment : Base // NOLINT
{
using Base::Base;
using value_type = typename Base::value_type;
using error_type = typename Base::error_type;
value_storage_nontrivial_move_assignment() = default;
value_storage_nontrivial_move_assignment(const value_storage_nontrivial_move_assignment &) = default;
value_storage_nontrivial_move_assignment(value_storage_nontrivial_move_assignment &&) = default; // NOLINT
value_storage_nontrivial_move_assignment &operator=(const value_storage_nontrivial_move_assignment &o) = default;
~value_storage_nontrivial_move_assignment() = default;
#if __cplusplus >= 202000L || _HAS_CXX20
constexpr
#endif
value_storage_nontrivial_move_assignment &
operator=(value_storage_nontrivial_move_assignment &&o) noexcept(std::is_nothrow_move_assignable<value_type>::value &&
std::is_nothrow_move_assignable<error_type>::value &&
noexcept(move_assign_to_empty<value_type>(static_cast<value_type *>(nullptr),
static_cast<value_type *>(nullptr))) &&
noexcept(move_assign_to_empty<error_type>(static_cast<error_type *>(nullptr),
static_cast<error_type *>(nullptr)))) // NOLINT
{
using _value_type_ = typename Base::_value_type_;
using _error_type_ = typename Base::_error_type_;
if(!this->_status.have_value() && !this->_status.have_error() && !o._status.have_value() && !o._status.have_error())
{
this->_status = o._status;
o._status.set_have_moved_from(true);
return *this;
}
if(this->_status.have_value() && o._status.have_value())
{
this->_value = static_cast<_value_type_ &&>(o._value); // NOLINT
this->_status = o._status;
o._status.set_have_moved_from(true);
return *this;
}
if(this->_status.have_error() && o._status.have_error())
{
this->_error = static_cast<_error_type_ &&>(o._error); // NOLINT
this->_status = o._status;
o._status.set_have_moved_from(true);
return *this;
}
if(this->_status.have_value() && !o._status.have_value() && !o._status.have_error())
{
if(!trait::is_move_bitcopying<value_type>::value || this->_status.have_moved_from())
{
this->_value.~_value_type_(); // NOLINT
}
this->_status = o._status;
o._status.set_have_moved_from(true);
return *this;
}
if(!this->_status.have_value() && !this->_status.have_error() && o._status.have_value())
{
move_assign_to_empty<_value_type_>(OUTCOME_ADDRESS_OF(this->_value), OUTCOME_ADDRESS_OF(o._value));
this->_status = o._status;
o._status.set_have_moved_from(true);
return *this;
}
if(this->_status.have_error() && !o._status.have_value() && !o._status.have_error())
{
if(!trait::is_move_bitcopying<error_type>::value || this->_status.have_moved_from())
{
this->_error.~_error_type_(); // NOLINT
}
this->_status = o._status;
o._status.set_have_moved_from(true);
return *this;
}
if(!this->_status.have_value() && !this->_status.have_error() && o._status.have_error())
{
move_assign_to_empty<_error_type_>(OUTCOME_ADDRESS_OF(this->_error), OUTCOME_ADDRESS_OF(o._error));
this->_status = o._status;
o._status.set_have_moved_from(true);
return *this;
}
if(this->_status.have_value() && o._status.have_error())
{
if(!trait::is_move_bitcopying<value_type>::value || this->_status.have_moved_from())
{
this->_value.~_value_type_(); // NOLINT
}
move_assign_to_empty<_error_type_>(OUTCOME_ADDRESS_OF(this->_error), OUTCOME_ADDRESS_OF(o._error));
this->_status = o._status;
o._status.set_have_moved_from(true);
return *this;
}
if(this->_status.have_error() && o._status.have_value())
{
if(!trait::is_move_bitcopying<error_type>::value || this->_status.have_moved_from())
{
this->_error.~_error_type_(); // NOLINT
}
move_assign_to_empty<_value_type_>(OUTCOME_ADDRESS_OF(this->_value), OUTCOME_ADDRESS_OF(o._value));
this->_status = o._status;
o._status.set_have_moved_from(true);
return *this;
}
// Should never reach here
make_ub(this->_value);
}
};
template <class Base> struct value_storage_nontrivial_copy_assignment : Base // NOLINT
{
using Base::Base;
using value_type = typename Base::value_type;
using error_type = typename Base::error_type;
value_storage_nontrivial_copy_assignment() = default;
value_storage_nontrivial_copy_assignment(const value_storage_nontrivial_copy_assignment &) = default;
value_storage_nontrivial_copy_assignment(value_storage_nontrivial_copy_assignment &&) = default; // NOLINT
value_storage_nontrivial_copy_assignment &operator=(value_storage_nontrivial_copy_assignment &&o) = default; // NOLINT
~value_storage_nontrivial_copy_assignment() = default;
#if __cplusplus >= 202000L || _HAS_CXX20
constexpr
#endif
value_storage_nontrivial_copy_assignment &
operator=(const value_storage_nontrivial_copy_assignment &o) noexcept(
std::is_nothrow_copy_assignable<value_type>::value && std::is_nothrow_copy_assignable<error_type>::value &&
noexcept(copy_assign_to_empty<value_type>(static_cast<value_type *>(nullptr), static_cast<value_type *>(nullptr))) &&
noexcept(copy_assign_to_empty<error_type>(static_cast<error_type *>(nullptr), static_cast<error_type *>(nullptr))))
{
using _value_type_ = typename Base::_value_type_;
using _error_type_ = typename Base::_error_type_;
if(!this->_status.have_value() && !this->_status.have_error() && !o._status.have_value() && !o._status.have_error())
{
this->_status = o._status;
return *this;
}
if(this->_status.have_value() && o._status.have_value())
{
this->_value = o._value; // NOLINT
this->_status = o._status;
return *this;
}
if(this->_status.have_error() && o._status.have_error())
{
this->_error = o._error; // NOLINT
this->_status = o._status;
return *this;
}
if(this->_status.have_value() && !o._status.have_value() && !o._status.have_error())
{
if(!trait::is_move_bitcopying<value_type>::value || this->_status.have_moved_from())
{
this->_value.~_value_type_(); // NOLINT
}
this->_status = o._status;
return *this;
}
if(!this->_status.have_value() && !this->_status.have_error() && o._status.have_value())
{
copy_assign_to_empty<_value_type_>(OUTCOME_ADDRESS_OF(this->_value), OUTCOME_ADDRESS_OF(o._value));
this->_status = o._status;
return *this;
}
if(this->_status.have_error() && !o._status.have_value() && !o._status.have_error())
{
if(!trait::is_move_bitcopying<error_type>::value || this->_status.have_moved_from())
{
this->_error.~_error_type_(); // NOLINT
}
this->_status = o._status;
return *this;
}
if(!this->_status.have_value() && !this->_status.have_error() && o._status.have_error())
{
copy_assign_to_empty<_error_type_>(OUTCOME_ADDRESS_OF(this->_error), OUTCOME_ADDRESS_OF(o._error));
this->_status = o._status;
return *this;
}
if(this->_status.have_value() && o._status.have_error())
{
if(!trait::is_move_bitcopying<value_type>::value || this->_status.have_moved_from())
{
this->_value.~_value_type_(); // NOLINT
}
copy_assign_to_empty<_error_type_>(OUTCOME_ADDRESS_OF(this->_error), OUTCOME_ADDRESS_OF(o._error));
this->_status = o._status;
return *this;
}
if(this->_status.have_error() && o._status.have_value())
{
if(!trait::is_move_bitcopying<error_type>::value || this->_status.have_moved_from())
{
this->_error.~_error_type_(); // NOLINT
}
copy_assign_to_empty<_value_type_>(OUTCOME_ADDRESS_OF(this->_value), OUTCOME_ADDRESS_OF(o._value));
this->_status = o._status;
return *this;
}
// Should never reach here
make_ub(this->_value);
}
};
#ifdef _MSC_VER
#pragma warning(pop)
#endif
// is_trivially_copyable is true even if type is not copyable, so handle that here
template <class T> struct is_storage_trivial
{
static constexpr bool value = std::is_void<T>::value || (std::is_trivially_copy_constructible<T>::value && std::is_trivially_copyable<T>::value);
};
// work around libstdc++ 7 bug
template <> struct is_storage_trivial<void>
{
static constexpr bool value = true;
};
template <> struct is_storage_trivial<const void>
{
static constexpr bool value = true;
};
// Ability to do copy assigns needs more than just copy assignment
template <class T> struct is_copy_assignable
{
static constexpr bool value = std::is_copy_assignable<T>::value && (std::is_copy_constructible<T>::value || std::is_default_constructible<T>::value);
};
// Ability to do move assigns needs more than just move assignment
template <class T> struct is_move_assignable
{
static constexpr bool value = std::is_move_assignable<T>::value && (std::is_move_constructible<T>::value || std::is_default_constructible<T>::value);
};
template <class T, class E>
using value_storage_select_trivality =
std::conditional_t<is_storage_trivial<T>::value && is_storage_trivial<E>::value, value_storage_trivial<T, E>, value_storage_nontrivial<T, E>>;
template <class T, class E>
using value_storage_select_move_constructor =
std::conditional_t<std::is_move_constructible<devoid<T>>::value && std::is_move_constructible<devoid<E>>::value, value_storage_select_trivality<T, E>,
value_storage_delete_move_constructor<value_storage_select_trivality<T, E>>>;
template <class T, class E>
using value_storage_select_copy_constructor =
std::conditional_t<std::is_copy_constructible<devoid<T>>::value && std::is_copy_constructible<devoid<E>>::value, value_storage_select_move_constructor<T, E>,
value_storage_delete_copy_constructor<value_storage_select_move_constructor<T, E>>>;
template <class T, class E>
using value_storage_select_move_assignment =
std::conditional_t<std::is_trivially_move_assignable<devoid<T>>::value && std::is_trivially_move_assignable<devoid<E>>::value,
value_storage_select_copy_constructor<T, E>,
std::conditional_t<is_move_assignable<devoid<T>>::value && is_move_assignable<devoid<E>>::value,
value_storage_nontrivial_move_assignment<value_storage_select_copy_constructor<T, E>>,
value_storage_delete_move_assignment<value_storage_select_copy_constructor<T, E>>>>;
template <class T, class E>
using value_storage_select_copy_assignment =
std::conditional_t<std::is_trivially_copy_assignable<devoid<T>>::value && std::is_trivially_copy_assignable<devoid<E>>::value,
value_storage_select_move_assignment<T, E>,
std::conditional_t<is_copy_assignable<devoid<T>>::value && is_copy_assignable<devoid<E>>::value,
value_storage_nontrivial_copy_assignment<value_storage_select_move_assignment<T, E>>,
value_storage_delete_copy_assignment<value_storage_select_move_assignment<T, E>>>>;
template <class T, class E> using value_storage_select_impl = value_storage_select_copy_assignment<T, E>;
#ifndef NDEBUG
// Check is trivial in all ways except default constructibility
// static_assert(std::is_trivial<value_storage_select_impl<int, long>>::value, "value_storage_select_impl<int, long> is not trivial!");
// static_assert(std::is_trivially_default_constructible<value_storage_select_impl<int, long>>::value, "value_storage_select_impl<int, long> is not
// trivially default constructible!");
static_assert(std::is_trivially_copyable<value_storage_select_impl<int, long>>::value, "value_storage_select_impl<int, long> is not trivially copyable!");
static_assert(std::is_trivially_assignable<value_storage_select_impl<int, long>, value_storage_select_impl<int, long>>::value,
"value_storage_select_impl<int, long> is not trivially assignable!");
static_assert(std::is_trivially_destructible<value_storage_select_impl<int, long>>::value,
"value_storage_select_impl<int, long> is not trivially destructible!");
static_assert(std::is_trivially_copy_constructible<value_storage_select_impl<int, long>>::value,
"value_storage_select_impl<int, long> is not trivially copy constructible!");
static_assert(std::is_trivially_move_constructible<value_storage_select_impl<int, long>>::value,
"value_storage_select_impl<int, long> is not trivially move constructible!");
static_assert(std::is_trivially_copy_assignable<value_storage_select_impl<int, long>>::value,
"value_storage_select_impl<int, long> is not trivially copy assignable!");
static_assert(std::is_trivially_move_assignable<value_storage_select_impl<int, long>>::value,
"value_storage_select_impl<int, long> is not trivially move assignable!");
// Also check is standard layout
static_assert(std::is_standard_layout<value_storage_select_impl<int, long>>::value, "value_storage_select_impl<int, long> is not a standard layout type!");
#endif
} // namespace detail
OUTCOME_V2_NAMESPACE_END
#endif
OUTCOME_V2_NAMESPACE_EXPORT_BEGIN
namespace detail
{
template <class R, class EC, class NoValuePolicy> class basic_result_storage;
} // namespace detail
namespace hooks
{
template <class R, class S, class NoValuePolicy> constexpr inline uint16_t spare_storage(const detail::basic_result_storage<R, S, NoValuePolicy> *r) noexcept;
template <class R, class S, class NoValuePolicy>
constexpr inline void set_spare_storage(detail::basic_result_storage<R, S, NoValuePolicy> *r, uint16_t v) noexcept;
} // namespace hooks
namespace policy
{
struct base;
} // namespace policy
namespace detail
{
template <class R, class EC, class NoValuePolicy> //
class basic_result_storage
{
static_assert(trait::type_can_be_used_in_basic_result<R>, "The type R cannot be used in a basic_result");
static_assert(trait::type_can_be_used_in_basic_result<EC>, "The type S cannot be used in a basic_result");
friend struct policy::base;
template <class T, class U, class V> //
friend class basic_result_storage;
template <class T, class U, class V> friend class basic_result_final;
template <class T, class U, class V>
friend constexpr inline uint16_t hooks::spare_storage(const detail::basic_result_storage<T, U, V> *r) noexcept; // NOLINT
template <class T, class U, class V>
friend constexpr inline void hooks::set_spare_storage(detail::basic_result_storage<T, U, V> *r, uint16_t v) noexcept; // NOLINT
struct disable_in_place_value_type
{
};
struct disable_in_place_error_type
{
};
protected:
using _value_type = std::conditional_t<std::is_same<R, EC>::value, disable_in_place_value_type, R>;
using _error_type = std::conditional_t<std::is_same<R, EC>::value, disable_in_place_error_type, EC>;
using _state_type = value_storage_select_impl<_value_type, _error_type>;
_state_type _state;
public:
// Used by iostream support to access state
_state_type &_iostreams_state() { return _state; }
const _state_type &_iostreams_state() const { return _state; }
protected:
basic_result_storage() = default;
basic_result_storage(const basic_result_storage &) = default; // NOLINT
basic_result_storage(basic_result_storage &&) = default; // NOLINT
basic_result_storage &operator=(const basic_result_storage &) = default; // NOLINT
basic_result_storage &operator=(basic_result_storage &&) = default; // NOLINT
~basic_result_storage() = default;
template <class... Args>
constexpr explicit basic_result_storage(in_place_type_t<_value_type> _,
Args &&... args) noexcept(detail::is_nothrow_constructible<_value_type, Args...>)
: _state{_, static_cast<Args &&>(args)...}
{
}
template <class U, class... Args>
constexpr basic_result_storage(in_place_type_t<_value_type> _, std::initializer_list<U> il,
Args &&... args) noexcept(detail::is_nothrow_constructible<_value_type, std::initializer_list<U>, Args...>)
: _state{_, il, static_cast<Args &&>(args)...}
{
}
template <class... Args>
constexpr explicit basic_result_storage(in_place_type_t<_error_type> _,
Args &&... args) noexcept(detail::is_nothrow_constructible<_error_type, Args...>)
: _state{_, static_cast<Args &&>(args)...}
{
}
template <class U, class... Args>
constexpr basic_result_storage(in_place_type_t<_error_type> _, std::initializer_list<U> il,
Args &&... args) noexcept(detail::is_nothrow_constructible<_error_type, std::initializer_list<U>, Args...>)
: _state{_, il, static_cast<Args &&>(args)...}
{
}
struct compatible_conversion_tag
{
};
template <class T, class U, class V>
constexpr basic_result_storage(compatible_conversion_tag /*unused*/, const basic_result_storage<T, U, V> &o) noexcept(
detail::is_nothrow_constructible<_value_type, T> &&detail::is_nothrow_constructible<_error_type, U>)
: _state(o._state)
{
}
template <class T, class U, class V>
constexpr basic_result_storage(compatible_conversion_tag /*unused*/, basic_result_storage<T, U, V> &&o) noexcept(
detail::is_nothrow_constructible<_value_type, T> &&detail::is_nothrow_constructible<_error_type, U>)
: _state(static_cast<decltype(o._state) &&>(o._state))
{
}
struct make_error_code_compatible_conversion_tag
{
};
template <class T, class U, class V>
constexpr basic_result_storage(make_error_code_compatible_conversion_tag /*unused*/, const basic_result_storage<T, U, V> &o) noexcept(
detail::is_nothrow_constructible<_value_type, T> &&noexcept(make_error_code(std::declval<U>())))
: _state(o._state._status.have_value() ? _state_type(in_place_type<_value_type>, o._state._value) :
_state_type(in_place_type<_error_type>, make_error_code(o._state._error)))
{
}
template <class T, class U, class V>
constexpr basic_result_storage(make_error_code_compatible_conversion_tag /*unused*/, basic_result_storage<T, U, V> &&o) noexcept(
detail::is_nothrow_constructible<_value_type, T> &&noexcept(make_error_code(std::declval<U>())))
: _state(o._state._status.have_value() ? _state_type(in_place_type<_value_type>, static_cast<T &&>(o._state._value)) :
_state_type(in_place_type<_error_type>, make_error_code(static_cast<U &&>(o._state._error))))
{
}
struct make_exception_ptr_compatible_conversion_tag
{
};
template <class T, class U, class V>
constexpr basic_result_storage(make_exception_ptr_compatible_conversion_tag /*unused*/, const basic_result_storage<T, U, V> &o) noexcept(
detail::is_nothrow_constructible<_value_type, T> &&noexcept(make_exception_ptr(std::declval<U>())))
: _state(o._state._status.have_value() ? _state_type(in_place_type<_value_type>, o._state._value) :
_state_type(in_place_type<_error_type>, make_exception_ptr(o._state._error)))
{
}
template <class T, class U, class V>
constexpr basic_result_storage(make_exception_ptr_compatible_conversion_tag /*unused*/, basic_result_storage<T, U, V> &&o) noexcept(
detail::is_nothrow_constructible<_value_type, T> &&noexcept(make_exception_ptr(std::declval<U>())))
: _state(o._state._status.have_value() ? _state_type(in_place_type<_value_type>, static_cast<T &&>(o._state._value)) :
_state_type(in_place_type<_error_type>, make_exception_ptr(static_cast<U &&>(o._state._error))))
{
}
};
} // namespace detail
OUTCOME_V2_NAMESPACE_END
#endif
OUTCOME_V2_NAMESPACE_EXPORT_BEGIN
namespace concepts
{
#if defined(__cpp_concepts)
#if (defined(_MSC_VER) || defined(__clang__) || (defined(__GNUC__) && __cpp_concepts >= 201707) || OUTCOME_FORCE_STD_CXX_CONCEPTS) && !OUTCOME_FORCE_LEGACY_GCC_CXX_CONCEPTS
#define OUTCOME_GCC6_CONCEPT_BOOL
#else
#ifndef OUTCOME_SUPPRESS_LEGACY_CONCEPTS_WARNING
#warning "WARNING: Legacy GCC concepts are known to fail to compile in a number of important situations!"
#endif
#define OUTCOME_GCC6_CONCEPT_BOOL bool
#endif
namespace detail
{
template <class T, class U>
concept OUTCOME_GCC6_CONCEPT_BOOL SameHelper = std::is_same<T, U>::value;
template <class T, class U>
concept OUTCOME_GCC6_CONCEPT_BOOL same_as = detail::SameHelper<T, U> && detail::SameHelper<U, T>;
template <class T, class U>
concept OUTCOME_GCC6_CONCEPT_BOOL convertible = std::is_convertible<T, U>::value;
template <class T, class U>
concept OUTCOME_GCC6_CONCEPT_BOOL base_of = std::is_base_of<T, U>::value;
} // namespace detail
/* The `value_or_none` concept.
\requires That `U::value_type` exists and that `std::declval<U>().has_value()` returns a `bool` and `std::declval<U>().value()` exists.
*/
template <class U>
concept OUTCOME_GCC6_CONCEPT_BOOL value_or_none = requires(U a) {
{
a.has_value()
} -> detail::same_as<bool>;
{
a.value()
};
};
/* The `value_or_error` concept.
\requires That `U::value_type` and `U::error_type` exist;
that `std::declval<U>().has_value()` returns a `bool`, `std::declval<U>().value()` and `std::declval<U>().error()` exists.
*/
template <class U>
concept OUTCOME_GCC6_CONCEPT_BOOL value_or_error = requires(U a) {
{
a.has_value()
} -> detail::same_as<bool>;
{
a.value()
};
{
a.error()
};
};
#else
namespace detail
{
struct no_match
{
};
inline no_match match_value_or_none(...);
inline no_match match_value_or_error(...);
OUTCOME_TEMPLATE(class U)
OUTCOME_TREQUIRES(OUTCOME_TEXPR(std::declval<U>().has_value()), OUTCOME_TEXPR(std::declval<U>().value()))
inline U match_value_or_none(U &&);
OUTCOME_TEMPLATE(class U)
OUTCOME_TREQUIRES(OUTCOME_TEXPR(std::declval<U>().has_value()), OUTCOME_TEXPR(std::declval<U>().value()), OUTCOME_TEXPR(std::declval<U>().error()))
inline U match_value_or_error(U &&);
template <class U>
static constexpr bool value_or_none =
!std::is_same<no_match, decltype(match_value_or_none(std::declval<OUTCOME_V2_NAMESPACE::detail::devoid<U>>()))>::value;
template <class U>
static constexpr bool value_or_error =
!std::is_same<no_match, decltype(match_value_or_error(std::declval<OUTCOME_V2_NAMESPACE::detail::devoid<U>>()))>::value;
} // namespace detail
/* The `value_or_none` concept.
\requires That `U::value_type` exists and that `std::declval<U>().has_value()` returns a `bool` and `std::declval<U>().value()` exists.
*/
template <class U> static constexpr bool value_or_none = detail::value_or_none<U>;
/* The `value_or_error` concept.
\requires That `U::value_type` and `U::error_type` exist;
that `std::declval<U>().has_value()` returns a `bool`, `std::declval<U>().value()` and `std::declval<U>().error()` exists.
*/
template <class U> static constexpr bool value_or_error = detail::value_or_error<U>;
#endif
} // namespace concepts
namespace convert
{
#if OUTCOME_ENABLE_LEGACY_SUPPORT_FOR < 220
#if defined(__cpp_concepts)
template <class U>
concept OUTCOME_GCC6_CONCEPT_BOOL ValueOrNone = concepts::value_or_none<U>;
template <class U>
concept OUTCOME_GCC6_CONCEPT_BOOL ValueOrError = concepts::value_or_error<U>;
#else
template <class U> static constexpr bool ValueOrNone = concepts::value_or_none<U>;
template <class U> static constexpr bool ValueOrError = concepts::value_or_error<U>;
#endif
#endif
namespace detail
{
template <class T, class X> struct make_type
{
template <class U> static constexpr T value(U &&v) { return T{in_place_type<typename T::value_type>, static_cast<U &&>(v).value()}; }
template <class U> static constexpr T error(U &&v) { return T{in_place_type<typename T::error_type>, static_cast<U &&>(v).error()}; }
static constexpr T error() { return T{in_place_type<typename T::error_type>}; }
};
template <class T> struct make_type<T, void>
{
template <class U> static constexpr T value(U && /*unused*/) { return T{in_place_type<typename T::value_type>}; }
template <class U> static constexpr T error(U && /*unused*/) { return T{in_place_type<typename T::error_type>}; }
static constexpr T error() { return T{in_place_type<typename T::error_type>}; }
};
} // namespace detail
/*! AWAITING HUGO JSON CONVERSION TOOL
type definition value_or_error. Potential doc page: NOT FOUND
*/
template <class T, class U> struct value_or_error
{
static constexpr bool enable_result_inputs = false;
static constexpr bool enable_outcome_inputs = false;
OUTCOME_TEMPLATE(class X)
OUTCOME_TREQUIRES(
OUTCOME_TPRED(std::is_same<U, std::decay_t<X>>::value //
&&concepts::value_or_error<U> //
&& (std::is_void<typename std::decay_t<X>::value_type>::value ||
OUTCOME_V2_NAMESPACE::detail::is_explicitly_constructible<typename T::value_type, typename std::decay_t<X>::value_type>) //
&&(std::is_void<typename std::decay_t<X>::error_type>::value ||
OUTCOME_V2_NAMESPACE::detail::is_explicitly_constructible<typename T::error_type, typename std::decay_t<X>::error_type>) ))
constexpr T operator()(X &&v)
{
return v.has_value() ? detail::make_type<T, typename T::value_type>::value(static_cast<X &&>(v)) :
detail::make_type<T, typename U::error_type>::error(static_cast<X &&>(v));
}
};
} // namespace convert
OUTCOME_V2_NAMESPACE_END
#endif
/* Finaliser for a very simple result type
(C) 2017-2019 Niall Douglas <http://www.nedproductions.biz/> (5 commits)
File Created: Oct 2017
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License in the accompanying file
Licence.txt or at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Distributed under the Boost Software License, Version 1.0.
(See accompanying file Licence.txt or copy at
http://www.boost.org/LICENSE_1_0.txt)
*/
#ifndef OUTCOME_BASIC_RESULT_FINAL_HPP
#define OUTCOME_BASIC_RESULT_FINAL_HPP
/* Error observers for a very simple basic_result type
(C) 2017-2019 Niall Douglas <http://www.nedproductions.biz/> (2 commits)
File Created: Oct 2017
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License in the accompanying file
Licence.txt or at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Distributed under the Boost Software License, Version 1.0.
(See accompanying file Licence.txt or copy at
http://www.boost.org/LICENSE_1_0.txt)
*/
#ifndef OUTCOME_BASIC_RESULT_ERROR_OBSERVERS_HPP
#define OUTCOME_BASIC_RESULT_ERROR_OBSERVERS_HPP
OUTCOME_V2_NAMESPACE_EXPORT_BEGIN
namespace detail
{
template <class Base, class EC, class NoValuePolicy> class basic_result_error_observers : public Base
{
public:
using error_type = EC;
using Base::Base;
constexpr error_type &assume_error() & noexcept
{
NoValuePolicy::narrow_error_check(static_cast<basic_result_error_observers &>(*this));
return this->_state._error;
}
constexpr const error_type &assume_error() const & noexcept
{
NoValuePolicy::narrow_error_check(static_cast<const basic_result_error_observers &>(*this));
return this->_state._error;
}
constexpr error_type &&assume_error() && noexcept
{
NoValuePolicy::narrow_error_check(static_cast<basic_result_error_observers &&>(*this));
return static_cast<error_type &&>(this->_state._error);
}
constexpr const error_type &&assume_error() const && noexcept
{
NoValuePolicy::narrow_error_check(static_cast<const basic_result_error_observers &&>(*this));
return static_cast<const error_type &&>(this->_state._error);
}
constexpr error_type &error() &
{
NoValuePolicy::wide_error_check(static_cast<basic_result_error_observers &>(*this));
return this->_state._error;
}
constexpr const error_type &error() const &
{
NoValuePolicy::wide_error_check(static_cast<const basic_result_error_observers &>(*this));
return this->_state._error;
}
constexpr error_type &&error() &&
{
NoValuePolicy::wide_error_check(static_cast<basic_result_error_observers &&>(*this));
return static_cast<error_type &&>(this->_state._error);
}
constexpr const error_type &&error() const &&
{
NoValuePolicy::wide_error_check(static_cast<const basic_result_error_observers &&>(*this));
return static_cast<const error_type &&>(this->_state._error);
}
};
template <class Base, class NoValuePolicy> class basic_result_error_observers<Base, void, NoValuePolicy> : public Base
{
public:
using Base::Base;
constexpr void assume_error() & noexcept { NoValuePolicy::narrow_error_check(static_cast<basic_result_error_observers &>(*this)); }
constexpr void assume_error() const & noexcept { NoValuePolicy::narrow_error_check(static_cast<const basic_result_error_observers &>(*this)); }
constexpr void assume_error() && noexcept { NoValuePolicy::narrow_error_check(static_cast<basic_result_error_observers &&>(*this)); }
constexpr void assume_error() const && noexcept { NoValuePolicy::narrow_error_check(static_cast<const basic_result_error_observers &&>(*this)); }
constexpr void error() & { NoValuePolicy::wide_error_check(static_cast<basic_result_error_observers &>(*this)); }
constexpr void error() const & { NoValuePolicy::wide_error_check(static_cast<const basic_result_error_observers &>(*this)); }
constexpr void error() && { NoValuePolicy::wide_error_check(static_cast<basic_result_error_observers &&>(*this)); }
constexpr void error() const && { NoValuePolicy::wide_error_check(static_cast<const basic_result_error_observers &&>(*this)); }
};
} // namespace detail
OUTCOME_V2_NAMESPACE_END
#endif
/* Value observers for a very simple basic_result type
(C) 2017-2019 Niall Douglas <http://www.nedproductions.biz/> (2 commits)
File Created: Oct 2017
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License in the accompanying file
Licence.txt or at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Distributed under the Boost Software License, Version 1.0.
(See accompanying file Licence.txt or copy at
http://www.boost.org/LICENSE_1_0.txt)
*/
#ifndef OUTCOME_RESULT_VALUE_OBSERVERS_HPP
#define OUTCOME_RESULT_VALUE_OBSERVERS_HPP
OUTCOME_V2_NAMESPACE_EXPORT_BEGIN
namespace detail
{
template <class Base, class R, class NoValuePolicy> class basic_result_value_observers : public Base
{
public:
using value_type = R;
using Base::Base;
constexpr value_type &assume_value() & noexcept
{
NoValuePolicy::narrow_value_check(static_cast<basic_result_value_observers &>(*this));
return this->_state._value; // NOLINT
}
constexpr const value_type &assume_value() const & noexcept
{
NoValuePolicy::narrow_value_check(static_cast<const basic_result_value_observers &>(*this));
return this->_state._value; // NOLINT
}
constexpr value_type &&assume_value() && noexcept
{
NoValuePolicy::narrow_value_check(static_cast<basic_result_value_observers &&>(*this));
return static_cast<value_type &&>(this->_state._value); // NOLINT
}
constexpr const value_type &&assume_value() const && noexcept
{
NoValuePolicy::narrow_value_check(static_cast<const basic_result_value_observers &&>(*this));
return static_cast<const value_type &&>(this->_state._value); // NOLINT
}
constexpr value_type &value() &
{
NoValuePolicy::wide_value_check(static_cast<basic_result_value_observers &>(*this));
return this->_state._value; // NOLINT
}
constexpr const value_type &value() const &
{
NoValuePolicy::wide_value_check(static_cast<const basic_result_value_observers &>(*this));
return this->_state._value; // NOLINT
}
constexpr value_type &&value() &&
{
NoValuePolicy::wide_value_check(static_cast<basic_result_value_observers &&>(*this));
return static_cast<value_type &&>(this->_state._value); // NOLINT
}
constexpr const value_type &&value() const &&
{
NoValuePolicy::wide_value_check(static_cast<const basic_result_value_observers &&>(*this));
return static_cast<const value_type &&>(this->_state._value); // NOLINT
}
};
template <class Base, class NoValuePolicy> class basic_result_value_observers<Base, void, NoValuePolicy> : public Base
{
public:
using Base::Base;
constexpr void assume_value() & noexcept { NoValuePolicy::narrow_value_check(static_cast<basic_result_value_observers &>(*this)); }
constexpr void assume_value() const & noexcept { NoValuePolicy::narrow_value_check(static_cast<const basic_result_value_observers &>(*this)); }
constexpr void assume_value() && noexcept { NoValuePolicy::narrow_value_check(static_cast<basic_result_value_observers &&>(*this)); }
constexpr void assume_value() const && noexcept { NoValuePolicy::narrow_value_check(static_cast<const basic_result_value_observers &&>(*this)); }
constexpr void value() & { NoValuePolicy::wide_value_check(static_cast<basic_result_value_observers &>(*this)); }
constexpr void value() const & { NoValuePolicy::wide_value_check(static_cast<const basic_result_value_observers &>(*this)); }
constexpr void value() && { NoValuePolicy::wide_value_check(static_cast<basic_result_value_observers &&>(*this)); }
constexpr void value() const && { NoValuePolicy::wide_value_check(static_cast<const basic_result_value_observers &&>(*this)); }
};
} // namespace detail
OUTCOME_V2_NAMESPACE_END
#endif
OUTCOME_V2_NAMESPACE_EXPORT_BEGIN
namespace detail
{
template <class R, class EC, class NoValuePolicy> using select_basic_result_impl = basic_result_error_observers<basic_result_value_observers<basic_result_storage<R, EC, NoValuePolicy>, R, NoValuePolicy>, EC, NoValuePolicy>;
template <class R, class S, class NoValuePolicy>
class basic_result_final
: public select_basic_result_impl<R, S, NoValuePolicy>
{
using base = select_basic_result_impl<R, S, NoValuePolicy>;
public:
using base::base;
constexpr explicit operator bool() const noexcept { return this->_state._status.have_value(); }
constexpr bool has_value() const noexcept { return this->_state._status.have_value(); }
constexpr bool has_error() const noexcept { return this->_state._status.have_error(); }
constexpr bool has_exception() const noexcept { return this->_state._status.have_exception(); }
constexpr bool has_lost_consistency() const noexcept { return this->_state._status.have_lost_consistency(); }
constexpr bool has_failure() const noexcept { return this->_state._status.have_error() || this->_state._status.have_exception(); }
OUTCOME_TEMPLATE(class T, class U, class V)
OUTCOME_TREQUIRES(OUTCOME_TEXPR(std::declval<detail::devoid<R>>() == std::declval<detail::devoid<T>>()), //
OUTCOME_TEXPR(std::declval<detail::devoid<S>>() == std::declval<detail::devoid<U>>()))
constexpr bool operator==(const basic_result_final<T, U, V> &o) const noexcept( //
noexcept(std::declval<detail::devoid<R>>() == std::declval<detail::devoid<T>>()) && noexcept(std::declval<detail::devoid<S>>() == std::declval<detail::devoid<U>>()))
{
if(this->_state._status.have_value() && o._state._status.have_value())
{
return this->_state._value == o._state._value; // NOLINT
}
if(this->_state._status.have_error() && o._state._status.have_error())
{
return this->_state._error == o._state._error;
}
return false;
}
OUTCOME_TEMPLATE(class T)
OUTCOME_TREQUIRES(OUTCOME_TEXPR(std::declval<R>() == std::declval<T>()))
constexpr bool operator==(const success_type<T> &o) const noexcept( //
noexcept(std::declval<R>() == std::declval<T>()))
{
if(this->_state._status.have_value())
{
return this->_state._value == o.value();
}
return false;
}
constexpr bool operator==(const success_type<void> &o) const noexcept
{
(void) o;
return this->_state._status.have_value();
}
OUTCOME_TEMPLATE(class T)
OUTCOME_TREQUIRES(OUTCOME_TEXPR(std::declval<S>() == std::declval<T>()))
constexpr bool operator==(const failure_type<T, void> &o) const noexcept( //
noexcept(std::declval<S>() == std::declval<T>()))
{
if(this->_state._status.have_error())
{
return this->_state._error == o.error();
}
return false;
}
OUTCOME_TEMPLATE(class T, class U, class V)
OUTCOME_TREQUIRES(OUTCOME_TEXPR(std::declval<detail::devoid<R>>() != std::declval<detail::devoid<T>>()), //
OUTCOME_TEXPR(std::declval<detail::devoid<S>>() != std::declval<detail::devoid<U>>()))
constexpr bool operator!=(const basic_result_final<T, U, V> &o) const noexcept( //
noexcept(std::declval<detail::devoid<R>>() != std::declval<detail::devoid<T>>()) && noexcept(std::declval<detail::devoid<S>>() != std::declval<detail::devoid<U>>()))
{
if(this->_state._status.have_value() && o._state._status.have_value())
{
return this->_state._value != o._state._value;
}
if(this->_state._status.have_error() && o._state._status.have_error())
{
return this->_state._error != o._state._error;
}
return true;
}
OUTCOME_TEMPLATE(class T)
OUTCOME_TREQUIRES(OUTCOME_TEXPR(std::declval<R>() != std::declval<T>()))
constexpr bool operator!=(const success_type<T> &o) const noexcept( //
noexcept(std::declval<R>() != std::declval<T>()))
{
if(this->_state._status.have_value())
{
return this->_state._value != o.value();
}
return false;
}
constexpr bool operator!=(const success_type<void> &o) const noexcept
{
(void) o;
return !this->_state._status.have_value();
}
OUTCOME_TEMPLATE(class T)
OUTCOME_TREQUIRES(OUTCOME_TEXPR(std::declval<S>() != std::declval<T>()))
constexpr bool operator!=(const failure_type<T, void> &o) const noexcept( //
noexcept(std::declval<S>() != std::declval<T>()))
{
if(this->_state._status.have_error())
{
return this->_state._error != o.error();
}
return true;
}
};
template <class T, class U, class V, class W> constexpr inline bool operator==(const success_type<W> &a, const basic_result_final<T, U, V> &b) noexcept(noexcept(b == a)) { return b == a; }
template <class T, class U, class V, class W> constexpr inline bool operator==(const failure_type<W, void> &a, const basic_result_final<T, U, V> &b) noexcept(noexcept(b == a)) { return b == a; }
template <class T, class U, class V, class W> constexpr inline bool operator!=(const success_type<W> &a, const basic_result_final<T, U, V> &b) noexcept(noexcept(b == a)) { return b != a; }
template <class T, class U, class V, class W> constexpr inline bool operator!=(const failure_type<W, void> &a, const basic_result_final<T, U, V> &b) noexcept(noexcept(b == a)) { return b != a; }
} // namespace detail
OUTCOME_V2_NAMESPACE_END
#endif
/* Inline GDB pretty printer for result
(C) 2024 Niall Douglas <http://www.nedproductions.biz/> (6 commits)
File Created: Jun 2024
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License in the accompanying file
Licence.txt or at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Distributed under the Boost Software License, Version 1.0.
(See accompanying file Licence.txt or copy at
http://www.boost.org/LICENSE_1_0.txt)
*/
#ifndef OUTCOME_INLINE_GDB_PRETTY_PRINTER_H
#define OUTCOME_INLINE_GDB_PRETTY_PRINTER_H
#ifndef OUTCOME_DISABLE_INLINE_GDB_PRETTY_PRINTERS
#if defined(__ELF__)
#ifdef __clang__
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Woverlength-strings"
#endif
__asm__(".pushsection \".debug_gdb_scripts\", \"MS\",@progbits,1\n"
".byte 4 /* Python Text */\n"
".ascii \"gdb.inlined-script\\n\"\n"
".ascii \"import gdb.printing\\n\"\n"
".ascii \"import os\\n\"\n"
".ascii \"def synthesise_gdb_value_from_string(s):\\n\"\n"
".ascii \" '''For when you want to return a synthetic string from children()'''\\n\"\n"
".ascii \" return gdb.Value(s + '\\0').cast(gdb.lookup_type('char').pointer())\\n\"\n"
".ascii \"class OutcomeBasicOutcomePrinter(object):\\n\"\n"
".ascii \" '''Print an outcome::basic_outcome<T> and outcome::basic_result<T>'''\\n\"\n"
".ascii \" def __init__(self, val):\\n\"\n"
".ascii \" self.val = val\\n\"\n"
".ascii \" def children(self):\\n\"\n"
".ascii \" if self.val['_state']['_status']['status_value'] & 1 == 1:\\n\"\n"
".ascii \" yield ('value', self.val['_state']['_value'])\\n\"\n"
".ascii \" if self.val['_state']['_status']['status_value'] & 2 == 2:\\n\"\n"
".ascii \" yield ('error', self.val['_state']['_error'])\\n\"\n"
".ascii \" if self.val['_state']['_status']['status_value'] & 4 == 4:\\n\"\n"
".ascii \" yield ('exception', self.val['_ptr'])\\n\"\n"
".ascii \" def display_hint(self):\\n\"\n"
".ascii \" return None\\n\"\n"
".ascii \" def to_string(self):\\n\"\n"
".ascii \" if self.val['_state']['_status']['status_value'] & 54 == 54:\\n\"\n"
".ascii \" return 'errored (errno, moved from) + exceptioned'\\n\"\n"
".ascii \" if self.val['_state']['_status']['status_value'] & 50 == 50:\\n\"\n"
".ascii \" return 'errored (errno, moved from)'\\n\"\n"
".ascii \" if self.val['_state']['_status']['status_value'] & 38 == 38:\\n\"\n"
".ascii \" return 'errored + exceptioned (moved from)'\\n\"\n"
".ascii \" if self.val['_state']['_status']['status_value'] & 36 == 36:\\n\"\n"
".ascii \" return 'exceptioned (moved from)'\\n\"\n"
".ascii \" if self.val['_state']['_status']['status_value'] & 35 == 35:\\n\"\n"
".ascii \" return 'errored (moved from)'\\n\"\n"
".ascii \" if self.val['_state']['_status']['status_value'] & 33 == 33:\\n\"\n"
".ascii \" return 'valued (moved from)'\\n\"\n"
".ascii \" if self.val['_state']['_status']['status_value'] & 22 == 22:\\n\"\n"
".ascii \" return 'errored (errno) + exceptioned'\\n\"\n"
".ascii \" if self.val['_state']['_status']['status_value'] & 18 == 18:\\n\"\n"
".ascii \" return 'errored (errno)'\\n\"\n"
".ascii \" if self.val['_state']['_status']['status_value'] & 6 == 6:\\n\"\n"
".ascii \" return 'errored + exceptioned'\\n\"\n"
".ascii \" if self.val['_state']['_status']['status_value'] & 4 == 4:\\n\"\n"
".ascii \" return 'exceptioned'\\n\"\n"
".ascii \" if self.val['_state']['_status']['status_value'] & 2 == 2:\\n\"\n"
".ascii \" return 'errored'\\n\"\n"
".ascii \" if self.val['_state']['_status']['status_value'] & 1 == 1:\\n\"\n"
".ascii \" return 'valued'\\n\"\n"
".ascii \" if self.val['_state']['_status']['status_value'] & 0xff == 0:\\n\"\n"
".ascii \" return 'empty'\\n\"\n"
".ascii \"class OutcomeCResultStatusPrinter(object):\\n\"\n"
".ascii \" '''Print a C result'''\\n\"\n"
".ascii \" def __init__(self, val):\\n\"\n"
".ascii \" self.val = val\\n\"\n"
".ascii \" def children(self):\\n\"\n"
".ascii \" if self.val['flags'] & 1 == 1:\\n\"\n"
".ascii \" yield ('value', self.val['value'])\\n\"\n"
".ascii \" if self.val['flags'] & 2 == 2:\\n\"\n"
".ascii \" yield ('error', self.val['error'])\\n\"\n"
".ascii \" def display_hint(self):\\n\"\n"
".ascii \" return None\\n\"\n"
".ascii \" def to_string(self):\\n\"\n"
".ascii \" if self.val['flags'] & 50 == 50:\\n\"\n"
".ascii \" return 'errored (errno, moved from)'\\n\"\n"
".ascii \" if self.val['flags'] & 35 == 35:\\n\"\n"
".ascii \" return 'errored (moved from)'\\n\"\n"
".ascii \" if self.val['flags'] & 33 == 33:\\n\"\n"
".ascii \" return 'valued (moved from)'\\n\"\n"
".ascii \" if self.val['flags'] & 18 == 18:\\n\"\n"
".ascii \" return 'errored (errno)'\\n\"\n"
".ascii \" if self.val['flags'] & 2 == 2:\\n\"\n"
".ascii \" return 'errored'\\n\"\n"
".ascii \" if self.val['flags'] & 1 == 1:\\n\"\n"
".ascii \" return 'valued'\\n\"\n"
".ascii \" if self.val['flags'] & 0xff == 0:\\n\"\n"
".ascii \" return 'empty'\\n\"\n"
".ascii \"class OutcomeCStatusCodePrinter(object):\\n\"\n"
".ascii \" '''Print a C status code'''\\n\"\n"
".ascii \" def __init__(self, val):\\n\"\n"
".ascii \" self.val = val\\n\"\n"
".ascii \" def children(self):\\n\"\n"
".ascii \" yield ('domain', self.val['domain'])\\n\"\n"
".ascii \" yield ('value', self.val['value'])\\n\"\n"
".ascii \" def display_hint(self):\\n\"\n"
".ascii \" return None\\n\"\n"
".ascii \" def to_string(self):\\n\"\n"
".ascii \" s = str(self.val['domain'])\\n\"\n"
".ascii \" if 'posix_code_domain' in s or 'generic_code_domain' in s:\\n\"\n"
".ascii \" return str(self.val['value']) + ' (' + os.strerror(int(self.val['value'])) + ')'\\n\"\n"
".ascii \" else:\\n\"\n"
".ascii \" return self.val['value']\\n\"\n"
".ascii \"def build_pretty_printer():\\n\"\n"
".ascii \" pp = gdb.printing.RegexpCollectionPrettyPrinter('outcome_v2')\\n\"\n"
".ascii \" pp.add_printer('outcome_v2::basic_result', '^(boost::)?outcome_v2[_0-9a-f]*::basic_result<.*>$', OutcomeBasicOutcomePrinter)\\n\"\n"
".ascii \" pp.add_printer('outcome_v2::basic_outcome', '^(boost::)?outcome_v2[_0-9a-f]*::basic_outcome<.*>$', OutcomeBasicOutcomePrinter)\\n\"\n"
".ascii \" pp.add_printer('cxx_result_status_code_*', '^cxx_result_status_code_.*$', OutcomeCResultStatusPrinter)\\n\"\n"
".ascii \" pp.add_printer('cxx_status_code_*', '^cxx_status_code_.*$', OutcomeCStatusCodePrinter)\\n\"\n"
".ascii \" return pp\\n\"\n"
".ascii \"def register_printers(obj = None):\\n\"\n"
".ascii \" gdb.printing.register_pretty_printer(obj, build_pretty_printer(), replace = True)\\n\"\n"
".ascii \"register_printers(gdb.current_objfile())\\n\"\n"
".byte 0\n"
".popsection\n");
#ifdef __clang__
#pragma clang diagnostic pop
#endif
#endif
#endif
#endif
/* Policies for result and outcome
(C) 2017-2019 Niall Douglas <http://www.nedproductions.biz/> (13 commits)
File Created: Oct 2017
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License in the accompanying file
Licence.txt or at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Distributed under the Boost Software License, Version 1.0.
(See accompanying file Licence.txt or copy at
http://www.boost.org/LICENSE_1_0.txt)
*/
#ifndef OUTCOME_POLICY_ALL_NARROW_HPP
#define OUTCOME_POLICY_ALL_NARROW_HPP
/* Policies for result and outcome
(C) 2017-2020 Niall Douglas <http://www.nedproductions.biz/> (6 commits) and Andrzej Krzemieński <[email protected]> (1 commit)
File Created: Oct 2017
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License in the accompanying file
Licence.txt or at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Distributed under the Boost Software License, Version 1.0.
(See accompanying file Licence.txt or copy at
http://www.boost.org/LICENSE_1_0.txt)
*/
#ifndef OUTCOME_POLICY_BASE_HPP
#define OUTCOME_POLICY_BASE_HPP
OUTCOME_V2_NAMESPACE_EXPORT_BEGIN
#if OUTCOME_ENABLE_LEGACY_SUPPORT_FOR < 220
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
namespace hooks
{
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
template <class T, class U> constexpr inline void hook_result_construction(T * /*unused*/, U && /*unused*/) noexcept {}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
template <class T, class U> constexpr inline void hook_result_copy_construction(T * /*unused*/, U && /*unused*/) noexcept {}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
template <class T, class U> constexpr inline void hook_result_move_construction(T * /*unused*/, U && /*unused*/) noexcept {}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
template <class T, class U, class... Args>
constexpr inline void hook_result_in_place_construction(T * /*unused*/, in_place_type_t<U> /*unused*/, Args &&... /*unused*/) noexcept
{
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
template <class T, class... U> constexpr inline void hook_outcome_construction(T * /*unused*/, U &&... /*unused*/) noexcept {}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
template <class T, class U> constexpr inline void hook_outcome_copy_construction(T * /*unused*/, U && /*unused*/) noexcept {}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
template <class T, class U> constexpr inline void hook_outcome_move_construction(T * /*unused*/, U && /*unused*/) noexcept {}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
template <class T, class U, class... Args>
constexpr inline void hook_outcome_in_place_construction(T * /*unused*/, in_place_type_t<U> /*unused*/, Args &&... /*unused*/) noexcept
{
}
} // namespace hooks
#endif
namespace policy
{
namespace detail
{
using OUTCOME_V2_NAMESPACE::detail::make_ub;
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
struct base
{
template <class... Args> static constexpr void _silence_unused(Args &&... /*unused*/) noexcept {}
protected:
template <class Impl> static constexpr void _make_ub(Impl &&self) noexcept { return detail::make_ub(static_cast<Impl &&>(self)); }
template <class Impl> static constexpr bool _has_value(Impl &&self) noexcept { return self._state._status.have_value(); }
template <class Impl> static constexpr bool _has_error(Impl &&self) noexcept { return self._state._status.have_error(); }
template <class Impl> static constexpr bool _has_exception(Impl &&self) noexcept { return self._state._status.have_exception(); }
template <class Impl> static constexpr bool _has_error_is_errno(Impl &&self) noexcept { return self._state._status.have_error_is_errno(); }
template <class Impl> static constexpr void _set_has_value(Impl &&self, bool v) noexcept { self._state._status.set_have_value(v); }
template <class Impl> static constexpr void _set_has_error(Impl &&self, bool v) noexcept { self._state._status.set_have_error(v); }
template <class Impl> static constexpr void _set_has_exception(Impl &&self, bool v) noexcept { self._state._status.set_have_exception(v); }
template <class Impl> static constexpr void _set_has_error_is_errno(Impl &&self, bool v) noexcept { self._state._status.set_have_error_is_errno(v); }
template <class Impl> static constexpr auto &&_value(Impl &&self) noexcept { return static_cast<Impl &&>(self)._state._value; }
template <class Impl> static constexpr auto &&_error(Impl &&self) noexcept { return static_cast<Impl &&>(self)._state._error; }
public:
template <class R, class S, class P, class NoValuePolicy, class Impl> static inline constexpr auto &&_exception(Impl &&self) noexcept;
template <class T, class U> static constexpr inline void on_result_construction(T *inst, U &&v) noexcept
{
#if OUTCOME_ENABLE_LEGACY_SUPPORT_FOR < 220
using namespace hooks;
hook_result_construction(inst, static_cast<U &&>(v));
#else
(void) inst;
(void) v;
#endif
}
template <class T, class U> static constexpr inline void on_result_copy_construction(T *inst, U &&v) noexcept
{
#if OUTCOME_ENABLE_LEGACY_SUPPORT_FOR < 220
using namespace hooks;
hook_result_copy_construction(inst, static_cast<U &&>(v));
#else
(void) inst;
(void) v;
#endif
}
template <class T, class U> static constexpr inline void on_result_move_construction(T *inst, U &&v) noexcept
{
#if OUTCOME_ENABLE_LEGACY_SUPPORT_FOR < 220
using namespace hooks;
hook_result_move_construction(inst, static_cast<U &&>(v));
#else
(void) inst;
(void) v;
#endif
}
template <class T, class U, class... Args>
static constexpr inline void on_result_in_place_construction(T *inst, in_place_type_t<U> _, Args &&... args) noexcept
{
#if OUTCOME_ENABLE_LEGACY_SUPPORT_FOR < 220
using namespace hooks;
hook_result_in_place_construction(inst, _, static_cast<Args &&>(args)...);
#else
(void) inst;
(void) _;
_silence_unused(static_cast<Args &&>(args)...);
#endif
}
template <class T, class... U> static constexpr inline void on_outcome_construction(T *inst, U &&... args) noexcept
{
#if OUTCOME_ENABLE_LEGACY_SUPPORT_FOR < 220
using namespace hooks;
hook_outcome_construction(inst, static_cast<U &&>(args)...);
#else
(void) inst;
_silence_unused(static_cast<U &&>(args)...);
#endif
}
template <class T, class U> static constexpr inline void on_outcome_copy_construction(T *inst, U &&v) noexcept
{
#if OUTCOME_ENABLE_LEGACY_SUPPORT_FOR < 220
using namespace hooks;
hook_outcome_copy_construction(inst, static_cast<U &&>(v));
#else
(void) inst;
(void) v;
#endif
}
template <class T, class U> static constexpr inline void on_outcome_move_construction(T *inst, U &&v) noexcept
{
#if OUTCOME_ENABLE_LEGACY_SUPPORT_FOR < 220
using namespace hooks;
hook_outcome_move_construction(inst, static_cast<U &&>(v));
#else
(void) inst;
(void) v;
#endif
}
template <class T, class U, class... Args>
static constexpr inline void on_outcome_in_place_construction(T *inst, in_place_type_t<U> _, Args &&... args) noexcept
{
#if OUTCOME_ENABLE_LEGACY_SUPPORT_FOR < 220
using namespace hooks;
hook_outcome_in_place_construction(inst, _, static_cast<Args &&>(args)...);
#else
(void) inst;
(void) _;
_silence_unused(static_cast<Args &&>(args)...);
#endif
}
template <class Impl> static constexpr void narrow_value_check(Impl &&self) noexcept
{
if(!_has_value(self))
{
_make_ub(self);
}
}
template <class Impl> static constexpr void narrow_error_check(Impl &&self) noexcept
{
if(!_has_error(self))
{
_make_ub(self);
}
}
template <class Impl> static constexpr void narrow_exception_check(Impl &&self) noexcept
{
if(!_has_exception(self))
{
_make_ub(self);
}
}
};
} // namespace policy
OUTCOME_V2_NAMESPACE_END
#endif
OUTCOME_V2_NAMESPACE_EXPORT_BEGIN
namespace policy
{
/*! AWAITING HUGO JSON CONVERSION TOOL
type definition all_narrow. Potential doc page: `all_narrow`
*/
struct all_narrow : base
{
template <class Impl> static constexpr void wide_value_check(Impl &&self) { base::narrow_value_check(static_cast<Impl &&>(self)); }
template <class Impl> static constexpr void wide_error_check(Impl &&self) { base::narrow_error_check(static_cast<Impl &&>(self)); }
template <class Impl> static constexpr void wide_exception_check(Impl &&self) { base::narrow_exception_check(static_cast<Impl &&>(self)); }
};
} // namespace policy
OUTCOME_V2_NAMESPACE_END
#endif
/* Policies for result and outcome
(C) 2017-2019 Niall Douglas <http://www.nedproductions.biz/> (12 commits)
File Created: Oct 2017
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License in the accompanying file
Licence.txt or at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Distributed under the Boost Software License, Version 1.0.
(See accompanying file Licence.txt or copy at
http://www.boost.org/LICENSE_1_0.txt)
*/
#ifndef OUTCOME_POLICY_TERMINATE_HPP
#define OUTCOME_POLICY_TERMINATE_HPP
#include <cstdlib>
OUTCOME_V2_NAMESPACE_EXPORT_BEGIN
namespace policy
{
/*! AWAITING HUGO JSON CONVERSION TOOL
type definition terminate. Potential doc page: `terminate`
*/
struct terminate : base
{
template <class Impl> static constexpr void wide_value_check(Impl &&self)
{
if(!base::_has_value(static_cast<Impl &&>(self)))
{
std::abort();
}
}
template <class Impl> static constexpr void wide_error_check(Impl &&self) noexcept
{
if(!base::_has_error(static_cast<Impl &&>(self)))
{
std::abort();
}
}
template <class Impl> static constexpr void wide_exception_check(Impl &&self)
{
if(!base::_has_exception(static_cast<Impl &&>(self)))
{
std::abort();
}
}
};
} // namespace policy
OUTCOME_V2_NAMESPACE_END
#endif
#ifdef __clang__
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdocumentation" // Standardese markup confuses clang
#endif
OUTCOME_V2_NAMESPACE_EXPORT_BEGIN
template <class R, class S, class NoValuePolicy> //
class basic_result;
namespace detail
{
// These are reused by basic_outcome to save load on the compiler
template <class value_type, class error_type> struct result_predicates
{
// Predicate for the implicit constructors to be available. Weakened to allow result<int, C enum>.
static constexpr bool implicit_constructors_enabled = //
!(trait::is_error_type<std::decay_t<value_type>>::value &&
trait::is_error_type<std::decay_t<error_type>>::value) // both value and error types are not whitelisted error types
&& ((!detail::is_implicitly_constructible<value_type, error_type> &&
!detail::is_implicitly_constructible<error_type, value_type>) // if value and error types cannot be constructed into one another
|| (trait::is_error_type<std::decay_t<error_type>>::value // if error type is a whitelisted error type
&& !detail::is_implicitly_constructible<error_type, value_type> // AND which cannot be constructed from the value type
&& std::is_integral<value_type>::value)); // AND the value type is some integral type
// Predicate for the value converting constructor to be available. Weakened to allow result<int, C enum>.
template <class T>
static constexpr bool enable_value_converting_constructor = //
implicit_constructors_enabled //
&& !is_in_place_type_t<std::decay_t<T>>::value // not in place construction
&& !trait::is_error_type_enum<error_type, std::decay_t<T>>::value // not an enum valid for my error type
&& ((detail::is_implicitly_constructible<value_type, T> && !detail::is_implicitly_constructible<error_type, T>) // is unambiguously for value type
|| (std::is_same<value_type, std::decay_t<T>>::value // OR is my value type exactly
&& detail::is_implicitly_constructible<value_type, T>) ); // and my value type is constructible from this ref form of T
// Predicate for the error converting constructor to be available. Weakened to allow result<int, C enum>.
template <class T>
static constexpr bool enable_error_converting_constructor = //
implicit_constructors_enabled //
&& !is_in_place_type_t<std::decay_t<T>>::value // not in place construction
&& !trait::is_error_type_enum<error_type, std::decay_t<T>>::value // not an enum valid for my error type
&& ((!detail::is_implicitly_constructible<value_type, T> && detail::is_implicitly_constructible<error_type, T>) // is unambiguously for error type
|| (std::is_same<error_type, std::decay_t<T>>::value // OR is my error type exactly
&& detail::is_implicitly_constructible<error_type, T>) ); // and my error type is constructible from this ref form of T
// Predicate for the error condition converting constructor to be available.
template <class ErrorCondEnum>
static constexpr bool enable_error_condition_converting_constructor = //
!is_in_place_type_t<std::decay_t<ErrorCondEnum>>::value // not in place construction
&& trait::is_error_type_enum<error_type, std::decay_t<ErrorCondEnum>>::value // is an error condition enum
/*&& !detail::is_implicitly_constructible<value_type, ErrorCondEnum> && !detail::is_implicitly_constructible<error_type, ErrorCondEnum>*/; // not
// constructible
// via any other
// means
// Predicate for the converting constructor from a compatible input to be available.
template <class T, class U, class V>
static constexpr bool enable_compatible_conversion = //
(std::is_void<T>::value ||
detail::is_explicitly_constructible<value_type, typename basic_result<T, U, V>::value_type>) // if our value types are constructible
&&(std::is_void<U>::value ||
detail::is_explicitly_constructible<error_type, typename basic_result<T, U, V>::error_type>) // if our error types are constructible
;
// Predicate for the converting constructor from a make_error_code() of the input to be available.
template <class T, class U, class V>
static constexpr bool enable_make_error_code_compatible_conversion = //
trait::is_error_code_available<std::decay_t<error_type>>::value // if error type has an error code
&& !enable_compatible_conversion<T, U, V> // and the normal compatible conversion is not available
&& (std::is_void<T>::value ||
detail::is_explicitly_constructible<value_type, typename basic_result<T, U, V>::value_type>) // and if our value types are constructible
&&detail::is_explicitly_constructible<error_type,
typename trait::is_error_code_available<U>::type>; // and our error type is constructible from a make_error_code()
// Predicate for the converting constructor from a make_exception_ptr() of the input to be available.
template <class T, class U, class V>
static constexpr bool enable_make_exception_ptr_compatible_conversion = //
trait::is_exception_ptr_available<std::decay_t<error_type>>::value // if error type has an exception ptr
&& !enable_compatible_conversion<T, U, V> // and the normal compatible conversion is not available
&& (std::is_void<T>::value ||
detail::is_explicitly_constructible<value_type, typename basic_result<T, U, V>::value_type>) // and if our value types are constructible
&&detail::is_explicitly_constructible<error_type, typename trait::is_exception_ptr_available<U>::type>; // and our error type is constructible from a
// make_exception_ptr()
// Predicate for the implicit converting inplace constructor from a compatible input to be available.
struct disable_inplace_value_error_constructor;
template <class... Args>
using choose_inplace_value_error_constructor = std::conditional_t< //
detail::is_constructible<value_type, Args...> && detail::is_constructible<error_type, Args...>, //
disable_inplace_value_error_constructor, //
std::conditional_t< //
detail::is_constructible<value_type, Args...>, //
value_type, //
std::conditional_t< //
detail::is_constructible<error_type, Args...>, //
error_type, //
disable_inplace_value_error_constructor>>>;
template <class... Args>
static constexpr bool enable_inplace_value_error_constructor =
implicit_constructors_enabled //
&& !std::is_same<choose_inplace_value_error_constructor<Args...>, disable_inplace_value_error_constructor>::value;
};
template <class T, class U> constexpr inline const U &extract_value_from_success(const success_type<U> &v)
{
return v.value();
}
template <class T, class U> constexpr inline U &&extract_value_from_success(success_type<U> &&v)
{
return static_cast<success_type<U> &&>(v).value();
}
template <class T> constexpr inline T extract_value_from_success(const success_type<void> & /*unused*/)
{
return T{};
}
template <class T, class U, class V> constexpr inline const U &extract_error_from_failure(const failure_type<U, V> &v)
{
return v.error();
}
template <class T, class U, class V> constexpr inline U &&extract_error_from_failure(failure_type<U, V> &&v)
{
return static_cast<failure_type<U, V> &&>(v).error();
}
template <class T, class V> constexpr inline T extract_error_from_failure(const failure_type<void, V> & /*unused*/)
{
return T{};
}
template <class T> struct is_basic_result
{
static constexpr bool value = false;
};
template <class R, class S, class T> struct is_basic_result<basic_result<R, S, T>>
{
static constexpr bool value = true;
};
} // namespace detail
/*! AWAITING HUGO JSON CONVERSION TOOL
type alias template <class T> is_basic_result. Potential doc page: `is_basic_result<T>`
*/
template <class T> using is_basic_result = detail::is_basic_result<std::decay_t<T>>;
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
template <class T> static constexpr bool is_basic_result_v = detail::is_basic_result<std::decay_t<T>>::value;
namespace concepts
{
#if defined(__cpp_concepts)
/* The `basic_result` concept.
\requires That `U` matches a `basic_result`.
*/
template <class U>
concept OUTCOME_GCC6_CONCEPT_BOOL basic_result =
OUTCOME_V2_NAMESPACE::is_basic_result<U>::value ||
(requires(U v) { OUTCOME_V2_NAMESPACE::basic_result<typename U::value_type, typename U::error_type, typename U::no_value_policy_type>(v); } && //
detail::convertible<U, OUTCOME_V2_NAMESPACE::basic_result<typename U::value_type, typename U::error_type, typename U::no_value_policy_type>> && //
detail::base_of<OUTCOME_V2_NAMESPACE::basic_result<typename U::value_type, typename U::error_type, typename U::no_value_policy_type>, U>);
#else
namespace detail
{
inline no_match match_basic_result(...);
template <class R, class S, class NVP, class T, //
typename = typename T::value_type, //
typename = typename T::error_type, //
typename = typename T::no_value_policy_type, //
typename std::enable_if_t<std::is_convertible<T, OUTCOME_V2_NAMESPACE::basic_result<R, S, NVP>>::value && //
std::is_base_of<OUTCOME_V2_NAMESPACE::basic_result<R, S, NVP>, T>::value,
bool> = true>
inline OUTCOME_V2_NAMESPACE::basic_result<R, S, NVP> match_basic_result(OUTCOME_V2_NAMESPACE::basic_result<R, S, NVP> &&, T &&);
template <class U>
static constexpr bool basic_result = OUTCOME_V2_NAMESPACE::is_basic_result<U>::value ||
!std::is_same<no_match, decltype(match_basic_result(std::declval<OUTCOME_V2_NAMESPACE::detail::devoid<U>>(),
std::declval<OUTCOME_V2_NAMESPACE::detail::devoid<U>>()))>::value;
} // namespace detail
/* The `basic_result` concept.
\requires That `U` matches a `basic_result`.
*/
template <class U> static constexpr bool basic_result = detail::basic_result<U>;
#endif
} // namespace concepts
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
namespace hooks
{
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
template <class R, class S, class NoValuePolicy> constexpr inline uint16_t spare_storage(const detail::basic_result_storage<R, S, NoValuePolicy> *r) noexcept
{
return r->_state._status.spare_storage_value;
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
template <class R, class S, class NoValuePolicy>
constexpr inline void set_spare_storage(detail::basic_result_storage<R, S, NoValuePolicy> *r, uint16_t v) noexcept
{
r->_state._status.spare_storage_value = v;
}
} // namespace hooks
/*! AWAITING HUGO JSON CONVERSION TOOL
type definition template <class R, class S, class NoValuePolicy> basic_result. Potential doc page: `basic_result<T, E, NoValuePolicy>`
*/
template <class R, class S, class NoValuePolicy> //
class OUTCOME_NODISCARD basic_result : public detail::basic_result_final<R, S, NoValuePolicy>
{
static_assert(trait::type_can_be_used_in_basic_result<R>, "The type R cannot be used in a basic_result");
static_assert(trait::type_can_be_used_in_basic_result<S>, "The type S cannot be used in a basic_result");
using base = detail::basic_result_final<R, S, NoValuePolicy>;
struct implicit_constructors_disabled_tag
{
};
struct value_converting_constructor_tag
{
};
struct error_converting_constructor_tag
{
};
struct error_condition_converting_constructor_tag
{
};
struct explicit_valueornone_converting_constructor_tag
{
};
struct explicit_valueorerror_converting_constructor_tag
{
};
struct explicit_compatible_copy_conversion_tag
{
};
struct explicit_compatible_move_conversion_tag
{
};
struct explicit_make_error_code_compatible_copy_conversion_tag
{
};
struct explicit_make_error_code_compatible_move_conversion_tag
{
};
struct explicit_make_exception_ptr_compatible_copy_conversion_tag
{
};
struct explicit_make_exception_ptr_compatible_move_conversion_tag
{
};
public:
using value_type = R;
using error_type = S;
using no_value_policy_type = NoValuePolicy;
using value_type_if_enabled = typename base::_value_type;
using error_type_if_enabled = typename base::_error_type;
template <class T, class U = S, class V = NoValuePolicy> using rebind = basic_result<T, U, V>;
protected:
// Requirement predicates for result.
struct predicate
{
using base = detail::result_predicates<value_type, error_type>;
// Predicate for any constructors to be available at all
static constexpr bool constructors_enabled = !std::is_same<std::decay_t<value_type>, std::decay_t<error_type>>::value;
// Predicate for implicit constructors to be available at all
static constexpr bool implicit_constructors_enabled = constructors_enabled && base::implicit_constructors_enabled;
// Predicate for the value converting constructor to be available.
template <class T>
static constexpr bool enable_value_converting_constructor = //
constructors_enabled //
&& !std::is_same<std::decay_t<T>, basic_result>::value // not my type
&& base::template enable_value_converting_constructor<T>;
// Predicate for the error converting constructor to be available.
template <class T>
static constexpr bool enable_error_converting_constructor = //
constructors_enabled //
&& !std::is_same<std::decay_t<T>, basic_result>::value // not my type
&& base::template enable_error_converting_constructor<T>;
// Predicate for the error condition converting constructor to be available.
template <class ErrorCondEnum>
static constexpr bool enable_error_condition_converting_constructor = //
constructors_enabled //
&& !std::is_same<std::decay_t<ErrorCondEnum>, basic_result>::value // not my type
&& base::template enable_error_condition_converting_constructor<ErrorCondEnum>;
// Predicate for the converting constructor from a compatible input to be available.
template <class T, class U, class V>
static constexpr bool enable_compatible_conversion = //
constructors_enabled //
&& !std::is_same<basic_result<T, U, V>, basic_result>::value // not my type
&& base::template enable_compatible_conversion<T, U, V>;
// Predicate for the converting constructor from a make_error_code() of the input to be available.
template <class T, class U, class V>
static constexpr bool enable_make_error_code_compatible_conversion = //
constructors_enabled //
&& !std::is_same<basic_result<T, U, V>, basic_result>::value // not my type
&& base::template enable_make_error_code_compatible_conversion<T, U, V>;
// Predicate for the converting constructor from a make_exception_ptr() of the input to be available.
template <class T, class U, class V>
static constexpr bool enable_make_exception_ptr_compatible_conversion = //
constructors_enabled //
&& !std::is_same<basic_result<T, U, V>, basic_result>::value // not my type
&& base::template enable_make_exception_ptr_compatible_conversion<T, U, V>;
// Predicate for the inplace construction of value to be available.
template <class... Args>
static constexpr bool enable_inplace_value_constructor = //
constructors_enabled //
&& (std::is_void<value_type>::value //
|| detail::is_constructible<value_type, Args...>);
// Predicate for the inplace construction of error to be available.
template <class... Args>
static constexpr bool enable_inplace_error_constructor = //
constructors_enabled //
&& (std::is_void<error_type>::value //
|| detail::is_constructible<error_type, Args...>);
// Predicate for the implicit converting inplace constructor to be available.
template <class... Args>
static constexpr bool enable_inplace_value_error_constructor = //
constructors_enabled //
&& base::template enable_inplace_value_error_constructor<Args...>;
template <class... Args> using choose_inplace_value_error_constructor = typename base::template choose_inplace_value_error_constructor<Args...>;
};
public:
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
basic_result() = delete;
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
basic_result(basic_result && /*unused*/) = default; // NOLINT
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
basic_result(const basic_result & /*unused*/) = default;
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
basic_result &operator=(basic_result && /*unused*/) = default; // NOLINT
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
basic_result &operator=(const basic_result & /*unused*/) = default;
~basic_result() = default;
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class Arg, class... Args)
OUTCOME_TREQUIRES(OUTCOME_TPRED(!predicate::constructors_enabled && (sizeof...(Args) >= 0)))
basic_result(Arg && /*unused*/, Args &&.../*unused*/) = delete; // NOLINT basic_result<T, T> is NOT SUPPORTED, see docs!
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class T)
OUTCOME_TREQUIRES(OUTCOME_TPRED((predicate::constructors_enabled && !predicate::implicit_constructors_enabled //
&& (detail::is_implicitly_constructible<value_type, T> || detail::is_implicitly_constructible<error_type, T>) )))
basic_result(T && /*unused*/, implicit_constructors_disabled_tag /*unused*/ = implicit_constructors_disabled_tag()) =
delete; // NOLINT Implicit constructors disabled, use explicit in_place_type<T>, success() or failure(). see docs!
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class T)
OUTCOME_TREQUIRES(OUTCOME_TPRED(predicate::template enable_value_converting_constructor<T>))
constexpr basic_result(T &&t, value_converting_constructor_tag /*unused*/ = value_converting_constructor_tag()) noexcept(
detail::is_nothrow_constructible<value_type, T>) // NOLINT
: base{in_place_type<typename base::value_type>, static_cast<T &&>(t)}
{
no_value_policy_type::on_result_construction(this, static_cast<T &&>(t));
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class T)
OUTCOME_TREQUIRES(OUTCOME_TPRED(predicate::template enable_error_converting_constructor<T>))
constexpr basic_result(T &&t, error_converting_constructor_tag /*unused*/ = error_converting_constructor_tag()) noexcept(
detail::is_nothrow_constructible<error_type, T>) // NOLINT
: base{in_place_type<typename base::error_type>, static_cast<T &&>(t)}
{
no_value_policy_type::on_result_construction(this, static_cast<T &&>(t));
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class ErrorCondEnum)
OUTCOME_TREQUIRES(OUTCOME_TEXPR(error_type(make_error_code(ErrorCondEnum()))), //
OUTCOME_TPRED(predicate::template enable_error_condition_converting_constructor<ErrorCondEnum>))
constexpr basic_result(ErrorCondEnum &&t, error_condition_converting_constructor_tag /*unused*/ = error_condition_converting_constructor_tag()) noexcept(
noexcept(error_type(make_error_code(static_cast<ErrorCondEnum &&>(t))))) // NOLINT
: base{in_place_type<typename base::error_type>, make_error_code(t)}
{
no_value_policy_type::on_result_construction(this, static_cast<ErrorCondEnum &&>(t));
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class T)
OUTCOME_TREQUIRES(OUTCOME_TPRED(convert::value_or_error<basic_result, std::decay_t<T>>::enable_result_inputs || !concepts::basic_result<T>), //
OUTCOME_TEXPR(convert::value_or_error<basic_result, std::decay_t<T>>{}(std::declval<T>())))
constexpr explicit basic_result(T &&o,
explicit_valueorerror_converting_constructor_tag /*unused*/ = explicit_valueorerror_converting_constructor_tag()) // NOLINT
: basic_result{convert::value_or_error<basic_result, std::decay_t<T>>{}(static_cast<T &&>(o))}
{
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class T, class U, class V)
OUTCOME_TREQUIRES(OUTCOME_TPRED(predicate::template enable_compatible_conversion<T, U, V>))
constexpr explicit basic_result(
const basic_result<T, U, V> &o,
explicit_compatible_copy_conversion_tag /*unused*/ = explicit_compatible_copy_conversion_tag()) noexcept(detail::is_nothrow_constructible<value_type, T> &&
detail::is_nothrow_constructible<error_type, U>)
: base{typename base::compatible_conversion_tag(), o}
{
no_value_policy_type::on_result_copy_construction(this, o);
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class T, class U, class V)
OUTCOME_TREQUIRES(OUTCOME_TPRED(predicate::template enable_compatible_conversion<T, U, V>))
constexpr explicit basic_result(
basic_result<T, U, V> &&o,
explicit_compatible_move_conversion_tag /*unused*/ = explicit_compatible_move_conversion_tag()) noexcept(detail::is_nothrow_constructible<value_type, T> &&
detail::is_nothrow_constructible<error_type, U>)
: base{typename base::compatible_conversion_tag(), static_cast<basic_result<T, U, V> &&>(o)}
{
no_value_policy_type::on_result_move_construction(this, static_cast<basic_result<T, U, V> &&>(o));
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class T, class U, class V)
OUTCOME_TREQUIRES(OUTCOME_TPRED(predicate::template enable_make_error_code_compatible_conversion<T, U, V>))
constexpr explicit basic_result(const basic_result<T, U, V> &o,
explicit_make_error_code_compatible_copy_conversion_tag /*unused*/ =
explicit_make_error_code_compatible_copy_conversion_tag()) noexcept(detail::is_nothrow_constructible<value_type, T> &&
noexcept(make_error_code(std::declval<U>())))
: base{typename base::make_error_code_compatible_conversion_tag(), o}
{
no_value_policy_type::on_result_copy_construction(this, o);
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class T, class U, class V)
OUTCOME_TREQUIRES(OUTCOME_TPRED(predicate::template enable_make_error_code_compatible_conversion<T, U, V>))
constexpr explicit basic_result(basic_result<T, U, V> &&o,
explicit_make_error_code_compatible_move_conversion_tag /*unused*/ =
explicit_make_error_code_compatible_move_conversion_tag()) noexcept(detail::is_nothrow_constructible<value_type, T> &&
noexcept(make_error_code(std::declval<U>())))
: base{typename base::make_error_code_compatible_conversion_tag(), static_cast<basic_result<T, U, V> &&>(o)}
{
no_value_policy_type::on_result_move_construction(this, static_cast<basic_result<T, U, V> &&>(o));
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class T, class U, class V)
OUTCOME_TREQUIRES(OUTCOME_TPRED(predicate::template enable_make_exception_ptr_compatible_conversion<T, U, V>))
constexpr explicit basic_result(const basic_result<T, U, V> &o,
explicit_make_exception_ptr_compatible_copy_conversion_tag /*unused*/ =
explicit_make_exception_ptr_compatible_copy_conversion_tag()) noexcept(detail::is_nothrow_constructible<value_type, T> &&
noexcept(make_exception_ptr(std::declval<U>())))
: base{typename base::make_exception_ptr_compatible_conversion_tag(), o}
{
no_value_policy_type::on_result_copy_construction(this, o);
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class T, class U, class V)
OUTCOME_TREQUIRES(OUTCOME_TPRED(predicate::template enable_make_exception_ptr_compatible_conversion<T, U, V>))
constexpr explicit basic_result(basic_result<T, U, V> &&o,
explicit_make_exception_ptr_compatible_move_conversion_tag /*unused*/ =
explicit_make_exception_ptr_compatible_move_conversion_tag()) noexcept(detail::is_nothrow_constructible<value_type, T> &&
noexcept(make_exception_ptr(std::declval<U>())))
: base{typename base::make_exception_ptr_compatible_conversion_tag(), static_cast<basic_result<T, U, V> &&>(o)}
{
no_value_policy_type::on_result_move_construction(this, static_cast<basic_result<T, U, V> &&>(o));
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class... Args)
OUTCOME_TREQUIRES(OUTCOME_TPRED(predicate::template enable_inplace_value_constructor<Args...>))
constexpr explicit basic_result(in_place_type_t<value_type_if_enabled> _, Args &&...args) noexcept(detail::is_nothrow_constructible<value_type, Args...>)
: base{_, static_cast<Args &&>(args)...}
{
no_value_policy_type::on_result_in_place_construction(this, in_place_type<value_type>, static_cast<Args &&>(args)...);
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class U, class... Args)
OUTCOME_TREQUIRES(OUTCOME_TPRED(predicate::template enable_inplace_value_constructor<std::initializer_list<U>, Args...>))
constexpr explicit basic_result(in_place_type_t<value_type_if_enabled> _, std::initializer_list<U> il,
Args &&...args) noexcept(detail::is_nothrow_constructible<value_type, std::initializer_list<U>, Args...>)
: base{_, il, static_cast<Args &&>(args)...}
{
no_value_policy_type::on_result_in_place_construction(this, in_place_type<value_type>, il, static_cast<Args &&>(args)...);
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class... Args)
OUTCOME_TREQUIRES(OUTCOME_TPRED(predicate::template enable_inplace_error_constructor<Args...>))
constexpr explicit basic_result(in_place_type_t<error_type_if_enabled> _, Args &&...args) noexcept(detail::is_nothrow_constructible<error_type, Args...>)
: base{_, static_cast<Args &&>(args)...}
{
no_value_policy_type::on_result_in_place_construction(this, in_place_type<error_type>, static_cast<Args &&>(args)...);
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class U, class... Args)
OUTCOME_TREQUIRES(OUTCOME_TPRED(predicate::template enable_inplace_error_constructor<std::initializer_list<U>, Args...>))
constexpr explicit basic_result(in_place_type_t<error_type_if_enabled> _, std::initializer_list<U> il,
Args &&...args) noexcept(detail::is_nothrow_constructible<error_type, std::initializer_list<U>, Args...>)
: base{_, il, static_cast<Args &&>(args)...}
{
no_value_policy_type::on_result_in_place_construction(this, in_place_type<error_type>, il, static_cast<Args &&>(args)...);
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class A1, class A2, class... Args)
OUTCOME_TREQUIRES(OUTCOME_TPRED(predicate::template enable_inplace_value_error_constructor<A1, A2, Args...>))
constexpr basic_result(A1 &&a1, A2 &&a2, Args &&...args) noexcept(noexcept(
typename predicate::template choose_inplace_value_error_constructor<A1, A2, Args...>(std::declval<A1>(), std::declval<A2>(), std::declval<Args>()...)))
: basic_result(in_place_type<typename predicate::template choose_inplace_value_error_constructor<A1, A2, Args...>>, static_cast<A1 &&>(a1),
static_cast<A2 &&>(a2), static_cast<Args &&>(args)...)
{
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
constexpr basic_result(const success_type<void> &o) noexcept(std::is_nothrow_default_constructible<value_type>::value) // NOLINT
: base{in_place_type<value_type_if_enabled>}
{
hooks::set_spare_storage(this, o.spare_storage());
no_value_policy_type::on_result_copy_construction(this, o);
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class T)
OUTCOME_TREQUIRES(OUTCOME_TPRED(predicate::template enable_compatible_conversion<T, void, void>))
constexpr basic_result(const success_type<T> &o) noexcept(detail::is_nothrow_constructible<value_type, T>) // NOLINT
: base{in_place_type<value_type_if_enabled>, detail::extract_value_from_success<value_type>(o)}
{
hooks::set_spare_storage(this, o.spare_storage());
no_value_policy_type::on_result_copy_construction(this, o);
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class T)
OUTCOME_TREQUIRES(OUTCOME_TPRED(!std::is_void<T>::value && predicate::template enable_compatible_conversion<T, void, void>))
constexpr basic_result(success_type<T> &&o) noexcept(detail::is_nothrow_constructible<value_type, T>) // NOLINT
: base{in_place_type<value_type_if_enabled>, detail::extract_value_from_success<value_type>(static_cast<success_type<T> &&>(o))}
{
hooks::set_spare_storage(this, o.spare_storage());
no_value_policy_type::on_result_move_construction(this, static_cast<success_type<T> &&>(o));
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class T)
OUTCOME_TREQUIRES(OUTCOME_TPRED(predicate::template enable_compatible_conversion<void, T, void>))
constexpr basic_result(const failure_type<T> &o, explicit_compatible_copy_conversion_tag /*unused*/ = explicit_compatible_copy_conversion_tag()) noexcept(
detail::is_nothrow_constructible<error_type, T>) // NOLINT
: base{in_place_type<error_type_if_enabled>, detail::extract_error_from_failure<error_type>(o)}
{
hooks::set_spare_storage(this, o.spare_storage());
no_value_policy_type::on_result_copy_construction(this, o);
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class T)
OUTCOME_TREQUIRES(OUTCOME_TPRED(predicate::template enable_compatible_conversion<void, T, void>))
constexpr basic_result(failure_type<T> &&o, explicit_compatible_move_conversion_tag /*unused*/ = explicit_compatible_move_conversion_tag()) noexcept(
detail::is_nothrow_constructible<error_type, T>) // NOLINT
: base{in_place_type<error_type_if_enabled>, detail::extract_error_from_failure<error_type>(static_cast<failure_type<T> &&>(o))}
{
hooks::set_spare_storage(this, o.spare_storage());
no_value_policy_type::on_result_move_construction(this, static_cast<failure_type<T> &&>(o));
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class T)
OUTCOME_TREQUIRES(OUTCOME_TPRED(predicate::template enable_make_error_code_compatible_conversion<void, T, void>))
constexpr basic_result(const failure_type<T> &o,
explicit_make_error_code_compatible_copy_conversion_tag /*unused*/ =
explicit_make_error_code_compatible_copy_conversion_tag()) noexcept(noexcept(make_error_code(std::declval<T>()))) // NOLINT
: base{in_place_type<error_type_if_enabled>, make_error_code(detail::extract_error_from_failure<error_type>(o))}
{
hooks::set_spare_storage(this, o.spare_storage());
no_value_policy_type::on_result_copy_construction(this, o);
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class T)
OUTCOME_TREQUIRES(OUTCOME_TPRED(predicate::template enable_make_error_code_compatible_conversion<void, T, void>))
constexpr basic_result(failure_type<T> &&o,
explicit_make_error_code_compatible_move_conversion_tag /*unused*/ =
explicit_make_error_code_compatible_move_conversion_tag()) noexcept(noexcept(make_error_code(std::declval<T>()))) // NOLINT
: base{in_place_type<error_type_if_enabled>, make_error_code(detail::extract_error_from_failure<error_type>(static_cast<failure_type<T> &&>(o)))}
{
hooks::set_spare_storage(this, o.spare_storage());
no_value_policy_type::on_result_move_construction(this, static_cast<failure_type<T> &&>(o));
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class T)
OUTCOME_TREQUIRES(OUTCOME_TPRED(predicate::template enable_make_exception_ptr_compatible_conversion<void, T, void>))
constexpr basic_result(const failure_type<T> &o,
explicit_make_exception_ptr_compatible_copy_conversion_tag /*unused*/ =
explicit_make_exception_ptr_compatible_copy_conversion_tag()) noexcept(noexcept(make_exception_ptr(std::declval<T>()))) // NOLINT
: base{in_place_type<error_type_if_enabled>, make_exception_ptr(detail::extract_error_from_failure<error_type>(o))}
{
hooks::set_spare_storage(this, o.spare_storage());
no_value_policy_type::on_result_copy_construction(this, o);
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class T)
OUTCOME_TREQUIRES(OUTCOME_TPRED(predicate::template enable_make_exception_ptr_compatible_conversion<void, T, void>))
constexpr basic_result(failure_type<T> &&o,
explicit_make_exception_ptr_compatible_move_conversion_tag /*unused*/ =
explicit_make_exception_ptr_compatible_move_conversion_tag()) noexcept(noexcept(make_exception_ptr(std::declval<T>()))) // NOLINT
: base{in_place_type<error_type_if_enabled>, make_exception_ptr(detail::extract_error_from_failure<error_type>(static_cast<failure_type<T> &&>(o)))}
{
hooks::set_spare_storage(this, o.spare_storage());
no_value_policy_type::on_result_move_construction(this, static_cast<failure_type<T> &&>(o));
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
constexpr void swap(basic_result &o) noexcept((std::is_void<value_type>::value || detail::is_nothrow_swappable<value_type>::value) //
&& (std::is_void<error_type>::value || detail::is_nothrow_swappable<error_type>::value))
{
this->_state.swap(o._state);
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
auto as_failure() const & { return failure(this->assume_error(), hooks::spare_storage(this)); }
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
auto as_failure() &&
{
this->_state._status.set_have_moved_from(true);
return failure(static_cast<basic_result &&>(*this).assume_error(), hooks::spare_storage(this));
}
#ifdef __APPLE__
failure_type<error_type> _xcode_workaround_as_failure() &&;
#endif
};
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
template <class R, class S, class P> inline void swap(basic_result<R, S, P> &a, basic_result<R, S, P> &b) noexcept(noexcept(a.swap(b)))
{
a.swap(b);
}
#if !defined(NDEBUG)
// Check is trivial in all ways except default constructibility
// static_assert(std::is_trivial<basic_result<int, long, policy::all_narrow>>::value, "result<int> is not trivial!");
// static_assert(std::is_trivially_default_constructible<basic_result<int, long, policy::all_narrow>>::value, "result<int> is not trivially default
// constructible!");
static_assert(std::is_trivially_copyable<basic_result<int, long, policy::all_narrow>>::value, "result<int> is not trivially copyable!");
static_assert(std::is_trivially_assignable<basic_result<int, long, policy::all_narrow>, basic_result<int, long, policy::all_narrow>>::value,
"result<int> is not trivially assignable!");
static_assert(std::is_trivially_destructible<basic_result<int, long, policy::all_narrow>>::value, "result<int> is not trivially destructible!");
static_assert(std::is_trivially_copy_constructible<basic_result<int, long, policy::all_narrow>>::value, "result<int> is not trivially copy constructible!");
static_assert(std::is_trivially_move_constructible<basic_result<int, long, policy::all_narrow>>::value, "result<int> is not trivially move constructible!");
static_assert(std::is_trivially_copy_assignable<basic_result<int, long, policy::all_narrow>>::value, "result<int> is not trivially copy assignable!");
static_assert(std::is_trivially_move_assignable<basic_result<int, long, policy::all_narrow>>::value, "result<int> is not trivially move assignable!");
// Also check is standard layout
static_assert(std::is_standard_layout<basic_result<int, long, policy::all_narrow>>::value, "result<int> is not a standard layout type!");
#endif
OUTCOME_V2_NAMESPACE_END
#ifdef __clang__
#pragma clang diagnostic pop
#endif
#endif
/* Traits for Outcome
(C) 2018-2019 Niall Douglas <http://www.nedproductions.biz/> (6 commits)
File Created: March 2018
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License in the accompanying file
Licence.txt or at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Distributed under the Boost Software License, Version 1.0.
(See accompanying file Licence.txt or copy at
http://www.boost.org/LICENSE_1_0.txt)
*/
#ifndef OUTCOME_TRAIT_STD_ERROR_CODE_HPP
#define OUTCOME_TRAIT_STD_ERROR_CODE_HPP
#include <system_error>
OUTCOME_V2_NAMESPACE_BEGIN
namespace detail
{
// Customise _set_error_is_errno
template <class State> constexpr inline void _set_error_is_errno(State &state, const std::error_code &error)
{
if(error.category() == std::generic_category()
#ifndef _WIN32
|| error.category() == std::system_category()
#endif
)
{
state._status.set_have_error_is_errno(true);
}
}
template <class State> constexpr inline void _set_error_is_errno(State &state, const std::error_condition &error)
{
if(error.category() == std::generic_category()
#ifndef _WIN32
|| error.category() == std::system_category()
#endif
)
{
state._status.set_have_error_is_errno(true);
}
}
template <class State> constexpr inline void _set_error_is_errno(State &state, const std::errc & /*unused*/) {
state._status.set_have_error_is_errno(true);
}
} // namespace detail
namespace policy
{
namespace detail
{
/* Pass through `make_error_code` function for `std::error_code`.
*/
inline std::error_code make_error_code(std::error_code v) { return v; }
// Try ADL, if not use fall backs above
template <class T> constexpr inline decltype(auto) error_code(T &&v) { return make_error_code(std::forward<T>(v)); }
struct std_enum_overload_tag
{
};
} // namespace detail
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
template <class T> constexpr inline decltype(auto) error_code(T &&v) { return detail::error_code(std::forward<T>(v)); }
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
// inline void outcome_throw_as_system_error_with_payload(...) = delete; // To use the error_code_throw_as_system_error policy with a custom Error type, you must define a outcome_throw_as_system_error_with_payload() free function to say how to handle the payload
inline void outcome_throw_as_system_error_with_payload(const std::error_code &error) { OUTCOME_THROW_EXCEPTION(std::system_error(error)); } // NOLINT
OUTCOME_TEMPLATE(class Error)
OUTCOME_TREQUIRES(OUTCOME_TPRED(std::is_error_code_enum<std::decay_t<Error>>::value || std::is_error_condition_enum<std::decay_t<Error>>::value))
inline void outcome_throw_as_system_error_with_payload(Error &&error, detail::std_enum_overload_tag /*unused*/ = detail::std_enum_overload_tag()) { OUTCOME_THROW_EXCEPTION(std::system_error(make_error_code(error))); } // NOLINT
} // namespace policy
namespace trait
{
namespace detail
{
template <> struct _is_error_code_available<std::error_code>
{
// Shortcut this for lower build impact
static constexpr bool value = true;
using type = std::error_code;
};
} // namespace detail
// std::error_code is an error type
template <> struct is_error_type<std::error_code>
{
static constexpr bool value = true;
};
// For std::error_code, std::is_error_condition_enum<> is the trait we want.
template <class Enum> struct is_error_type_enum<std::error_code, Enum>
{
static constexpr bool value = std::is_error_condition_enum<Enum>::value;
};
} // namespace trait
OUTCOME_V2_NAMESPACE_END
#endif
/* Traits for Outcome
(C) 2018-2019 Niall Douglas <http://www.nedproductions.biz/> (3 commits)
File Created: March 2018
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License in the accompanying file
Licence.txt or at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Distributed under the Boost Software License, Version 1.0.
(See accompanying file Licence.txt or copy at
http://www.boost.org/LICENSE_1_0.txt)
*/
#ifndef OUTCOME_TRAIT_STD_EXCEPTION_HPP
#define OUTCOME_TRAIT_STD_EXCEPTION_HPP
#include <exception>
OUTCOME_V2_NAMESPACE_BEGIN
namespace policy
{
namespace detail
{
/* Pass through `make_exception_ptr` function for `std::exception_ptr`.
*/
inline std::exception_ptr make_exception_ptr(std::exception_ptr v) { return v; }
// Try ADL, if not use fall backs above
template <class T> constexpr inline decltype(auto) exception_ptr(T &&v) { return make_exception_ptr(std::forward<T>(v)); }
} // namespace detail
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
template <class T> constexpr inline decltype(auto) exception_ptr(T &&v) { return detail::exception_ptr(std::forward<T>(v)); }
namespace detail
{
template <bool has_error_payload> struct _rethrow_exception
{
template <class Exception> explicit _rethrow_exception(Exception && /*unused*/) // NOLINT
{
}
};
template <> struct _rethrow_exception<true>
{
template <class Exception> explicit _rethrow_exception(Exception &&excpt) // NOLINT
{
// ADL
rethrow_exception(policy::exception_ptr(std::forward<Exception>(excpt)));
}
};
} // namespace detail
} // namespace policy
namespace trait
{
namespace detail
{
// Shortcut this for lower build impact
template <> struct _is_exception_ptr_available<std::exception_ptr>
{
static constexpr bool value = true;
using type = std::exception_ptr;
};
} // namespace detail
// std::exception_ptr is an error type
template <> struct is_error_type<std::exception_ptr>
{
static constexpr bool value = true;
};
} // namespace trait
OUTCOME_V2_NAMESPACE_END
#endif
/* Policies for result and outcome
(C) 2018-2019 Niall Douglas <http://www.nedproductions.biz/> (4 commits)
File Created: Sep 2018
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License in the accompanying file
Licence.txt or at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Distributed under the Boost Software License, Version 1.0.
(See accompanying file Licence.txt or copy at
http://www.boost.org/LICENSE_1_0.txt)
*/
#ifndef OUTCOME_POLICY_FAIL_TO_COMPILE_OBSERVERS_HPP
#define OUTCOME_POLICY_FAIL_TO_COMPILE_OBSERVERS_HPP
OUTCOME_V2_NAMESPACE_EXPORT_BEGIN
#define OUTCOME_FAIL_TO_COMPILE_OBSERVERS_MESSAGE "Attempt to wide observe value, error or " "exception for a basic_result/basic_outcome given an EC or EP type which is not void, and for whom " "trait::is_error_code_available<EC>, trait::is_exception_ptr_available<EC>, and trait::is_exception_ptr_available<EP> " "are all false. Please specify a NoValuePolicy to tell basic_result/basic_outcome what to do, or else use " "a more specific convenience type alias such as unchecked<T, E> to indicate you want the wide " "observers to be narrow, or checked<T, E> to indicate you always want an exception throw etc."
namespace policy
{
struct fail_to_compile_observers : base
{
template <class Impl> static constexpr void wide_value_check(Impl && /* unused */) { static_assert(!std::is_same<Impl, Impl>::value, "Attempt to wide observe value, error or " "exception for a basic_result/basic_outcome given an EC or EP type which is not void, and for whom " "trait::is_error_code_available<EC>, trait::is_exception_ptr_available<EC>, and trait::is_exception_ptr_available<EP> " "are all false. Please specify a NoValuePolicy to tell basic_result/basic_outcome what to do, or else use " "a more specific convenience type alias such as unchecked<T, E> to indicate you want the wide " "observers to be narrow, or checked<T, E> to indicate you always want an exception throw etc."); }
template <class Impl> static constexpr void wide_error_check(Impl && /* unused */) { static_assert(!std::is_same<Impl, Impl>::value, "Attempt to wide observe value, error or " "exception for a basic_result/basic_outcome given an EC or EP type which is not void, and for whom " "trait::is_error_code_available<EC>, trait::is_exception_ptr_available<EC>, and trait::is_exception_ptr_available<EP> " "are all false. Please specify a NoValuePolicy to tell basic_result/basic_outcome what to do, or else use " "a more specific convenience type alias such as unchecked<T, E> to indicate you want the wide " "observers to be narrow, or checked<T, E> to indicate you always want an exception throw etc."); }
template <class Impl> static constexpr void wide_exception_check(Impl && /* unused */) { static_assert(!std::is_same<Impl, Impl>::value, "Attempt to wide observe value, error or " "exception for a basic_result/basic_outcome given an EC or EP type which is not void, and for whom " "trait::is_error_code_available<EC>, trait::is_exception_ptr_available<EC>, and trait::is_exception_ptr_available<EP> " "are all false. Please specify a NoValuePolicy to tell basic_result/basic_outcome what to do, or else use " "a more specific convenience type alias such as unchecked<T, E> to indicate you want the wide " "observers to be narrow, or checked<T, E> to indicate you always want an exception throw etc."); }
};
} // namespace policy
#undef OUTCOME_FAIL_TO_COMPILE_OBSERVERS_MESSAGE
OUTCOME_V2_NAMESPACE_END
#endif
/* Policies for result and outcome
(C) 2017-2019 Niall Douglas <http://www.nedproductions.biz/> (8 commits)
File Created: Oct 2017
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License in the accompanying file
Licence.txt or at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Distributed under the Boost Software License, Version 1.0.
(See accompanying file Licence.txt or copy at
http://www.boost.org/LICENSE_1_0.txt)
*/
#ifndef OUTCOME_POLICY_RESULT_ERROR_CODE_THROW_AS_SYSTEM_ERROR_HPP
#define OUTCOME_POLICY_RESULT_ERROR_CODE_THROW_AS_SYSTEM_ERROR_HPP
/* Exception types throwable
(C) 2017-2019 Niall Douglas <http://www.nedproductions.biz/> (9 commits)
File Created: Oct 2017
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License in the accompanying file
Licence.txt or at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Distributed under the Boost Software License, Version 1.0.
(See accompanying file Licence.txt or copy at
http://www.boost.org/LICENSE_1_0.txt)
*/
#ifndef OUTCOME_BAD_ACCESS_HPP
#define OUTCOME_BAD_ACCESS_HPP
#include <stdexcept>
OUTCOME_V2_NAMESPACE_EXPORT_BEGIN
/*! AWAITING HUGO JSON CONVERSION TOOL
type definition bad_result_access. Potential doc page: `bad_result_access`
*/
class OUTCOME_SYMBOL_VISIBLE bad_result_access : public std::logic_error
{
public:
explicit bad_result_access(const char *what)
: std::logic_error(what)
{
}
};
/*! AWAITING HUGO JSON CONVERSION TOOL
type definition template <class S> bad_result_access_with. Potential doc page: `bad_result_access_with<EC>`
*/
template <class S> class OUTCOME_SYMBOL_VISIBLE bad_result_access_with : public bad_result_access
{
S _error;
public:
explicit bad_result_access_with(S v)
: bad_result_access("no value")
, _error(std::move(v))
{
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
const S &error() const & { return _error; }
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
S &error() & { return _error; }
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
const S &&error() const && { return _error; }
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
S &&error() && { return _error; }
};
/*! AWAITING HUGO JSON CONVERSION TOOL
type definition bad_outcome_access. Potential doc page: `bad_outcome_access`
*/
class OUTCOME_SYMBOL_VISIBLE bad_outcome_access : public std::logic_error
{
public:
explicit bad_outcome_access(const char *what)
: std::logic_error(what)
{
}
};
OUTCOME_V2_NAMESPACE_END
#endif
#include <system_error>
OUTCOME_V2_NAMESPACE_EXPORT_BEGIN
namespace policy
{
template <class T, class EC, class E> struct error_code_throw_as_system_error;
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
template <class T, class EC> struct error_code_throw_as_system_error<T, EC, void> : base
{
template <class Impl> static constexpr void wide_value_check(Impl &&self)
{
if(!base::_has_value(std::forward<Impl>(self)))
{
if(base::_has_error(std::forward<Impl>(self)))
{
// ADL discovered
outcome_throw_as_system_error_with_payload(base::_error(std::forward<Impl>(self)));
}
OUTCOME_THROW_EXCEPTION(bad_result_access("no value")); // NOLINT
}
}
template <class Impl> static constexpr void wide_error_check(Impl &&self)
{
if(!base::_has_error(std::forward<Impl>(self)))
{
OUTCOME_THROW_EXCEPTION(bad_result_access("no error")); // NOLINT
}
}
};
} // namespace policy
OUTCOME_V2_NAMESPACE_END
#endif
/* Policies for result and outcome
(C) 2017-2019 Niall Douglas <http://www.nedproductions.biz/> (6 commits)
File Created: Oct 2017
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License in the accompanying file
Licence.txt or at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Distributed under the Boost Software License, Version 1.0.
(See accompanying file Licence.txt or copy at
http://www.boost.org/LICENSE_1_0.txt)
*/
#ifndef OUTCOME_POLICY_RESULT_EXCEPTION_PTR_RETHROW_HPP
#define OUTCOME_POLICY_RESULT_EXCEPTION_PTR_RETHROW_HPP
OUTCOME_V2_NAMESPACE_EXPORT_BEGIN
namespace policy
{
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
template <class T, class EC, class E> struct exception_ptr_rethrow;
template <class T, class EC> struct exception_ptr_rethrow<T, EC, void> : base
{
template <class Impl> static constexpr void wide_value_check(Impl &&self)
{
if(!base::_has_value(std::forward<Impl>(self)))
{
if(base::_has_error(std::forward<Impl>(self)))
{
// ADL
rethrow_exception(policy::exception_ptr(base::_error(std::forward<Impl>(self))));
}
OUTCOME_THROW_EXCEPTION(bad_result_access("no value")); // NOLINT
}
}
template <class Impl> static constexpr void wide_error_check(Impl &&self)
{
if(!base::_has_error(std::forward<Impl>(self)))
{
OUTCOME_THROW_EXCEPTION(bad_result_access("no error")); // NOLINT
}
}
};
} // namespace policy
OUTCOME_V2_NAMESPACE_END
#endif
/* Policies for result and outcome
(C) 2017-2019 Niall Douglas <http://www.nedproductions.biz/> (13 commits)
File Created: Oct 2017
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License in the accompanying file
Licence.txt or at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Distributed under the Boost Software License, Version 1.0.
(See accompanying file Licence.txt or copy at
http://www.boost.org/LICENSE_1_0.txt)
*/
#ifndef OUTCOME_POLICY_THROW_BAD_RESULT_ACCESS_HPP
#define OUTCOME_POLICY_THROW_BAD_RESULT_ACCESS_HPP
OUTCOME_V2_NAMESPACE_EXPORT_BEGIN
namespace policy
{
/*! AWAITING HUGO JSON CONVERSION TOOL
type definition throw_bad_result_access. Potential doc page: NOT FOUND
*/
template <class EC, class EP> struct throw_bad_result_access : base
{
template <class Impl> static constexpr void wide_value_check(Impl &&self)
{
if(!base::_has_value(std::forward<Impl>(self)))
{
OUTCOME_THROW_EXCEPTION(bad_outcome_access("no value")); // NOLINT
}
}
template <class Impl> static constexpr void wide_error_check(Impl &&self)
{
if(!base::_has_error(std::forward<Impl>(self)))
{
OUTCOME_THROW_EXCEPTION(bad_outcome_access("no error")); // NOLINT
}
}
template <class Impl> static constexpr void wide_exception_check(Impl &&self)
{
if(!base::_has_exception(std::forward<Impl>(self)))
{
OUTCOME_THROW_EXCEPTION(bad_outcome_access("no exception")); // NOLINT
}
}
};
template <class EC> struct throw_bad_result_access<EC, void> : base
{
template <class Impl> static constexpr void wide_value_check(Impl &&self)
{
if(!base::_has_value(std::forward<Impl>(self)))
{
if(base::_has_error(std::forward<Impl>(self)))
{
OUTCOME_THROW_EXCEPTION(bad_result_access_with<EC>(base::_error(std::forward<Impl>(self))));
}
OUTCOME_THROW_EXCEPTION(bad_result_access("no value")); // NOLINT
}
}
template <class Impl> static constexpr void wide_error_check(Impl &&self)
{
if(!base::_has_error(std::forward<Impl>(self)))
{
OUTCOME_THROW_EXCEPTION(bad_result_access("no error")); // NOLINT
}
}
};
} // namespace policy
OUTCOME_V2_NAMESPACE_END
#endif
OUTCOME_V2_NAMESPACE_EXPORT_BEGIN
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
namespace policy
{
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
template <class T, class EC, class E>
using default_policy = std::conditional_t< //
std::is_void<EC>::value && std::is_void<E>::value,
terminate, //
std::conditional_t< //
trait::is_error_code_available<EC>::value, error_code_throw_as_system_error<T, EC, E>, //
std::conditional_t< //
trait::is_exception_ptr_available<EC>::value || trait::is_exception_ptr_available<E>::value, exception_ptr_rethrow<T, EC, E>, //
fail_to_compile_observers //
>>>;
} // namespace policy
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
template <class R, class S = std::error_code, class NoValuePolicy = policy::default_policy<R, S, void>> //
using std_result = basic_result<R, S, NoValuePolicy>;
/*! AWAITING HUGO JSON CONVERSION TOOL
type alias template <class R, class S = std::error_code> std_unchecked. Potential doc page: `std_unchecked<T, E = std::error_code>`
*/
template <class R, class S = std::error_code> using std_unchecked = std_result<R, S, policy::all_narrow>;
/*! AWAITING HUGO JSON CONVERSION TOOL
type alias template <class R, class S = std::error_code> std_checked. Potential doc page: `std_checked<T, E = std::error_code>`
*/
template <class R, class S = std::error_code> using std_checked = std_result<R, S, policy::throw_bad_result_access<S, void>>;
OUTCOME_V2_NAMESPACE_END
#endif
OUTCOME_V2_NAMESPACE_EXPORT_BEGIN
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
template <class R, class S = std::error_code, class NoValuePolicy = policy::default_policy<R, S, void>> //
using result = std_result<R, S, NoValuePolicy>;
/*! AWAITING HUGO JSON CONVERSION TOOL
type alias template <class R, class S = std::error_code> unchecked. Potential doc page: `unchecked<T, E = varies>`
*/
template <class R, class S = std::error_code> using unchecked = result<R, S, policy::all_narrow>;
/*! AWAITING HUGO JSON CONVERSION TOOL
type alias template <class R, class S = std::error_code> checked. Potential doc page: `checked<T, E = varies>`
*/
template <class R, class S = std::error_code> using checked = result<R, S, policy::throw_bad_result_access<S, void>>;
OUTCOME_V2_NAMESPACE_END
#endif
/* A less simple result type
(C) 2017-2019 Niall Douglas <http://www.nedproductions.biz/> (6 commits)
File Created: June 2017
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License in the accompanying file
Licence.txt or at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Distributed under the Boost Software License, Version 1.0.
(See accompanying file Licence.txt or copy at
http://www.boost.org/LICENSE_1_0.txt)
*/
#ifndef OUTCOME_STD_OUTCOME_HPP
#define OUTCOME_STD_OUTCOME_HPP
/* A less simple result type
(C) 2017-2024 Niall Douglas <http://www.nedproductions.biz/> (20 commits)
File Created: June 2017
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License in the accompanying file
Licence.txt or at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Distributed under the Boost Software License, Version 1.0.
(See accompanying file Licence.txt or copy at
http://www.boost.org/LICENSE_1_0.txt)
*/
#ifndef OUTCOME_BASIC_OUTCOME_HPP
#define OUTCOME_BASIC_OUTCOME_HPP
/* Exception observers for outcome type
(C) 2017-2019 Niall Douglas <http://www.nedproductions.biz/> (3 commits)
File Created: Oct 2017
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License in the accompanying file
Licence.txt or at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Distributed under the Boost Software License, Version 1.0.
(See accompanying file Licence.txt or copy at
http://www.boost.org/LICENSE_1_0.txt)
*/
#ifndef OUTCOME_BASIC_OUTCOME_EXCEPTION_OBSERVERS_HPP
#define OUTCOME_BASIC_OUTCOME_EXCEPTION_OBSERVERS_HPP
OUTCOME_V2_NAMESPACE_EXPORT_BEGIN
namespace detail
{
template <class Base, class R, class S, class P, class NoValuePolicy> class basic_outcome_exception_observers : public Base
{
public:
using exception_type = P;
using Base::Base;
constexpr inline exception_type &assume_exception() & noexcept;
constexpr inline const exception_type &assume_exception() const & noexcept;
constexpr inline exception_type &&assume_exception() && noexcept;
constexpr inline const exception_type &&assume_exception() const && noexcept;
constexpr inline exception_type &exception() &;
constexpr inline const exception_type &exception() const &;
constexpr inline exception_type &&exception() &&;
constexpr inline const exception_type &&exception() const &&;
};
// Exception observers not present
template <class Base, class R, class S, class NoValuePolicy> class basic_outcome_exception_observers<Base, R, S, void, NoValuePolicy> : public Base
{
public:
using Base::Base;
constexpr void assume_exception() & noexcept { NoValuePolicy::narrow_exception_check(*this); }
constexpr void assume_exception() const & noexcept { NoValuePolicy::narrow_exception_check(*this); }
constexpr void assume_exception() && noexcept { NoValuePolicy::narrow_exception_check(std::move(*this)); }
constexpr void assume_exception() const && noexcept { NoValuePolicy::narrow_exception_check(std::move(*this)); }
constexpr void exception() & { NoValuePolicy::wide_exception_check(*this); }
constexpr void exception() const & { NoValuePolicy::wide_exception_check(*this); }
constexpr void exception() && { NoValuePolicy::wide_exception_check(std::move(*this)); }
constexpr void exception() const && { NoValuePolicy::wide_exception_check(std::move(*this)); }
};
} // namespace detail
OUTCOME_V2_NAMESPACE_END
#endif
/* Failure observers for outcome type
(C) 2017-2019 Niall Douglas <http://www.nedproductions.biz/> (7 commits)
File Created: Oct 2017
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License in the accompanying file
Licence.txt or at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Distributed under the Boost Software License, Version 1.0.
(See accompanying file Licence.txt or copy at
http://www.boost.org/LICENSE_1_0.txt)
*/
#ifndef OUTCOME_BASIC_OUTCOME_FAILURE_OBSERVERS_HPP
#define OUTCOME_BASIC_OUTCOME_FAILURE_OBSERVERS_HPP
#include <exception>
OUTCOME_V2_NAMESPACE_EXPORT_BEGIN
namespace detail
{
namespace adl
{
struct search_detail_adl
{
};
// Do NOT use template requirements here!
template <class S, typename = decltype(basic_outcome_failure_exception_from_error(std::declval<S>()))>
inline auto _delayed_lookup_basic_outcome_failure_exception_from_error(const S &ec, search_detail_adl /*unused*/)
{
// ADL discovered
return basic_outcome_failure_exception_from_error(ec);
}
} // namespace adl
#if defined(_MSC_VER) && _MSC_VER <= 1923 // VS2019
// VS2017 and VS2019 with /permissive- chokes on the correct form due to over eager early instantiation.
template <class S, class P> inline void _delayed_lookup_basic_outcome_failure_exception_from_error(...) { static_assert(sizeof(S) == 0, "No specialisation for these error and exception types available!"); }
#else
template <class S, class P> inline void _delayed_lookup_basic_outcome_failure_exception_from_error(...) = delete; // NOLINT No specialisation for these error and exception types available!
#endif
template <class exception_type> inline exception_type current_exception_or_fatal(std::exception_ptr e) { std::rethrow_exception(e); }
template <> inline std::exception_ptr current_exception_or_fatal<std::exception_ptr>(std::exception_ptr e) { return e; }
template <class Base, class R, class S, class P, class NoValuePolicy> class basic_outcome_failure_observers : public Base
{
public:
using exception_type = P;
using Base::Base;
exception_type failure() const noexcept
{
#ifdef __cpp_exceptions
try
#endif
{
if(this->_state._status.have_exception())
{
return this->assume_exception();
}
if(this->_state._status.have_error())
{
return _delayed_lookup_basic_outcome_failure_exception_from_error(this->assume_error(), adl::search_detail_adl());
}
return exception_type();
}
#ifdef __cpp_exceptions
catch(...)
{
// Return the failure if exception_type is std::exception_ptr,
// otherwise terminate same as throwing an exception inside noexcept
return current_exception_or_fatal<exception_type>(std::current_exception());
}
#endif
}
};
} // namespace detail
OUTCOME_V2_NAMESPACE_END
#endif
#ifdef __clang__
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdocumentation" // Standardese markup confuses clang
#endif
OUTCOME_V2_NAMESPACE_EXPORT_BEGIN
template <class R, class S, class P, class NoValuePolicy> //
class basic_outcome;
namespace detail
{
// May be reused by basic_outcome subclasses to save load on the compiler
template <class value_type, class error_type, class exception_type> struct outcome_predicates
{
using result = result_predicates<value_type, error_type>;
// Predicate for the implicit constructors to be available
static constexpr bool implicit_constructors_enabled = //
result::implicit_constructors_enabled //
&& !detail::is_implicitly_constructible<value_type, exception_type> //
&& !detail::is_implicitly_constructible<error_type, exception_type> //
&& !detail::is_implicitly_constructible<exception_type, value_type> //
&& !detail::is_implicitly_constructible<exception_type, error_type>;
// Predicate for the value converting constructor to be available.
template <class T>
static constexpr bool enable_value_converting_constructor = //
implicit_constructors_enabled //
&& result::template enable_value_converting_constructor<T> //
&& !detail::is_implicitly_constructible<exception_type, T>; // deliberately less tolerant of ambiguity than result's edition
// Predicate for the error converting constructor to be available.
template <class T>
static constexpr bool enable_error_converting_constructor = //
implicit_constructors_enabled //
&& result::template enable_error_converting_constructor<T> //
&& !detail::is_implicitly_constructible<exception_type, T>; // deliberately less tolerant of ambiguity than result's edition
// Predicate for the error condition converting constructor to be available.
template <class ErrorCondEnum>
static constexpr bool enable_error_condition_converting_constructor = result::template enable_error_condition_converting_constructor<ErrorCondEnum> //
&& !detail::is_implicitly_constructible<exception_type, ErrorCondEnum>;
// Predicate for the exception converting constructor to be available.
template <class T>
static constexpr bool enable_exception_converting_constructor = //
implicit_constructors_enabled //
&& !is_in_place_type_t<std::decay_t<T>>::value // not in place construction
&& !detail::is_implicitly_constructible<value_type, T> && !detail::is_implicitly_constructible<error_type, T> &&
detail::is_implicitly_constructible<exception_type, T>;
// Predicate for the error + exception converting constructor to be available.
template <class T, class U>
static constexpr bool enable_error_exception_converting_constructor = //
implicit_constructors_enabled //
&& !is_in_place_type_t<std::decay_t<T>>::value // not in place construction
&& !detail::is_implicitly_constructible<value_type, T> && detail::is_implicitly_constructible<error_type, T> //
&& !detail::is_implicitly_constructible<value_type, U> && detail::is_implicitly_constructible<exception_type, U>;
// Predicate for the converting copy constructor from a compatible outcome to be available.
template <class T, class U, class V, class W>
static constexpr bool enable_compatible_conversion = //
(std::is_void<T>::value ||
detail::is_explicitly_constructible<value_type, typename basic_outcome<T, U, V, W>::value_type>) // if our value types are constructible
&&(std::is_void<U>::value ||
detail::is_explicitly_constructible<error_type, typename basic_outcome<T, U, V, W>::error_type>) // if our error types are constructible
&&(std::is_void<V>::value ||
detail::is_explicitly_constructible<exception_type, typename basic_outcome<T, U, V, W>::exception_type>) // if our exception types are constructible
;
// Predicate for the converting constructor from a make_error_code() of the input to be available.
template <class T, class U, class V, class W>
static constexpr bool enable_make_error_code_compatible_conversion = //
trait::is_error_code_available<std::decay_t<error_type>>::value // if error type has an error code
&& !enable_compatible_conversion<T, U, V, W> // and the normal compatible conversion is not available
&& (std::is_void<T>::value ||
detail::is_explicitly_constructible<value_type, typename basic_outcome<T, U, V, W>::value_type>) // and if our value types are constructible
&&detail::is_explicitly_constructible<error_type,
typename trait::is_error_code_available<U>::type> // and our error type is constructible from a make_error_code()
&& (std::is_void<V>::value ||
detail::is_explicitly_constructible<exception_type, typename basic_outcome<T, U, V, W>::exception_type>); // and our exception types are constructible
// Predicate for the implicit converting inplace constructor from a compatible input to be available.
struct disable_inplace_value_error_exception_constructor;
template <class... Args>
using choose_inplace_value_error_exception_constructor = std::conditional_t< //
((static_cast<int>(detail::is_constructible<value_type, Args...>) + static_cast<int>(detail::is_constructible<error_type, Args...>) +
static_cast<int>(detail::is_constructible<exception_type, Args...>)) > 1), //
disable_inplace_value_error_exception_constructor, //
std::conditional_t< //
detail::is_constructible<value_type, Args...>, //
value_type, //
std::conditional_t< //
detail::is_constructible<error_type, Args...>, //
error_type, //
std::conditional_t< //
detail::is_constructible<exception_type, Args...>, //
exception_type, //
disable_inplace_value_error_exception_constructor>>>>;
template <class... Args>
static constexpr bool enable_inplace_value_error_exception_constructor = //
implicit_constructors_enabled &&
!std::is_same<choose_inplace_value_error_exception_constructor<Args...>, disable_inplace_value_error_exception_constructor>::value;
};
// Select whether to use basic_outcome_failure_observers or not
template <class Base, class R, class S, class P, class NoValuePolicy>
using select_basic_outcome_failure_observers = //
std::conditional_t<trait::is_error_code_available<S>::value && trait::is_exception_ptr_available<P>::value,
basic_outcome_failure_observers<Base, R, S, P, NoValuePolicy>, Base>;
template <class T, class U, class V> constexpr inline const V &extract_exception_from_failure(const failure_type<U, V> &v)
{
return v.exception();
}
template <class T, class U, class V> constexpr inline V &&extract_exception_from_failure(failure_type<U, V> &&v)
{
return static_cast<failure_type<U, V> &&>(v).exception();
}
template <class T, class U> constexpr inline const U &extract_exception_from_failure(const failure_type<U, void> &v)
{
return v.error();
}
template <class T, class U> constexpr inline U &&extract_exception_from_failure(failure_type<U, void> &&v)
{
return static_cast<failure_type<U, void> &&>(v).error();
}
template <class T> struct is_basic_outcome
{
static constexpr bool value = false;
};
template <class R, class S, class T, class N> struct is_basic_outcome<basic_outcome<R, S, T, N>>
{
static constexpr bool value = true;
};
} // namespace detail
/*! AWAITING HUGO JSON CONVERSION TOOL
type alias template <class T> is_basic_outcome. Potential doc page: `is_basic_outcome<T>`
*/
template <class T> using is_basic_outcome = detail::is_basic_outcome<std::decay_t<T>>;
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
template <class T> static constexpr bool is_basic_outcome_v = detail::is_basic_outcome<std::decay_t<T>>::value;
namespace concepts
{
#if defined(__cpp_concepts)
/* The `basic_outcome` concept.
\requires That `U` matches a `basic_outcome`.
*/
template <class U>
concept OUTCOME_GCC6_CONCEPT_BOOL basic_outcome =
OUTCOME_V2_NAMESPACE::is_basic_outcome<U>::value ||
(requires(U v) {
OUTCOME_V2_NAMESPACE::basic_outcome<typename U::value_type, typename U::error_type, typename U::exception_type, typename U::no_value_policy_type>(v);
} && //
detail::convertible<
U, OUTCOME_V2_NAMESPACE::basic_outcome<typename U::value_type, typename U::error_type, typename U::exception_type, typename U::no_value_policy_type>> && //
detail::base_of<
OUTCOME_V2_NAMESPACE::basic_outcome<typename U::value_type, typename U::error_type, typename U::exception_type, typename U::no_value_policy_type>, U>);
#else
namespace detail
{
inline no_match match_basic_outcome(...);
template <class R, class S, class P, class NVP, class T, //
typename = typename T::value_type, //
typename = typename T::error_type, //
typename = typename T::exception_type, //
typename = typename T::no_value_policy_type, //
typename std::enable_if_t<std::is_convertible<T, OUTCOME_V2_NAMESPACE::basic_outcome<R, S, P, NVP>>::value && //
std::is_base_of<OUTCOME_V2_NAMESPACE::basic_outcome<R, S, P, NVP>, T>::value,
bool> = true>
inline OUTCOME_V2_NAMESPACE::basic_outcome<R, S, P, NVP> match_basic_outcome(OUTCOME_V2_NAMESPACE::basic_outcome<R, S, P, NVP> &&, T &&);
template <class U>
static constexpr bool basic_outcome =
OUTCOME_V2_NAMESPACE::is_basic_outcome<U>::value ||
!std::is_same<no_match, decltype(match_basic_outcome(std::declval<OUTCOME_V2_NAMESPACE::detail::devoid<U>>(),
std::declval<OUTCOME_V2_NAMESPACE::detail::devoid<U>>()))>::value;
} // namespace detail
/* The `basic_outcome` concept.
\requires That `U` matches a `basic_outcome`.
*/
template <class U> static constexpr bool basic_outcome = detail::basic_outcome<U>;
#endif
} // namespace concepts
namespace hooks
{
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
template <class R, class S, class P, class NoValuePolicy, class U>
constexpr inline void override_outcome_exception(basic_outcome<R, S, P, NoValuePolicy> *o, U &&v) noexcept;
} // namespace hooks
/*! AWAITING HUGO JSON CONVERSION TOOL
type definition template <class R, class S, class P, class NoValuePolicy> basic_outcome. Potential doc page: `basic_outcome<T, EC, EP, NoValuePolicy>`
*/
template <class R, class S, class P, class NoValuePolicy> //
class OUTCOME_NODISCARD basic_outcome
: public detail::select_basic_outcome_failure_observers<
detail::basic_outcome_exception_observers<detail::basic_result_final<R, S, NoValuePolicy>, R, S, P, NoValuePolicy>, R, S, P, NoValuePolicy>
{
static_assert(trait::type_can_be_used_in_basic_result<P>, "The exception_type cannot be used");
static_assert(std::is_void<P>::value || std::is_default_constructible<P>::value, "exception_type must be void or default constructible");
using base = detail::select_basic_outcome_failure_observers<
detail::basic_outcome_exception_observers<detail::basic_result_final<R, S, NoValuePolicy>, R, S, P, NoValuePolicy>, R, S, P, NoValuePolicy>;
friend struct policy::base;
template <class T, class U, class V, class W> //
friend class basic_outcome;
template <class T, class U, class V, class W, class X>
friend constexpr inline void hooks::override_outcome_exception(basic_outcome<T, U, V, W> *o, X &&v) noexcept; // NOLINT
struct implicit_constructors_disabled_tag
{
};
struct value_converting_constructor_tag
{
};
struct error_converting_constructor_tag
{
};
struct error_condition_converting_constructor_tag
{
};
struct exception_converting_constructor_tag
{
};
struct error_exception_converting_constructor_tag
{
};
struct explicit_valueorerror_converting_constructor_tag
{
};
struct explicit_compatible_copy_conversion_tag
{
};
struct explicit_compatible_move_conversion_tag
{
};
struct explicit_make_error_code_compatible_copy_conversion_tag
{
};
struct explicit_make_error_code_compatible_move_conversion_tag
{
};
struct error_failure_tag
{
};
struct exception_failure_tag
{
};
struct disable_in_place_value_type
{
};
struct disable_in_place_error_type
{
};
struct disable_in_place_exception_type
{
};
public:
using value_type = R;
using error_type = S;
using exception_type = P;
using no_value_policy_type = NoValuePolicy;
template <class T, class U = S, class V = P, class W = NoValuePolicy> using rebind = basic_outcome<T, U, V, W>;
protected:
// Requirement predicates for outcome.
struct predicate
{
using base = detail::outcome_predicates<value_type, error_type, exception_type>;
// Predicate for any constructors to be available at all
static constexpr bool constructors_enabled =
(!std::is_same<std::decay_t<value_type>, std::decay_t<error_type>>::value || (std::is_void<value_type>::value && std::is_void<error_type>::value)) //
&& (!std::is_same<std::decay_t<value_type>, std::decay_t<exception_type>>::value ||
(std::is_void<value_type>::value && std::is_void<exception_type>::value)) //
&& (!std::is_same<std::decay_t<error_type>, std::decay_t<exception_type>>::value ||
(std::is_void<error_type>::value && std::is_void<exception_type>::value)) //
;
// Predicate for implicit constructors to be available at all
static constexpr bool implicit_constructors_enabled = constructors_enabled && base::implicit_constructors_enabled;
// Predicate for the value converting constructor to be available.
template <class T>
static constexpr bool enable_value_converting_constructor = //
constructors_enabled //
&& !std::is_same<std::decay_t<T>, basic_outcome>::value // not my type
&& base::template enable_value_converting_constructor<T>;
// Predicate for the error converting constructor to be available.
template <class T>
static constexpr bool enable_error_converting_constructor = //
constructors_enabled //
&& !std::is_same<std::decay_t<T>, basic_outcome>::value // not my type
&& base::template enable_error_converting_constructor<T>;
// Predicate for the error condition converting constructor to be available.
template <class ErrorCondEnum>
static constexpr bool enable_error_condition_converting_constructor = //
constructors_enabled //
&& !std::is_same<std::decay_t<ErrorCondEnum>, basic_outcome>::value // not my type
&& base::template enable_error_condition_converting_constructor<ErrorCondEnum>;
// Predicate for the exception converting constructor to be available.
template <class T>
static constexpr bool enable_exception_converting_constructor = //
constructors_enabled //
&& !std::is_same<std::decay_t<T>, basic_outcome>::value // not my type
&& base::template enable_exception_converting_constructor<T>;
// Predicate for the error + exception converting constructor to be available.
template <class T, class U>
static constexpr bool enable_error_exception_converting_constructor = //
constructors_enabled //
&& !std::is_same<std::decay_t<T>, basic_outcome>::value // not my type
&& base::template enable_error_exception_converting_constructor<T, U>;
// Predicate for the converting constructor from a compatible input to be available.
template <class T, class U, class V, class W>
static constexpr bool enable_compatible_conversion = //
constructors_enabled //
&& !std::is_same<basic_outcome<T, U, V, W>, basic_outcome>::value // not my type
&& base::template enable_compatible_conversion<T, U, V, W>;
// Predicate for the converting constructor from a make_error_code() of the input to be available.
template <class T, class U, class V, class W>
static constexpr bool enable_make_error_code_compatible_conversion = //
constructors_enabled //
&& !std::is_same<basic_outcome<T, U, V, W>, basic_outcome>::value // not my type
&& base::template enable_make_error_code_compatible_conversion<T, U, V, W>;
// Predicate for the inplace construction of value to be available.
template <class... Args>
static constexpr bool enable_inplace_value_constructor = //
constructors_enabled //
&& (std::is_void<value_type>::value //
|| detail::is_constructible<value_type, Args...>);
// Predicate for the inplace construction of error to be available.
template <class... Args>
static constexpr bool enable_inplace_error_constructor = //
constructors_enabled //
&& (std::is_void<error_type>::value //
|| detail::is_constructible<error_type, Args...>);
// Predicate for the inplace construction of exception to be available.
template <class... Args>
static constexpr bool enable_inplace_exception_constructor = //
constructors_enabled //
&& (std::is_void<exception_type>::value //
|| detail::is_constructible<exception_type, Args...>);
// Predicate for the implicit converting inplace constructor to be available.
template <class... Args>
static constexpr bool enable_inplace_value_error_exception_constructor = //
constructors_enabled //
&& base::template enable_inplace_value_error_exception_constructor<Args...>;
template <class... Args>
using choose_inplace_value_error_exception_constructor = typename base::template choose_inplace_value_error_exception_constructor<Args...>;
};
public:
using value_type_if_enabled =
std::conditional_t<std::is_same<value_type, error_type>::value || std::is_same<value_type, exception_type>::value, disable_in_place_value_type, value_type>;
using error_type_if_enabled =
std::conditional_t<std::is_same<error_type, value_type>::value || std::is_same<error_type, exception_type>::value, disable_in_place_error_type, error_type>;
using exception_type_if_enabled = std::conditional_t<std::is_same<exception_type, value_type>::value || std::is_same<exception_type, error_type>::value,
disable_in_place_exception_type, exception_type>;
protected:
detail::devoid<exception_type> _ptr;
public:
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class Arg, class... Args)
OUTCOME_TREQUIRES(OUTCOME_TPRED((!predicate::constructors_enabled && sizeof...(Args) >= 0)))
basic_outcome(Arg && /*unused*/, Args &&.../*unused*/) = delete; // NOLINT basic_outcome<> with any of the same type is NOT SUPPORTED, see docs!
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class T)
OUTCOME_TREQUIRES(OUTCOME_TPRED((predicate::constructors_enabled && !predicate::implicit_constructors_enabled //
&& (detail::is_implicitly_constructible<value_type, T> || detail::is_implicitly_constructible<error_type, T> ||
detail::is_implicitly_constructible<exception_type, T>) )))
basic_outcome(T && /*unused*/, implicit_constructors_disabled_tag /*unused*/ = implicit_constructors_disabled_tag()) =
delete; // NOLINT Implicit constructors disabled, use explicit in_place_type<T>, success() or failure(). see docs!
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class T)
OUTCOME_TREQUIRES(OUTCOME_TPRED(predicate::template enable_value_converting_constructor<T>))
constexpr basic_outcome(T &&t, value_converting_constructor_tag /*unused*/ = value_converting_constructor_tag()) noexcept(
detail::is_nothrow_constructible<value_type, T>) // NOLINT
: base{in_place_type<typename base::_value_type>, static_cast<T &&>(t)}
, _ptr()
{
no_value_policy_type::on_outcome_construction(this, static_cast<T &&>(t));
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class T)
OUTCOME_TREQUIRES(OUTCOME_TPRED(predicate::template enable_error_converting_constructor<T>))
constexpr basic_outcome(T &&t, error_converting_constructor_tag /*unused*/ = error_converting_constructor_tag()) noexcept(
detail::is_nothrow_constructible<error_type, T>) // NOLINT
: base{in_place_type<typename base::_error_type>, static_cast<T &&>(t)}
, _ptr()
{
no_value_policy_type::on_outcome_construction(this, static_cast<T &&>(t));
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class ErrorCondEnum)
OUTCOME_TREQUIRES(OUTCOME_TEXPR(error_type(make_error_code(ErrorCondEnum()))), //
OUTCOME_TPRED(predicate::template enable_error_condition_converting_constructor<ErrorCondEnum>))
constexpr basic_outcome(ErrorCondEnum &&t, error_condition_converting_constructor_tag /*unused*/ = error_condition_converting_constructor_tag()) noexcept(
noexcept(error_type(make_error_code(static_cast<ErrorCondEnum &&>(t))))) // NOLINT
: base{in_place_type<typename base::_error_type>, make_error_code(t)}
{
no_value_policy_type::on_outcome_construction(this, static_cast<ErrorCondEnum &&>(t));
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class T)
OUTCOME_TREQUIRES(OUTCOME_TPRED(predicate::template enable_exception_converting_constructor<T>))
constexpr basic_outcome(T &&t, exception_converting_constructor_tag /*unused*/ = exception_converting_constructor_tag()) noexcept(
detail::is_nothrow_constructible<exception_type, T>) // NOLINT
: base()
, _ptr(static_cast<T &&>(t))
{
this->_state._status.set_have_exception(true);
no_value_policy_type::on_outcome_construction(this, static_cast<T &&>(t));
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class T, class U)
OUTCOME_TREQUIRES(OUTCOME_TPRED(predicate::template enable_error_exception_converting_constructor<T, U>))
constexpr basic_outcome(T &&a, U &&b, error_exception_converting_constructor_tag /*unused*/ = error_exception_converting_constructor_tag()) noexcept(
detail::is_nothrow_constructible<error_type, T> && detail::is_nothrow_constructible<exception_type, U>) // NOLINT
: base{in_place_type<typename base::_error_type>, static_cast<T &&>(a)}
, _ptr(static_cast<U &&>(b))
{
this->_state._status.set_have_exception(true);
no_value_policy_type::on_outcome_construction(this, static_cast<T &&>(a), static_cast<U &&>(b));
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class T)
OUTCOME_TREQUIRES(OUTCOME_TPRED(convert::value_or_error<basic_outcome, std::decay_t<T>>::enable_result_inputs || !concepts::basic_result<T>), //
OUTCOME_TPRED(convert::value_or_error<basic_outcome, std::decay_t<T>>::enable_outcome_inputs || !concepts::basic_outcome<T>), //
OUTCOME_TEXPR(convert::value_or_error<basic_outcome, std::decay_t<T>>{}(std::declval<T>())))
constexpr explicit basic_outcome(T &&o,
explicit_valueorerror_converting_constructor_tag /*unused*/ = explicit_valueorerror_converting_constructor_tag()) // NOLINT
: basic_outcome{convert::value_or_error<basic_outcome, std::decay_t<T>>{}(static_cast<T &&>(o))}
{
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class T, class U, class V, class W)
OUTCOME_TREQUIRES(OUTCOME_TPRED(predicate::template enable_compatible_conversion<T, U, V, W>))
constexpr explicit basic_outcome(
const basic_outcome<T, U, V, W> &o,
explicit_compatible_copy_conversion_tag /*unused*/ = explicit_compatible_copy_conversion_tag()) noexcept(detail::is_nothrow_constructible<value_type, T> &&
detail::is_nothrow_constructible<error_type, U> &&
detail::is_nothrow_constructible<exception_type, V>)
: base{typename base::compatible_conversion_tag(), o}
, _ptr(o._ptr)
{
no_value_policy_type::on_outcome_copy_construction(this, o);
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class T, class U, class V, class W)
OUTCOME_TREQUIRES(OUTCOME_TPRED(predicate::template enable_compatible_conversion<T, U, V, W>))
constexpr explicit basic_outcome(
basic_outcome<T, U, V, W> &&o,
explicit_compatible_move_conversion_tag /*unused*/ = explicit_compatible_move_conversion_tag()) noexcept(detail::is_nothrow_constructible<value_type, T> &&
detail::is_nothrow_constructible<error_type, U> &&
detail::is_nothrow_constructible<exception_type, V>)
: base{typename base::compatible_conversion_tag(), static_cast<basic_outcome<T, U, V, W> &&>(o)}
, _ptr(static_cast<typename basic_outcome<T, U, V, W>::exception_type &&>(o._ptr))
{
no_value_policy_type::on_outcome_move_construction(this, static_cast<basic_outcome<T, U, V, W> &&>(o));
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class T, class U, class V)
OUTCOME_TREQUIRES(OUTCOME_TPRED(detail::result_predicates<value_type, error_type>::template enable_compatible_conversion<T, U, V>))
constexpr explicit basic_outcome(
const basic_result<T, U, V> &o,
explicit_compatible_copy_conversion_tag /*unused*/ = explicit_compatible_copy_conversion_tag()) noexcept(detail::is_nothrow_constructible<value_type, T> &&
detail::is_nothrow_constructible<error_type, U> &&
detail::is_nothrow_constructible<exception_type>)
: base{typename base::compatible_conversion_tag(), o}
, _ptr()
{
no_value_policy_type::on_outcome_copy_construction(this, o);
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class T, class U, class V)
OUTCOME_TREQUIRES(OUTCOME_TPRED(detail::result_predicates<value_type, error_type>::template enable_compatible_conversion<T, U, V>))
constexpr explicit basic_outcome(
basic_result<T, U, V> &&o,
explicit_compatible_move_conversion_tag /*unused*/ = explicit_compatible_move_conversion_tag()) noexcept(detail::is_nothrow_constructible<value_type, T> &&
detail::is_nothrow_constructible<error_type, U> &&
detail::is_nothrow_constructible<exception_type>)
: base{typename base::compatible_conversion_tag(), static_cast<basic_result<T, U, V> &&>(o)}
, _ptr()
{
no_value_policy_type::on_outcome_move_construction(this, static_cast<basic_result<T, U, V> &&>(o));
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class T, class U, class V)
OUTCOME_TREQUIRES(OUTCOME_TPRED(detail::result_predicates<value_type, error_type>::template enable_make_error_code_compatible_conversion<T, U, V>))
constexpr explicit basic_outcome(const basic_result<T, U, V> &o,
explicit_make_error_code_compatible_copy_conversion_tag /*unused*/ =
explicit_make_error_code_compatible_copy_conversion_tag()) noexcept(detail::is_nothrow_constructible<value_type, T> &&
noexcept(make_error_code(std::declval<U>())) &&
detail::is_nothrow_constructible<exception_type>)
: base{typename base::make_error_code_compatible_conversion_tag(), o}
, _ptr()
{
no_value_policy_type::on_outcome_copy_construction(this, o);
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class T, class U, class V)
OUTCOME_TREQUIRES(OUTCOME_TPRED(detail::result_predicates<value_type, error_type>::template enable_make_error_code_compatible_conversion<T, U, V>))
constexpr explicit basic_outcome(basic_result<T, U, V> &&o,
explicit_make_error_code_compatible_move_conversion_tag /*unused*/ =
explicit_make_error_code_compatible_move_conversion_tag()) noexcept(detail::is_nothrow_constructible<value_type, T> &&
noexcept(make_error_code(std::declval<U>())) &&
detail::is_nothrow_constructible<exception_type>)
: base{typename base::make_error_code_compatible_conversion_tag(), static_cast<basic_result<T, U, V> &&>(o)}
, _ptr()
{
no_value_policy_type::on_outcome_move_construction(this, static_cast<basic_result<T, U, V> &&>(o));
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class... Args)
OUTCOME_TREQUIRES(OUTCOME_TPRED(predicate::template enable_inplace_value_constructor<Args...>))
constexpr explicit basic_outcome(in_place_type_t<value_type_if_enabled> _, Args &&...args) noexcept(detail::is_nothrow_constructible<value_type, Args...>)
: base{_, static_cast<Args &&>(args)...}
, _ptr()
{
no_value_policy_type::on_outcome_in_place_construction(this, in_place_type<value_type>, static_cast<Args &&>(args)...);
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class U, class... Args)
OUTCOME_TREQUIRES(OUTCOME_TPRED(predicate::template enable_inplace_value_constructor<std::initializer_list<U>, Args...>))
constexpr explicit basic_outcome(in_place_type_t<value_type_if_enabled> _, std::initializer_list<U> il,
Args &&...args) noexcept(detail::is_nothrow_constructible<value_type, std::initializer_list<U>, Args...>)
: base{_, il, static_cast<Args &&>(args)...}
, _ptr()
{
no_value_policy_type::on_outcome_in_place_construction(this, in_place_type<value_type>, il, static_cast<Args &&>(args)...);
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class... Args)
OUTCOME_TREQUIRES(OUTCOME_TPRED(predicate::template enable_inplace_error_constructor<Args...>))
constexpr explicit basic_outcome(in_place_type_t<error_type_if_enabled> _, Args &&...args) noexcept(detail::is_nothrow_constructible<error_type, Args...>)
: base{_, static_cast<Args &&>(args)...}
, _ptr()
{
no_value_policy_type::on_outcome_in_place_construction(this, in_place_type<error_type>, static_cast<Args &&>(args)...);
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class U, class... Args)
OUTCOME_TREQUIRES(OUTCOME_TPRED(predicate::template enable_inplace_error_constructor<std::initializer_list<U>, Args...>))
constexpr explicit basic_outcome(in_place_type_t<error_type_if_enabled> _, std::initializer_list<U> il,
Args &&...args) noexcept(detail::is_nothrow_constructible<error_type, std::initializer_list<U>, Args...>)
: base{_, il, static_cast<Args &&>(args)...}
, _ptr()
{
no_value_policy_type::on_outcome_in_place_construction(this, in_place_type<error_type>, il, static_cast<Args &&>(args)...);
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class... Args)
OUTCOME_TREQUIRES(OUTCOME_TPRED(predicate::template enable_inplace_exception_constructor<Args...>))
constexpr explicit basic_outcome(in_place_type_t<exception_type_if_enabled> /*unused*/,
Args &&...args) noexcept(detail::is_nothrow_constructible<exception_type, Args...>)
: base()
, _ptr(static_cast<Args &&>(args)...)
{
this->_state._status.set_have_exception(true);
no_value_policy_type::on_outcome_in_place_construction(this, in_place_type<exception_type>, static_cast<Args &&>(args)...);
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class U, class... Args)
OUTCOME_TREQUIRES(OUTCOME_TPRED(predicate::template enable_inplace_exception_constructor<std::initializer_list<U>, Args...>))
constexpr explicit basic_outcome(in_place_type_t<exception_type_if_enabled> /*unused*/, std::initializer_list<U> il,
Args &&...args) noexcept(detail::is_nothrow_constructible<exception_type, std::initializer_list<U>, Args...>)
: base()
, _ptr(il, static_cast<Args &&>(args)...)
{
this->_state._status.set_have_exception(true);
no_value_policy_type::on_outcome_in_place_construction(this, in_place_type<exception_type>, il, static_cast<Args &&>(args)...);
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class A1, class A2, class... Args)
OUTCOME_TREQUIRES(OUTCOME_TPRED(predicate::template enable_inplace_value_error_exception_constructor<A1, A2, Args...>))
constexpr basic_outcome(A1 &&a1, A2 &&a2, Args &&...args) noexcept(
noexcept(typename predicate::template choose_inplace_value_error_exception_constructor<A1, A2, Args...>(std::declval<A1>(), std::declval<A2>(),
std::declval<Args>()...)))
: basic_outcome(in_place_type<typename predicate::template choose_inplace_value_error_exception_constructor<A1, A2, Args...>>, static_cast<A1 &&>(a1),
static_cast<A2 &&>(a2), static_cast<Args &&>(args)...)
{
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
constexpr basic_outcome(const success_type<void> &o) noexcept(std::is_nothrow_default_constructible<value_type>::value) // NOLINT
: base{in_place_type<typename base::_value_type>}
{
hooks::set_spare_storage(this, o.spare_storage());
no_value_policy_type::on_outcome_copy_construction(this, o);
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class T)
OUTCOME_TREQUIRES(OUTCOME_TPRED(!std::is_void<T>::value && predicate::template enable_compatible_conversion<T, void, void, void>))
constexpr basic_outcome(const success_type<T> &o) noexcept(detail::is_nothrow_constructible<value_type, T>) // NOLINT
: base{in_place_type<typename base::_value_type>, detail::extract_value_from_success<value_type>(o)}
{
hooks::set_spare_storage(this, o.spare_storage());
no_value_policy_type::on_outcome_copy_construction(this, o);
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class T)
OUTCOME_TREQUIRES(OUTCOME_TPRED(!std::is_void<T>::value && predicate::template enable_compatible_conversion<T, void, void, void>))
constexpr basic_outcome(success_type<T> &&o) noexcept(detail::is_nothrow_constructible<value_type, T>) // NOLINT
: base{in_place_type<typename base::_value_type>, detail::extract_value_from_success<value_type>(static_cast<success_type<T> &&>(o))}
{
hooks::set_spare_storage(this, o.spare_storage());
no_value_policy_type::on_outcome_move_construction(this, static_cast<success_type<T> &&>(o));
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class T)
OUTCOME_TREQUIRES(OUTCOME_TPRED(!std::is_void<T>::value && predicate::template enable_compatible_conversion<void, T, void, void>))
constexpr basic_outcome(const failure_type<T> &o,
error_failure_tag /*unused*/ = error_failure_tag()) noexcept(detail::is_nothrow_constructible<error_type, T>) // NOLINT
: base{in_place_type<typename base::_error_type>, detail::extract_error_from_failure<error_type>(o)}
, _ptr()
{
hooks::set_spare_storage(this, o.spare_storage());
no_value_policy_type::on_outcome_copy_construction(this, o);
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class T)
OUTCOME_TREQUIRES(OUTCOME_TPRED(!std::is_void<T>::value && predicate::template enable_compatible_conversion<void, void, T, void>))
constexpr basic_outcome(const failure_type<T> &o,
exception_failure_tag /*unused*/ = exception_failure_tag()) noexcept(detail::is_nothrow_constructible<exception_type, T>) // NOLINT
: base()
, _ptr(detail::extract_exception_from_failure<exception_type>(o))
{
this->_state._status.set_have_exception(true);
hooks::set_spare_storage(this, o.spare_storage());
no_value_policy_type::on_outcome_copy_construction(this, o);
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class T)
OUTCOME_TREQUIRES(OUTCOME_TPRED(!std::is_void<T>::value && predicate::template enable_make_error_code_compatible_conversion<void, T, void, void>))
constexpr basic_outcome(const failure_type<T> &o,
explicit_make_error_code_compatible_copy_conversion_tag /*unused*/ =
explicit_make_error_code_compatible_copy_conversion_tag()) noexcept(noexcept(make_error_code(std::declval<T>()))) // NOLINT
: base{in_place_type<typename base::_error_type>, make_error_code(detail::extract_error_from_failure<error_type>(o))}
, _ptr()
{
hooks::set_spare_storage(this, o.spare_storage());
no_value_policy_type::on_outcome_copy_construction(this, o);
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class T, class U)
OUTCOME_TREQUIRES(OUTCOME_TPRED(!std::is_void<U>::value && predicate::template enable_compatible_conversion<void, T, U, void>))
constexpr basic_outcome(const failure_type<T, U> &o, explicit_compatible_copy_conversion_tag /*unused*/ = explicit_compatible_copy_conversion_tag()) noexcept(
detail::is_nothrow_constructible<error_type, T> && detail::is_nothrow_constructible<exception_type, U>) // NOLINT
: base{in_place_type<typename base::_error_type>, detail::extract_error_from_failure<error_type>(o)}
, _ptr(detail::extract_exception_from_failure<exception_type>(o))
{
if(!o.has_error())
{
this->_state._status.set_have_error(false);
}
if(o.has_exception())
{
this->_state._status.set_have_exception(true);
}
hooks::set_spare_storage(this, o.spare_storage());
no_value_policy_type::on_outcome_copy_construction(this, o);
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class T)
OUTCOME_TREQUIRES(OUTCOME_TPRED(!std::is_void<T>::value && predicate::template enable_compatible_conversion<void, T, void, void>))
constexpr basic_outcome(failure_type<T> &&o,
error_failure_tag /*unused*/ = error_failure_tag()) noexcept(detail::is_nothrow_constructible<error_type, T>) // NOLINT
: base{in_place_type<typename base::_error_type>, detail::extract_error_from_failure<error_type>(static_cast<failure_type<T> &&>(o))}
, _ptr()
{
hooks::set_spare_storage(this, o.spare_storage());
no_value_policy_type::on_outcome_copy_construction(this, o);
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class T)
OUTCOME_TREQUIRES(OUTCOME_TPRED(!std::is_void<T>::value && predicate::template enable_compatible_conversion<void, void, T, void>))
constexpr basic_outcome(failure_type<T> &&o,
exception_failure_tag /*unused*/ = exception_failure_tag()) noexcept(detail::is_nothrow_constructible<exception_type, T>) // NOLINT
: base()
, _ptr(detail::extract_exception_from_failure<exception_type>(static_cast<failure_type<T> &&>(o)))
{
this->_state._status.set_have_exception(true);
hooks::set_spare_storage(this, o.spare_storage());
no_value_policy_type::on_outcome_copy_construction(this, o);
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class T)
OUTCOME_TREQUIRES(OUTCOME_TPRED(!std::is_void<T>::value && predicate::template enable_make_error_code_compatible_conversion<void, T, void, void>))
constexpr basic_outcome(failure_type<T> &&o,
explicit_make_error_code_compatible_move_conversion_tag /*unused*/ =
explicit_make_error_code_compatible_move_conversion_tag()) noexcept(noexcept(make_error_code(std::declval<T>()))) // NOLINT
: base{in_place_type<typename base::_error_type>, make_error_code(detail::extract_error_from_failure<error_type>(static_cast<failure_type<T> &&>(o)))}
, _ptr()
{
hooks::set_spare_storage(this, o.spare_storage());
no_value_policy_type::on_outcome_copy_construction(this, o);
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class T, class U)
OUTCOME_TREQUIRES(OUTCOME_TPRED(!std::is_void<U>::value && predicate::template enable_compatible_conversion<void, T, U, void>))
constexpr basic_outcome(failure_type<T, U> &&o, explicit_compatible_move_conversion_tag /*unused*/ = explicit_compatible_move_conversion_tag()) noexcept(
detail::is_nothrow_constructible<error_type, T> && detail::is_nothrow_constructible<exception_type, U>) // NOLINT
: base{in_place_type<typename base::_error_type>, detail::extract_error_from_failure<error_type>(static_cast<failure_type<T, U> &&>(o))}
, _ptr(detail::extract_exception_from_failure<exception_type>(static_cast<failure_type<T, U> &&>(o)))
{
if(!o.has_error())
{
this->_state._status.set_have_error(false);
}
if(o.has_exception())
{
this->_state._status.set_have_exception(true);
}
hooks::set_spare_storage(this, o.spare_storage());
no_value_policy_type::on_outcome_move_construction(this, static_cast<failure_type<T, U> &&>(o));
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
using base::operator==;
using base::operator!=;
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class T, class U, class V, class W)
OUTCOME_TREQUIRES(OUTCOME_TEXPR(std::declval<detail::devoid<value_type>>() == std::declval<detail::devoid<T>>()), //
OUTCOME_TEXPR(std::declval<detail::devoid<error_type>>() == std::declval<detail::devoid<U>>()), //
OUTCOME_TEXPR(std::declval<detail::devoid<exception_type>>() == std::declval<detail::devoid<V>>()))
constexpr bool operator==(const basic_outcome<T, U, V, W> &o) const noexcept( //
noexcept(std::declval<detail::devoid<value_type>>() == std::declval<detail::devoid<T>>()) //
&& noexcept(std::declval<detail::devoid<error_type>>() == std::declval<detail::devoid<U>>()) //
&& noexcept(std::declval<detail::devoid<exception_type>>() == std::declval<detail::devoid<V>>()))
{
if(this->_state._status.have_value() && o._state._status.have_value())
{
return this->_state._value == o._state._value; // NOLINT
}
if(this->_state._status.have_error() && o._state._status.have_error() //
&& this->_state._status.have_exception() && o._state._status.have_exception())
{
return this->_state._error == o._state._error && this->_ptr == o._ptr;
}
if(this->_state._status.have_error() && o._state._status.have_error())
{
return this->_state._error == o._state._error;
}
if(this->_state._status.have_exception() && o._state._status.have_exception())
{
return this->_ptr == o._ptr;
}
return false;
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class T, class U)
OUTCOME_TREQUIRES(OUTCOME_TEXPR(std::declval<error_type>() == std::declval<T>()), //
OUTCOME_TEXPR(std::declval<exception_type>() == std::declval<U>()))
constexpr bool operator==(const failure_type<T, U> &o) const noexcept( //
noexcept(std::declval<error_type>() == std::declval<T>()) && noexcept(std::declval<exception_type>() == std::declval<U>()))
{
if(this->_state._status.have_error() && o._state._status.have_error() //
&& this->_state._status.have_exception() && o._state._status.have_exception())
{
return this->_state._error == o.error() && this->_ptr == o.exception();
}
if(this->_state._status.have_error() && o._state._status.have_error())
{
return this->_state._error == o.error();
}
if(this->_state._status.have_exception() && o._state._status.have_exception())
{
return this->_ptr == o.exception();
}
return false;
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class T, class U, class V, class W)
OUTCOME_TREQUIRES(OUTCOME_TEXPR(std::declval<detail::devoid<value_type>>() != std::declval<detail::devoid<T>>()), //
OUTCOME_TEXPR(std::declval<detail::devoid<error_type>>() != std::declval<detail::devoid<U>>()), //
OUTCOME_TEXPR(std::declval<detail::devoid<exception_type>>() != std::declval<detail::devoid<V>>()))
constexpr bool operator!=(const basic_outcome<T, U, V, W> &o) const noexcept( //
noexcept(std::declval<detail::devoid<value_type>>() != std::declval<detail::devoid<T>>()) //
&& noexcept(std::declval<detail::devoid<error_type>>() != std::declval<detail::devoid<U>>()) //
&& noexcept(std::declval<detail::devoid<exception_type>>() != std::declval<detail::devoid<V>>()))
{
if(this->_state._status.have_value() && o._state._status.have_value())
{
return this->_state._value != o._state._value; // NOLINT
}
if(this->_state._status.have_error() && o._state._status.have_error() //
&& this->_state._status.have_exception() && o._state._status.have_exception())
{
return this->_state._error != o._state._error || this->_ptr != o._ptr;
}
if(this->_state._status.have_error() && o._state._status.have_error())
{
return this->_state._error != o._state._error;
}
if(this->_state._status.have_exception() && o._state._status.have_exception())
{
return this->_ptr != o._ptr;
}
return true;
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class T, class U)
OUTCOME_TREQUIRES(OUTCOME_TEXPR(std::declval<error_type>() != std::declval<T>()), //
OUTCOME_TEXPR(std::declval<exception_type>() != std::declval<U>()))
constexpr bool operator!=(const failure_type<T, U> &o) const noexcept( //
noexcept(std::declval<error_type>() == std::declval<T>()) && noexcept(std::declval<exception_type>() == std::declval<U>()))
{
if(this->_state._status.have_error() && o._state._status.have_error() //
&& this->_state._status.have_exception() && o._state._status.have_exception())
{
return this->_state._error != o.error() || this->_ptr != o.exception();
}
if(this->_state._status.have_error() && o._state._status.have_error())
{
return this->_state._error != o.error();
}
if(this->_state._status.have_exception() && o._state._status.have_exception())
{
return this->_ptr != o.exception();
}
return true;
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
constexpr void swap(basic_outcome &o) noexcept((std::is_void<value_type>::value || detail::is_nothrow_swappable<value_type>::value) //
&& (std::is_void<error_type>::value || detail::is_nothrow_swappable<error_type>::value) //
&& (std::is_void<exception_type>::value || detail::is_nothrow_swappable<exception_type>::value))
{
#ifdef __cpp_exceptions
constexpr bool value_throws = !std::is_void<value_type>::value && !detail::is_nothrow_swappable<value_type>::value;
constexpr bool error_throws = !std::is_void<error_type>::value && !detail::is_nothrow_swappable<error_type>::value;
constexpr bool exception_throws = !std::is_void<exception_type>::value && !detail::is_nothrow_swappable<exception_type>::value;
#ifdef _MSC_VER
#pragma warning(push)
#pragma warning(disable : 4127) // conditional expression is constant
#endif
if(!exception_throws && !value_throws && !error_throws)
{
// Simples
this->_state.swap(o._state);
using std::swap;
swap(this->_ptr, o._ptr);
return;
}
struct some_type
{
basic_outcome &a, &b;
bool exceptioned{false};
bool all_good{false};
~some_type()
{
if(!this->all_good)
{
// We lost one of the values
this->a._state._status.set_have_lost_consistency(true);
this->b._state._status.set_have_lost_consistency(true);
return;
}
if(this->exceptioned)
{
// The value + error swap threw an exception. Try to swap back _ptr
try
{
strong_swap(this->all_good, this->a._ptr, this->b._ptr);
}
catch(...)
{
// We lost one of the values
this->a._state._status.set_have_lost_consistency(true);
this->b._state._status.set_have_lost_consistency(true);
// throw away second exception
}
// Prevent has_value() == has_error() or has_value() == has_exception()
auto check = [](basic_outcome *t)
{
if(t->has_value() && (t->has_error() || t->has_exception()))
{
t->_state._status.set_have_error(false).set_have_exception(false);
t->_state._status.set_have_lost_consistency(true);
}
if(!t->has_value() && !(t->has_error() || t->has_exception()))
{
// Choose error, for no particular reason
t->_state._status.set_have_error(true).set_have_lost_consistency(true);
}
};
check(&this->a);
check(&this->b);
}
}
} some_type_value{*this, o};
strong_swap(some_type_value.all_good, this->_ptr, o._ptr);
some_type_value.exceptioned = true;
this->_state.swap(o._state);
some_type_value.exceptioned = false;
#ifdef _MSC_VER
#pragma warning(pop)
#endif
#else
this->_state.swap(o._state);
using std::swap;
swap(this->_ptr, o._ptr);
#endif
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
failure_type<error_type, exception_type> as_failure() const &
{
if(this->has_error() && this->has_exception())
{
return failure_type<error_type, exception_type>(this->assume_error(), this->assume_exception(), hooks::spare_storage(this));
}
if(this->has_exception())
{
return failure_type<error_type, exception_type>(in_place_type<exception_type>, this->assume_exception(), hooks::spare_storage(this));
}
return failure_type<error_type, exception_type>(in_place_type<error_type>, this->assume_error(), hooks::spare_storage(this));
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
failure_type<error_type, exception_type> as_failure() &&
{
this->_state._status.set_have_moved_from(true);
if(this->has_error() && this->has_exception())
{
return failure_type<error_type, exception_type>(static_cast<S &&>(this->assume_error()), static_cast<P &&>(this->assume_exception()),
hooks::spare_storage(this));
}
if(this->has_exception())
{
return failure_type<error_type, exception_type>(in_place_type<exception_type>, static_cast<P &&>(this->assume_exception()), hooks::spare_storage(this));
}
return failure_type<error_type, exception_type>(in_place_type<error_type>, static_cast<S &&>(this->assume_error()), hooks::spare_storage(this));
}
#ifdef __APPLE__
failure_type<error_type, exception_type> _xcode_workaround_as_failure() &&;
#endif
};
// C++ 20 operator== rewriting should take care of this for us, indeed
// if we don't disable it, we cause Concept recursion to infinity!
#if __cplusplus < 202000L && !_HAS_CXX20
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class T, class U, class V, //
class R, class S, class P, class N)
OUTCOME_TREQUIRES(OUTCOME_TEXPR(std::declval<basic_outcome<R, S, P, N>>() == std::declval<basic_result<T, U, V>>()))
constexpr inline bool operator==(const basic_result<T, U, V> &a, const basic_outcome<R, S, P, N> &b) noexcept( //
noexcept(std::declval<basic_outcome<R, S, P, N>>() == std::declval<basic_result<T, U, V>>()))
{
return b == a;
}
#endif
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class T, class U, class V, //
class R, class S, class P, class N)
OUTCOME_TREQUIRES(OUTCOME_TEXPR(std::declval<basic_outcome<R, S, P, N>>() != std::declval<basic_result<T, U, V>>()))
constexpr inline bool operator!=(const basic_result<T, U, V> &a, const basic_outcome<R, S, P, N> &b) noexcept( //
noexcept(std::declval<basic_outcome<R, S, P, N>>() != std::declval<basic_result<T, U, V>>()))
{
return b != a;
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
template <class R, class S, class P, class N> inline void swap(basic_outcome<R, S, P, N> &a, basic_outcome<R, S, P, N> &b) noexcept(noexcept(a.swap(b)))
{
a.swap(b);
}
namespace hooks
{
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
template <class R, class S, class P, class NoValuePolicy, class U>
constexpr inline void override_outcome_exception(basic_outcome<R, S, P, NoValuePolicy> *o, U &&v) noexcept
{
o->_ptr = static_cast<U &&>(v); // NOLINT
o->_state._status.set_have_exception(true);
}
} // namespace hooks
OUTCOME_V2_NAMESPACE_END
#ifdef __clang__
#pragma clang diagnostic pop
#endif
/* Exception observers for outcome type
(C) 2017-2019 Niall Douglas <http://www.nedproductions.biz/> (6 commits)
File Created: Oct 2017
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License in the accompanying file
Licence.txt or at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Distributed under the Boost Software License, Version 1.0.
(See accompanying file Licence.txt or copy at
http://www.boost.org/LICENSE_1_0.txt)
*/
#ifndef OUTCOME_BASIC_OUTCOME_EXCEPTION_OBSERVERS_IMPL_HPP
#define OUTCOME_BASIC_OUTCOME_EXCEPTION_OBSERVERS_IMPL_HPP
OUTCOME_V2_NAMESPACE_EXPORT_BEGIN
namespace policy
{
template <class R, class S, class P, class NoValuePolicy, class Impl> inline constexpr auto &&base::_exception(Impl &&self) noexcept
{
// Impl will be some internal implementation class which has no knowledge of the _ptr stored
// beneath it. So statically cast, preserving rvalue and constness, to the derived class.
using Outcome = OUTCOME_V2_NAMESPACE::detail::rebind_type<basic_outcome<R, S, P, NoValuePolicy>, decltype(self)>;
#if defined(_MSC_VER) && _MSC_VER < 1920
// VS2017 tries a copy construction in the correct implementation despite that Outcome is always a rvalue or lvalue ref! :(
basic_outcome<R, S, P, NoValuePolicy> &_self = (basic_outcome<R, S, P, NoValuePolicy> &) (self); // NOLINT
#else
Outcome _self = static_cast<Outcome>(self); // NOLINT
#endif
return static_cast<Outcome>(_self)._ptr;
}
} // namespace policy
namespace detail
{
template <class Base, class R, class S, class P, class NoValuePolicy> inline constexpr typename basic_outcome_exception_observers<Base, R, S, P, NoValuePolicy>::exception_type &basic_outcome_exception_observers<Base, R, S, P, NoValuePolicy>::assume_exception() & noexcept
{
NoValuePolicy::narrow_exception_check(*this);
return NoValuePolicy::template _exception<R, S, P, NoValuePolicy>(*this);
}
template <class Base, class R, class S, class P, class NoValuePolicy> inline constexpr const typename basic_outcome_exception_observers<Base, R, S, P, NoValuePolicy>::exception_type &basic_outcome_exception_observers<Base, R, S, P, NoValuePolicy>::assume_exception() const &noexcept
{
NoValuePolicy::narrow_exception_check(*this);
return NoValuePolicy::template _exception<R, S, P, NoValuePolicy>(*this);
}
template <class Base, class R, class S, class P, class NoValuePolicy> inline constexpr typename basic_outcome_exception_observers<Base, R, S, P, NoValuePolicy>::exception_type &&basic_outcome_exception_observers<Base, R, S, P, NoValuePolicy>::assume_exception() && noexcept
{
NoValuePolicy::narrow_exception_check(std::move(*this));
return NoValuePolicy::template _exception<R, S, P, NoValuePolicy>(std::move(*this));
}
template <class Base, class R, class S, class P, class NoValuePolicy> inline constexpr const typename basic_outcome_exception_observers<Base, R, S, P, NoValuePolicy>::exception_type &&basic_outcome_exception_observers<Base, R, S, P, NoValuePolicy>::assume_exception() const &&noexcept
{
NoValuePolicy::narrow_exception_check(std::move(*this));
return NoValuePolicy::template _exception<R, S, P, NoValuePolicy>(std::move(*this));
}
template <class Base, class R, class S, class P, class NoValuePolicy> inline constexpr typename basic_outcome_exception_observers<Base, R, S, P, NoValuePolicy>::exception_type &basic_outcome_exception_observers<Base, R, S, P, NoValuePolicy>::exception() &
{
NoValuePolicy::wide_exception_check(*this);
return NoValuePolicy::template _exception<R, S, P, NoValuePolicy>(*this);
}
template <class Base, class R, class S, class P, class NoValuePolicy> inline constexpr const typename basic_outcome_exception_observers<Base, R, S, P, NoValuePolicy>::exception_type &basic_outcome_exception_observers<Base, R, S, P, NoValuePolicy>::exception() const &
{
NoValuePolicy::wide_exception_check(*this);
return NoValuePolicy::template _exception<R, S, P, NoValuePolicy>(*this);
}
template <class Base, class R, class S, class P, class NoValuePolicy> inline constexpr typename basic_outcome_exception_observers<Base, R, S, P, NoValuePolicy>::exception_type &&basic_outcome_exception_observers<Base, R, S, P, NoValuePolicy>::exception() &&
{
NoValuePolicy::wide_exception_check(std::move(*this));
return NoValuePolicy::template _exception<R, S, P, NoValuePolicy>(std::move(*this));
}
template <class Base, class R, class S, class P, class NoValuePolicy> inline constexpr const typename basic_outcome_exception_observers<Base, R, S, P, NoValuePolicy>::exception_type &&basic_outcome_exception_observers<Base, R, S, P, NoValuePolicy>::exception() const &&
{
NoValuePolicy::wide_exception_check(std::move(*this));
return NoValuePolicy::template _exception<R, S, P, NoValuePolicy>(std::move(*this));
}
} // namespace detail
OUTCOME_V2_NAMESPACE_END
#endif
#if !defined(NDEBUG)
OUTCOME_V2_NAMESPACE_BEGIN
// Check is trivial in all ways except default constructibility and standard layout
// static_assert(std::is_trivial<basic_outcome<int, long, double, policy::all_narrow>>::value, "outcome<int> is not trivial!");
// static_assert(std::is_trivially_default_constructible<basic_outcome<int, long, double, policy::all_narrow>>::value, "outcome<int> is not trivially default
// constructible!");
static_assert(std::is_trivially_copyable<basic_outcome<int, long, double, policy::all_narrow>>::value, "outcome<int> is not trivially copyable!");
static_assert(std::is_trivially_assignable<basic_outcome<int, long, double, policy::all_narrow>, basic_outcome<int, long, double, policy::all_narrow>>::value,
"outcome<int> is not trivially assignable!");
static_assert(std::is_trivially_destructible<basic_outcome<int, long, double, policy::all_narrow>>::value, "outcome<int> is not trivially destructible!");
static_assert(std::is_trivially_copy_constructible<basic_outcome<int, long, double, policy::all_narrow>>::value,
"outcome<int> is not trivially copy constructible!");
static_assert(std::is_trivially_move_constructible<basic_outcome<int, long, double, policy::all_narrow>>::value,
"outcome<int> is not trivially move constructible!");
static_assert(std::is_trivially_copy_assignable<basic_outcome<int, long, double, policy::all_narrow>>::value, "outcome<int> is not trivially copy assignable!");
static_assert(std::is_trivially_move_assignable<basic_outcome<int, long, double, policy::all_narrow>>::value, "outcome<int> is not trivially move assignable!");
// Can't be standard layout as non-static member data is defined in more than one inherited class
// static_assert(std::is_standard_layout<basic_outcome<int, long, double, policy::all_narrow>>::value, "outcome<int> is not a standard layout type!");
OUTCOME_V2_NAMESPACE_END
#endif
#endif
#ifndef STD_BASIC_OUTCOME_FAILURE_EXCEPTION_FROM_ERROR
#define STD_BASIC_OUTCOME_FAILURE_EXCEPTION_FROM_ERROR
namespace std // NOLINT
{
inline exception_ptr basic_outcome_failure_exception_from_error(const error_code &ec) { return make_exception_ptr(system_error(ec)); }
} // namespace std
#endif
OUTCOME_V2_NAMESPACE_EXPORT_BEGIN
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
template <class R, class S = std::error_code, class P = std::exception_ptr, class NoValuePolicy = policy::default_policy<R, S, P>> //
using std_outcome = basic_outcome<R, S, P, NoValuePolicy>;
OUTCOME_V2_NAMESPACE_END
/* Policies for result and outcome
(C) 2017-2019 Niall Douglas <http://www.nedproductions.biz/> (12 commits)
File Created: Oct 2017
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License in the accompanying file
Licence.txt or at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Distributed under the Boost Software License, Version 1.0.
(See accompanying file Licence.txt or copy at
http://www.boost.org/LICENSE_1_0.txt)
*/
#ifndef OUTCOME_POLICY_OUTCOME_ERROR_CODE_THROW_AS_SYSTEM_ERROR_HPP
#define OUTCOME_POLICY_OUTCOME_ERROR_CODE_THROW_AS_SYSTEM_ERROR_HPP
OUTCOME_V2_NAMESPACE_EXPORT_BEGIN
namespace policy
{
/*! AWAITING HUGO JSON CONVERSION TOOL
type definition error_code_throw_as_system_error. Potential doc page: NOT FOUND
*/
template <class T, class EC, class E> struct error_code_throw_as_system_error : base
{
template <class Impl> static constexpr void wide_value_check(Impl &&self)
{
if(!base::_has_value(std::forward<Impl>(self)))
{
if(base::_has_exception(std::forward<Impl>(self)))
{
detail::_rethrow_exception<trait::is_exception_ptr_available<E>::value>{base::_exception<T, EC, E, error_code_throw_as_system_error>(std::forward<Impl>(self))}; // NOLINT
}
if(base::_has_error(std::forward<Impl>(self)))
{
// ADL discovered
outcome_throw_as_system_error_with_payload(base::_error(std::forward<Impl>(self)));
}
OUTCOME_THROW_EXCEPTION(bad_outcome_access("no value")); // NOLINT
}
}
template <class Impl> static constexpr void wide_error_check(Impl &&self)
{
if(!base::_has_error(std::forward<Impl>(self)))
{
OUTCOME_THROW_EXCEPTION(bad_outcome_access("no error")); // NOLINT
}
}
template <class Impl> static constexpr void wide_exception_check(Impl &&self)
{
if(!base::_has_exception(std::forward<Impl>(self)))
{
OUTCOME_THROW_EXCEPTION(bad_outcome_access("no exception")); // NOLINT
}
}
};
} // namespace policy
OUTCOME_V2_NAMESPACE_END
#endif
/* Policies for result and outcome
(C) 2017-2019 Niall Douglas <http://www.nedproductions.biz/> (10 commits)
File Created: Oct 2017
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License in the accompanying file
Licence.txt or at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Distributed under the Boost Software License, Version 1.0.
(See accompanying file Licence.txt or copy at
http://www.boost.org/LICENSE_1_0.txt)
*/
#ifndef OUTCOME_POLICY_OUTCOME_EXCEPTION_PTR_RETHROW_HPP
#define OUTCOME_POLICY_OUTCOME_EXCEPTION_PTR_RETHROW_HPP
OUTCOME_V2_NAMESPACE_EXPORT_BEGIN
namespace policy
{
/*! AWAITING HUGO JSON CONVERSION TOOL
type definition exception_ptr_rethrow. Potential doc page: NOT FOUND
*/
template <class T, class EC, class E> struct exception_ptr_rethrow : base
{
template <class Impl> static constexpr void wide_value_check(Impl &&self)
{
if(!base::_has_value(std::forward<Impl>(self)))
{
if(base::_has_exception(std::forward<Impl>(self)))
{
detail::_rethrow_exception<trait::is_exception_ptr_available<E>::value>{base::_exception<T, EC, E, exception_ptr_rethrow>(std::forward<Impl>(self))};
}
if(base::_has_error(std::forward<Impl>(self)))
{
detail::_rethrow_exception<trait::is_exception_ptr_available<EC>::value>{base::_error(std::forward<Impl>(self))};
}
OUTCOME_THROW_EXCEPTION(bad_outcome_access("no value")); // NOLINT
}
}
template <class Impl> static constexpr void wide_error_check(Impl &&self)
{
if(!base::_has_error(std::forward<Impl>(self)))
{
OUTCOME_THROW_EXCEPTION(bad_outcome_access("no error")); // NOLINT
}
}
template <class Impl> static constexpr void wide_exception_check(Impl &&self)
{
if(!base::_has_exception(std::forward<Impl>(self)))
{
OUTCOME_THROW_EXCEPTION(bad_outcome_access("no exception")); // NOLINT
}
}
};
} // namespace policy
OUTCOME_V2_NAMESPACE_END
#endif
#endif
OUTCOME_V2_NAMESPACE_EXPORT_BEGIN
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
template <class R, class S = std::error_code, class P = std::exception_ptr, class NoValuePolicy = policy::default_policy<R, S, P>> //
using outcome = std_outcome<R, S, P, NoValuePolicy>;
OUTCOME_V2_NAMESPACE_END
#endif
#include <iostream>
#include <sstream>
OUTCOME_V2_NAMESPACE_BEGIN
namespace detail
{
template <class T> typename std::add_lvalue_reference<T>::type lvalueref() noexcept;
template <template <class, class> class ValueStorage, class T, class E> inline std::ostream &value_storage_out(std::ostream &s, const ValueStorage<T, E> &v)
{
s << static_cast<uint16_t>(v._status.status_value) << " " << v._status.spare_storage_value << " ";
if(v._status.have_value())
{
s << v._value; // NOLINT
}
if(v._status.have_error())
{
s << v._error; // NOLINT
}
return s;
}
template <template <class, class> class ValueStorage, class E> inline std::ostream &value_storage_out(std::ostream &s, const ValueStorage<void, E> &v)
{
s << static_cast<uint16_t>(v._status.status_value) << " " << v._status.spare_storage_value << " ";
if(v._status.have_error())
{
s << v._error; // NOLINT
}
return s;
}
template <template <class, class> class ValueStorage, class T> inline std::ostream &value_storage_out(std::ostream &s, const ValueStorage<T, void> &v)
{
s << static_cast<uint16_t>(v._status.status_value) << " " << v._status.spare_storage_value << " ";
if(v._status.have_value())
{
s << v._value; // NOLINT
}
return s;
}
template <class T, class E> inline std::ostream &operator<<(std::ostream &s, const value_storage_trivial<T, E> &v) { return value_storage_out(s, v); }
template <class T, class E> inline std::ostream &operator<<(std::ostream &s, const value_storage_nontrivial<T, E> &v) { return value_storage_out(s, v); }
template <template <class, class> class ValueStorage, class T, class E> inline std::istream &value_storage_in(std::istream &s, ValueStorage<T, E> &v)
{
using type = ValueStorage<T, E>;
v.~type();
new(&v) type;
uint16_t x, y;
s >> x >> y;
v._status.status_value = static_cast<detail::status>(x);
v._status.spare_storage_value = y;
if(v._status.have_value())
{
new(OUTCOME_ADDRESS_OF(v._value)) decltype(v._value)(); // NOLINT
s >> v._value; // NOLINT
}
if(v._status.have_error())
{
new(OUTCOME_ADDRESS_OF(v._error)) decltype(v._error)(); // NOLINT
s >> v._error; // NOLINT
}
return s;
}
template <template <class, class> class ValueStorage, class E> inline std::istream &value_storage_in(std::istream &s, ValueStorage<void, E> &v)
{
using type = ValueStorage<void, E>;
v.~type();
new(&v) type;
uint16_t x, y;
s >> x >> y;
v._status.status_value = static_cast<detail::status>(x);
v._status.spare_storage_value = y;
if(v._status.have_error())
{
new(OUTCOME_ADDRESS_OF(v._error)) decltype(v._error)(); // NOLINT
s >> v._error; // NOLINT
}
return s;
}
template <template <class, class> class ValueStorage, class T> inline std::istream &value_storage_in(std::istream &s, ValueStorage<T, void> &v)
{
using type = ValueStorage<T, void>;
v.~type();
new(&v) type;
uint16_t x, y;
s >> x >> y;
v._status.status_value = static_cast<detail::status>(x);
v._status.spare_storage_value = y;
if(v._status.have_value())
{
new(OUTCOME_ADDRESS_OF(v._value)) decltype(v._value)(); // NOLINT
s >> v._value; // NOLINT
}
return s;
}
template <class T, class E> inline std::istream &operator>>(std::istream &s, value_storage_trivial<T, E> &v) { return value_storage_in(s, v); }
template <class T, class E> inline std::istream &operator>>(std::istream &s, value_storage_nontrivial<T, E> &v) { return value_storage_in(s, v); }
OUTCOME_TEMPLATE(class T)
OUTCOME_TREQUIRES(OUTCOME_TPRED(!std::is_constructible<std::error_code, T>::value))
inline std::string safe_message(T && /*unused*/) { return {}; }
inline std::string safe_message(const std::error_code &ec) { return " (" + ec.message() + ")"; }
} // namespace detail
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class R, class S, class P)
OUTCOME_TREQUIRES(OUTCOME_TEXPR(detail::lvalueref<std::istream>() >> detail::lvalueref<R>()), OUTCOME_TEXPR(detail::lvalueref<std::istream>() >> detail::lvalueref<S>()))
inline std::istream &operator>>(std::istream &s, basic_result<R, S, P> &v)
{
s >> v._iostreams_state();
if(v.has_error())
{
s >> v.assume_error();
}
return s;
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class R, class S, class P)
OUTCOME_TREQUIRES(OUTCOME_TEXPR(detail::lvalueref<std::ostream>() << detail::lvalueref<R>()), OUTCOME_TEXPR(detail::lvalueref<std::ostream>() << detail::lvalueref<S>()))
inline std::ostream &operator<<(std::ostream &s, const basic_result<R, S, P> &v)
{
s << v._iostreams_state();
if(v.has_error())
{
s << v.assume_error();
}
return s;
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
template <class R, class S, class P> inline std::string print(const basic_result<R, S, P> &v)
{
std::stringstream s;
if(v.has_value())
{
s << v.value();
}
if(v.has_error())
{
s << v.error() << detail::safe_message(v.error());
}
return s.str();
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
template <class S, class P> inline std::string print(const basic_result<void, S, P> &v)
{
std::stringstream s;
if(v.has_value())
{
s << "(+void)";
}
if(v.has_error())
{
s << v.error() << detail::safe_message(v.error());
}
return s.str();
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
template <class R, class P> inline std::string print(const basic_result<R, void, P> &v)
{
std::stringstream s;
if(v.has_value())
{
s << v.value();
}
if(v.has_error())
{
s << "(-void)";
}
return s.str();
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
template <class P> inline std::string print(const basic_result<void, void, P> &v)
{
std::stringstream s;
if(v.has_value())
{
s << "(+void)";
}
if(v.has_error())
{
s << "(-void)";
}
return s.str();
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class R, class S, class P, class N)
OUTCOME_TREQUIRES(OUTCOME_TEXPR(detail::lvalueref<std::istream>() >> detail::lvalueref<R>()), OUTCOME_TEXPR(detail::lvalueref<std::istream>() >> detail::lvalueref<S>()), OUTCOME_TEXPR(detail::lvalueref<std::istream>() >> detail::lvalueref<P>()))
inline std::istream &operator>>(std::istream &s, outcome<R, S, P, N> &v)
{
s >> v._iostreams_state();
if(v.has_error())
{
s >> v.assume_error();
}
if(v.has_exception())
{
s >> v.assume_exception();
}
return s;
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class R, class S, class P, class N)
OUTCOME_TREQUIRES(OUTCOME_TEXPR(detail::lvalueref<std::ostream>() << detail::lvalueref<R>()), OUTCOME_TEXPR(detail::lvalueref<std::ostream>() << detail::lvalueref<S>()), OUTCOME_TEXPR(detail::lvalueref<std::ostream>() << detail::lvalueref<P>()))
inline std::ostream &operator<<(std::ostream &s, const outcome<R, S, P, N> &v)
{
s << v._iostreams_state();
if(v.has_error())
{
s << v.assume_error();
}
if(v.has_exception())
{
s << v.assume_exception();
}
return s;
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
template <class R, class S, class P, class N> inline std::string print(const outcome<R, S, P, N> &v)
{
std::stringstream s;
int total = static_cast<int>(v.has_value()) + static_cast<int>(v.has_error()) + static_cast<int>(v.has_exception());
if(total > 1)
{
s << "{ ";
}
s << print(static_cast<const basic_result<R, S, N> &>(static_cast<const detail::basic_result_final<R, S, N> &>(v))); // NOLINT
if(total > 1)
{
s << ", ";
}
if(v.has_exception())
{
#ifdef __cpp_exceptions
try
{
rethrow_exception(v.exception());
}
catch(const std::system_error &e)
{
s << "std::system_error code " << e.code() << ": " << e.what();
}
catch(const std::exception &e)
{
s << "std::exception: " << e.what();
}
catch(...)
#endif
{
s << "unknown exception";
}
}
if(total > 1)
{
s << " }";
}
return s.str();
}
OUTCOME_V2_NAMESPACE_END
#endif
/* Try operation macros
(C) 2017-2021 Niall Douglas <http://www.nedproductions.biz/> (20 commits)
File Created: July 2017
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License in the accompanying file
Licence.txt or at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Distributed under the Boost Software License, Version 1.0.
(See accompanying file Licence.txt or copy at
http://www.boost.org/LICENSE_1_0.txt)
*/
#ifndef OUTCOME_TRY_HPP
#define OUTCOME_TRY_HPP
/* Try operation macros
(C) 2017-2024 Niall Douglas <http://www.nedproductions.biz/> (20 commits)
File Created: July 2017
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License in the accompanying file
Licence.txt or at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Distributed under the Boost Software License, Version 1.0.
(See accompanying file Licence.txt or copy at
http://www.boost.org/LICENSE_1_0.txt)
*/
#ifndef OUTCOME_TRY_H
#define OUTCOME_TRY_H
#if !defined(__clang__) && defined(__GNUC__) && __GNUC__ >= 8
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wparentheses"
#endif
#define OUTCOME_TRY_GLUE2(x, y) x##y
#define OUTCOME_TRY_GLUE(x, y) OUTCOME_TRY_GLUE2(x, y)
#define OUTCOME_TRY_UNIQUE_NAME OUTCOME_TRY_GLUE(_outcome_try_unique_name_temporary, __COUNTER__)
#define OUTCOME_TRY_RETURN_ARG_COUNT(_1_, _2_, _3_, _4_, _5_, _6_, _7_, _8_, count, ...) count
#define OUTCOME_TRY_EXPAND_ARGS(args) OUTCOME_TRY_RETURN_ARG_COUNT args
#define OUTCOME_TRY_COUNT_ARGS_MAX8(...) OUTCOME_TRY_EXPAND_ARGS((__VA_ARGS__, 8, 7, 6, 5, 4, 3, 2, 1, 0))
#define OUTCOME_TRY_OVERLOAD_MACRO2(name, count) name##count
#define OUTCOME_TRY_OVERLOAD_MACRO1(name, count) OUTCOME_TRY_OVERLOAD_MACRO2(name, count)
#define OUTCOME_TRY_OVERLOAD_MACRO(name, count) OUTCOME_TRY_OVERLOAD_MACRO1(name, count)
#define OUTCOME_TRY_OVERLOAD_GLUE(x, y) x y
#define OUTCOME_TRY_CALL_OVERLOAD(name, ...) OUTCOME_TRY_OVERLOAD_GLUE(OUTCOME_TRY_OVERLOAD_MACRO(name, OUTCOME_TRY_COUNT_ARGS_MAX8(__VA_ARGS__)), (__VA_ARGS__))
#define _OUTCOME_TRY_RETURN_ARG_COUNT(_1_, _2_, _3_, _4_, _5_, _6_, _7_, _8_, count, ...) count
#define _OUTCOME_TRY_EXPAND_ARGS(args) _OUTCOME_TRY_RETURN_ARG_COUNT args
#define _OUTCOME_TRY_COUNT_ARGS_MAX8(...) _OUTCOME_TRY_EXPAND_ARGS((__VA_ARGS__, 8, 7, 6, 5, 4, 3, 2, 1, 0))
#define _OUTCOME_TRY_OVERLOAD_MACRO2(name, count) name##count
#define _OUTCOME_TRY_OVERLOAD_MACRO1(name, count) _OUTCOME_TRY_OVERLOAD_MACRO2(name, count)
#define _OUTCOME_TRY_OVERLOAD_MACRO(name, count) _OUTCOME_TRY_OVERLOAD_MACRO1(name, count)
#define _OUTCOME_TRY_OVERLOAD_GLUE(x, y) x y
#define _OUTCOME_TRY_CALL_OVERLOAD(name, ...) _OUTCOME_TRY_OVERLOAD_GLUE(_OUTCOME_TRY_OVERLOAD_MACRO(name, _OUTCOME_TRY_COUNT_ARGS_MAX8(__VA_ARGS__)), (__VA_ARGS__))
#if !defined(OUTCOME_TRY_LIKELY_IF) && defined(__has_cpp_attribute)
#if __has_cpp_attribute(likely)
#define OUTCOME_TRY_LIKELY_IF(...) if(__VA_ARGS__) [[likely]]
#endif
#endif
#ifndef OUTCOME_TRY_LIKELY_IF
#if defined(__clang__) || defined(__GNUC__)
#define OUTCOME_TRY_LIKELY_IF(...) if(__builtin_expect(!!(__VA_ARGS__), 1))
#else
#define OUTCOME_TRY_LIKELY_IF(...) if(__VA_ARGS__)
#endif
#endif
#ifdef __cplusplus
#define OUTCOME_TRYV2_UNIQUE_STORAGE_AUTO(...) auto
#else
#define OUTCOME_TRYV2_UNIQUE_STORAGE_AUTO(...) __typeof__(__VA_ARGS__)
#endif
#define OUTCOME_TRYV2_UNIQUE_STORAGE_UNPACK(...) __VA_ARGS__
#define OUTCOME_TRYV2_UNIQUE_STORAGE_DEDUCE3(unique, ...) OUTCOME_TRYV2_UNIQUE_STORAGE_AUTO(__VA_ARGS__) unique = (__VA_ARGS__)
#define OUTCOME_TRYV2_UNIQUE_STORAGE_DEDUCE2(x) x
#define OUTCOME_TRYV2_UNIQUE_STORAGE_DEDUCE(unique, x, ...) OUTCOME_TRYV2_UNIQUE_STORAGE_DEDUCE2(OUTCOME_TRYV2_UNIQUE_STORAGE_DEDUCE3(unique, __VA_ARGS__))
#define OUTCOME_TRYV2_UNIQUE_STORAGE_SPECIFIED3(unique, x, y, ...) x unique = (__VA_ARGS__)
#define OUTCOME_TRYV2_UNIQUE_STORAGE_SPECIFIED2(x) x
#define OUTCOME_TRYV2_UNIQUE_STORAGE_SPECIFIED(unique, ...) OUTCOME_TRYV2_UNIQUE_STORAGE_SPECIFIED2(OUTCOME_TRYV2_UNIQUE_STORAGE_SPECIFIED3(unique, __VA_ARGS__))
#define OUTCOME_TRYV2_UNIQUE_STORAGE1(...) OUTCOME_TRYV2_UNIQUE_STORAGE_DEDUCE
#define OUTCOME_TRYV2_UNIQUE_STORAGE2(...) OUTCOME_TRYV2_UNIQUE_STORAGE_SPECIFIED
#define OUTCOME_TRYV2_UNIQUE_STORAGE(unique, spec, ...) _OUTCOME_TRY_CALL_OVERLOAD(OUTCOME_TRYV2_UNIQUE_STORAGE, OUTCOME_TRYV2_UNIQUE_STORAGE_UNPACK spec) (unique, OUTCOME_TRYV2_UNIQUE_STORAGE_UNPACK spec, __VA_ARGS__)
#define OUTCOME_TRY2_VAR_SECOND2(x, var) var
#define OUTCOME_TRY2_VAR_SECOND3(x, y, ...) x y
#define OUTCOME_TRY2_VAR(spec) _OUTCOME_TRY_CALL_OVERLOAD(OUTCOME_TRY2_VAR_SECOND, OUTCOME_TRYV2_UNIQUE_STORAGE_UNPACK spec, spec)
#if !defined(__clang__) && defined(__GNUC__) && __GNUC__ >= 8
#pragma GCC diagnostic pop
#endif
#endif
OUTCOME_V2_NAMESPACE_BEGIN
namespace detail
{
struct has_value_overload
{
};
struct as_failure_overload
{
};
struct assume_error_overload
{
};
struct error_overload
{
};
struct assume_value_overload
{
};
struct value_overload
{
};
// #ifdef __APPLE__
// OUTCOME_TEMPLATE(class T, class R = decltype(std::declval<T>()._xcode_workaround_as_failure()))
// #else
OUTCOME_TEMPLATE(class T, class R = decltype(std::declval<T>().as_failure()))
// #endif
OUTCOME_TREQUIRES(OUTCOME_TPRED(OUTCOME_V2_NAMESPACE::is_failure_type<R>))
constexpr inline bool has_as_failure(int /*unused */)
{
return true;
}
template <class T> constexpr inline bool has_as_failure(...)
{
return false;
}
OUTCOME_TEMPLATE(class T)
OUTCOME_TREQUIRES(OUTCOME_TEXPR(std::declval<T>().assume_error()))
constexpr inline bool has_assume_error(int /*unused */)
{
return true;
}
template <class T> constexpr inline bool has_assume_error(...)
{
return false;
}
OUTCOME_TEMPLATE(class T)
OUTCOME_TREQUIRES(OUTCOME_TEXPR(std::declval<T>().error()))
constexpr inline bool has_error(int /*unused */)
{
return true;
}
template <class T> constexpr inline bool has_error(...)
{
return false;
}
OUTCOME_TEMPLATE(class T)
OUTCOME_TREQUIRES(OUTCOME_TEXPR(std::declval<T>().assume_value()))
constexpr inline bool has_assume_value(int /*unused */)
{
return true;
}
template <class T> constexpr inline bool has_assume_value(...)
{
return false;
}
OUTCOME_TEMPLATE(class T)
OUTCOME_TREQUIRES(OUTCOME_TEXPR(std::declval<T>().value()))
constexpr inline bool has_value(int /*unused */)
{
return true;
}
template <class T> constexpr inline bool has_value(...)
{
return false;
}
} // namespace detail
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class T)
OUTCOME_TREQUIRES(OUTCOME_TEXPR(std::declval<T>().has_value()))
constexpr inline bool try_operation_has_value(T &&v, detail::has_value_overload = {})
{
return v.has_value();
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class T)
OUTCOME_TREQUIRES(OUTCOME_TPRED(detail::has_as_failure<T>(5)))
constexpr inline decltype(auto) try_operation_return_as(T &&v, detail::as_failure_overload = {})
{
return static_cast<T &&>(v).as_failure();
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class T)
OUTCOME_TREQUIRES(OUTCOME_TPRED(!detail::has_as_failure<T>(5) && detail::has_assume_error<T>(5)))
constexpr inline decltype(auto) try_operation_return_as(T &&v, detail::assume_error_overload = {})
{
return failure(static_cast<T &&>(v).assume_error());
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class T)
OUTCOME_TREQUIRES(OUTCOME_TPRED(!detail::has_as_failure<T>(5) && !detail::has_assume_error<T>(5) && detail::has_error<T>(5)))
constexpr inline decltype(auto) try_operation_return_as(T &&v, detail::error_overload = {})
{
return failure(static_cast<T &&>(v).error());
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class T)
OUTCOME_TREQUIRES(OUTCOME_TPRED(detail::has_assume_value<T>(5)))
constexpr inline decltype(auto) try_operation_extract_value(T &&v, detail::assume_value_overload = {})
{
return static_cast<T &&>(v).assume_value();
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class T)
OUTCOME_TREQUIRES(OUTCOME_TPRED(!detail::has_assume_value<T>(5) && detail::has_value<T>(5)))
constexpr inline decltype(auto) try_operation_extract_value(T &&v, detail::value_overload = {})
{
return static_cast<T &&>(v).value();
}
OUTCOME_V2_NAMESPACE_END
#if !defined(__clang__) && defined(__GNUC__) && __GNUC__ >= 8
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wparentheses"
#endif
// Use if(!expr); else as some compilers assume else clauses are always unlikely
#define OUTCOME_TRYV2_SUCCESS_LIKELY(unique, retstmt, spec, ...) OUTCOME_TRYV2_UNIQUE_STORAGE(unique, spec, __VA_ARGS__); OUTCOME_TRY_LIKELY_IF(::OUTCOME_V2_NAMESPACE::try_operation_has_value(unique)); else { /* works around ICE in GCC's coroutines implementation */ auto unique##_f(::OUTCOME_V2_NAMESPACE::try_operation_return_as(static_cast<decltype(unique) &&>(unique))); retstmt unique##_f; }
#define OUTCOME_TRYV3_FAILURE_LIKELY(unique, retstmt, spec, ...) OUTCOME_TRYV2_UNIQUE_STORAGE(unique, spec, __VA_ARGS__); OUTCOME_TRY_LIKELY_IF(!OUTCOME_V2_NAMESPACE::try_operation_has_value(unique)) { /* works around ICE in GCC's coroutines implementation */ auto unique##_f(::OUTCOME_V2_NAMESPACE::try_operation_return_as(static_cast<decltype(unique) &&>(unique))); retstmt unique##_f; }
#define OUTCOME_TRY2_SUCCESS_LIKELY(unique, retstmt, var, ...) OUTCOME_TRYV2_SUCCESS_LIKELY(unique, retstmt, var, __VA_ARGS__); OUTCOME_TRY2_VAR(var) = ::OUTCOME_V2_NAMESPACE::try_operation_extract_value(static_cast<decltype(unique) &&>(unique))
#define OUTCOME_TRY2_FAILURE_LIKELY(unique, retstmt, var, ...) OUTCOME_TRYV3_FAILURE_LIKELY(unique, retstmt, var, __VA_ARGS__); OUTCOME_TRY2_VAR(var) = ::OUTCOME_V2_NAMESPACE::try_operation_extract_value(static_cast<decltype(unique) &&>(unique))
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
#define OUTCOME_TRYV(...) OUTCOME_TRYV2_SUCCESS_LIKELY(OUTCOME_TRY_UNIQUE_NAME, return, deduce, __VA_ARGS__)
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
#define OUTCOME_TRYV_FAILURE_LIKELY(...) OUTCOME_TRYV3_FAILURE_LIKELY(OUTCOME_TRY_UNIQUE_NAME, return, deduce, __VA_ARGS__)
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
#define OUTCOME_CO_TRYV(...) OUTCOME_TRYV2_SUCCESS_LIKELY(OUTCOME_TRY_UNIQUE_NAME, co_return, deduce, __VA_ARGS__)
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
#define OUTCOME_CO_TRYV_FAILURE_LIKELY(...) OUTCOME_TRYV3_FAILURE_LIKELY(OUTCOME_TRY_UNIQUE_NAME, co_return, deduce, __VA_ARGS__)
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
#define OUTCOME_TRYV2(s, ...) OUTCOME_TRYV2_SUCCESS_LIKELY(OUTCOME_TRY_UNIQUE_NAME, return, (s, ), __VA_ARGS__)
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
#define OUTCOME_TRYV2_FAILURE_LIKELY(s, ...) OUTCOME_TRYV3_FAILURE_LIKELY(OUTCOME_TRY_UNIQUE_NAME, return, (s, ), __VA_ARGS__)
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
#define OUTCOME_CO_TRYV2(s, ...) OUTCOME_TRYV2_SUCCESS_LIKELY(OUTCOME_TRY_UNIQUE_NAME, co_return, (s, ), __VA_ARGS__)
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
#define OUTCOME_CO_TRYV2_FAILURE_LIKELY(s, ...) OUTCOME_TRYV3_FAILURE_LIKELY(OUTCOME_TRY_UNIQUE_NAME, co_return, s(, ), __VA_ARGS__)
#if defined(__GNUC__) || defined(__clang__)
#define OUTCOME_TRYX2(unique, retstmt, ...) ({ OUTCOME_TRYV2_SUCCESS_LIKELY(unique, retstmt, deduce, __VA_ARGS__); ::OUTCOME_V2_NAMESPACE::try_operation_extract_value(static_cast<decltype(unique) &&>(unique)); })
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
#define OUTCOME_TRYX(...) OUTCOME_TRYX2(OUTCOME_TRY_UNIQUE_NAME, return, __VA_ARGS__)
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
#define OUTCOME_CO_TRYX(...) OUTCOME_TRYX2(OUTCOME_TRY_UNIQUE_NAME, co_return, __VA_ARGS__)
#endif
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
#define OUTCOME_TRYA(v, ...) OUTCOME_TRY2_SUCCESS_LIKELY(OUTCOME_TRY_UNIQUE_NAME, return, v, __VA_ARGS__)
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
#define OUTCOME_TRYA_FAILURE_LIKELY(v, ...) OUTCOME_TRY2_FAILURE_LIKELY(OUTCOME_TRY_UNIQUE_NAME, return, v, __VA_ARGS__)
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
#define OUTCOME_CO_TRYA(v, ...) OUTCOME_TRY2_SUCCESS_LIKELY(OUTCOME_TRY_UNIQUE_NAME, co_return, v, __VA_ARGS__)
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
#define OUTCOME_CO_TRYA_FAILURE_LIKELY(v, ...) OUTCOME_TRY2_FAILURE_LIKELY(OUTCOME_TRY_UNIQUE_NAME, co_return, v, __VA_ARGS__)
#define OUTCOME_TRY_INVOKE_TRY8(a, b, c, d, e, f, g, h) OUTCOME_TRYA(a, b, c, d, e, f, g, h)
#define OUTCOME_TRY_INVOKE_TRY7(a, b, c, d, e, f, g) OUTCOME_TRYA(a, b, c, d, e, f, g)
#define OUTCOME_TRY_INVOKE_TRY6(a, b, c, d, e, f) OUTCOME_TRYA(a, b, c, d, e, f)
#define OUTCOME_TRY_INVOKE_TRY5(a, b, c, d, e) OUTCOME_TRYA(a, b, c, d, e)
#define OUTCOME_TRY_INVOKE_TRY4(a, b, c, d) OUTCOME_TRYA(a, b, c, d)
#define OUTCOME_TRY_INVOKE_TRY3(a, b, c) OUTCOME_TRYA(a, b, c)
#define OUTCOME_TRY_INVOKE_TRY2(a, b) OUTCOME_TRYA(a, b)
#define OUTCOME_TRY_INVOKE_TRY1(a) OUTCOME_TRYV(a)
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
#define OUTCOME_TRY(...) OUTCOME_TRY_CALL_OVERLOAD(OUTCOME_TRY_INVOKE_TRY, __VA_ARGS__)
#define OUTCOME_TRY_FAILURE_LIKELY_INVOKE_TRY8(a, b, c, d, e, f, g, h) OUTCOME_TRYA_FAILURE_LIKELY(a, b, c, d, e, f, g, h)
#define OUTCOME_TRY_FAILURE_LIKELY_INVOKE_TRY7(a, b, c, d, e, f, g) OUTCOME_TRYA_FAILURE_LIKELY(a, b, c, d, e, f, g)
#define OUTCOME_TRY_FAILURE_LIKELY_INVOKE_TRY6(a, b, c, d, e, f) OUTCOME_TRYA_FAILURE_LIKELY(a, b, c, d, e, f)
#define OUTCOME_TRY_FAILURE_LIKELY_INVOKE_TRY5(a, b, c, d, e) OUTCOME_TRYA_FAILURE_LIKELY(a, b, c, d, e)
#define OUTCOME_TRY_FAILURE_LIKELY_INVOKE_TRY4(a, b, c, d) OUTCOME_TRYA_FAILURE_LIKELY(a, b, c, d)
#define OUTCOME_TRY_FAILURE_LIKELY_INVOKE_TRY3(a, b, c) OUTCOME_TRYA_FAILURE_LIKELY(a, b, c)
#define OUTCOME_TRY_FAILURE_LIKELY_INVOKE_TRY2(a, b) OUTCOME_TRYA_FAILURE_LIKELY(a, b)
#define OUTCOME_TRY_FAILURE_LIKELY_INVOKE_TRY1(a) OUTCOME_TRYV_FAILURE_LIKELY(a)
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
#define OUTCOME_TRY_FAILURE_LIKELY(...) OUTCOME_TRY_CALL_OVERLOAD(OUTCOME_TRY_FAILURE_LIKELY_INVOKE_TRY, __VA_ARGS__)
#define OUTCOME_CO_TRY_INVOKE_TRY8(a, b, c, d, e, f, g, h) OUTCOME_CO_TRYA(a, b, c, d, e, f, g, h)
#define OUTCOME_CO_TRY_INVOKE_TRY7(a, b, c, d, e, f, g) OUTCOME_CO_TRYA(a, b, c, d, e, f, g)
#define OUTCOME_CO_TRY_INVOKE_TRY6(a, b, c, d, e, f) OUTCOME_CO_TRYA(a, b, c, d, e, f)
#define OUTCOME_CO_TRY_INVOKE_TRY5(a, b, c, d, e) OUTCOME_CO_TRYA(a, b, c, d, e)
#define OUTCOME_CO_TRY_INVOKE_TRY4(a, b, c, d) OUTCOME_CO_TRYA(a, b, c, d)
#define OUTCOME_CO_TRY_INVOKE_TRY3(a, b, c) OUTCOME_CO_TRYA(a, b, c)
#define OUTCOME_CO_TRY_INVOKE_TRY2(a, b) OUTCOME_CO_TRYA(a, b)
#define OUTCOME_CO_TRY_INVOKE_TRY1(a) OUTCOME_CO_TRYV(a)
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
#define OUTCOME_CO_TRY(...) OUTCOME_TRY_CALL_OVERLOAD(OUTCOME_CO_TRY_INVOKE_TRY, __VA_ARGS__)
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
#define OUTCOME_TRY(...) OUTCOME_TRY_CALL_OVERLOAD(OUTCOME_TRY_INVOKE_TRY, __VA_ARGS__)
#define OUTCOME_CO_TRY_FAILURE_LIKELY_INVOKE_TRY8(a, b, c, d, e, f, g, h) OUTCOME_CO_TRYA_FAILURE_LIKELY(a, b, c, d, e, f, g, h)
#define OUTCOME_CO_TRY_FAILURE_LIKELY_INVOKE_TRY7(a, b, c, d, e, f, g) OUTCOME_CO_TRYA_FAILURE_LIKELY(a, b, c, d, e, f, g)
#define OUTCOME_CO_TRY_FAILURE_LIKELY_INVOKE_TRY6(a, b, c, d, e, f) OUTCOME_CO_TRYA_FAILURE_LIKELY(a, b, c, d, e, f)
#define OUTCOME_CO_TRY_FAILURE_LIKELY_INVOKE_TRY5(a, b, c, d, e) OUTCOME_CO_TRYA_FAILURE_LIKELY(a, b, c, d, e)
#define OUTCOME_CO_TRY_FAILURE_LIKELY_INVOKE_TRY4(a, b, c, d) OUTCOME_CO_TRYA_FAILURE_LIKELY(a, b, c, d)
#define OUTCOME_CO_TRY_FAILURE_LIKELY_INVOKE_TRY3(a, b, c) OUTCOME_CO_TRYA_FAILURE_LIKELY(a, b, c)
#define OUTCOME_CO_TRY_FAILURE_LIKELY_INVOKE_TRY2(a, b) OUTCOME_CO_TRYA_FAILURE_LIKELY(a, b)
#define OUTCOME_CO_TRY_FAILURE_LIKELY_INVOKE_TRY1(a) OUTCOME_CO_TRYV_FAILURE_LIKELY(a)
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
#define OUTCOME_CO_TRY_FAILURE_LIKELY(...) OUTCOME_TRY_CALL_OVERLOAD(OUTCOME_CO_TRY_FAILURE_LIKELY_INVOKE_TRY, __VA_ARGS__)
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
#define OUTCOME21_TRYA(v, ...) OUTCOME_TRY2_SUCCESS_LIKELY(OUTCOME_TRY_UNIQUE_NAME, return, deduce, auto &&v, __VA_ARGS__)
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
#define OUTCOME21_TRYA_FAILURE_LIKELY(v, ...) OUTCOME_TRY2_FAILURE_LIKELY(OUTCOME_TRY_UNIQUE_NAME, return, deduce, auto &&v, __VA_ARGS__)
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
#define OUTCOME21_CO_TRYA(v, ...) OUTCOME_TRY2_FAILURE_LIKELY(OUTCOME_TRY_UNIQUE_NAME, co_return, deduce, auto &&v, __VA_ARGS__)
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
#define OUTCOME21_CO_TRYA_FAILURE_LIKELY(v, ...) OUTCOME_TRY2_FAILURE_LIKELY(OUTCOME_TRY_UNIQUE_NAME, co_retrn, deduce, auto &&v, __VA_ARGS__)
#define OUTCOME21_TRY_INVOKE_TRY8(a, b, c, d, e, f, g, h) OUTCOME21_TRYA(a, b, c, d, e, f, g, h)
#define OUTCOME21_TRY_INVOKE_TRY7(a, b, c, d, e, f, g) OUTCOME21_TRYA(a, b, c, d, e, f, g)
#define OUTCOME21_TRY_INVOKE_TRY6(a, b, c, d, e, f) OUTCOME21_TRYA(a, b, c, d, e, f)
#define OUTCOME21_TRY_INVOKE_TRY5(a, b, c, d, e) OUTCOME21_TRYA(a, b, c, d, e)
#define OUTCOME21_TRY_INVOKE_TRY4(a, b, c, d) OUTCOME21_TRYA(a, b, c, d)
#define OUTCOME21_TRY_INVOKE_TRY3(a, b, c) OUTCOME21_TRYA(a, b, c)
#define OUTCOME21_TRY_INVOKE_TRY2(a, b) OUTCOME21_TRYA(a, b)
#define OUTCOME21_TRY_INVOKE_TRY1(a) OUTCOME_TRYV(a)
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
#define OUTCOME21_TRY(...) OUTCOME_TRY_CALL_OVERLOAD(OUTCOME21_TRY_INVOKE_TRY, __VA_ARGS__)
#define OUTCOME21_TRY_FAILURE_LIKELY_INVOKE_TRY8(a, b, c, d, e, f, g, h) OUTCOME21_TRYA_FAILURE_LIKELY(a, b, c, d, e, f, g, h)
#define OUTCOME21_TRY_FAILURE_LIKELY_INVOKE_TRY7(a, b, c, d, e, f, g) OUTCOME21_TRYA_FAILURE_LIKELY(a, b, c, d, e, f, g)
#define OUTCOME21_TRY_FAILURE_LIKELY_INVOKE_TRY6(a, b, c, d, e, f) OUTCOME21_TRYA_FAILURE_LIKELY(a, b, c, d, e, f)
#define OUTCOME21_TRY_FAILURE_LIKELY_INVOKE_TRY5(a, b, c, d, e) OUTCOME21_TRYA_FAILURE_LIKELY(a, b, c, d, e)
#define OUTCOME21_TRY_FAILURE_LIKELY_INVOKE_TRY4(a, b, c, d) OUTCOME21_TRYA_FAILURE_LIKELY(a, b, c, d)
#define OUTCOME21_TRY_FAILURE_LIKELY_INVOKE_TRY3(a, b, c) OUTCOME21_TRYA_FAILURE_LIKELY(a, b, c)
#define OUTCOME21_TRY_FAILURE_LIKELY_INVOKE_TRY2(a, b) OUTCOME21_TRYA_FAILURE_LIKELY(a, b)
#define OUTCOME21_TRY_FAILURE_LIKELY_INVOKE_TRY1(a) OUTCOME_TRYV_FAILURE_LIKELY(a)
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
#define OUTCOME21_TRY_FAILURE_LIKELY(...) OUTCOME_TRY_CALL_OVERLOAD(OUTCOME21_TRY_FAILURE_LIKELY_INVOKE_TRY, __VA_ARGS__)
#define OUTCOME21_CO_TRY_INVOKE_TRY8(a, b, c, d, e, f, g, h) OUTCOME21_CO_TRYA(a, b, c, d, e, f, g, h)
#define OUTCOME21_CO_TRY_INVOKE_TRY7(a, b, c, d, e, f, g) OUTCOME21_CO_TRYA(a, b, c, d, e, f, g)
#define OUTCOME21_CO_TRY_INVOKE_TRY6(a, b, c, d, e, f) OUTCOME21_CO_TRYA(a, b, c, d, e, f)
#define OUTCOME21_CO_TRY_INVOKE_TRY5(a, b, c, d, e) OUTCOME21_CO_TRYA(a, b, c, d, e)
#define OUTCOME21_CO_TRY_INVOKE_TRY4(a, b, c, d) OUTCOME21_CO_TRYA(a, b, c, d)
#define OUTCOME21_CO_TRY_INVOKE_TRY3(a, b, c) OUTCOME21_CO_TRYA(a, b, c)
#define OUTCOME21_CO_TRY_INVOKE_TRY2(a, b) OUTCOME21_CO_TRYA(a, b)
#define OUTCOME21_CO_TRY_INVOKE_TRY1(a) OUTCOME_CO_TRYV(a)
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
#define OUTCOME21_CO_TRY(...) OUTCOME_TRY_CALL_OVERLOAD(OUTCOME21_CO_TRY_INVOKE_TRY, __VA_ARGS__)
#define OUTCOME21_CO_TRY_FAILURE_LIKELY_INVOKE_TRY8(a, b, c, d, e, f, g, h) OUTCOME21_CO_TRYA_FAILURE_LIKELY(a, b, c, d, e, f, g, h)
#define OUTCOME21_CO_TRY_FAILURE_LIKELY_INVOKE_TRY7(a, b, c, d, e, f, g) OUTCOME21_CO_TRYA_FAILURE_LIKELY(a, b, c, d, e, f, g)
#define OUTCOME21_CO_TRY_FAILURE_LIKELY_INVOKE_TRY6(a, b, c, d, e, f) OUTCOME21_CO_TRYA_FAILURE_LIKELY(a, b, c, d, e, f)
#define OUTCOME21_CO_TRY_FAILURE_LIKELY_INVOKE_TRY5(a, b, c, d, e) OUTCOME21_CO_TRYA_FAILURE_LIKELY(a, b, c, d, e)
#define OUTCOME21_CO_TRY_FAILURE_LIKELY_INVOKE_TRY4(a, b, c, d) OUTCOME21_CO_TRYA_FAILURE_LIKELY(a, b, c, d)
#define OUTCOME21_CO_TRY_FAILURE_LIKELY_INVOKE_TRY3(a, b, c) OUTCOME21_CO_TRYA_FAILURE_LIKELY(a, b, c)
#define OUTCOME21_CO_TRY_FAILURE_LIKELY_INVOKE_TRY2(a, b) OUTCOME21_CO_TRYA_FAILURE_LIKELY(a, b)
#define OUTCOME21_CO_TRY_FAILURE_LIKELY_INVOKE_TRY1(a) OUTCOME_CO_TRYV_FAILURE_LIKELY(a)
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
#define OUTCOME21_CO_TRY_FAILURE_LIKELY(...) OUTCOME_TRY_CALL_OVERLOAD(OUTCOME21_CO_TRY_FAILURE_LIKELY_INVOKE_TRY, __VA_ARGS__)
#if !defined(__clang__) && defined(__GNUC__) && __GNUC__ >= 8
#pragma GCC diagnostic pop
#endif
#endif
#else
import OUTCOME_V2_CXX_MODULE_NAME;
#endif
|
0 | repos/outcome | repos/outcome/single-header/outcome-experimental.hpp | /* A less simple result type
(C) 2018-2019 Niall Douglas <http://www.nedproductions.biz/> (17 commits)
File Created: Apr 2018
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License in the accompanying file
Licence.txt or at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Distributed under the Boost Software License, Version 1.0.
(See accompanying file Licence.txt or copy at
http://www.boost.org/LICENSE_1_0.txt)
*/
#ifndef OUTCOME_EXPERIMENTAL_STATUS_OUTCOME_HPP
#define OUTCOME_EXPERIMENTAL_STATUS_OUTCOME_HPP
/* A less simple result type
(C) 2017-2024 Niall Douglas <http://www.nedproductions.biz/> (20 commits)
File Created: June 2017
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License in the accompanying file
Licence.txt or at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Distributed under the Boost Software License, Version 1.0.
(See accompanying file Licence.txt or copy at
http://www.boost.org/LICENSE_1_0.txt)
*/
#ifndef OUTCOME_BASIC_OUTCOME_HPP
#define OUTCOME_BASIC_OUTCOME_HPP
/* Configure Outcome with QuickCppLib
(C) 2015-2021 Niall Douglas <http://www.nedproductions.biz/> (24 commits)
File Created: August 2015
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License in the accompanying file
Licence.txt or at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Distributed under the Boost Software License, Version 1.0.
(See accompanying file Licence.txt or copy at
http://www.boost.org/LICENSE_1_0.txt)
*/
#ifndef OUTCOME_V2_CONFIG_HPP
#define OUTCOME_V2_CONFIG_HPP
/* Sets Outcome version
(C) 2017-2023 Niall Douglas <http://www.nedproductions.biz/> (4 commits)
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License in the accompanying file
Licence.txt or at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Distributed under the Boost Software License, Version 1.0.
(See accompanying file Licence.txt or copy at
http://www.boost.org/LICENSE_1_0.txt)
*/
/*! AWAITING HUGO JSON CONVERSION TOOL */
#define OUTCOME_VERSION_MAJOR 2
/*! AWAITING HUGO JSON CONVERSION TOOL */
#define OUTCOME_VERSION_MINOR 2
/*! AWAITING HUGO JSON CONVERSION TOOL */
#define OUTCOME_VERSION_PATCH 9
/*! AWAITING HUGO JSON CONVERSION TOOL */
#define OUTCOME_VERSION_REVISION 0 // Revision version for cmake and DLL version stamping
/*! AWAITING HUGO JSON CONVERSION TOOL */
// Pull in detection of __MINGW64_VERSION_MAJOR
#if defined(__MINGW32__) && !0L
#include <_mingw.h>
#endif
/* Configure QuickCppLib
(C) 2016-2021 Niall Douglas <http://www.nedproductions.biz/> (8 commits)
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License in the accompanying file
Licence.txt or at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Distributed under the Boost Software License, Version 1.0.
(See accompanying file Licence.txt or copy at
http://www.boost.org/LICENSE_1_0.txt)
*/
#ifndef QUICKCPPLIB_CONFIG_HPP
#define QUICKCPPLIB_CONFIG_HPP
/* Provides SG-10 feature checking for all C++ compilers
(C) 2014-2017 Niall Douglas <http://www.nedproductions.biz/> (13 commits)
File Created: Nov 2014
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License in the accompanying file
Licence.txt or at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Distributed under the Boost Software License, Version 1.0.
(See accompanying file Licence.txt or copy at
http://www.boost.org/LICENSE_1_0.txt)
*/
#ifndef QUICKCPPLIB_HAS_FEATURE_H
#define QUICKCPPLIB_HAS_FEATURE_H
#if __cplusplus >= 201103L
// Some of these macros ended up getting removed by ISO standards,
// they are prefixed with ////
////#if !defined(__cpp_alignas)
////#define __cpp_alignas 190000
////#endif
////#if !defined(__cpp_default_function_template_args)
////#define __cpp_default_function_template_args 190000
////#endif
////#if !defined(__cpp_defaulted_functions)
////#define __cpp_defaulted_functions 190000
////#endif
////#if !defined(__cpp_deleted_functions)
////#define __cpp_deleted_functions 190000
////#endif
////#if !defined(__cpp_generalized_initializers)
////#define __cpp_generalized_initializers 190000
////#endif
////#if !defined(__cpp_implicit_moves)
////#define __cpp_implicit_moves 190000
////#endif
////#if !defined(__cpp_inline_namespaces)
////#define __cpp_inline_namespaces 190000
////#endif
////#if !defined(__cpp_local_type_template_args)
////#define __cpp_local_type_template_args 190000
////#endif
////#if !defined(__cpp_noexcept)
////#define __cpp_noexcept 190000
////#endif
////#if !defined(__cpp_nonstatic_member_init)
////#define __cpp_nonstatic_member_init 190000
////#endif
////#if !defined(__cpp_nullptr)
////#define __cpp_nullptr 190000
////#endif
////#if !defined(__cpp_override_control)
////#define __cpp_override_control 190000
////#endif
////#if !defined(__cpp_thread_local)
////#define __cpp_thread_local 190000
////#endif
////#if !defined(__cpp_auto_type)
////#define __cpp_auto_type 190000
////#endif
////#if !defined(__cpp_strong_enums)
////#define __cpp_strong_enums 190000
////#endif
////#if !defined(__cpp_trailing_return)
////#define __cpp_trailing_return 190000
////#endif
////#if !defined(__cpp_unrestricted_unions)
////#define __cpp_unrestricted_unions 190000
////#endif
#if !defined(__cpp_alias_templates)
#define __cpp_alias_templates 190000
#endif
#if !defined(__cpp_attributes)
#define __cpp_attributes 190000
#endif
#if !defined(__cpp_constexpr)
#if __cplusplus >= 201402L
#define __cpp_constexpr 201304 // relaxed constexpr
#else
#define __cpp_constexpr 190000
#endif
#endif
#if !defined(__cpp_decltype)
#define __cpp_decltype 190000
#endif
#if !defined(__cpp_delegating_constructors)
#define __cpp_delegating_constructors 190000
#endif
#if !defined(__cpp_explicit_conversion) //// renamed from __cpp_explicit_conversions
#define __cpp_explicit_conversion 190000
#endif
#if !defined(__cpp_inheriting_constructors)
#define __cpp_inheriting_constructors 190000
#endif
#if !defined(__cpp_initializer_lists) //// NEW
#define __cpp_initializer_lists 190000
#endif
#if !defined(__cpp_lambdas)
#define __cpp_lambdas 190000
#endif
#if !defined(__cpp_nsdmi)
#define __cpp_nsdmi 190000 //// NEW
#endif
#if !defined(__cpp_range_based_for) //// renamed from __cpp_range_for
#define __cpp_range_based_for 190000
#endif
#if !defined(__cpp_raw_strings)
#define __cpp_raw_strings 190000
#endif
#if !defined(__cpp_ref_qualifiers) //// renamed from __cpp_reference_qualified_functions
#define __cpp_ref_qualifiers 190000
#endif
#if !defined(__cpp_rvalue_references)
#define __cpp_rvalue_references 190000
#endif
#if !defined(__cpp_static_assert)
#define __cpp_static_assert 190000
#endif
#if !defined(__cpp_unicode_characters) //// NEW
#define __cpp_unicode_characters 190000
#endif
#if !defined(__cpp_unicode_literals)
#define __cpp_unicode_literals 190000
#endif
#if !defined(__cpp_user_defined_literals)
#define __cpp_user_defined_literals 190000
#endif
#if !defined(__cpp_variadic_templates)
#define __cpp_variadic_templates 190000
#endif
#endif
#if __cplusplus >= 201402L
// Some of these macros ended up getting removed by ISO standards,
// they are prefixed with ////
////#if !defined(__cpp_contextual_conversions)
////#define __cpp_contextual_conversions 190000
////#endif
////#if !defined(__cpp_digit_separators)
////#define __cpp_digit_separators 190000
////#endif
////#if !defined(__cpp_relaxed_constexpr)
////#define __cpp_relaxed_constexpr 190000
////#endif
////#if !defined(__cpp_runtime_arrays)
////# define __cpp_runtime_arrays 190000
////#endif
#if !defined(__cpp_aggregate_nsdmi)
#define __cpp_aggregate_nsdmi 190000
#endif
#if !defined(__cpp_binary_literals)
#define __cpp_binary_literals 190000
#endif
#if !defined(__cpp_decltype_auto)
#define __cpp_decltype_auto 190000
#endif
#if !defined(__cpp_generic_lambdas)
#define __cpp_generic_lambdas 190000
#endif
#if !defined(__cpp_init_captures)
#define __cpp_init_captures 190000
#endif
#if !defined(__cpp_return_type_deduction)
#define __cpp_return_type_deduction 190000
#endif
#if !defined(__cpp_sized_deallocation)
#define __cpp_sized_deallocation 190000
#endif
#if !defined(__cpp_variable_templates)
#define __cpp_variable_templates 190000
#endif
#endif
// VS2010: _MSC_VER=1600
// VS2012: _MSC_VER=1700
// VS2013: _MSC_VER=1800
// VS2015: _MSC_VER=1900
// VS2017: _MSC_VER=1910
#if defined(_MSC_VER) && !defined(__clang__)
#if !defined(__cpp_exceptions) && defined(_CPPUNWIND)
#define __cpp_exceptions 190000
#endif
#if !defined(__cpp_rtti) && defined(_CPPRTTI)
#define __cpp_rtti 190000
#endif
// C++ 11
#if !defined(__cpp_alias_templates) && _MSC_VER >= 1800
#define __cpp_alias_templates 190000
#endif
#if !defined(__cpp_attributes)
#define __cpp_attributes 190000
#endif
#if !defined(__cpp_constexpr) && _MSC_FULL_VER >= 190023506 /* VS2015 */
#define __cpp_constexpr 190000
#endif
#if !defined(__cpp_decltype) && _MSC_VER >= 1600
#define __cpp_decltype 190000
#endif
#if !defined(__cpp_delegating_constructors) && _MSC_VER >= 1800
#define __cpp_delegating_constructors 190000
#endif
#if !defined(__cpp_explicit_conversion) && _MSC_VER >= 1800
#define __cpp_explicit_conversion 190000
#endif
#if !defined(__cpp_inheriting_constructors) && _MSC_VER >= 1900
#define __cpp_inheriting_constructors 190000
#endif
#if !defined(__cpp_initializer_lists) && _MSC_VER >= 1900
#define __cpp_initializer_lists 190000
#endif
#if !defined(__cpp_lambdas) && _MSC_VER >= 1600
#define __cpp_lambdas 190000
#endif
#if !defined(__cpp_nsdmi) && _MSC_VER >= 1900
#define __cpp_nsdmi 190000
#endif
#if !defined(__cpp_range_based_for) && _MSC_VER >= 1700
#define __cpp_range_based_for 190000
#endif
#if !defined(__cpp_raw_strings) && _MSC_VER >= 1800
#define __cpp_raw_strings 190000
#endif
#if !defined(__cpp_ref_qualifiers) && _MSC_VER >= 1900
#define __cpp_ref_qualifiers 190000
#endif
#if !defined(__cpp_rvalue_references) && _MSC_VER >= 1600
#define __cpp_rvalue_references 190000
#endif
#if !defined(__cpp_static_assert) && _MSC_VER >= 1600
#define __cpp_static_assert 190000
#endif
//#if !defined(__cpp_unicode_literals)
//# define __cpp_unicode_literals 190000
//#endif
#if !defined(__cpp_user_defined_literals) && _MSC_VER >= 1900
#define __cpp_user_defined_literals 190000
#endif
#if !defined(__cpp_variadic_templates) && _MSC_VER >= 1800
#define __cpp_variadic_templates 190000
#endif
// C++ 14
//#if !defined(__cpp_aggregate_nsdmi)
//#define __cpp_aggregate_nsdmi 190000
//#endif
#if !defined(__cpp_binary_literals) && _MSC_VER >= 1900
#define __cpp_binary_literals 190000
#endif
#if !defined(__cpp_decltype_auto) && _MSC_VER >= 1900
#define __cpp_decltype_auto 190000
#endif
#if !defined(__cpp_generic_lambdas) && _MSC_VER >= 1900
#define __cpp_generic_lambdas 190000
#endif
#if !defined(__cpp_init_captures) && _MSC_VER >= 1900
#define __cpp_init_captures 190000
#endif
#if !defined(__cpp_return_type_deduction) && _MSC_VER >= 1900
#define __cpp_return_type_deduction 190000
#endif
#if !defined(__cpp_sized_deallocation) && _MSC_VER >= 1900
#define __cpp_sized_deallocation 190000
#endif
#if !defined(__cpp_variable_templates) && _MSC_FULL_VER >= 190023506
#define __cpp_variable_templates 190000
#endif
#endif // _MSC_VER
// Much to my surprise, GCC's support of these is actually incomplete, so fill in the gaps
#if (defined(__GNUC__) && !defined(__clang__))
#define QUICKCPPLIB_GCC (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__)
#if !defined(__cpp_exceptions) && defined(__EXCEPTIONS)
#define __cpp_exceptions 190000
#endif
#if !defined(__cpp_rtti) && defined(__GXX_RTTI)
#define __cpp_rtti 190000
#endif
// C++ 11
#if defined(__GXX_EXPERIMENTAL_CXX0X__)
#if !defined(__cpp_alias_templates) && (QUICKCPPLIB_GCC >= 40700)
#define __cpp_alias_templates 190000
#endif
#if !defined(__cpp_attributes) && (QUICKCPPLIB_GCC >= 40800)
#define __cpp_attributes 190000
#endif
#if !defined(__cpp_constexpr) && (QUICKCPPLIB_GCC >= 40600)
#define __cpp_constexpr 190000
#endif
#if !defined(__cpp_decltype) && (QUICKCPPLIB_GCC >= 40300)
#define __cpp_decltype 190000
#endif
#if !defined(__cpp_delegating_constructors) && (QUICKCPPLIB_GCC >= 40700)
#define __cpp_delegating_constructors 190000
#endif
#if !defined(__cpp_explicit_conversion) && (QUICKCPPLIB_GCC >= 40500)
#define __cpp_explicit_conversion 190000
#endif
#if !defined(__cpp_inheriting_constructors) && (QUICKCPPLIB_GCC >= 40800)
#define __cpp_inheriting_constructors 190000
#endif
#if !defined(__cpp_initializer_lists) && (QUICKCPPLIB_GCC >= 40800)
#define __cpp_initializer_lists 190000
#endif
#if !defined(__cpp_lambdas) && (QUICKCPPLIB_GCC >= 40500)
#define __cpp_lambdas 190000
#endif
#if !defined(__cpp_nsdmi) && (QUICKCPPLIB_GCC >= 40700)
#define __cpp_nsdmi 190000
#endif
#if !defined(__cpp_range_based_for) && (QUICKCPPLIB_GCC >= 40600)
#define __cpp_range_based_for 190000
#endif
#if !defined(__cpp_raw_strings) && (QUICKCPPLIB_GCC >= 40500)
#define __cpp_raw_strings 190000
#endif
#if !defined(__cpp_ref_qualifiers) && (QUICKCPPLIB_GCC >= 40801)
#define __cpp_ref_qualifiers 190000
#endif
// __cpp_rvalue_reference deviation
#if !defined(__cpp_rvalue_references) && defined(__cpp_rvalue_reference)
#define __cpp_rvalue_references __cpp_rvalue_reference
#endif
#if !defined(__cpp_static_assert) && (QUICKCPPLIB_GCC >= 40300)
#define __cpp_static_assert 190000
#endif
#if !defined(__cpp_unicode_characters) && (QUICKCPPLIB_GCC >= 40500)
#define __cpp_unicode_characters 190000
#endif
#if !defined(__cpp_unicode_literals) && (QUICKCPPLIB_GCC >= 40500)
#define __cpp_unicode_literals 190000
#endif
#if !defined(__cpp_user_defined_literals) && (QUICKCPPLIB_GCC >= 40700)
#define __cpp_user_defined_literals 190000
#endif
#if !defined(__cpp_variadic_templates) && (QUICKCPPLIB_GCC >= 40400)
#define __cpp_variadic_templates 190000
#endif
// C++ 14
// Every C++ 14 supporting GCC does the right thing here
#endif // __GXX_EXPERIMENTAL_CXX0X__
#endif // GCC
// clang deviates in some places from the present SG-10 draft, plus older
// clangs are quite incomplete
#if defined(__clang__)
#define QUICKCPPLIB_CLANG (__clang_major__ * 10000 + __clang_minor__ * 100 + __clang_patchlevel__)
#if !defined(__cpp_exceptions) && (defined(__EXCEPTIONS) || defined(_CPPUNWIND))
#define __cpp_exceptions 190000
#endif
#if !defined(__cpp_rtti) && (defined(__GXX_RTTI) || defined(_CPPRTTI))
#define __cpp_rtti 190000
#endif
// C++ 11
#if defined(__GXX_EXPERIMENTAL_CXX0X__)
#if !defined(__cpp_alias_templates) && (QUICKCPPLIB_CLANG >= 30000)
#define __cpp_alias_templates 190000
#endif
#if !defined(__cpp_attributes) && (QUICKCPPLIB_CLANG >= 30300)
#define __cpp_attributes 190000
#endif
#if !defined(__cpp_constexpr) && (QUICKCPPLIB_CLANG >= 30100)
#define __cpp_constexpr 190000
#endif
#if !defined(__cpp_decltype) && (QUICKCPPLIB_CLANG >= 20900)
#define __cpp_decltype 190000
#endif
#if !defined(__cpp_delegating_constructors) && (QUICKCPPLIB_CLANG >= 30000)
#define __cpp_delegating_constructors 190000
#endif
#if !defined(__cpp_explicit_conversion) && (QUICKCPPLIB_CLANG >= 30000)
#define __cpp_explicit_conversion 190000
#endif
#if !defined(__cpp_inheriting_constructors) && (QUICKCPPLIB_CLANG >= 30300)
#define __cpp_inheriting_constructors 190000
#endif
#if !defined(__cpp_initializer_lists) && (QUICKCPPLIB_CLANG >= 30100)
#define __cpp_initializer_lists 190000
#endif
#if !defined(__cpp_lambdas) && (QUICKCPPLIB_CLANG >= 30100)
#define __cpp_lambdas 190000
#endif
#if !defined(__cpp_nsdmi) && (QUICKCPPLIB_CLANG >= 30000)
#define __cpp_nsdmi 190000
#endif
#if !defined(__cpp_range_based_for) && (QUICKCPPLIB_CLANG >= 30000)
#define __cpp_range_based_for 190000
#endif
// __cpp_raw_string_literals deviation
#if !defined(__cpp_raw_strings) && defined(__cpp_raw_string_literals)
#define __cpp_raw_strings __cpp_raw_string_literals
#endif
#if !defined(__cpp_raw_strings) && (QUICKCPPLIB_CLANG >= 30000)
#define __cpp_raw_strings 190000
#endif
#if !defined(__cpp_ref_qualifiers) && (QUICKCPPLIB_CLANG >= 20900)
#define __cpp_ref_qualifiers 190000
#endif
// __cpp_rvalue_reference deviation
#if !defined(__cpp_rvalue_references) && defined(__cpp_rvalue_reference)
#define __cpp_rvalue_references __cpp_rvalue_reference
#endif
#if !defined(__cpp_rvalue_references) && (QUICKCPPLIB_CLANG >= 20900)
#define __cpp_rvalue_references 190000
#endif
#if !defined(__cpp_static_assert) && (QUICKCPPLIB_CLANG >= 20900)
#define __cpp_static_assert 190000
#endif
#if !defined(__cpp_unicode_characters) && (QUICKCPPLIB_CLANG >= 30000)
#define __cpp_unicode_characters 190000
#endif
#if !defined(__cpp_unicode_literals) && (QUICKCPPLIB_CLANG >= 30000)
#define __cpp_unicode_literals 190000
#endif
// __cpp_user_literals deviation
#if !defined(__cpp_user_defined_literals) && defined(__cpp_user_literals)
#define __cpp_user_defined_literals __cpp_user_literals
#endif
#if !defined(__cpp_user_defined_literals) && (QUICKCPPLIB_CLANG >= 30100)
#define __cpp_user_defined_literals 190000
#endif
#if !defined(__cpp_variadic_templates) && (QUICKCPPLIB_CLANG >= 20900)
#define __cpp_variadic_templates 190000
#endif
// C++ 14
// Every C++ 14 supporting clang does the right thing here
#endif // __GXX_EXPERIMENTAL_CXX0X__
#endif // clang
#endif
/*
This is a dummy header file which is a placeholder for the real config.hpp which
gets generated by the build system. This file is here to allow the library to be
used without the build system.
*/
#if defined(min)
#error "You must not define min() as a macro, because this is unsupported and known to break e.g. LLFIO"
#elif defined(max)
#error "You must not define max() as a macro, because this is unsupported and known to break e.g. LLFIO"
#endif
#define QUICKCPPLIB_VERSION_GLUE2(a, b) a##b
#define QUICKCPPLIB_VERSION_GLUE(a, b) QUICKCPPLIB_VERSION_GLUE2(a, b)
// clang-format off
#define QUICKCPPLIB_NAMESPACE quickcpplib
#define QUICKCPPLIB_NAMESPACE_BEGIN namespace quickcpplib {
#define QUICKCPPLIB_NAMESPACE_END }
// clang-format on
#ifdef _MSC_VER
#define QUICKCPPLIB_BIND_MESSAGE_PRAGMA2(x) __pragma(message(x))
#define QUICKCPPLIB_BIND_MESSAGE_PRAGMA(x) QUICKCPPLIB_BIND_MESSAGE_PRAGMA2(x)
#define QUICKCPPLIB_BIND_MESSAGE_PREFIX(type) __FILE__ "(" QUICKCPPLIB_BIND_STRINGIZE2(__LINE__) "): " type ": "
#define QUICKCPPLIB_BIND_MESSAGE_(type, prefix, msg) QUICKCPPLIB_BIND_MESSAGE_PRAGMA(prefix msg)
#else
#define QUICKCPPLIB_BIND_MESSAGE_PRAGMA2(x) _Pragma(#x)
#define QUICKCPPLIB_BIND_MESSAGE_PRAGMA(type, x) QUICKCPPLIB_BIND_MESSAGE_PRAGMA2(type x)
#define QUICKCPPLIB_BIND_MESSAGE_(type, prefix, msg) QUICKCPPLIB_BIND_MESSAGE_PRAGMA(type, msg)
#endif
//! Have the compiler output a message
#define QUICKCPPLIB_MESSAGE(msg) QUICKCPPLIB_BIND_MESSAGE_(message, QUICKCPPLIB_BIND_MESSAGE_PREFIX("message"), msg)
//! Have the compiler output a note
#define QUICKCPPLIB_NOTE(msg) QUICKCPPLIB_BIND_MESSAGE_(message, QUICKCPPLIB_BIND_MESSAGE_PREFIX("note"), msg)
//! Have the compiler output a warning
#define QUICKCPPLIB_WARNING(msg) QUICKCPPLIB_BIND_MESSAGE_(GCC warning, QUICKCPPLIB_BIND_MESSAGE_PREFIX("warning"), msg)
//! Have the compiler output an error
#define QUICKCPPLIB_ERROR(msg) QUICKCPPLIB_BIND_MESSAGE_(GCC error, QUICKCPPLIB_BIND_MESSAGE_PREFIX("error"), msg)
#define QUICKCPPLIB_ANNOTATE_RWLOCK_CREATE(p)
#define QUICKCPPLIB_ANNOTATE_RWLOCK_DESTROY(p)
#define QUICKCPPLIB_ANNOTATE_RWLOCK_ACQUIRED(p, s)
#define QUICKCPPLIB_ANNOTATE_RWLOCK_RELEASED(p, s)
#define QUICKCPPLIB_ANNOTATE_IGNORE_READS_BEGIN()
#define QUICKCPPLIB_ANNOTATE_IGNORE_READS_END()
#define QUICKCPPLIB_ANNOTATE_IGNORE_WRITES_BEGIN()
#define QUICKCPPLIB_ANNOTATE_IGNORE_WRITES_END()
#define QUICKCPPLIB_DRD_IGNORE_VAR(x)
#define QUICKCPPLIB_DRD_STOP_IGNORING_VAR(x)
#define QUICKCPPLIB_RUNNING_ON_VALGRIND (0)
#ifndef QUICKCPPLIB_IN_ADDRESS_SANITIZER
#if defined(__has_feature)
#if __has_feature(address_sanitizer) || defined(__SANITIZE_ADDRESS__)
#define QUICKCPPLIB_IN_ADDRESS_SANITIZER 1
#endif
#elif defined(__SANITIZE_ADDRESS__)
#define QUICKCPPLIB_IN_ADDRESS_SANITIZER 1
#endif
#endif
#ifndef QUICKCPPLIB_IN_ADDRESS_SANITIZER
#define QUICKCPPLIB_IN_ADDRESS_SANITIZER 0
#endif
#ifndef QUICKCPPLIB_IN_THREAD_SANITIZER
#if defined(__has_feature)
#if __has_feature(thread_sanitizer) || defined(__SANITIZE_THREAD__)
#define QUICKCPPLIB_IN_THREAD_SANITIZER 1
#endif
#elif defined(__SANITIZE_THREAD__)
#define QUICKCPPLIB_IN_THREAD_SANITIZER 1
#endif
#endif
#ifndef QUICKCPPLIB_IN_THREAD_SANITIZER
#define QUICKCPPLIB_IN_THREAD_SANITIZER 0
#endif
#ifndef QUICKCPPLIB_IN_UNDEFINED_SANITIZER
#if defined(__has_feature)
#if __has_feature(undefined_behavior_sanitizer) || defined(__SANITIZE_UNDEFINED__) || (__GNUC__ <= 9 && defined(__SANITIZE_ADDRESS__))
#define QUICKCPPLIB_IN_UNDEFINED_SANITIZER 1
#endif
#elif defined(__SANITIZE_UNDEFINED__) || (__GNUC__ <= 9 && defined(__SANITIZE_ADDRESS__))
#define QUICKCPPLIB_IN_UNDEFINED_SANITIZER 1
#endif
#endif
#ifndef QUICKCPPLIB_IN_UNDEFINED_SANITIZER
#define QUICKCPPLIB_IN_UNDEFINED_SANITIZER 0
#endif
#if QUICKCPPLIB_IN_THREAD_SANITIZER
#define QUICKCPPLIB_DISABLE_THREAD_SANITIZE __attribute__((no_sanitize_thread))
#else
#define QUICKCPPLIB_DISABLE_THREAD_SANITIZE
#endif
#if QUICKCPPLIB_IN_THREAD_SANITIZER
#define QUICKCPPLIB_DISABLE_THREAD_SANITIZE __attribute__((no_sanitize_thread))
#else
#define QUICKCPPLIB_DISABLE_THREAD_SANITIZE
#endif
#if QUICKCPPLIB_IN_UNDEFINED_SANITIZER
#define QUICKCPPLIB_DISABLE_UNDEFINED_SANITIZE __attribute__((no_sanitize_undefined))
#else
#define QUICKCPPLIB_DISABLE_UNDEFINED_SANITIZE
#endif
#ifndef QUICKCPPLIB_SMT_PAUSE
#if !defined(__clang__) && defined(_MSC_VER) && _MSC_VER >= 1310 && (defined(_M_IX86) || defined(_M_X64))
extern "C" void _mm_pause();
#if !defined(_M_ARM64EC)
#pragma intrinsic(_mm_pause)
#endif
#define QUICKCPPLIB_SMT_PAUSE _mm_pause();
#elif !defined(__c2__) && defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
#define QUICKCPPLIB_SMT_PAUSE __asm__ __volatile__("rep; nop" : : : "memory");
#endif
#endif
#ifndef QUICKCPPLIB_FORCEINLINE
#if defined(_MSC_VER)
#define QUICKCPPLIB_FORCEINLINE __forceinline
#elif defined(__GNUC__)
#define QUICKCPPLIB_FORCEINLINE __attribute__((always_inline))
#else
#define QUICKCPPLIB_FORCEINLINE
#endif
#endif
#ifndef QUICKCPPLIB_NOINLINE
#if defined(_MSC_VER)
#define QUICKCPPLIB_NOINLINE __declspec(noinline)
#elif defined(__GNUC__)
#define QUICKCPPLIB_NOINLINE __attribute__((noinline))
#else
#define QUICKCPPLIB_NOINLINE
#endif
#endif
#if defined(QUICKCPPLIB_REQUIRE_CXX_STANDARD)
#define QUICKCPPLIB_REQUIRE_CXX17 (QUICKCPPLIB_REQUIRE_CXX_STANDARD >= 201703L)
#define QUICKCPPLIB_REQUIRE_CXX20 (QUICKCPPLIB_REQUIRE_CXX_STANDARD >= 202002L)
#define QUICKCPPLIB_USE_STD_BYTE QUICKCPPLIB_REQUIRE_CXX17
#define QUICKCPPLIB_USE_STD_OPTIONAL QUICKCPPLIB_REQUIRE_CXX17
#define QUICKCPPLIB_USE_STD_SPAN QUICKCPPLIB_REQUIRE_CXX20
#endif // ^^^ defined QUICKCPPLIB_REQUIRE_CXX_STANDARD ^^^
#if !defined(QUICKCPPLIB_USE_SYSTEM_BYTE_LITE)
#define QUICKCPPLIB_USE_SYSTEM_BYTE_LITE 0
#endif
#if !defined(QUICKCPPLIB_USE_SYSTEM_SPAN_LITE)
#define QUICKCPPLIB_USE_SYSTEM_SPAN_LITE 0
#endif
#ifdef __has_cpp_attribute
#define QUICKCPPLIB_HAS_CPP_ATTRIBUTE(attr, edition) (__has_cpp_attribute(attr) >= (edition) && __cplusplus >= (edition))
#else
#define QUICKCPPLIB_HAS_CPP_ATTRIBUTE(attr, edition) (0)
#endif
#if !defined(QUICKCPPLIB_NORETURN)
#if QUICKCPPLIB_HAS_CPP_ATTRIBUTE(noreturn, 201100)
#define QUICKCPPLIB_NORETURN [[noreturn]]
#elif defined(_MSC_VER)
#define QUICKCPPLIB_NORETURN __declspec(noreturn)
#elif defined(__GNUC__)
#define QUICKCPPLIB_NORETURN __attribute__((__noreturn__))
#else
#define QUICKCPPLIB_NORETURN
#endif
#endif
#ifndef QUICKCPPLIB_NODISCARD
#if 0L || (_HAS_CXX17 && _MSC_VER >= 1911 /* VS2017.3 */)
#define QUICKCPPLIB_NODISCARD [[nodiscard]]
#endif
#endif
#ifndef QUICKCPPLIB_NODISCARD
#if QUICKCPPLIB_HAS_CPP_ATTRIBUTE(nodiscard, 201700) && (!defined(__GNUC__) || !defined(__cpp_concepts) || __cpp_concepts >= 202000L /* -fconcepts-ts and [[nodiscard]] don't mix on GCC \
*/)
#define QUICKCPPLIB_NODISCARD [[nodiscard]]
#elif defined(__clang__) // deliberately not GCC
#define QUICKCPPLIB_NODISCARD __attribute__((warn_unused_result))
#elif defined(_MSC_VER)
// _Must_inspect_result_ expands into this
#define QUICKCPPLIB_NODISCARD __declspec( "SAL_name" "(" "\"_Must_inspect_result_\"" "," "\"\"" "," "\"2\"" ")") __declspec("SAL_begin") __declspec("SAL_post") __declspec("SAL_mustInspect") __declspec("SAL_post") __declspec("SAL_checkReturn") __declspec("SAL_end")
#endif
#endif
#ifndef QUICKCPPLIB_NODISCARD
#define QUICKCPPLIB_NODISCARD
#endif
#ifndef QUICKCPPLIB_SYMBOL_VISIBLE
#if defined(_MSC_VER)
#define QUICKCPPLIB_SYMBOL_VISIBLE
#elif defined(__GNUC__)
#define QUICKCPPLIB_SYMBOL_VISIBLE __attribute__((visibility("default")))
#else
#define QUICKCPPLIB_SYMBOL_VISIBLE
#endif
#endif
#ifndef QUICKCPPLIB_SYMBOL_EXPORT
#if defined(_MSC_VER)
#define QUICKCPPLIB_SYMBOL_EXPORT __declspec(dllexport)
#elif defined(__GNUC__)
#define QUICKCPPLIB_SYMBOL_EXPORT __attribute__((visibility("default")))
#else
#define QUICKCPPLIB_SYMBOL_EXPORT
#endif
#endif
#ifndef QUICKCPPLIB_SYMBOL_IMPORT
#if defined(_MSC_VER)
#define QUICKCPPLIB_SYMBOL_IMPORT __declspec(dllimport)
#elif defined(__GNUC__)
#define QUICKCPPLIB_SYMBOL_IMPORT
#else
#define QUICKCPPLIB_SYMBOL_IMPORT
#endif
#endif
#ifndef QUICKCPPLIB_THREAD_LOCAL
#if _MSC_VER >= 1800
#define QUICKCPPLIB_THREAD_LOCAL_IS_CXX11 1
#elif __cplusplus >= 201103L
#if __GNUC__ >= 5 && !defined(__clang__)
#define QUICKCPPLIB_THREAD_LOCAL_IS_CXX11 1
#elif defined(__has_feature)
#if __has_feature(cxx_thread_local)
#define QUICKCPPLIB_THREAD_LOCAL_IS_CXX11 1
#endif
#endif
#endif
#ifdef QUICKCPPLIB_THREAD_LOCAL_IS_CXX11
#define QUICKCPPLIB_THREAD_LOCAL thread_local
#endif
#ifndef QUICKCPPLIB_THREAD_LOCAL
#if defined(_MSC_VER)
#define QUICKCPPLIB_THREAD_LOCAL __declspec(thread)
#elif defined(__GNUC__)
#define QUICKCPPLIB_THREAD_LOCAL __thread
#else
#error Unknown compiler, cannot set QUICKCPPLIB_THREAD_LOCAL
#endif
#endif
#endif
#ifndef QUICKCPPLIB_DISABLE_EXECINFO
#if defined(__EMSCRIPTEN__)
#define QUICKCPPLIB_DISABLE_EXECINFO 1
#endif
#endif
#ifndef QUICKCPPLIB_PLATFORM_NATIVE_BITLENGTH
#if defined(__SIZEOF_POINTER__)
#define QUICKCPPLIB_PLATFORM_NATIVE_BITLENGTH (__SIZEOF_POINTER__ * __CHAR_BIT__)
#elif defined(_WIN64) || defined(__x86_64__) || defined(_M_X64) || defined(__aarch64__) || defined(_M_ARM64) || defined(__ia64__) || defined(_M_IA64) || defined(__ppc64__)
#define QUICKCPPLIB_PLATFORM_NATIVE_BITLENGTH (64)
#else
#define QUICKCPPLIB_PLATFORM_NATIVE_BITLENGTH (32)
#endif
#endif
/* MSVC capable preprocessor macro overloading
(C) 2014-2017 Niall Douglas <http://www.nedproductions.biz/> (3 commits)
File Created: Aug 2014
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License in the accompanying file
Licence.txt or at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Distributed under the Boost Software License, Version 1.0.
(See accompanying file Licence.txt or copy at
http://www.boost.org/LICENSE_1_0.txt)
*/
#ifndef QUICKCPPLIB_PREPROCESSOR_MACRO_OVERLOAD_H
#define QUICKCPPLIB_PREPROCESSOR_MACRO_OVERLOAD_H
#define QUICKCPPLIB_GLUE(x, y) x y
#define QUICKCPPLIB_RETURN_ARG_COUNT(_1_, _2_, _3_, _4_, _5_, _6_, _7_, _8_, count, ...) count
#define QUICKCPPLIB_EXPAND_ARGS(args) QUICKCPPLIB_RETURN_ARG_COUNT args
#define QUICKCPPLIB_COUNT_ARGS_MAX8(...) QUICKCPPLIB_EXPAND_ARGS((__VA_ARGS__, 8, 7, 6, 5, 4, 3, 2, 1, 0))
#define QUICKCPPLIB_OVERLOAD_MACRO2(name, count) name##count
#define QUICKCPPLIB_OVERLOAD_MACRO1(name, count) QUICKCPPLIB_OVERLOAD_MACRO2(name, count)
#define QUICKCPPLIB_OVERLOAD_MACRO(name, count) QUICKCPPLIB_OVERLOAD_MACRO1(name, count)
#define QUICKCPPLIB_CALL_OVERLOAD(name, ...) QUICKCPPLIB_GLUE(QUICKCPPLIB_OVERLOAD_MACRO(name, QUICKCPPLIB_COUNT_ARGS_MAX8(__VA_ARGS__)), (__VA_ARGS__))
#define QUICKCPPLIB_GLUE_(x, y) x y
#define QUICKCPPLIB_RETURN_ARG_COUNT_(_1_, _2_, _3_, _4_, _5_, _6_, _7_, _8_, count, ...) count
#define QUICKCPPLIB_EXPAND_ARGS_(args) QUICKCPPLIB_RETURN_ARG_COUNT_ args
#define QUICKCPPLIB_COUNT_ARGS_MAX8_(...) QUICKCPPLIB_EXPAND_ARGS_((__VA_ARGS__, 8, 7, 6, 5, 4, 3, 2, 1, 0))
#define QUICKCPPLIB_OVERLOAD_MACRO2_(name, count) name##count
#define QUICKCPPLIB_OVERLOAD_MACRO1_(name, count) QUICKCPPLIB_OVERLOAD_MACRO2_(name, count)
#define QUICKCPPLIB_OVERLOAD_MACRO_(name, count) QUICKCPPLIB_OVERLOAD_MACRO1_(name, count)
#define QUICKCPPLIB_CALL_OVERLOAD_(name, ...) QUICKCPPLIB_GLUE_(QUICKCPPLIB_OVERLOAD_MACRO_(name, QUICKCPPLIB_COUNT_ARGS_MAX8_(__VA_ARGS__)), (__VA_ARGS__))
#endif
#if defined(__cpp_concepts) && !defined(QUICKCPPLIB_DISABLE_CONCEPTS_SUPPORT)
#define QUICKCPPLIB_TREQUIRES_EXPAND8(a, b, c, d, e, f, g, h) a &&QUICKCPPLIB_TREQUIRES_EXPAND7(b, c, d, e, f, g, h)
#define QUICKCPPLIB_TREQUIRES_EXPAND7(a, b, c, d, e, f, g) a &&QUICKCPPLIB_TREQUIRES_EXPAND6(b, c, d, e, f, g)
#define QUICKCPPLIB_TREQUIRES_EXPAND6(a, b, c, d, e, f) a &&QUICKCPPLIB_TREQUIRES_EXPAND5(b, c, d, e, f)
#define QUICKCPPLIB_TREQUIRES_EXPAND5(a, b, c, d, e) a &&QUICKCPPLIB_TREQUIRES_EXPAND4(b, c, d, e)
#define QUICKCPPLIB_TREQUIRES_EXPAND4(a, b, c, d) a &&QUICKCPPLIB_TREQUIRES_EXPAND3(b, c, d)
#define QUICKCPPLIB_TREQUIRES_EXPAND3(a, b, c) a &&QUICKCPPLIB_TREQUIRES_EXPAND2(b, c)
#define QUICKCPPLIB_TREQUIRES_EXPAND2(a, b) a &&QUICKCPPLIB_TREQUIRES_EXPAND1(b)
#define QUICKCPPLIB_TREQUIRES_EXPAND1(a) a
//! Expands into a && b && c && ...
#define QUICKCPPLIB_TREQUIRES(...) requires QUICKCPPLIB_CALL_OVERLOAD(QUICKCPPLIB_TREQUIRES_EXPAND, __VA_ARGS__)
#define QUICKCPPLIB_TEMPLATE(...) template <__VA_ARGS__>
#define QUICKCPPLIB_TEXPR(...) requires { (__VA_ARGS__); }
#define QUICKCPPLIB_TPRED(...) (__VA_ARGS__)
#if !defined(_MSC_VER) || _MSC_FULL_VER >= 192400000 // VS 2019 16.3 is broken here
#define QUICKCPPLIB_REQUIRES(...) requires(__VA_ARGS__)
#else
#define QUICKCPPLIB_REQUIRES(...)
#endif
#else
#define QUICKCPPLIB_TEMPLATE(...) template <__VA_ARGS__
#define QUICKCPPLIB_TREQUIRES(...) , __VA_ARGS__ >
#define QUICKCPPLIB_TEXPR(...) typename = decltype(__VA_ARGS__)
#ifdef _MSC_VER
// MSVC gives an error if every specialisation of a template is always ill-formed, so
// the more powerful SFINAE form below causes pukeage :(
#define QUICKCPPLIB_TPRED(...) typename = typename std::enable_if<(__VA_ARGS__)>::type
#else
#define QUICKCPPLIB_TPRED(...) typename std::enable_if<(__VA_ARGS__), bool>::type = true
#endif
#define QUICKCPPLIB_REQUIRES(...)
#endif
#endif
#ifndef __cpp_variadic_templates
#error Outcome needs variadic template support in the compiler
#endif
#if __cpp_constexpr < 201304 && _MSC_FULL_VER < 191100000
#error Outcome needs constexpr (C++ 14) support in the compiler
#endif
#ifndef __cpp_variable_templates
#error Outcome needs variable template support in the compiler
#endif
#if !defined(__clang__) && defined(__GNUC__) && __GNUC__ < 6
#error Due to a bug in nested template variables parsing, Outcome does not work on GCCs earlier than v6.
#endif
#ifndef OUTCOME_SYMBOL_VISIBLE
#define OUTCOME_SYMBOL_VISIBLE QUICKCPPLIB_SYMBOL_VISIBLE
#endif
#ifndef OUTCOME_FORCEINLINE
#define OUTCOME_FORCEINLINE QUICKCPPLIB_FORCEINLINE
#endif
#ifndef OUTCOME_NODISCARD
#define OUTCOME_NODISCARD QUICKCPPLIB_NODISCARD
#endif
#ifndef OUTCOME_THREAD_LOCAL
#define OUTCOME_THREAD_LOCAL QUICKCPPLIB_THREAD_LOCAL
#endif
#ifndef OUTCOME_TEMPLATE
#define OUTCOME_TEMPLATE(...) QUICKCPPLIB_TEMPLATE(__VA_ARGS__)
#endif
#ifndef OUTCOME_TREQUIRES
#define OUTCOME_TREQUIRES(...) QUICKCPPLIB_TREQUIRES(__VA_ARGS__)
#endif
#ifndef OUTCOME_TEXPR
#define OUTCOME_TEXPR(...) QUICKCPPLIB_TEXPR(__VA_ARGS__)
#endif
#ifndef OUTCOME_TPRED
#define OUTCOME_TPRED(...) QUICKCPPLIB_TPRED(__VA_ARGS__)
#endif
#ifndef OUTCOME_REQUIRES
#define OUTCOME_REQUIRES(...) QUICKCPPLIB_REQUIRES(__VA_ARGS__)
#endif
/* Convenience macros for importing local namespace binds
(C) 2014-2017 Niall Douglas <http://www.nedproductions.biz/> (9 commits)
File Created: Aug 2014
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License in the accompanying file
Licence.txt or at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Distributed under the Boost Software License, Version 1.0.
(See accompanying file Licence.txt or copy at
http://www.boost.org/LICENSE_1_0.txt)
*/
#ifndef QUICKCPPLIB_BIND_IMPORT_HPP
#define QUICKCPPLIB_BIND_IMPORT_HPP
/* 2014-10-9 ned: I lost today figuring out the below. I really hate the C preprocessor now.
*
* Anyway, infinity = 8. It's easy to expand below if needed.
*/
#define QUICKCPPLIB_BIND_STRINGIZE(a) #a
#define QUICKCPPLIB_BIND_STRINGIZE2(a) QUICKCPPLIB_BIND_STRINGIZE(a)
#define QUICKCPPLIB_BIND_NAMESPACE_VERSION8(a, b, c, d, e, f, g, h) a##_##b##_##c##_##d##_##e##_##f##_##g##_##h
#define QUICKCPPLIB_BIND_NAMESPACE_VERSION7(a, b, c, d, e, f, g) a##_##b##_##c##_##d##_##e##_##f##_##g
#define QUICKCPPLIB_BIND_NAMESPACE_VERSION6(a, b, c, d, e, f) a##_##b##_##c##_##d##_##e##_##f
#define QUICKCPPLIB_BIND_NAMESPACE_VERSION5(a, b, c, d, e) a##_##b##_##c##_##d##_##e
#define QUICKCPPLIB_BIND_NAMESPACE_VERSION4(a, b, c, d) a##_##b##_##c##_##d
#define QUICKCPPLIB_BIND_NAMESPACE_VERSION3(a, b, c) a##_##b##_##c
#define QUICKCPPLIB_BIND_NAMESPACE_VERSION2(a, b) a##_##b
#define QUICKCPPLIB_BIND_NAMESPACE_VERSION1(a) a
//! Concatenates each parameter with _
#define QUICKCPPLIB_BIND_NAMESPACE_VERSION(...) QUICKCPPLIB_CALL_OVERLOAD(QUICKCPPLIB_BIND_NAMESPACE_VERSION, __VA_ARGS__)
#define QUICKCPPLIB_BIND_NAMESPACE_SELECT_2(name, modifier) name
#define QUICKCPPLIB_BIND_NAMESPACE_SELECT2(name, modifier) ::name
#define QUICKCPPLIB_BIND_NAMESPACE_SELECT_1(name) name
#define QUICKCPPLIB_BIND_NAMESPACE_SELECT1(name) ::name
#define QUICKCPPLIB_BIND_NAMESPACE_SELECT_(...) QUICKCPPLIB_CALL_OVERLOAD_(QUICKCPPLIB_BIND_NAMESPACE_SELECT_, __VA_ARGS__)
#define QUICKCPPLIB_BIND_NAMESPACE_SELECT(...) QUICKCPPLIB_CALL_OVERLOAD_(QUICKCPPLIB_BIND_NAMESPACE_SELECT, __VA_ARGS__)
#define QUICKCPPLIB_BIND_NAMESPACE_EXPAND8(a, b, c, d, e, f, g, h) QUICKCPPLIB_BIND_NAMESPACE_SELECT_ a QUICKCPPLIB_BIND_NAMESPACE_SELECT b QUICKCPPLIB_BIND_NAMESPACE_SELECT c QUICKCPPLIB_BIND_NAMESPACE_SELECT d QUICKCPPLIB_BIND_NAMESPACE_SELECT e QUICKCPPLIB_BIND_NAMESPACE_SELECT f QUICKCPPLIB_BIND_NAMESPACE_SELECT g QUICKCPPLIB_BIND_NAMESPACE_SELECT h
#define QUICKCPPLIB_BIND_NAMESPACE_EXPAND7(a, b, c, d, e, f, g) QUICKCPPLIB_BIND_NAMESPACE_SELECT_ a QUICKCPPLIB_BIND_NAMESPACE_SELECT b QUICKCPPLIB_BIND_NAMESPACE_SELECT c QUICKCPPLIB_BIND_NAMESPACE_SELECT d QUICKCPPLIB_BIND_NAMESPACE_SELECT e QUICKCPPLIB_BIND_NAMESPACE_SELECT f QUICKCPPLIB_BIND_NAMESPACE_SELECT g
#define QUICKCPPLIB_BIND_NAMESPACE_EXPAND6(a, b, c, d, e, f) QUICKCPPLIB_BIND_NAMESPACE_SELECT_ a QUICKCPPLIB_BIND_NAMESPACE_SELECT b QUICKCPPLIB_BIND_NAMESPACE_SELECT c QUICKCPPLIB_BIND_NAMESPACE_SELECT d QUICKCPPLIB_BIND_NAMESPACE_SELECT e QUICKCPPLIB_BIND_NAMESPACE_SELECT f
#define QUICKCPPLIB_BIND_NAMESPACE_EXPAND5(a, b, c, d, e) QUICKCPPLIB_BIND_NAMESPACE_SELECT_ a QUICKCPPLIB_BIND_NAMESPACE_SELECT b QUICKCPPLIB_BIND_NAMESPACE_SELECT c QUICKCPPLIB_BIND_NAMESPACE_SELECT d QUICKCPPLIB_BIND_NAMESPACE_SELECT e
#define QUICKCPPLIB_BIND_NAMESPACE_EXPAND4(a, b, c, d) QUICKCPPLIB_BIND_NAMESPACE_SELECT_ a QUICKCPPLIB_BIND_NAMESPACE_SELECT b QUICKCPPLIB_BIND_NAMESPACE_SELECT c QUICKCPPLIB_BIND_NAMESPACE_SELECT d
#define QUICKCPPLIB_BIND_NAMESPACE_EXPAND3(a, b, c) QUICKCPPLIB_BIND_NAMESPACE_SELECT_ a QUICKCPPLIB_BIND_NAMESPACE_SELECT b QUICKCPPLIB_BIND_NAMESPACE_SELECT c
#define QUICKCPPLIB_BIND_NAMESPACE_EXPAND2(a, b) QUICKCPPLIB_BIND_NAMESPACE_SELECT_ a QUICKCPPLIB_BIND_NAMESPACE_SELECT b
#define QUICKCPPLIB_BIND_NAMESPACE_EXPAND1(a) QUICKCPPLIB_BIND_NAMESPACE_SELECT_ a
//! Expands into a::b::c:: ...
#define QUICKCPPLIB_BIND_NAMESPACE(...) QUICKCPPLIB_CALL_OVERLOAD(QUICKCPPLIB_BIND_NAMESPACE_EXPAND, __VA_ARGS__)
#define QUICKCPPLIB_BIND_NAMESPACE_BEGIN_NAMESPACE_SELECT2(name, modifier) modifier namespace name {
#define QUICKCPPLIB_BIND_NAMESPACE_BEGIN_NAMESPACE_SELECT1(name) namespace name {
#define QUICKCPPLIB_BIND_NAMESPACE_BEGIN_NAMESPACE_SELECT(...) QUICKCPPLIB_CALL_OVERLOAD_(QUICKCPPLIB_BIND_NAMESPACE_BEGIN_NAMESPACE_SELECT, __VA_ARGS__)
#define QUICKCPPLIB_BIND_NAMESPACE_BEGIN_EXPAND8(a, b, c, d, e, f, g, h) QUICKCPPLIB_BIND_NAMESPACE_BEGIN_NAMESPACE_SELECT a QUICKCPPLIB_BIND_NAMESPACE_BEGIN_EXPAND7(b, c, d, e, f, g, h)
#define QUICKCPPLIB_BIND_NAMESPACE_BEGIN_EXPAND7(a, b, c, d, e, f, g) QUICKCPPLIB_BIND_NAMESPACE_BEGIN_NAMESPACE_SELECT a QUICKCPPLIB_BIND_NAMESPACE_BEGIN_EXPAND6(b, c, d, e, f, g)
#define QUICKCPPLIB_BIND_NAMESPACE_BEGIN_EXPAND6(a, b, c, d, e, f) QUICKCPPLIB_BIND_NAMESPACE_BEGIN_NAMESPACE_SELECT a QUICKCPPLIB_BIND_NAMESPACE_BEGIN_EXPAND5(b, c, d, e, f)
#define QUICKCPPLIB_BIND_NAMESPACE_BEGIN_EXPAND5(a, b, c, d, e) QUICKCPPLIB_BIND_NAMESPACE_BEGIN_NAMESPACE_SELECT a QUICKCPPLIB_BIND_NAMESPACE_BEGIN_EXPAND4(b, c, d, e)
#define QUICKCPPLIB_BIND_NAMESPACE_BEGIN_EXPAND4(a, b, c, d) QUICKCPPLIB_BIND_NAMESPACE_BEGIN_NAMESPACE_SELECT a QUICKCPPLIB_BIND_NAMESPACE_BEGIN_EXPAND3(b, c, d)
#define QUICKCPPLIB_BIND_NAMESPACE_BEGIN_EXPAND3(a, b, c) QUICKCPPLIB_BIND_NAMESPACE_BEGIN_NAMESPACE_SELECT a QUICKCPPLIB_BIND_NAMESPACE_BEGIN_EXPAND2(b, c)
#define QUICKCPPLIB_BIND_NAMESPACE_BEGIN_EXPAND2(a, b) QUICKCPPLIB_BIND_NAMESPACE_BEGIN_NAMESPACE_SELECT a QUICKCPPLIB_BIND_NAMESPACE_BEGIN_EXPAND1(b)
#define QUICKCPPLIB_BIND_NAMESPACE_BEGIN_EXPAND1(a) QUICKCPPLIB_BIND_NAMESPACE_BEGIN_NAMESPACE_SELECT a
//! Expands into namespace a { namespace b { namespace c ...
#define QUICKCPPLIB_BIND_NAMESPACE_BEGIN(...) QUICKCPPLIB_CALL_OVERLOAD(QUICKCPPLIB_BIND_NAMESPACE_BEGIN_EXPAND, __VA_ARGS__)
#define QUICKCPPLIB_BIND_NAMESPACE_EXPORT_BEGIN_NAMESPACE_SELECT2(name, modifier) modifier namespace name {
#define QUICKCPPLIB_BIND_NAMESPACE_EXPORT_BEGIN_NAMESPACE_SELECT1(name) export namespace name {
#define QUICKCPPLIB_BIND_NAMESPACE_EXPORT_BEGIN_NAMESPACE_SELECT(...) QUICKCPPLIB_CALL_OVERLOAD_(QUICKCPPLIB_BIND_NAMESPACE_EXPORT_BEGIN_NAMESPACE_SELECT, __VA_ARGS__)
#define QUICKCPPLIB_BIND_NAMESPACE_EXPORT_BEGIN_EXPAND8(a, b, c, d, e, f, g, h) QUICKCPPLIB_BIND_NAMESPACE_EXPORT_BEGIN_NAMESPACE_SELECT a QUICKCPPLIB_BIND_NAMESPACE_EXPORT_BEGIN_EXPAND7(b, c, d, e, f, g, h)
#define QUICKCPPLIB_BIND_NAMESPACE_EXPORT_BEGIN_EXPAND7(a, b, c, d, e, f, g) QUICKCPPLIB_BIND_NAMESPACE_EXPORT_BEGIN_NAMESPACE_SELECT a QUICKCPPLIB_BIND_NAMESPACE_EXPORT_BEGIN_EXPAND6(b, c, d, e, f, g)
#define QUICKCPPLIB_BIND_NAMESPACE_EXPORT_BEGIN_EXPAND6(a, b, c, d, e, f) QUICKCPPLIB_BIND_NAMESPACE_EXPORT_BEGIN_NAMESPACE_SELECT a QUICKCPPLIB_BIND_NAMESPACE_EXPORT_BEGIN_EXPAND5(b, c, d, e, f)
#define QUICKCPPLIB_BIND_NAMESPACE_EXPORT_BEGIN_EXPAND5(a, b, c, d, e) QUICKCPPLIB_BIND_NAMESPACE_EXPORT_BEGIN_NAMESPACE_SELECT a QUICKCPPLIB_BIND_NAMESPACE_EXPORT_BEGIN_EXPAND4(b, c, d, e)
#define QUICKCPPLIB_BIND_NAMESPACE_EXPORT_BEGIN_EXPAND4(a, b, c, d) QUICKCPPLIB_BIND_NAMESPACE_EXPORT_BEGIN_NAMESPACE_SELECT a QUICKCPPLIB_BIND_NAMESPACE_EXPORT_BEGIN_EXPAND3(b, c, d)
#define QUICKCPPLIB_BIND_NAMESPACE_EXPORT_BEGIN_EXPAND3(a, b, c) QUICKCPPLIB_BIND_NAMESPACE_EXPORT_BEGIN_NAMESPACE_SELECT a QUICKCPPLIB_BIND_NAMESPACE_EXPORT_BEGIN_EXPAND2(b, c)
#define QUICKCPPLIB_BIND_NAMESPACE_EXPORT_BEGIN_EXPAND2(a, b) QUICKCPPLIB_BIND_NAMESPACE_EXPORT_BEGIN_NAMESPACE_SELECT a QUICKCPPLIB_BIND_NAMESPACE_EXPORT_BEGIN_EXPAND1(b)
#define QUICKCPPLIB_BIND_NAMESPACE_EXPORT_BEGIN_EXPAND1(a) QUICKCPPLIB_BIND_NAMESPACE_EXPORT_BEGIN_NAMESPACE_SELECT a
//! Expands into export namespace a { namespace b { namespace c ...
#define QUICKCPPLIB_BIND_NAMESPACE_EXPORT_BEGIN(...) QUICKCPPLIB_CALL_OVERLOAD(QUICKCPPLIB_BIND_NAMESPACE_EXPORT_BEGIN_EXPAND, __VA_ARGS__)
#define QUICKCPPLIB_BIND_NAMESPACE_END_NAMESPACE_SELECT2(name, modifier) }
#define QUICKCPPLIB_BIND_NAMESPACE_END_NAMESPACE_SELECT1(name) }
#define QUICKCPPLIB_BIND_NAMESPACE_END_NAMESPACE_SELECT(...) QUICKCPPLIB_CALL_OVERLOAD_(QUICKCPPLIB_BIND_NAMESPACE_END_NAMESPACE_SELECT, __VA_ARGS__)
#define QUICKCPPLIB_BIND_NAMESPACE_END_EXPAND8(a, b, c, d, e, f, g, h) QUICKCPPLIB_BIND_NAMESPACE_END_NAMESPACE_SELECT a QUICKCPPLIB_BIND_NAMESPACE_END_EXPAND7(b, c, d, e, f, g, h)
#define QUICKCPPLIB_BIND_NAMESPACE_END_EXPAND7(a, b, c, d, e, f, g) QUICKCPPLIB_BIND_NAMESPACE_END_NAMESPACE_SELECT a QUICKCPPLIB_BIND_NAMESPACE_END_EXPAND6(b, c, d, e, f, g)
#define QUICKCPPLIB_BIND_NAMESPACE_END_EXPAND6(a, b, c, d, e, f) QUICKCPPLIB_BIND_NAMESPACE_END_NAMESPACE_SELECT a QUICKCPPLIB_BIND_NAMESPACE_END_EXPAND5(b, c, d, e, f)
#define QUICKCPPLIB_BIND_NAMESPACE_END_EXPAND5(a, b, c, d, e) QUICKCPPLIB_BIND_NAMESPACE_END_NAMESPACE_SELECT a QUICKCPPLIB_BIND_NAMESPACE_END_EXPAND4(b, c, d, e)
#define QUICKCPPLIB_BIND_NAMESPACE_END_EXPAND4(a, b, c, d) QUICKCPPLIB_BIND_NAMESPACE_END_NAMESPACE_SELECT a QUICKCPPLIB_BIND_NAMESPACE_END_EXPAND3(b, c, d)
#define QUICKCPPLIB_BIND_NAMESPACE_END_EXPAND3(a, b, c) QUICKCPPLIB_BIND_NAMESPACE_END_NAMESPACE_SELECT a QUICKCPPLIB_BIND_NAMESPACE_END_EXPAND2(b, c)
#define QUICKCPPLIB_BIND_NAMESPACE_END_EXPAND2(a, b) QUICKCPPLIB_BIND_NAMESPACE_END_NAMESPACE_SELECT a QUICKCPPLIB_BIND_NAMESPACE_END_EXPAND1(b)
#define QUICKCPPLIB_BIND_NAMESPACE_END_EXPAND1(a) QUICKCPPLIB_BIND_NAMESPACE_END_NAMESPACE_SELECT a
//! Expands into } } ...
#define QUICKCPPLIB_BIND_NAMESPACE_END(...) QUICKCPPLIB_CALL_OVERLOAD(QUICKCPPLIB_BIND_NAMESPACE_END_EXPAND, __VA_ARGS__)
//! Expands into a static const char string array used to mark BindLib compatible namespaces
#define QUICKCPPLIB_BIND_DECLARE(decl, desc) static const char *quickcpplib_out[] = {#decl, desc};
#endif
#ifndef OUTCOME_ENABLE_LEGACY_SUPPORT_FOR
#define OUTCOME_ENABLE_LEGACY_SUPPORT_FOR 220 // the v2.2 Outcome release
#endif
/* UPDATED BY SCRIPT
(C) 2017-2019 Niall Douglas <http://www.nedproductions.biz/> (225 commits)
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License in the accompanying file
Licence.txt or at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Distributed under the Boost Software License, Version 1.0.
(See accompanying file Licence.txt or copy at
http://www.boost.org/LICENSE_1_0.txt)
*/
// Note the second line of this file must ALWAYS be the git SHA, third line ALWAYS the git SHA update time
#define OUTCOME_PREVIOUS_COMMIT_REF b01ac71096775daf18d9a57a69be5e129f421a67
#define OUTCOME_PREVIOUS_COMMIT_DATE "2024-07-17 20:54:50 +00:00"
#define OUTCOME_PREVIOUS_COMMIT_UNIQUE b01ac710
#define OUTCOME_V2 (QUICKCPPLIB_BIND_NAMESPACE_VERSION(outcome_v2))
#ifdef _DEBUG
#define OUTCOME_V2_CXX_MODULE_NAME QUICKCPPLIB_BIND_NAMESPACE((QUICKCPPLIB_BIND_NAMESPACE_VERSION(outcome_v2d)))
#else
#define OUTCOME_V2_CXX_MODULE_NAME QUICKCPPLIB_BIND_NAMESPACE((QUICKCPPLIB_BIND_NAMESPACE_VERSION(outcome_v2)))
#endif
#if defined(GENERATING_OUTCOME_MODULE_INTERFACE)
#define OUTCOME_V2_NAMESPACE QUICKCPPLIB_BIND_NAMESPACE(OUTCOME_V2)
#define OUTCOME_V2_NAMESPACE_BEGIN QUICKCPPLIB_BIND_NAMESPACE_BEGIN(OUTCOME_V2)
#define OUTCOME_V2_NAMESPACE_EXPORT_BEGIN QUICKCPPLIB_BIND_NAMESPACE_EXPORT_BEGIN(OUTCOME_V2)
#define OUTCOME_V2_NAMESPACE_END QUICKCPPLIB_BIND_NAMESPACE_END(OUTCOME_V2)
#else
#define OUTCOME_V2_NAMESPACE QUICKCPPLIB_BIND_NAMESPACE(OUTCOME_V2)
#define OUTCOME_V2_NAMESPACE_BEGIN QUICKCPPLIB_BIND_NAMESPACE_BEGIN(OUTCOME_V2)
#define OUTCOME_V2_NAMESPACE_EXPORT_BEGIN QUICKCPPLIB_BIND_NAMESPACE_BEGIN(OUTCOME_V2)
#define OUTCOME_V2_NAMESPACE_END QUICKCPPLIB_BIND_NAMESPACE_END(OUTCOME_V2)
#endif
#include <cstdint> // for uint32_t etc
#include <initializer_list>
#include <iosfwd> // for future serialisation
#include <new> // for placement in moves etc
#include <type_traits>
#ifndef OUTCOME_USE_STD_IN_PLACE_TYPE
#if defined(_MSC_VER) && _HAS_CXX17
#define OUTCOME_USE_STD_IN_PLACE_TYPE 1 // MSVC always has std::in_place_type
#elif __cplusplus >= 201700
// libstdc++ before GCC 6 doesn't have it, despite claiming C++ 17 support
#ifdef __has_include
#if !__has_include(<variant>)
#define OUTCOME_USE_STD_IN_PLACE_TYPE 0 // must have it if <variant> is present
#endif
#endif
#ifndef OUTCOME_USE_STD_IN_PLACE_TYPE
#define OUTCOME_USE_STD_IN_PLACE_TYPE 1
#endif
#else
#define OUTCOME_USE_STD_IN_PLACE_TYPE 0
#endif
#endif
#if OUTCOME_USE_STD_IN_PLACE_TYPE
#include <utility> // for in_place_type_t
OUTCOME_V2_NAMESPACE_BEGIN
template <class T> using in_place_type_t = std::in_place_type_t<T>;
using std::in_place_type;
OUTCOME_V2_NAMESPACE_END
#else
OUTCOME_V2_NAMESPACE_BEGIN
/*! AWAITING HUGO JSON CONVERSION TOOL
type definition template <class T> in_place_type_t. Potential doc page: `in_place_type_t<T>`
*/
template <class T> struct in_place_type_t
{
explicit in_place_type_t() = default;
};
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
template <class T> constexpr in_place_type_t<T> in_place_type{};
OUTCOME_V2_NAMESPACE_END
#endif
#if OUTCOME_USE_STD_ADDRESSOF
#include <memory> // for std::addressof
#define OUTCOME_ADDRESS_OF(...) std::addressof(__VA_ARGS__)
#else
#define OUTCOME_ADDRESS_OF(...) (&__VA_ARGS__)
#endif
#ifndef OUTCOME_ASSERT
#include <cassert>
#define OUTCOME_ASSERT(...) assert(__VA_ARGS__)
#endif
#ifndef OUTCOME_TRIVIAL_ABI
#if 0L || __clang_major__ >= 7
//! Defined to be `[[clang::trivial_abi]]` when on a new enough clang compiler. Usually automatic, can be overriden.
#define OUTCOME_TRIVIAL_ABI [[clang::trivial_abi]]
#else
#define OUTCOME_TRIVIAL_ABI
#endif
#endif
OUTCOME_V2_NAMESPACE_BEGIN
namespace detail
{
// Test if type is an in_place_type_t
template <class T> struct is_in_place_type_t
{
static constexpr bool value = false;
};
template <class U> struct is_in_place_type_t<in_place_type_t<U>>
{
static constexpr bool value = true;
};
// Replace void with constructible void_type
struct empty_type
{
};
struct void_type
{
// We always compare true to another instance of me
constexpr bool operator==(void_type /*unused*/) const noexcept { return true; }
constexpr bool operator!=(void_type /*unused*/) const noexcept { return false; }
};
template <class T> using devoid = std::conditional_t<std::is_void<T>::value, void_type, T>;
template <class Output, class Input> using rebind_type5 = Output;
template <class Output, class Input>
using rebind_type4 = std::conditional_t< //
std::is_volatile<Input>::value, //
std::add_volatile_t<rebind_type5<Output, std::remove_volatile_t<Input>>>, //
rebind_type5<Output, Input>>;
template <class Output, class Input>
using rebind_type3 = std::conditional_t< //
std::is_const<Input>::value, //
std::add_const_t<rebind_type4<Output, std::remove_const_t<Input>>>, //
rebind_type4<Output, Input>>;
template <class Output, class Input>
using rebind_type2 = std::conditional_t< //
std::is_lvalue_reference<Input>::value, //
std::add_lvalue_reference_t<rebind_type3<Output, std::remove_reference_t<Input>>>, //
rebind_type3<Output, Input>>;
template <class Output, class Input>
using rebind_type = std::conditional_t< //
std::is_rvalue_reference<Input>::value, //
std::add_rvalue_reference_t<rebind_type2<Output, std::remove_reference_t<Input>>>, //
rebind_type2<Output, Input>>;
// static_assert(std::is_same_v<rebind_type<int, volatile const double &&>, volatile const int &&>, "");
/* True if type is the same or constructible. Works around a bug where clang + libstdc++
pukes on std::is_constructible<filesystem::path, void> (this bug is fixed upstream).
*/
template <class T, class U> struct _is_explicitly_constructible
{
static constexpr bool value = std::is_constructible<T, U>::value;
};
template <class T> struct _is_explicitly_constructible<T, void>
{
static constexpr bool value = false;
};
template <> struct _is_explicitly_constructible<void, void>
{
static constexpr bool value = false;
};
template <class T, class U> static constexpr bool is_explicitly_constructible = _is_explicitly_constructible<T, U>::value;
template <class T, class U> struct _is_implicitly_constructible
{
static constexpr bool value = std::is_convertible<U, T>::value;
};
template <class T> struct _is_implicitly_constructible<T, void>
{
static constexpr bool value = false;
};
template <> struct _is_implicitly_constructible<void, void>
{
static constexpr bool value = false;
};
template <class T, class U> static constexpr bool is_implicitly_constructible = _is_implicitly_constructible<T, U>::value;
template <class T, class... Args> struct _is_nothrow_constructible
{
static constexpr bool value = std::is_nothrow_constructible<T, Args...>::value;
};
template <class T> struct _is_nothrow_constructible<T, void>
{
static constexpr bool value = false;
};
template <> struct _is_nothrow_constructible<void, void>
{
static constexpr bool value = false;
};
template <class T, class... Args> static constexpr bool is_nothrow_constructible = _is_nothrow_constructible<T, Args...>::value;
template <class T, class... Args> struct _is_constructible
{
static constexpr bool value = std::is_constructible<T, Args...>::value;
};
template <class T> struct _is_constructible<T, void>
{
static constexpr bool value = false;
};
template <> struct _is_constructible<void, void>
{
static constexpr bool value = false;
};
template <class T, class... Args> static constexpr bool is_constructible = _is_constructible<T, Args...>::value;
#ifndef OUTCOME_USE_STD_IS_NOTHROW_SWAPPABLE
#if defined(_MSC_VER) && _HAS_CXX17
#define OUTCOME_USE_STD_IS_NOTHROW_SWAPPABLE 1 // MSVC always has std::is_nothrow_swappable
#elif __cplusplus >= 201700
// libstdc++ before GCC 6 doesn't have it, despite claiming C++ 17 support
#ifdef __has_include
#if !__has_include(<variant>)
#define OUTCOME_USE_STD_IS_NOTHROW_SWAPPABLE 0
#endif
#endif
#ifndef OUTCOME_USE_STD_IS_NOTHROW_SWAPPABLE
#define OUTCOME_USE_STD_IS_NOTHROW_SWAPPABLE 1
#endif
#else
#define OUTCOME_USE_STD_IS_NOTHROW_SWAPPABLE 0
#endif
#endif
// True if type is nothrow swappable
#if !0L && OUTCOME_USE_STD_IS_NOTHROW_SWAPPABLE
template <class T> using is_nothrow_swappable = std::is_nothrow_swappable<T>;
#else
template <class T> struct is_nothrow_swappable
{
static constexpr bool value = std::is_nothrow_move_constructible<T>::value && std::is_nothrow_move_assignable<T>::value;
};
#endif
} // namespace detail
OUTCOME_V2_NAMESPACE_END
#ifndef OUTCOME_THROW_EXCEPTION
#ifdef __cpp_exceptions
#define OUTCOME_THROW_EXCEPTION(expr) throw expr
#else
#ifdef __ANDROID__
#define OUTCOME_DISABLE_EXECINFO
#endif
#ifndef OUTCOME_DISABLE_EXECINFO
#ifdef _WIN32
/* Implements backtrace() et al from glibc on win64
(C) 2016-2017 Niall Douglas <http://www.nedproductions.biz/> (4 commits)
File Created: Mar 2016
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License in the accompanying file
Licence.txt or at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Distributed under the Boost Software License, Version 1.0.
(See accompanying file Licence.txt or copy at
http://www.boost.org/LICENSE_1_0.txt)
*/
#ifndef BOOST_BINDLIB_EXECINFO_WIN64_H
#define BOOST_BINDLIB_EXECINFO_WIN64_H
#ifndef _WIN32
#error Can only be included on Windows
#endif
#include <sal.h>
#include <stddef.h>
#ifdef QUICKCPPLIB_EXPORTS
#define EXECINFO_DECL extern __declspec(dllexport)
#else
#if defined(__cplusplus) && (!defined(QUICKCPPLIB_HEADERS_ONLY) || QUICKCPPLIB_HEADERS_ONLY == 1) && !0L
#define EXECINFO_DECL inline
#elif defined(QUICKCPPLIB_DYN_LINK) && !defined(QUICKCPPLIB_STATIC_LINK)
#define EXECINFO_DECL extern __declspec(dllimport)
#else
#define EXECINFO_DECL extern
#endif
#endif
#ifdef __cplusplus
extern "C" {
#endif
//! Fill the array of void * at bt with up to len entries, returning entries filled.
EXECINFO_DECL _Check_return_ size_t backtrace(_Out_writes_(len) void **bt, _In_ size_t len);
//! Returns a malloced block of string representations of the input backtrace.
EXECINFO_DECL _Check_return_ _Ret_writes_maybenull_(len) char **backtrace_symbols(_In_reads_(len) void *const *bt, _In_ size_t len);
// extern void backtrace_symbols_fd(void *const *bt, size_t len, int fd);
#ifdef __cplusplus
}
#if (!defined(QUICKCPPLIB_HEADERS_ONLY) || QUICKCPPLIB_HEADERS_ONLY == 1) && !0L
#define QUICKCPPLIB_INCLUDED_BY_HEADER 1
/* Implements backtrace() et al from glibc on win64
(C) 2016-2017 Niall Douglas <http://www.nedproductions.biz/> (14 commits)
File Created: Mar 2016
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License in the accompanying file
Licence.txt or at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Distributed under the Boost Software License, Version 1.0.
(See accompanying file Licence.txt or copy at
http://www.boost.org/LICENSE_1_0.txt)
*/
/* Implements backtrace() et al from glibc on win64
(C) 2016-2017 Niall Douglas <http://www.nedproductions.biz/> (4 commits)
File Created: Mar 2016
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License in the accompanying file
Licence.txt or at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Distributed under the Boost Software License, Version 1.0.
(See accompanying file Licence.txt or copy at
http://www.boost.org/LICENSE_1_0.txt)
*/
#include <atomic>
#include <stdlib.h> // for abort
#include <string.h>
// To avoid including windows.h, this source has been macro expanded and win32 function shimmed for C++ only
#if defined(__cplusplus) && !defined(__clang__)
namespace win32
{
extern _Ret_maybenull_ void *__stdcall LoadLibraryA(_In_ const char *lpLibFileName);
typedef int(__stdcall *GetProcAddress_returntype)();
extern GetProcAddress_returntype __stdcall GetProcAddress(_In_ void *hModule, _In_ const char *lpProcName);
extern _Success_(return != 0) unsigned short __stdcall RtlCaptureStackBackTrace(_In_ unsigned long FramesToSkip, _In_ unsigned long FramesToCapture,
_Out_writes_to_(FramesToCapture, return ) void **BackTrace,
_Out_opt_ unsigned long *BackTraceHash);
extern _Success_(return != 0)
_When_((cchWideChar == -1) && (cbMultiByte != 0),
_Post_equal_to_(_String_length_(lpMultiByteStr) +
1)) int __stdcall WideCharToMultiByte(_In_ unsigned int CodePage, _In_ unsigned long dwFlags, const wchar_t *lpWideCharStr,
_In_ int cchWideChar, _Out_writes_bytes_to_opt_(cbMultiByte, return ) char *lpMultiByteStr,
_In_ int cbMultiByte, _In_opt_ const char *lpDefaultChar, _Out_opt_ int *lpUsedDefaultChar);
#pragma comment(lib, "kernel32.lib")
#if (defined(__x86_64__) || defined(_M_X64)) || (defined(__aarch64__) || defined(_M_ARM64))
#pragma comment(linker, "/alternatename:?LoadLibraryA@win32@@YAPEAXPEBD@Z=LoadLibraryA")
#pragma comment(linker, "/alternatename:?GetProcAddress@win32@@YAP6AHXZPEAXPEBD@Z=GetProcAddress")
#pragma comment(linker, "/alternatename:?RtlCaptureStackBackTrace@win32@@YAGKKPEAPEAXPEAK@Z=RtlCaptureStackBackTrace")
#pragma comment(linker, "/alternatename:?WideCharToMultiByte@win32@@YAHIKPEB_WHPEADHPEBDPEAH@Z=WideCharToMultiByte")
#elif defined(__x86__) || defined(_M_IX86) || defined(__i386__)
#pragma comment(linker, "/alternatename:?LoadLibraryA@win32@@YGPAXPBD@Z=__imp__LoadLibraryA@4")
#pragma comment(linker, "/alternatename:?GetProcAddress@win32@@YGP6GHXZPAXPBD@Z=__imp__GetProcAddress@8")
#pragma comment(linker, "/alternatename:?RtlCaptureStackBackTrace@win32@@YGGKKPAPAXPAK@Z=__imp__RtlCaptureStackBackTrace@16")
#pragma comment(linker, "/alternatename:?WideCharToMultiByte@win32@@YGHIKPB_WHPADHPBDPAH@Z=__imp__WideCharToMultiByte@32")
#elif defined(__arm__) || defined(_M_ARM)
#pragma comment(linker, "/alternatename:?LoadLibraryA@win32@@YAPAXPBD@Z=LoadLibraryA")
#pragma comment(linker, "/alternatename:?GetProcAddress@win32@@YAP6AHXZPAXPBD@Z=GetProcAddress")
#pragma comment(linker, "/alternatename:?RtlCaptureStackBackTrace@win32@@YAGKKPAPAXPAK@Z=RtlCaptureStackBackTrace")
#pragma comment(linker, "/alternatename:?WideCharToMultiByte@win32@@YAHIKPB_WHPADHPBDPAH@Z=WideCharToMultiByte")
#else
#error Unknown architecture
#endif
} // namespace win32
#else
#ifndef WIN32_LEAN_AND_MEAN
#define WIN32_LEAN_AND_MEAN
#endif
#ifndef NOMINMAX
#define NOMINMAX
#endif
#include <Windows.h>
#endif
#ifdef __cplusplus
namespace
{
#endif
typedef struct _IMAGEHLP_LINE64
{
unsigned long SizeOfStruct;
void *Key;
unsigned long LineNumber;
wchar_t *FileName;
unsigned long long int Address;
} IMAGEHLP_LINE64, *PIMAGEHLP_LINE64;
typedef int(__stdcall *SymInitialize_t)(_In_ void *hProcess, _In_opt_ const wchar_t *UserSearchPath, _In_ int fInvadeProcess);
typedef int(__stdcall *SymGetLineFromAddr64_t)(_In_ void *hProcess, _In_ unsigned long long int dwAddr, _Out_ unsigned long *pdwDisplacement,
_Out_ PIMAGEHLP_LINE64 Line);
static std::atomic<unsigned> dbghelp_init_lock;
#if defined(__cplusplus) && !defined(__clang__)
static void *dbghelp;
#else
static HMODULE dbghelp;
#endif
static SymInitialize_t SymInitialize;
static SymGetLineFromAddr64_t SymGetLineFromAddr64;
static void load_dbghelp()
{
#if defined(__cplusplus) && !defined(__clang__)
using win32::GetProcAddress;
using win32::LoadLibraryA;
#endif
while(dbghelp_init_lock.exchange(1, std::memory_order_acq_rel))
;
if(dbghelp)
{
dbghelp_init_lock.store(0, std::memory_order_release);
return;
}
dbghelp = LoadLibraryA("DBGHELP.DLL");
if(dbghelp)
{
SymInitialize = (SymInitialize_t) GetProcAddress(dbghelp, "SymInitializeW");
if(!SymInitialize)
abort();
if(!SymInitialize((void *) (size_t) -1 /*GetCurrentProcess()*/, NULL, 1))
abort();
SymGetLineFromAddr64 = (SymGetLineFromAddr64_t) GetProcAddress(dbghelp, "SymGetLineFromAddrW64");
if(!SymGetLineFromAddr64)
abort();
}
dbghelp_init_lock.store(0, std::memory_order_release);
}
#ifdef __cplusplus
}
#endif
#ifdef __cplusplus
extern "C"
{
#endif
_Check_return_ size_t backtrace(_Out_writes_(len) void **bt, _In_ size_t len)
{
#if defined(__cplusplus) && !defined(__clang__)
using win32::RtlCaptureStackBackTrace;
#endif
return RtlCaptureStackBackTrace(1, (unsigned long) len, bt, NULL);
}
#ifdef _MSC_VER
#pragma warning(push)
#pragma warning(disable : 6385 6386) // MSVC static analyser can't grok this function. clang's analyser gives it thumbs up.
#endif
_Check_return_ _Ret_writes_maybenull_(len) char **backtrace_symbols(_In_reads_(len) void *const *bt, _In_ size_t len)
{
#if defined(__cplusplus) && !defined(__clang__)
using win32::WideCharToMultiByte;
#endif
size_t bytes = (len + 1) * sizeof(void *) + 256, n;
if(!len)
return NULL;
else
{
char **ret = (char **) malloc(bytes);
char *p = (char *) (ret + len + 1), *end = (char *) ret + bytes;
if(!ret)
return NULL;
for(n = 0; n < len + 1; n++)
ret[n] = NULL;
load_dbghelp();
for(n = 0; n < len; n++)
{
unsigned long displ;
IMAGEHLP_LINE64 ihl;
memset(&ihl, 0, sizeof(ihl));
ihl.SizeOfStruct = sizeof(IMAGEHLP_LINE64);
int please_realloc = 0;
if(!bt[n])
{
ret[n] = NULL;
}
else
{
// Keep offset till later
ret[n] = (char *) ((char *) p - (char *) ret);
{
static std::atomic<unsigned> symlock(0);
while(symlock.exchange(1, std::memory_order_acq_rel))
;
if(!SymGetLineFromAddr64 || !SymGetLineFromAddr64((void *) (size_t) -1 /*GetCurrentProcess()*/, (size_t) bt[n], &displ, &ihl))
{
symlock.store(0, std::memory_order_release);
if(n == 0)
{
free(ret);
return NULL;
}
ihl.FileName = (wchar_t *) L"unknown";
ihl.LineNumber = 0;
}
else
{
symlock.store(0, std::memory_order_release);
}
}
retry:
if(please_realloc)
{
char **temp = (char **) realloc(ret, bytes + 256);
if(!temp)
{
free(ret);
return NULL;
}
p = (char *) temp + (p - (char *) ret);
ret = temp;
bytes += 256;
end = (char *) ret + bytes;
}
if(ihl.FileName && ihl.FileName[0])
{
int plen = WideCharToMultiByte(65001 /*CP_UTF8*/, 0, ihl.FileName, -1, p, (int) (end - p), NULL, NULL);
if(!plen)
{
please_realloc = 1;
goto retry;
}
p[plen - 1] = 0;
p += plen - 1;
}
else
{
if(end - p < 16)
{
please_realloc = 1;
goto retry;
}
_ui64toa_s((size_t) bt[n], p, end - p, 16);
p = strchr(p, 0);
}
if(end - p < 16)
{
please_realloc = 1;
goto retry;
}
*p++ = ':';
_itoa_s(ihl.LineNumber, p, end - p, 10);
p = strchr(p, 0) + 1;
}
}
for(n = 0; n < len; n++)
{
if(ret[n])
ret[n] = (char *) ret + (size_t) ret[n];
}
return ret;
}
}
#ifdef _MSC_VER
#pragma warning(pop)
#endif
// extern void backtrace_symbols_fd(void *const *bt, size_t len, int fd);
#ifdef __cplusplus
}
#endif
#undef QUICKCPPLIB_INCLUDED_BY_HEADER
#endif
#endif
#endif
#else
#include <execinfo.h>
#endif
#endif // OUTCOME_DISABLE_EXECINFO
#include <cstdio>
#include <cstdlib>
OUTCOME_V2_NAMESPACE_BEGIN
namespace detail
{
QUICKCPPLIB_NORETURN inline void do_fatal_exit(const char *expr)
{
#if !defined(OUTCOME_DISABLE_EXECINFO)
void *bt[16];
size_t btlen = backtrace(bt, sizeof(bt) / sizeof(bt[0])); // NOLINT
#endif
fprintf(stderr, "FATAL: Outcome throws exception %s with exceptions disabled\n", expr); // NOLINT
#if !defined(OUTCOME_DISABLE_EXECINFO)
char **bts = backtrace_symbols(bt, btlen); // NOLINT
if(bts != nullptr)
{
for(size_t n = 0; n < btlen; n++)
{
fprintf(stderr, " %s\n", bts[n]); // NOLINT
}
free(bts); // NOLINT
}
#endif
abort();
}
} // namespace detail
OUTCOME_V2_NAMESPACE_END
#define OUTCOME_THROW_EXCEPTION(expr) OUTCOME_V2_NAMESPACE::detail::do_fatal_exit(#expr), (void) (expr)
#endif
#endif
#ifndef BOOST_OUTCOME_AUTO_TEST_CASE
#define BOOST_OUTCOME_AUTO_TEST_CASE(a, b) BOOST_AUTO_TEST_CASE(a, b)
#endif
#endif
/* A very simple result type
(C) 2017-2024 Niall Douglas <http://www.nedproductions.biz/> (14 commits)
File Created: June 2017
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License in the accompanying file
Licence.txt or at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Distributed under the Boost Software License, Version 1.0.
(See accompanying file Licence.txt or copy at
http://www.boost.org/LICENSE_1_0.txt)
*/
#ifndef OUTCOME_BASIC_RESULT_HPP
#define OUTCOME_BASIC_RESULT_HPP
/* Says how to convert value, error and exception types
(C) 2017-2019 Niall Douglas <http://www.nedproductions.biz/> (12 commits)
File Created: Nov 2017
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License in the accompanying file
Licence.txt or at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Distributed under the Boost Software License, Version 1.0.
(See accompanying file Licence.txt or copy at
http://www.boost.org/LICENSE_1_0.txt)
*/
#ifndef OUTCOME_CONVERT_HPP
#define OUTCOME_CONVERT_HPP
/* Storage for a very simple basic_result type
(C) 2017-2019 Niall Douglas <http://www.nedproductions.biz/> (6 commits)
File Created: Oct 2017
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License in the accompanying file
Licence.txt or at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Distributed under the Boost Software License, Version 1.0.
(See accompanying file Licence.txt or copy at
http://www.boost.org/LICENSE_1_0.txt)
*/
#ifndef OUTCOME_BASIC_RESULT_STORAGE_HPP
#define OUTCOME_BASIC_RESULT_STORAGE_HPP
/* Type sugar for success and failure
(C) 2017-2019 Niall Douglas <http://www.nedproductions.biz/> (25 commits)
File Created: July 2017
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License in the accompanying file
Licence.txt or at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Distributed under the Boost Software License, Version 1.0.
(See accompanying file Licence.txt or copy at
http://www.boost.org/LICENSE_1_0.txt)
*/
#ifndef OUTCOME_SUCCESS_FAILURE_HPP
#define OUTCOME_SUCCESS_FAILURE_HPP
OUTCOME_V2_NAMESPACE_BEGIN
/*! AWAITING HUGO JSON CONVERSION TOOL
type definition template <class T> success_type. Potential doc page: `success_type<T>`
*/
template <class T> struct OUTCOME_NODISCARD success_type
{
using value_type = T;
private:
value_type _value;
uint16_t _spare_storage{0};
public:
success_type() = default;
success_type(const success_type &) = default;
success_type(success_type &&) = default; // NOLINT
success_type &operator=(const success_type &) = default;
success_type &operator=(success_type &&) = default; // NOLINT
~success_type() = default;
OUTCOME_TEMPLATE(class U)
OUTCOME_TREQUIRES(OUTCOME_TPRED(!std::is_same<success_type, std::decay_t<U>>::value))
constexpr explicit success_type(U &&v, uint16_t spare_storage = 0)
: _value(static_cast<U &&>(v)) // NOLINT
, _spare_storage(spare_storage)
{
}
constexpr value_type &value() & { return _value; }
constexpr const value_type &value() const & { return _value; }
constexpr value_type &&value() && { return static_cast<value_type &&>(_value); }
constexpr const value_type &&value() const && { return static_cast<value_type &&>(_value); }
constexpr uint16_t spare_storage() const { return _spare_storage; }
};
template <> struct OUTCOME_NODISCARD success_type<void>
{
using value_type = void;
constexpr uint16_t spare_storage() const { return 0; }
};
/*! Returns type sugar for implicitly constructing a `basic_result<T>` with a successful state,
default constructing `T` if necessary.
*/
inline constexpr success_type<void> success() noexcept
{
return success_type<void>{};
}
/*! Returns type sugar for implicitly constructing a `basic_result<T>` with a successful state.
\effects Copies the successful state supplied into the returned type sugar.
*/
OUTCOME_TEMPLATE(class T)
OUTCOME_TREQUIRES(OUTCOME_TPRED(std::is_copy_constructible<T>::value))
inline constexpr success_type<std::decay_t<T>> success(const T &v, uint16_t spare_storage = 0)
{
return success_type<std::decay_t<T>>{v, spare_storage};
}
/*! Returns type sugar for implicitly constructing a `basic_result<T>` with a successful state.
\effects Moves the successful state supplied into the returned type sugar.
*/
OUTCOME_TEMPLATE(class T)
OUTCOME_TREQUIRES(OUTCOME_TPRED(std::is_move_constructible<T>::value))
inline constexpr success_type<std::decay_t<T>> success(T &&v, uint16_t spare_storage = 0)
{
return success_type<std::decay_t<T>>{static_cast<T &&>(v), spare_storage};
}
/*! AWAITING HUGO JSON CONVERSION TOOL
type definition template <class EC, class E = void> failure_type. Potential doc page: `failure_type<EC, EP = void>`
*/
template <class EC, class E = void> struct OUTCOME_NODISCARD failure_type
{
using error_type = EC;
using exception_type = E;
private:
error_type _error;
exception_type _exception;
bool _have_error{false}, _have_exception{false};
uint16_t _spare_storage{0};
struct error_init_tag
{
};
struct exception_init_tag
{
};
public:
failure_type() = default;
failure_type(const failure_type &) = default;
failure_type(failure_type &&) = default; // NOLINT
failure_type &operator=(const failure_type &) = default;
failure_type &operator=(failure_type &&) = default; // NOLINT
~failure_type() = default;
template <class U, class V>
constexpr explicit failure_type(U &&u, V &&v, uint16_t spare_storage = 0)
: _error(static_cast<U &&>(u))
, _exception(static_cast<V &&>(v))
, _have_error(true)
, _have_exception(true)
, _spare_storage(spare_storage)
{
}
template <class U>
constexpr explicit failure_type(in_place_type_t<error_type> /*unused*/, U &&u, uint16_t spare_storage = 0, error_init_tag /*unused*/ = error_init_tag())
: _error(static_cast<U &&>(u))
, _exception()
, _have_error(true)
, _spare_storage(spare_storage)
{
}
template <class U>
constexpr explicit failure_type(in_place_type_t<exception_type> /*unused*/, U &&u, uint16_t spare_storage = 0,
exception_init_tag /*unused*/ = exception_init_tag())
: _error()
, _exception(static_cast<U &&>(u))
, _have_exception(true)
, _spare_storage(spare_storage)
{
}
constexpr bool has_error() const { return _have_error; }
constexpr bool has_exception() const { return _have_exception; }
constexpr error_type &error() & { return _error; }
constexpr const error_type &error() const & { return _error; }
constexpr error_type &&error() && { return static_cast<error_type &&>(_error); }
constexpr const error_type &&error() const && { return static_cast<error_type &&>(_error); }
constexpr exception_type &exception() & { return _exception; }
constexpr const exception_type &exception() const & { return _exception; }
constexpr exception_type &&exception() && { return static_cast<exception_type &&>(_exception); }
constexpr const exception_type &&exception() const && { return static_cast<exception_type &&>(_exception); }
constexpr uint16_t spare_storage() const { return _spare_storage; }
};
template <class EC> struct OUTCOME_NODISCARD failure_type<EC, void>
{
using error_type = EC;
using exception_type = void;
private:
error_type _error;
uint16_t _spare_storage{0};
public:
failure_type() = default;
failure_type(const failure_type &) = default;
failure_type(failure_type &&) = default; // NOLINT
failure_type &operator=(const failure_type &) = default;
failure_type &operator=(failure_type &&) = default; // NOLINT
~failure_type() = default;
OUTCOME_TEMPLATE(class U)
OUTCOME_TREQUIRES(OUTCOME_TPRED(!std::is_same<failure_type, std::decay_t<U>>::value))
constexpr explicit failure_type(U &&u, uint16_t spare_storage = 0)
: _error(static_cast<U &&>(u)) // NOLINT
, _spare_storage(spare_storage)
{
}
constexpr error_type &error() & { return _error; }
constexpr const error_type &error() const & { return _error; }
constexpr error_type &&error() && { return static_cast<error_type &&>(_error); }
constexpr const error_type &&error() const && { return static_cast<error_type &&>(_error); }
constexpr uint16_t spare_storage() const { return _spare_storage; }
};
template <class E> struct OUTCOME_NODISCARD failure_type<void, E>
{
using error_type = void;
using exception_type = E;
private:
exception_type _exception;
uint16_t _spare_storage{0};
public:
failure_type() = default;
failure_type(const failure_type &) = default;
failure_type(failure_type &&) = default; // NOLINT
failure_type &operator=(const failure_type &) = default;
failure_type &operator=(failure_type &&) = default; // NOLINT
~failure_type() = default;
OUTCOME_TEMPLATE(class V)
OUTCOME_TREQUIRES(OUTCOME_TPRED(!std::is_same<failure_type, std::decay_t<V>>::value))
constexpr explicit failure_type(V &&v, uint16_t spare_storage = 0)
: _exception(static_cast<V &&>(v)) // NOLINT
, _spare_storage(spare_storage)
{
}
constexpr exception_type &exception() & { return _exception; }
constexpr const exception_type &exception() const & { return _exception; }
constexpr exception_type &&exception() && { return static_cast<exception_type &&>(_exception); }
constexpr const exception_type &&exception() const && { return static_cast<exception_type &&>(_exception); }
constexpr uint16_t spare_storage() const { return _spare_storage; }
};
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class EC)
OUTCOME_TREQUIRES(OUTCOME_TPRED(std::is_copy_constructible<EC>::value))
inline constexpr failure_type<std::decay_t<EC>> failure(const EC &v, uint16_t spare_storage = 0)
{
return failure_type<std::decay_t<EC>>{v, spare_storage};
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class EC)
OUTCOME_TREQUIRES(OUTCOME_TPRED(std::is_move_constructible<EC>::value))
inline constexpr failure_type<std::decay_t<EC>> failure(EC &&v, uint16_t spare_storage = 0)
{
return failure_type<std::decay_t<EC>>{static_cast<EC &&>(v), spare_storage};
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class EC, class E)
OUTCOME_TREQUIRES(OUTCOME_TPRED(std::is_copy_constructible<EC>::value &&std::is_copy_constructible<E>::value))
inline constexpr failure_type<std::decay_t<EC>, std::decay_t<E>> failure(const EC &v, const E &w, uint16_t spare_storage = 0)
{
return failure_type<std::decay_t<EC>, std::decay_t<E>>{v, w, spare_storage};
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class EC, class E)
OUTCOME_TREQUIRES(OUTCOME_TPRED(std::is_copy_constructible<EC>::value &&std::is_move_constructible<E>::value))
inline constexpr failure_type<std::decay_t<EC>, std::decay_t<E>> failure(const EC &v, E &&w, uint16_t spare_storage = 0)
{
return failure_type<std::decay_t<EC>, std::decay_t<E>>{v, static_cast<E &&>(w), spare_storage};
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class EC, class E)
OUTCOME_TREQUIRES(OUTCOME_TPRED(std::is_move_constructible<EC>::value &&std::is_copy_constructible<E>::value))
inline constexpr failure_type<std::decay_t<EC>, std::decay_t<E>> failure(EC &&v, const E &w, uint16_t spare_storage = 0)
{
return failure_type<std::decay_t<EC>, std::decay_t<E>>{static_cast<EC &&>(v), w, spare_storage};
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class EC, class E)
OUTCOME_TREQUIRES(OUTCOME_TPRED(std::is_move_constructible<EC>::value &&std::is_move_constructible<E>::value))
inline constexpr failure_type<std::decay_t<EC>, std::decay_t<E>> failure(EC &&v, E &&w, uint16_t spare_storage = 0)
{
return failure_type<std::decay_t<EC>, std::decay_t<E>>{static_cast<EC &&>(v), static_cast<E &&>(w), spare_storage};
}
namespace detail
{
template <class T> struct is_success_type
{
static constexpr bool value = false;
};
template <class T> struct is_success_type<success_type<T>>
{
static constexpr bool value = true;
};
template <class T> struct is_failure_type
{
static constexpr bool value = false;
};
template <class EC, class E> struct is_failure_type<failure_type<EC, E>>
{
static constexpr bool value = true;
};
} // namespace detail
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
template <class T> static constexpr bool is_success_type = detail::is_success_type<std::decay_t<T>>::value;
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
template <class T> static constexpr bool is_failure_type = detail::is_failure_type<std::decay_t<T>>::value;
OUTCOME_V2_NAMESPACE_END
#endif
/* Traits for Outcome
(C) 2018-2019 Niall Douglas <http://www.nedproductions.biz/> (8 commits)
File Created: March 2018
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License in the accompanying file
Licence.txt or at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Distributed under the Boost Software License, Version 1.0.
(See accompanying file Licence.txt or copy at
http://www.boost.org/LICENSE_1_0.txt)
*/
#ifndef OUTCOME_TRAIT_HPP
#define OUTCOME_TRAIT_HPP
OUTCOME_V2_NAMESPACE_EXPORT_BEGIN
namespace trait
{
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
template <class R> //
static constexpr bool type_can_be_used_in_basic_result = //
(!std::is_reference<R>::value //
&& !OUTCOME_V2_NAMESPACE::detail::is_in_place_type_t<std::decay_t<R>>::value //
&& !is_success_type<R> //
&& !is_failure_type<R> //
&& !std::is_array<R>::value //
&& (std::is_void<R>::value || (std::is_object<R>::value //
&& std::is_destructible<R>::value)) //
);
/*! AWAITING HUGO JSON CONVERSION TOOL
type definition is_error_type. Potential doc page: NOT FOUND
*/
template <class T> struct is_move_bitcopying
{
static constexpr bool value = false;
};
/*! AWAITING HUGO JSON CONVERSION TOOL
type definition is_error_type. Potential doc page: NOT FOUND
*/
template <class E> struct is_error_type
{
static constexpr bool value = false;
};
/*! AWAITING HUGO JSON CONVERSION TOOL
type definition is_error_type_enum. Potential doc page: NOT FOUND
*/
template <class E, class Enum> struct is_error_type_enum
{
static constexpr bool value = false;
};
namespace detail
{
template <class T> using devoid = OUTCOME_V2_NAMESPACE::detail::devoid<T>;
template <class T> std::add_rvalue_reference_t<devoid<T>> declval() noexcept;
// From http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2015/n4436.pdf
namespace detector_impl
{
template <class...> using void_t = void;
template <class Default, class, template <class...> class Op, class... Args> struct detector
{
static constexpr bool value = false;
using type = Default;
};
template <class Default, template <class...> class Op, class... Args> struct detector<Default, void_t<Op<Args...>>, Op, Args...>
{
static constexpr bool value = true;
using type = Op<Args...>;
};
} // namespace detector_impl
template <template <class...> class Op, class... Args> using is_detected = detector_impl::detector<void, void, Op, Args...>;
template <class Arg> using result_of_make_error_code = decltype(make_error_code(declval<Arg>()));
template <class Arg> using introspect_make_error_code = is_detected<result_of_make_error_code, Arg>;
template <class Arg> using result_of_make_exception_ptr = decltype(make_exception_ptr(declval<Arg>()));
template <class Arg> using introspect_make_exception_ptr = is_detected<result_of_make_exception_ptr, Arg>;
template <class T> struct _is_error_code_available
{
static constexpr bool value = detail::introspect_make_error_code<T>::value;
using type = typename detail::introspect_make_error_code<T>::type;
};
template <class T> struct _is_exception_ptr_available
{
static constexpr bool value = detail::introspect_make_exception_ptr<T>::value;
using type = typename detail::introspect_make_exception_ptr<T>::type;
};
} // namespace detail
/*! AWAITING HUGO JSON CONVERSION TOOL
type definition is_error_code_available. Potential doc page: NOT FOUND
*/
template <class T> struct is_error_code_available
{
static constexpr bool value = detail::_is_error_code_available<std::decay_t<T>>::value;
using type = typename detail::_is_error_code_available<std::decay_t<T>>::type;
};
template <class T> constexpr bool is_error_code_available_v = detail::_is_error_code_available<std::decay_t<T>>::value;
/*! AWAITING HUGO JSON CONVERSION TOOL
type definition is_exception_ptr_available. Potential doc page: NOT FOUND
*/
template <class T> struct is_exception_ptr_available
{
static constexpr bool value = detail::_is_exception_ptr_available<std::decay_t<T>>::value;
using type = typename detail::_is_exception_ptr_available<std::decay_t<T>>::type;
};
template <class T> constexpr bool is_exception_ptr_available_v = detail::_is_exception_ptr_available<std::decay_t<T>>::value;
} // namespace trait
OUTCOME_V2_NAMESPACE_END
#endif
/* Essentially an internal optional implementation :)
(C) 2017-2022 Niall Douglas <http://www.nedproductions.biz/> (24 commits)
File Created: June 2017
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License in the accompanying file
Licence.txt or at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Distributed under the Boost Software License, Version 1.0.
(See accompanying file Licence.txt or copy at
http://www.boost.org/LICENSE_1_0.txt)
*/
#ifndef OUTCOME_VALUE_STORAGE_HPP
#define OUTCOME_VALUE_STORAGE_HPP
OUTCOME_V2_NAMESPACE_EXPORT_BEGIN
namespace detail
{
// Helpers for move assigning to empty storage
template <class T, bool isCopyOrMoveConstructible = std::is_copy_constructible<T>::value || std::is_move_constructible<T>::value,
bool isDefaultConstructibleAndCopyOrMoveAssignable =
std::is_default_constructible<T>::value && (std::is_copy_assignable<T>::value || std::is_move_assignable<T>::value)>
struct move_assign_to_empty;
// Prefer to use move or copy construction
template <class T> struct move_assign_to_empty<T, true, false>
{
move_assign_to_empty(T *dest, T *o) noexcept(std::is_nothrow_move_constructible<T>::value) { new(dest) T(static_cast<T &&>(*o)); }
};
template <class T> struct move_assign_to_empty<T, true, true>
{
move_assign_to_empty(T *dest, T *o) noexcept(std::is_nothrow_move_constructible<T>::value) { new(dest) T(static_cast<T &&>(*o)); }
};
// But fall back on default construction and move assign if necessary
template <class T> struct move_assign_to_empty<T, false, true>
{
move_assign_to_empty(T *dest, T *o) noexcept(std::is_nothrow_default_constructible<T>::value && std::is_nothrow_move_assignable<T>::value)
{
new(dest) T;
*dest = static_cast<T &&>(*o);
}
};
// Void does nothing
template <> struct move_assign_to_empty<void, false, false>
{
move_assign_to_empty(void *, void *) noexcept { /* nothing to assign */ }
};
template <> struct move_assign_to_empty<const void, false, false>
{
move_assign_to_empty(const void *, const void *) noexcept { /* nothing to assign */ }
};
// Helpers for copy assigning to empty storage
template <class T, bool isCopyConstructible = std::is_copy_constructible<T>::value,
bool isDefaultConstructibleAndCopyAssignable = std::is_default_constructible<T>::value && std::is_copy_assignable<T>::value>
struct copy_assign_to_empty;
// Prefer to use copy construction
template <class T> struct copy_assign_to_empty<T, true, false>
{
copy_assign_to_empty(T *dest, const T *o) noexcept(std::is_nothrow_copy_constructible<T>::value) { new(dest) T(*o); }
};
template <class T> struct copy_assign_to_empty<T, true, true>
{
copy_assign_to_empty(T *dest, const T *o) noexcept(std::is_nothrow_copy_constructible<T>::value) { new(dest) T(*o); }
};
// But fall back on default construction and copy assign if necessary
template <class T> struct copy_assign_to_empty<T, false, true>
{
copy_assign_to_empty(T *dest, const T *o) noexcept(std::is_nothrow_default_constructible<T>::value && std::is_nothrow_copy_assignable<T>::value)
{
new(dest) T;
*dest = *o;
}
};
// Void does nothing
template <> struct copy_assign_to_empty<void, false, false>
{
copy_assign_to_empty(void *, void *) noexcept { /* nothing to assign */ }
};
template <> struct copy_assign_to_empty<const void, false, false>
{
copy_assign_to_empty(const void *, const void *) noexcept { /* nothing to assign */ }
};
template <class T, bool nothrow> struct strong_swap_impl
{
constexpr strong_swap_impl(bool &allgood, T &a, T &b)
{
allgood = true;
using std::swap;
swap(a, b);
}
};
template <class T, bool nothrow> struct strong_placement_impl
{
template <class F> constexpr strong_placement_impl(bool &allgood, T *a, T *b, F &&f)
{
allgood = true;
new(a) T(static_cast<T &&>(*b));
b->~T();
f();
}
};
#ifdef __cpp_exceptions
template <class T> struct strong_swap_impl<T, false>
{
strong_swap_impl(bool &allgood, T &a, T &b)
{
allgood = true;
T v(static_cast<T &&>(a));
try
{
a = static_cast<T &&>(b);
}
catch(...)
{
// Try to put back a
try
{
a = static_cast<T &&>(v);
// fall through as all good
}
catch(...)
{
// failed to completely restore
allgood = false;
// throw away second exception
}
throw; // rethrow original exception
}
// b has been moved to a, try to move v to b
try
{
b = static_cast<T &&>(v);
}
catch(...)
{
// Try to restore a to b, and v to a
try
{
b = static_cast<T &&>(a);
a = static_cast<T &&>(v);
// fall through as all good
}
catch(...)
{
// failed to completely restore
allgood = false;
// throw away second exception
}
throw; // rethrow original exception
}
}
};
template <class T> struct strong_placement_impl<T, false>
{
template <class F> strong_placement_impl(bool &allgood, T *a, T *b, F &&f)
{
new(a) T(static_cast<T &&>(*b));
try
{
b->~T();
f();
}
catch(...)
{
// Try to put back a, but only if we are still good
if(allgood)
{
try
{
new(b) T(static_cast<T &&>(*a));
// fall through as all good
}
catch(...)
{
// failed to completely restore
allgood = false;
// throw away second exception
}
throw; // rethrow original exception
}
}
}
};
#endif
} // namespace detail
/*!
*/
OUTCOME_TEMPLATE(class T)
OUTCOME_TREQUIRES(OUTCOME_TPRED(std::is_move_constructible<T>::value &&std::is_move_assignable<T>::value))
constexpr inline void strong_swap(bool &allgood, T &a, T &b) noexcept(detail::is_nothrow_swappable<T>::value)
{
detail::strong_swap_impl<T, detail::is_nothrow_swappable<T>::value>(allgood, a, b);
}
/*!
*/
OUTCOME_TEMPLATE(class T, class F)
OUTCOME_TREQUIRES(OUTCOME_TPRED(std::is_move_constructible<T>::value &&std::is_move_assignable<T>::value))
constexpr inline void strong_placement(bool &allgood, T *a, T *b, F &&f) noexcept(std::is_nothrow_move_constructible<T>::value)
{
detail::strong_placement_impl<T, std::is_nothrow_move_constructible<T>::value>(allgood, a, b, static_cast<F &&>(f));
}
namespace detail
{
template <class T>
constexpr
#ifdef _MSC_VER
__declspec(noreturn)
#elif defined(__GNUC__) || defined(__clang__)
__attribute__((noreturn))
#endif
void
make_ub(T && /*unused*/)
{
OUTCOME_ASSERT(false); // NOLINT
#if defined(__GNUC__) || defined(__clang__)
__builtin_unreachable();
#elif defined(_MSC_VER)
__assume(0);
#endif
}
/* Outcome v1 used a C bitfield whose values were tracked by compiler optimisers nicely,
but that produces ICEs when used in constexpr.
Outcome v2.0-v2.1 used a 32 bit integer and manually set and cleared bits. Unfortunately
only GCC's optimiser tracks bit values during constant folding, and only per byte, and
even then unreliably. https://wg21.link/P1886 "Error speed benchmarking" showed just how
poorly clang and MSVC fails to optimise outcome-using code, if you manually set bits.
Outcome v2.2 therefore uses an enum with fixed values, and constexpr manipulation functions
to change the value to one of the enum's values. This is stupid to look at in source code,
but it make clang's optimiser do the right thing, so it's worth it.
*/
#define OUTCOME_USE_CONSTEXPR_ENUM_STATUS 0
enum class status : uint16_t
{
// WARNING: These bits are not tracked by abi-dumper, but changing them will break ABI!
none = 0,
have_value = (1U << 0U),
have_error = (1U << 1U),
have_exception = (2U << 1U),
have_error_exception = (3U << 1U),
// failed to complete a strong swap
have_lost_consistency = (1U << 3U),
have_value_lost_consistency = (1U << 0U) | (1U << 3U),
have_error_lost_consistency = (1U << 1U) | (1U << 3U),
have_exception_lost_consistency = (2U << 1U) | (1U << 3U),
have_error_exception_lost_consistency = (3U << 1U) | (1U << 3U),
// can errno be set from this error?
have_error_is_errno = (1U << 4U),
have_error_error_is_errno = (1U << 1U) | (1U << 4U),
have_error_exception_error_is_errno = (3U << 1U) | (1U << 4U),
have_error_lost_consistency_error_is_errno = (1U << 1U) | (1U << 3U) | (1U << 4U),
have_error_exception_lost_consistency_error_is_errno = (3U << 1U) | (1U << 3U) | (1U << 4U),
// value has been moved from
have_moved_from = (1U << 5U)
};
struct status_bitfield_type
{
status status_value{status::none};
uint16_t spare_storage_value{0}; // hooks::spare_storage()
constexpr status_bitfield_type() = default;
constexpr status_bitfield_type(status v) noexcept
: status_value(v)
{
} // NOLINT
constexpr status_bitfield_type(status v, uint16_t s) noexcept
: status_value(v)
, spare_storage_value(s)
{
}
constexpr status_bitfield_type(const status_bitfield_type &) = default;
constexpr status_bitfield_type(status_bitfield_type &&) = default;
constexpr status_bitfield_type &operator=(const status_bitfield_type &) = default;
constexpr status_bitfield_type &operator=(status_bitfield_type &&) = default;
//~status_bitfield_type() = default; // Do NOT uncomment this, it breaks older clangs!
constexpr bool have_value() const noexcept
{
return (static_cast<uint16_t>(status_value) & static_cast<uint16_t>(status::have_value)) != 0;
}
constexpr bool have_error() const noexcept
{
return (static_cast<uint16_t>(status_value) & static_cast<uint16_t>(status::have_error)) != 0;
}
constexpr bool have_exception() const noexcept
{
return (static_cast<uint16_t>(status_value) & static_cast<uint16_t>(status::have_exception)) != 0;
}
constexpr bool have_lost_consistency() const noexcept
{
return (static_cast<uint16_t>(status_value) & static_cast<uint16_t>(status::have_lost_consistency)) != 0;
}
constexpr bool have_error_is_errno() const noexcept
{
return (static_cast<uint16_t>(status_value) & static_cast<uint16_t>(status::have_error_is_errno)) != 0;
}
constexpr bool have_moved_from() const noexcept
{
return (static_cast<uint16_t>(status_value) & static_cast<uint16_t>(status::have_moved_from)) != 0;
}
constexpr status_bitfield_type &set_have_value(bool v) noexcept
{
status_value = static_cast<status>(v ? (static_cast<uint16_t>(status_value) | static_cast<uint16_t>(status::have_value)) :
(static_cast<uint16_t>(status_value) & ~static_cast<uint16_t>(status::have_value)));
return *this;
}
constexpr status_bitfield_type &set_have_error(bool v) noexcept
{
status_value = static_cast<status>(v ? (static_cast<uint16_t>(status_value) | static_cast<uint16_t>(status::have_error)) :
(static_cast<uint16_t>(status_value) & ~static_cast<uint16_t>(status::have_error)));
return *this;
}
constexpr status_bitfield_type &set_have_exception(bool v) noexcept
{
status_value = static_cast<status>(v ? (static_cast<uint16_t>(status_value) | static_cast<uint16_t>(status::have_exception)) :
(static_cast<uint16_t>(status_value) & ~static_cast<uint16_t>(status::have_exception)));
return *this;
}
constexpr status_bitfield_type &set_have_error_is_errno(bool v) noexcept
{
status_value = static_cast<status>(v ? (static_cast<uint16_t>(status_value) | static_cast<uint16_t>(status::have_error_is_errno)) :
(static_cast<uint16_t>(status_value) & ~static_cast<uint16_t>(status::have_error_is_errno)));
return *this;
}
constexpr status_bitfield_type &set_have_lost_consistency(bool v) noexcept
{
status_value = static_cast<status>(v ? (static_cast<uint16_t>(status_value) | static_cast<uint16_t>(status::have_lost_consistency)) :
(static_cast<uint16_t>(status_value) & ~static_cast<uint16_t>(status::have_lost_consistency)));
return *this;
}
constexpr status_bitfield_type &set_have_moved_from(bool v) noexcept
{
status_value = static_cast<status>(v ? (static_cast<uint16_t>(status_value) | static_cast<uint16_t>(status::have_moved_from)) :
(static_cast<uint16_t>(status_value) & ~static_cast<uint16_t>(status::have_moved_from)));
return *this;
}
};
#if !defined(NDEBUG)
// Check is trivial in all ways except default constructibility
static_assert(sizeof(status_bitfield_type) == 4, "status_bitfield_type is not sized 4 bytes!");
static_assert(std::is_trivially_copyable<status_bitfield_type>::value, "status_bitfield_type is not trivially copyable!");
static_assert(std::is_trivially_assignable<status_bitfield_type, status_bitfield_type>::value, "status_bitfield_type is not trivially assignable!");
static_assert(std::is_trivially_destructible<status_bitfield_type>::value, "status_bitfield_type is not trivially destructible!");
static_assert(std::is_trivially_copy_constructible<status_bitfield_type>::value, "status_bitfield_type is not trivially copy constructible!");
static_assert(std::is_trivially_move_constructible<status_bitfield_type>::value, "status_bitfield_type is not trivially move constructible!");
static_assert(std::is_trivially_copy_assignable<status_bitfield_type>::value, "status_bitfield_type is not trivially copy assignable!");
static_assert(std::is_trivially_move_assignable<status_bitfield_type>::value, "status_bitfield_type is not trivially move assignable!");
// Also check is standard layout
static_assert(std::is_standard_layout<status_bitfield_type>::value, "status_bitfield_type is not a standard layout type!");
#endif
template <class State> constexpr inline void _set_error_is_errno(State & /*unused*/) {}
#ifdef _MSC_VER
#pragma warning(push)
#pragma warning(disable : 4127) // conditional expression is constant
#pragma warning(disable : 4624) // destructor was implicitly defined as deleted
#endif
// Used if both T and E are trivial
template <class T, class E> struct value_storage_trivial
{
using value_type = T;
using error_type = E;
// Disable in place construction if they are the same type
struct disable_in_place_value_type
{
};
struct disable_in_place_error_type
{
};
using _value_type = std::conditional_t<std::is_same<value_type, error_type>::value, disable_in_place_value_type, value_type>;
using _error_type = std::conditional_t<std::is_same<value_type, error_type>::value, disable_in_place_error_type, error_type>;
using _value_type_ = devoid<value_type>;
using _error_type_ = devoid<error_type>;
union
{
empty_type _empty;
_value_type_ _value;
_error_type_ _error;
};
status_bitfield_type _status;
constexpr value_storage_trivial() noexcept
: _empty{}
{
}
value_storage_trivial(const value_storage_trivial &) = default; // NOLINT
value_storage_trivial(value_storage_trivial &&) = default; // NOLINT
value_storage_trivial &operator=(const value_storage_trivial &) = default; // NOLINT
value_storage_trivial &operator=(value_storage_trivial &&) = default; // NOLINT
~value_storage_trivial() = default;
constexpr explicit value_storage_trivial(status_bitfield_type status)
: _empty()
, _status(status)
{
}
template <class... Args>
constexpr explicit value_storage_trivial(in_place_type_t<_value_type> /*unused*/,
Args &&...args) noexcept(detail::is_nothrow_constructible<_value_type_, Args...>)
: _value(static_cast<Args &&>(args)...)
, _status(status::have_value)
{
}
template <class U, class... Args>
constexpr value_storage_trivial(in_place_type_t<_value_type> /*unused*/, std::initializer_list<U> il,
Args &&...args) noexcept(detail::is_nothrow_constructible<_value_type_, std::initializer_list<U>, Args...>)
: _value(il, static_cast<Args &&>(args)...)
, _status(status::have_value)
{
}
template <class... Args>
constexpr explicit value_storage_trivial(in_place_type_t<_error_type> /*unused*/,
Args &&...args) noexcept(detail::is_nothrow_constructible<_error_type_, Args...>)
: _error(static_cast<Args &&>(args)...)
, _status(status::have_error)
{
_set_error_is_errno(*this);
}
template <class U, class... Args>
constexpr value_storage_trivial(in_place_type_t<_error_type> /*unused*/, std::initializer_list<U> il,
Args &&...args) noexcept(detail::is_nothrow_constructible<_error_type_, std::initializer_list<U>, Args...>)
: _error(il, static_cast<Args &&>(args)...)
, _status(status::have_error)
{
_set_error_is_errno(*this);
}
struct nonvoid_converting_constructor_tag
{
};
template <class U, class V>
static constexpr bool enable_nonvoid_converting_constructor =
!(std::is_same<std::decay_t<U>, value_type>::value && std::is_same<std::decay_t<V>, error_type>::value) //
&& detail::is_constructible<value_type, U> && detail::is_constructible<error_type, V>;
OUTCOME_TEMPLATE(class U, class V)
OUTCOME_TREQUIRES(OUTCOME_TPRED(enable_nonvoid_converting_constructor<U, V>))
constexpr explicit value_storage_trivial(const value_storage_trivial<U, V> &o,
nonvoid_converting_constructor_tag /*unused*/ = {}) noexcept(detail::is_nothrow_constructible<_value_type_, U> &&
detail::is_nothrow_constructible<_error_type_, V>)
: value_storage_trivial(o._status.have_value() ?
value_storage_trivial(in_place_type<value_type>, o._value) :
(o._status.have_error() ? value_storage_trivial(in_place_type<error_type>, o._error) : value_storage_trivial())) // NOLINT
{
_status = o._status;
}
OUTCOME_TEMPLATE(class U, class V)
OUTCOME_TREQUIRES(OUTCOME_TPRED(enable_nonvoid_converting_constructor<U, V>))
constexpr explicit value_storage_trivial(value_storage_trivial<U, V> &&o,
nonvoid_converting_constructor_tag /*unused*/ = {}) noexcept(detail::is_nothrow_constructible<_value_type_, U> &&
detail::is_nothrow_constructible<_error_type_, V>)
: value_storage_trivial(
o._status.have_value() ?
value_storage_trivial(in_place_type<value_type>, static_cast<U &&>(o._value)) :
(o._status.have_error() ? value_storage_trivial(in_place_type<error_type>, static_cast<V &&>(o._error)) : value_storage_trivial())) // NOLINT
{
_status = o._status;
}
struct void_value_converting_constructor_tag
{
};
template <class V>
static constexpr bool enable_void_value_converting_constructor =
std::is_default_constructible<value_type>::value && detail::is_constructible<error_type, V>;
OUTCOME_TEMPLATE(class V)
OUTCOME_TREQUIRES(OUTCOME_TPRED(enable_void_value_converting_constructor<V>))
constexpr explicit value_storage_trivial(const value_storage_trivial<void, V> &o, void_value_converting_constructor_tag /*unused*/ = {}) noexcept(
std::is_nothrow_default_constructible<_value_type_>::value && detail::is_nothrow_constructible<_error_type_, V>)
: value_storage_trivial(o._status.have_value() ?
value_storage_trivial(in_place_type<value_type>) :
(o._status.have_error() ? value_storage_trivial(in_place_type<error_type>, o._error) : value_storage_trivial())) // NOLINT
{
_status = o._status;
}
OUTCOME_TEMPLATE(class V)
OUTCOME_TREQUIRES(OUTCOME_TPRED(enable_void_value_converting_constructor<V>))
constexpr explicit value_storage_trivial(value_storage_trivial<void, V> &&o, void_value_converting_constructor_tag /*unused*/ = {}) noexcept(
std::is_nothrow_default_constructible<_value_type_>::value && detail::is_nothrow_constructible<_error_type_, V>)
: value_storage_trivial(
o._status.have_value() ?
value_storage_trivial(in_place_type<value_type>) :
(o._status.have_error() ? value_storage_trivial(in_place_type<error_type>, static_cast<V &&>(o._error)) : value_storage_trivial())) // NOLINT
{
_status = o._status;
}
struct void_error_converting_constructor_tag
{
};
template <class U>
static constexpr bool enable_void_error_converting_constructor =
std::is_default_constructible<error_type>::value && detail::is_constructible<value_type, U>;
OUTCOME_TEMPLATE(class U)
OUTCOME_TREQUIRES(OUTCOME_TPRED(enable_void_error_converting_constructor<U>))
constexpr explicit value_storage_trivial(const value_storage_trivial<U, void> &o, void_error_converting_constructor_tag /*unused*/ = {}) noexcept(
detail::is_nothrow_constructible<_value_type_, U> && std::is_nothrow_default_constructible<_error_type_>::value)
: value_storage_trivial(o._status.have_value() ?
value_storage_trivial(in_place_type<value_type>, o._value) :
(o._status.have_error() ? value_storage_trivial(in_place_type<error_type>) : value_storage_trivial())) // NOLINT
{
_status = o._status;
}
OUTCOME_TEMPLATE(class U)
OUTCOME_TREQUIRES(OUTCOME_TPRED(enable_void_error_converting_constructor<U>))
constexpr explicit value_storage_trivial(value_storage_trivial<U, void> &&o, void_error_converting_constructor_tag /*unused*/ = {}) noexcept(
detail::is_nothrow_constructible<_value_type_, U> && std::is_nothrow_default_constructible<_error_type_>::value)
: value_storage_trivial(o._status.have_value() ?
value_storage_trivial(in_place_type<value_type>, static_cast<U &&>(o._value)) :
(o._status.have_error() ? value_storage_trivial(in_place_type<error_type>) : value_storage_trivial())) // NOLINT
{
_status = o._status;
}
constexpr void swap(value_storage_trivial &o) noexcept
{
// storage is trivial, so just use assignment
auto temp = static_cast<value_storage_trivial &&>(*this);
*this = static_cast<value_storage_trivial &&>(o);
o = static_cast<value_storage_trivial &&>(temp);
}
};
/* Used if T or E is non-trivial. The additional constexpr is injected in C++ 20 to enable Outcome to
work in constexpr evaluation contexts in C++ 20 where non-trivial constexpr destructors are now allowed.
*/
template <class T, class E> struct value_storage_nontrivial
{
using value_type = T;
using error_type = E;
struct disable_in_place_value_type
{
};
struct disable_in_place_error_type
{
};
using _value_type = std::conditional_t<std::is_same<value_type, error_type>::value, disable_in_place_value_type, value_type>;
using _error_type = std::conditional_t<std::is_same<value_type, error_type>::value, disable_in_place_error_type, error_type>;
using _value_type_ = devoid<value_type>;
using _error_type_ = devoid<error_type>;
union
{
empty_type _empty1;
_value_type_ _value;
};
status_bitfield_type _status;
union
{
empty_type _empty2;
_error_type_ _error;
};
#if __cplusplus >= 202000L || _HAS_CXX20
constexpr
#endif
value_storage_nontrivial() noexcept
: _empty1{}
, _empty2{}
{
}
value_storage_nontrivial &operator=(const value_storage_nontrivial &) = default; // if reaches here, copy assignment is trivial
value_storage_nontrivial &operator=(value_storage_nontrivial &&) = default; // NOLINT if reaches here, move assignment is trivial
#if __cplusplus >= 202000L || _HAS_CXX20
constexpr
#endif
value_storage_nontrivial(value_storage_nontrivial &&o) noexcept(std::is_nothrow_move_constructible<_value_type_>::value &&
std::is_nothrow_move_constructible<_error_type_>::value) // NOLINT
{
if(o._status.have_value())
{
new(OUTCOME_ADDRESS_OF(_value)) _value_type_(static_cast<_value_type_ &&>(o._value)); // NOLINT
}
else if(o._status.have_error())
{
new(OUTCOME_ADDRESS_OF(_error)) _error_type_(static_cast<_error_type_ &&>(o._error)); // NOLINT
}
_status = o._status;
o._status.set_have_moved_from(true);
}
#if __cplusplus >= 202000L || _HAS_CXX20
constexpr
#endif
value_storage_nontrivial(const value_storage_nontrivial &o) noexcept(std::is_nothrow_copy_constructible<_value_type_>::value &&
std::is_nothrow_copy_constructible<_error_type_>::value)
{
if(o._status.have_value())
{
new(OUTCOME_ADDRESS_OF(_value)) _value_type_(o._value); // NOLINT
}
else if(o._status.have_error())
{
new(OUTCOME_ADDRESS_OF(_error)) _error_type_(o._error); // NOLINT
}
_status = o._status;
}
#if __cplusplus >= 202000L || _HAS_CXX20
constexpr
#endif
explicit value_storage_nontrivial(status_bitfield_type status)
: _empty1()
, _status(status)
, _empty2()
{
}
template <class... Args>
constexpr explicit value_storage_nontrivial(in_place_type_t<_value_type> /*unused*/,
Args &&...args) noexcept(detail::is_nothrow_constructible<_value_type_, Args...>)
: _value(static_cast<Args &&>(args)...) // NOLINT
, _status(status::have_value)
{
}
template <class U, class... Args>
constexpr value_storage_nontrivial(in_place_type_t<_value_type> /*unused*/, std::initializer_list<U> il,
Args &&...args) noexcept(detail::is_nothrow_constructible<_value_type_, std::initializer_list<U>, Args...>)
: _value(il, static_cast<Args &&>(args)...)
, _status(status::have_value)
{
}
template <class... Args>
constexpr explicit value_storage_nontrivial(in_place_type_t<_error_type> /*unused*/,
Args &&...args) noexcept(detail::is_nothrow_constructible<_error_type_, Args...>)
: _status(status::have_error)
, _error(static_cast<Args &&>(args)...) // NOLINT
{
_set_error_is_errno(*this);
}
template <class U, class... Args>
constexpr value_storage_nontrivial(in_place_type_t<_error_type> /*unused*/, std::initializer_list<U> il,
Args &&...args) noexcept(detail::is_nothrow_constructible<_error_type_, std::initializer_list<U>, Args...>)
: _status(status::have_error)
, _error(il, static_cast<Args &&>(args)...)
{
_set_error_is_errno(*this);
}
struct nonvoid_converting_constructor_tag
{
};
template <class U, class V>
static constexpr bool enable_nonvoid_converting_constructor =
!(std::is_same<std::decay_t<U>, value_type>::value && std::is_same<std::decay_t<V>, error_type>::value) //
&& detail::is_constructible<value_type, U> && detail::is_constructible<error_type, V>;
OUTCOME_TEMPLATE(class U, class V)
OUTCOME_TREQUIRES(OUTCOME_TPRED(enable_nonvoid_converting_constructor<U, V>))
constexpr explicit value_storage_nontrivial(const value_storage_trivial<U, V> &o, nonvoid_converting_constructor_tag /*unused*/ = {}) noexcept(
detail::is_nothrow_constructible<_value_type_, U> && detail::is_nothrow_constructible<_error_type_, V>)
: value_storage_nontrivial(o._status.have_value() ?
value_storage_nontrivial(in_place_type<value_type>, o._value) :
(o._status.have_error() ? value_storage_nontrivial(in_place_type<error_type>, o._error) : value_storage_nontrivial()))
{
_status = o._status;
}
OUTCOME_TEMPLATE(class U, class V)
OUTCOME_TREQUIRES(OUTCOME_TPRED(enable_nonvoid_converting_constructor<U, V>))
constexpr explicit value_storage_nontrivial(value_storage_trivial<U, V> &&o, nonvoid_converting_constructor_tag /*unused*/ = {}) noexcept(
detail::is_nothrow_constructible<_value_type_, U> && detail::is_nothrow_constructible<_error_type_, V>)
: value_storage_nontrivial(
o._status.have_value() ?
value_storage_nontrivial(in_place_type<value_type>, static_cast<U &&>(o._value)) :
(o._status.have_error() ? value_storage_nontrivial(in_place_type<error_type>, static_cast<V &&>(o._error)) : value_storage_nontrivial()))
{
_status = o._status;
}
OUTCOME_TEMPLATE(class U, class V)
OUTCOME_TREQUIRES(OUTCOME_TPRED(enable_nonvoid_converting_constructor<U, V>))
constexpr explicit value_storage_nontrivial(const value_storage_nontrivial<U, V> &o, nonvoid_converting_constructor_tag /*unused*/ = {}) noexcept(
detail::is_nothrow_constructible<_value_type_, U> && detail::is_nothrow_constructible<_error_type_, V>)
: value_storage_nontrivial(o._status.have_value() ?
value_storage_nontrivial(in_place_type<value_type>, o._value) :
(o._status.have_error() ? value_storage_nontrivial(in_place_type<error_type>, o._error) : value_storage_nontrivial()))
{
_status = o._status;
}
OUTCOME_TEMPLATE(class U, class V)
OUTCOME_TREQUIRES(OUTCOME_TPRED(enable_nonvoid_converting_constructor<U, V>))
constexpr explicit value_storage_nontrivial(value_storage_nontrivial<U, V> &&o, nonvoid_converting_constructor_tag /*unused*/ = {}) noexcept(
detail::is_nothrow_constructible<_value_type_, U> && detail::is_nothrow_constructible<_error_type_, V>)
: value_storage_nontrivial(
o._status.have_value() ?
value_storage_nontrivial(in_place_type<value_type>, static_cast<U &&>(o._value)) :
(o._status.have_error() ? value_storage_nontrivial(in_place_type<error_type>, static_cast<V &&>(o._error)) : value_storage_nontrivial()))
{
_status = o._status;
}
struct void_value_converting_constructor_tag
{
};
template <class V>
static constexpr bool enable_void_value_converting_constructor =
std::is_default_constructible<value_type>::value && detail::is_constructible<error_type, V>;
OUTCOME_TEMPLATE(class V)
OUTCOME_TREQUIRES(OUTCOME_TPRED(enable_void_value_converting_constructor<V>))
constexpr explicit value_storage_nontrivial(const value_storage_trivial<void, V> &o, void_value_converting_constructor_tag /*unused*/ = {}) noexcept(
std::is_nothrow_default_constructible<_value_type_>::value && detail::is_nothrow_constructible<_error_type_, V>)
{
if(o._status.have_value())
{
new(OUTCOME_ADDRESS_OF(_value)) _value_type_(); // NOLINT
}
else if(o._status.have_error())
{
new(OUTCOME_ADDRESS_OF(_error)) _error_type_(o._error); // NOLINT
}
_status = o._status;
}
OUTCOME_TEMPLATE(class V)
OUTCOME_TREQUIRES(OUTCOME_TPRED(enable_void_value_converting_constructor<V>))
constexpr explicit value_storage_nontrivial(value_storage_trivial<void, V> &&o, void_value_converting_constructor_tag /*unused*/ = {}) noexcept(
std::is_nothrow_default_constructible<_value_type_>::value && detail::is_nothrow_constructible<_error_type_, V>)
{
if(o._status.have_value())
{
new(OUTCOME_ADDRESS_OF(_value)) _value_type_(); // NOLINT
}
else if(o._status.have_error())
{
new(OUTCOME_ADDRESS_OF(_error)) _error_type_(static_cast<_error_type_ &&>(o._error)); // NOLINT
}
_status = o._status;
o._status.set_have_moved_from(true);
}
struct void_error_converting_constructor_tag
{
};
template <class U>
static constexpr bool enable_void_error_converting_constructor =
std::is_default_constructible<error_type>::value && detail::is_constructible<value_type, U>;
OUTCOME_TEMPLATE(class U)
OUTCOME_TREQUIRES(OUTCOME_TPRED(enable_void_error_converting_constructor<U>))
constexpr explicit value_storage_nontrivial(const value_storage_trivial<U, void> &o, void_error_converting_constructor_tag /*unused*/ = {}) noexcept(
detail::is_nothrow_constructible<_value_type_, U> && std::is_nothrow_default_constructible<_error_type_>::value)
{
if(o._status.have_value())
{
new(OUTCOME_ADDRESS_OF(_value)) _value_type_(o._value); // NOLINT
}
else if(o._status.have_error())
{
new(OUTCOME_ADDRESS_OF(_error)) _error_type_(); // NOLINT
}
_status = o._status;
}
OUTCOME_TEMPLATE(class U)
OUTCOME_TREQUIRES(OUTCOME_TPRED(enable_void_error_converting_constructor<U>))
constexpr explicit value_storage_nontrivial(value_storage_trivial<U, void> &&o, void_error_converting_constructor_tag /*unused*/ = {}) noexcept(
detail::is_nothrow_constructible<_value_type_, U> && std::is_nothrow_default_constructible<_error_type_>::value)
{
if(o._status.have_value())
{
new(OUTCOME_ADDRESS_OF(_value)) _value_type_(static_cast<_value_type_ &&>(o._value)); // NOLINT
}
else if(o._status.have_error())
{
new(OUTCOME_ADDRESS_OF(_error)) _error_type_(); // NOLINT
}
_status = o._status;
o._status.set_have_moved_from(true);
}
#if __cplusplus >= 202000L || _HAS_CXX20
constexpr
#endif
~value_storage_nontrivial() noexcept(std::is_nothrow_destructible<_value_type_>::value && std::is_nothrow_destructible<_error_type_>::value)
{
if(this->_status.have_value())
{
if(!trait::is_move_bitcopying<value_type>::value || !this->_status.have_moved_from())
{
this->_value.~_value_type_(); // NOLINT
}
this->_status.set_have_value(false);
}
else if(this->_status.have_error())
{
if(!trait::is_move_bitcopying<error_type>::value || !this->_status.have_moved_from())
{
this->_error.~_error_type_(); // NOLINT
}
this->_status.set_have_error(false);
}
}
#if __cplusplus >= 202000L || _HAS_CXX20
constexpr
#endif
void
swap(value_storage_nontrivial &o) noexcept(detail::is_nothrow_swappable<_value_type_>::value && detail::is_nothrow_swappable<_error_type_>::value)
{
using std::swap;
// empty/empty
if(!_status.have_value() && !o._status.have_value() && !_status.have_error() && !o._status.have_error())
{
swap(_status, o._status);
return;
}
// value/value
if(_status.have_value() && o._status.have_value())
{
struct some_type
{
status_bitfield_type &a, &b;
bool all_good{false};
~some_type()
{
if(!this->all_good)
{
// We lost one of the values
this->a.set_have_lost_consistency(true);
this->b.set_have_lost_consistency(true);
}
}
} some_type_value{_status, o._status};
strong_swap(some_type_value.all_good, _value, o._value);
swap(_status, o._status);
return;
}
// error/error
if(_status.have_error() && o._status.have_error())
{
struct some_type
{
status_bitfield_type &a, &b;
bool all_good{false};
~some_type()
{
if(!this->all_good)
{
// We lost one of the values
this->a.set_have_lost_consistency(true);
this->b.set_have_lost_consistency(true);
}
}
} some_type_value{_status, o._status};
strong_swap(some_type_value.all_good, _error, o._error);
swap(_status, o._status);
return;
}
// Could be value/empty, error/empty, etc
if(_status.have_value() && !o._status.have_error())
{
// Move construct me into other
new(OUTCOME_ADDRESS_OF(o._value)) _value_type_(static_cast<_value_type_ &&>(_value)); // NOLINT
if(!trait::is_move_bitcopying<value_type>::value)
{
this->_value.~value_type(); // NOLINT
}
swap(_status, o._status);
return;
}
if(o._status.have_value() && !_status.have_error())
{
// Move construct other into me
new(OUTCOME_ADDRESS_OF(_value)) _value_type_(static_cast<_value_type_ &&>(o._value)); // NOLINT
if(!trait::is_move_bitcopying<value_type>::value)
{
o._value.~value_type(); // NOLINT
}
swap(_status, o._status);
return;
}
if(_status.have_error() && !o._status.have_value())
{
// Move construct me into other
new(OUTCOME_ADDRESS_OF(o._error)) _error_type_(static_cast<_error_type_ &&>(_error)); // NOLINT
if(!trait::is_move_bitcopying<error_type>::value)
{
this->_error.~error_type(); // NOLINT
}
swap(_status, o._status);
return;
}
if(o._status.have_error() && !_status.have_value())
{
// Move construct other into me
new(OUTCOME_ADDRESS_OF(_error)) _error_type_(static_cast<_error_type_ &&>(o._error)); // NOLINT
if(!trait::is_move_bitcopying<error_type>::value)
{
o._error.~error_type(); // NOLINT
}
swap(_status, o._status);
return;
}
// It can now only be value/error, or error/value
struct some_type
{
status_bitfield_type &a, &b;
_value_type_ *value, *o_value;
_error_type_ *error, *o_error;
bool all_good{true};
~some_type()
{
if(!this->all_good)
{
// We lost one of the values
this->a.set_have_lost_consistency(true);
this->b.set_have_lost_consistency(true);
}
}
} some_type_value{_status, o._status, OUTCOME_ADDRESS_OF(_value), OUTCOME_ADDRESS_OF(o._value), OUTCOME_ADDRESS_OF(_error), OUTCOME_ADDRESS_OF(o._error)};
if(_status.have_value() && o._status.have_error())
{
strong_placement(some_type_value.all_good, some_type_value.o_value, some_type_value.value, [&some_type_value] { //
strong_placement(some_type_value.all_good, some_type_value.error, some_type_value.o_error, [&some_type_value] { //
swap(some_type_value.a, some_type_value.b); //
});
});
return;
}
if(_status.have_error() && o._status.have_value())
{
strong_placement(some_type_value.all_good, some_type_value.o_error, some_type_value.error, [&some_type_value] { //
strong_placement(some_type_value.all_good, some_type_value.value, some_type_value.o_value, [&some_type_value] { //
swap(some_type_value.a, some_type_value.b); //
});
});
return;
}
// Should never reach here
make_ub(_value);
}
};
template <class Base> struct value_storage_delete_copy_constructor : Base // NOLINT
{
using Base::Base;
using value_type = typename Base::value_type;
using error_type = typename Base::error_type;
value_storage_delete_copy_constructor() = default;
value_storage_delete_copy_constructor(const value_storage_delete_copy_constructor &) = delete;
value_storage_delete_copy_constructor(value_storage_delete_copy_constructor &&) = default; // NOLINT
value_storage_delete_copy_constructor &operator=(const value_storage_delete_copy_constructor &o) = default;
value_storage_delete_copy_constructor &operator=(value_storage_delete_copy_constructor &&o) = default; // NOLINT
~value_storage_delete_copy_constructor() = default;
};
template <class Base> struct value_storage_delete_copy_assignment : Base // NOLINT
{
using Base::Base;
using value_type = typename Base::value_type;
using error_type = typename Base::error_type;
value_storage_delete_copy_assignment() = default;
value_storage_delete_copy_assignment(const value_storage_delete_copy_assignment &) = default;
value_storage_delete_copy_assignment(value_storage_delete_copy_assignment &&) = default; // NOLINT
value_storage_delete_copy_assignment &operator=(const value_storage_delete_copy_assignment &o) = delete;
value_storage_delete_copy_assignment &operator=(value_storage_delete_copy_assignment &&o) = default; // NOLINT
~value_storage_delete_copy_assignment() = default;
};
template <class Base> struct value_storage_delete_move_assignment : Base // NOLINT
{
using Base::Base;
using value_type = typename Base::value_type;
using error_type = typename Base::error_type;
value_storage_delete_move_assignment() = default;
value_storage_delete_move_assignment(const value_storage_delete_move_assignment &) = default;
value_storage_delete_move_assignment(value_storage_delete_move_assignment &&) = default; // NOLINT
value_storage_delete_move_assignment &operator=(const value_storage_delete_move_assignment &o) = default;
value_storage_delete_move_assignment &operator=(value_storage_delete_move_assignment &&o) = delete;
~value_storage_delete_move_assignment() = default;
};
template <class Base> struct value_storage_delete_move_constructor : Base // NOLINT
{
using Base::Base;
using value_type = typename Base::value_type;
using error_type = typename Base::error_type;
value_storage_delete_move_constructor() = default;
value_storage_delete_move_constructor(const value_storage_delete_move_constructor &) = default;
value_storage_delete_move_constructor(value_storage_delete_move_constructor &&) = delete;
value_storage_delete_move_constructor &operator=(const value_storage_delete_move_constructor &o) = default;
value_storage_delete_move_constructor &operator=(value_storage_delete_move_constructor &&o) = default;
~value_storage_delete_move_constructor() = default;
};
template <class Base> struct value_storage_nontrivial_move_assignment : Base // NOLINT
{
using Base::Base;
using value_type = typename Base::value_type;
using error_type = typename Base::error_type;
value_storage_nontrivial_move_assignment() = default;
value_storage_nontrivial_move_assignment(const value_storage_nontrivial_move_assignment &) = default;
value_storage_nontrivial_move_assignment(value_storage_nontrivial_move_assignment &&) = default; // NOLINT
value_storage_nontrivial_move_assignment &operator=(const value_storage_nontrivial_move_assignment &o) = default;
~value_storage_nontrivial_move_assignment() = default;
#if __cplusplus >= 202000L || _HAS_CXX20
constexpr
#endif
value_storage_nontrivial_move_assignment &
operator=(value_storage_nontrivial_move_assignment &&o) noexcept(std::is_nothrow_move_assignable<value_type>::value &&
std::is_nothrow_move_assignable<error_type>::value &&
noexcept(move_assign_to_empty<value_type>(static_cast<value_type *>(nullptr),
static_cast<value_type *>(nullptr))) &&
noexcept(move_assign_to_empty<error_type>(static_cast<error_type *>(nullptr),
static_cast<error_type *>(nullptr)))) // NOLINT
{
using _value_type_ = typename Base::_value_type_;
using _error_type_ = typename Base::_error_type_;
if(!this->_status.have_value() && !this->_status.have_error() && !o._status.have_value() && !o._status.have_error())
{
this->_status = o._status;
o._status.set_have_moved_from(true);
return *this;
}
if(this->_status.have_value() && o._status.have_value())
{
this->_value = static_cast<_value_type_ &&>(o._value); // NOLINT
this->_status = o._status;
o._status.set_have_moved_from(true);
return *this;
}
if(this->_status.have_error() && o._status.have_error())
{
this->_error = static_cast<_error_type_ &&>(o._error); // NOLINT
this->_status = o._status;
o._status.set_have_moved_from(true);
return *this;
}
if(this->_status.have_value() && !o._status.have_value() && !o._status.have_error())
{
if(!trait::is_move_bitcopying<value_type>::value || this->_status.have_moved_from())
{
this->_value.~_value_type_(); // NOLINT
}
this->_status = o._status;
o._status.set_have_moved_from(true);
return *this;
}
if(!this->_status.have_value() && !this->_status.have_error() && o._status.have_value())
{
move_assign_to_empty<_value_type_>(OUTCOME_ADDRESS_OF(this->_value), OUTCOME_ADDRESS_OF(o._value));
this->_status = o._status;
o._status.set_have_moved_from(true);
return *this;
}
if(this->_status.have_error() && !o._status.have_value() && !o._status.have_error())
{
if(!trait::is_move_bitcopying<error_type>::value || this->_status.have_moved_from())
{
this->_error.~_error_type_(); // NOLINT
}
this->_status = o._status;
o._status.set_have_moved_from(true);
return *this;
}
if(!this->_status.have_value() && !this->_status.have_error() && o._status.have_error())
{
move_assign_to_empty<_error_type_>(OUTCOME_ADDRESS_OF(this->_error), OUTCOME_ADDRESS_OF(o._error));
this->_status = o._status;
o._status.set_have_moved_from(true);
return *this;
}
if(this->_status.have_value() && o._status.have_error())
{
if(!trait::is_move_bitcopying<value_type>::value || this->_status.have_moved_from())
{
this->_value.~_value_type_(); // NOLINT
}
move_assign_to_empty<_error_type_>(OUTCOME_ADDRESS_OF(this->_error), OUTCOME_ADDRESS_OF(o._error));
this->_status = o._status;
o._status.set_have_moved_from(true);
return *this;
}
if(this->_status.have_error() && o._status.have_value())
{
if(!trait::is_move_bitcopying<error_type>::value || this->_status.have_moved_from())
{
this->_error.~_error_type_(); // NOLINT
}
move_assign_to_empty<_value_type_>(OUTCOME_ADDRESS_OF(this->_value), OUTCOME_ADDRESS_OF(o._value));
this->_status = o._status;
o._status.set_have_moved_from(true);
return *this;
}
// Should never reach here
make_ub(this->_value);
}
};
template <class Base> struct value_storage_nontrivial_copy_assignment : Base // NOLINT
{
using Base::Base;
using value_type = typename Base::value_type;
using error_type = typename Base::error_type;
value_storage_nontrivial_copy_assignment() = default;
value_storage_nontrivial_copy_assignment(const value_storage_nontrivial_copy_assignment &) = default;
value_storage_nontrivial_copy_assignment(value_storage_nontrivial_copy_assignment &&) = default; // NOLINT
value_storage_nontrivial_copy_assignment &operator=(value_storage_nontrivial_copy_assignment &&o) = default; // NOLINT
~value_storage_nontrivial_copy_assignment() = default;
#if __cplusplus >= 202000L || _HAS_CXX20
constexpr
#endif
value_storage_nontrivial_copy_assignment &
operator=(const value_storage_nontrivial_copy_assignment &o) noexcept(
std::is_nothrow_copy_assignable<value_type>::value && std::is_nothrow_copy_assignable<error_type>::value &&
noexcept(copy_assign_to_empty<value_type>(static_cast<value_type *>(nullptr), static_cast<value_type *>(nullptr))) &&
noexcept(copy_assign_to_empty<error_type>(static_cast<error_type *>(nullptr), static_cast<error_type *>(nullptr))))
{
using _value_type_ = typename Base::_value_type_;
using _error_type_ = typename Base::_error_type_;
if(!this->_status.have_value() && !this->_status.have_error() && !o._status.have_value() && !o._status.have_error())
{
this->_status = o._status;
return *this;
}
if(this->_status.have_value() && o._status.have_value())
{
this->_value = o._value; // NOLINT
this->_status = o._status;
return *this;
}
if(this->_status.have_error() && o._status.have_error())
{
this->_error = o._error; // NOLINT
this->_status = o._status;
return *this;
}
if(this->_status.have_value() && !o._status.have_value() && !o._status.have_error())
{
if(!trait::is_move_bitcopying<value_type>::value || this->_status.have_moved_from())
{
this->_value.~_value_type_(); // NOLINT
}
this->_status = o._status;
return *this;
}
if(!this->_status.have_value() && !this->_status.have_error() && o._status.have_value())
{
copy_assign_to_empty<_value_type_>(OUTCOME_ADDRESS_OF(this->_value), OUTCOME_ADDRESS_OF(o._value));
this->_status = o._status;
return *this;
}
if(this->_status.have_error() && !o._status.have_value() && !o._status.have_error())
{
if(!trait::is_move_bitcopying<error_type>::value || this->_status.have_moved_from())
{
this->_error.~_error_type_(); // NOLINT
}
this->_status = o._status;
return *this;
}
if(!this->_status.have_value() && !this->_status.have_error() && o._status.have_error())
{
copy_assign_to_empty<_error_type_>(OUTCOME_ADDRESS_OF(this->_error), OUTCOME_ADDRESS_OF(o._error));
this->_status = o._status;
return *this;
}
if(this->_status.have_value() && o._status.have_error())
{
if(!trait::is_move_bitcopying<value_type>::value || this->_status.have_moved_from())
{
this->_value.~_value_type_(); // NOLINT
}
copy_assign_to_empty<_error_type_>(OUTCOME_ADDRESS_OF(this->_error), OUTCOME_ADDRESS_OF(o._error));
this->_status = o._status;
return *this;
}
if(this->_status.have_error() && o._status.have_value())
{
if(!trait::is_move_bitcopying<error_type>::value || this->_status.have_moved_from())
{
this->_error.~_error_type_(); // NOLINT
}
copy_assign_to_empty<_value_type_>(OUTCOME_ADDRESS_OF(this->_value), OUTCOME_ADDRESS_OF(o._value));
this->_status = o._status;
return *this;
}
// Should never reach here
make_ub(this->_value);
}
};
#ifdef _MSC_VER
#pragma warning(pop)
#endif
// is_trivially_copyable is true even if type is not copyable, so handle that here
template <class T> struct is_storage_trivial
{
static constexpr bool value = std::is_void<T>::value || (std::is_trivially_copy_constructible<T>::value && std::is_trivially_copyable<T>::value);
};
// work around libstdc++ 7 bug
template <> struct is_storage_trivial<void>
{
static constexpr bool value = true;
};
template <> struct is_storage_trivial<const void>
{
static constexpr bool value = true;
};
// Ability to do copy assigns needs more than just copy assignment
template <class T> struct is_copy_assignable
{
static constexpr bool value = std::is_copy_assignable<T>::value && (std::is_copy_constructible<T>::value || std::is_default_constructible<T>::value);
};
// Ability to do move assigns needs more than just move assignment
template <class T> struct is_move_assignable
{
static constexpr bool value = std::is_move_assignable<T>::value && (std::is_move_constructible<T>::value || std::is_default_constructible<T>::value);
};
template <class T, class E>
using value_storage_select_trivality =
std::conditional_t<is_storage_trivial<T>::value && is_storage_trivial<E>::value, value_storage_trivial<T, E>, value_storage_nontrivial<T, E>>;
template <class T, class E>
using value_storage_select_move_constructor =
std::conditional_t<std::is_move_constructible<devoid<T>>::value && std::is_move_constructible<devoid<E>>::value, value_storage_select_trivality<T, E>,
value_storage_delete_move_constructor<value_storage_select_trivality<T, E>>>;
template <class T, class E>
using value_storage_select_copy_constructor =
std::conditional_t<std::is_copy_constructible<devoid<T>>::value && std::is_copy_constructible<devoid<E>>::value, value_storage_select_move_constructor<T, E>,
value_storage_delete_copy_constructor<value_storage_select_move_constructor<T, E>>>;
template <class T, class E>
using value_storage_select_move_assignment =
std::conditional_t<std::is_trivially_move_assignable<devoid<T>>::value && std::is_trivially_move_assignable<devoid<E>>::value,
value_storage_select_copy_constructor<T, E>,
std::conditional_t<is_move_assignable<devoid<T>>::value && is_move_assignable<devoid<E>>::value,
value_storage_nontrivial_move_assignment<value_storage_select_copy_constructor<T, E>>,
value_storage_delete_move_assignment<value_storage_select_copy_constructor<T, E>>>>;
template <class T, class E>
using value_storage_select_copy_assignment =
std::conditional_t<std::is_trivially_copy_assignable<devoid<T>>::value && std::is_trivially_copy_assignable<devoid<E>>::value,
value_storage_select_move_assignment<T, E>,
std::conditional_t<is_copy_assignable<devoid<T>>::value && is_copy_assignable<devoid<E>>::value,
value_storage_nontrivial_copy_assignment<value_storage_select_move_assignment<T, E>>,
value_storage_delete_copy_assignment<value_storage_select_move_assignment<T, E>>>>;
template <class T, class E> using value_storage_select_impl = value_storage_select_copy_assignment<T, E>;
#ifndef NDEBUG
// Check is trivial in all ways except default constructibility
// static_assert(std::is_trivial<value_storage_select_impl<int, long>>::value, "value_storage_select_impl<int, long> is not trivial!");
// static_assert(std::is_trivially_default_constructible<value_storage_select_impl<int, long>>::value, "value_storage_select_impl<int, long> is not
// trivially default constructible!");
static_assert(std::is_trivially_copyable<value_storage_select_impl<int, long>>::value, "value_storage_select_impl<int, long> is not trivially copyable!");
static_assert(std::is_trivially_assignable<value_storage_select_impl<int, long>, value_storage_select_impl<int, long>>::value,
"value_storage_select_impl<int, long> is not trivially assignable!");
static_assert(std::is_trivially_destructible<value_storage_select_impl<int, long>>::value,
"value_storage_select_impl<int, long> is not trivially destructible!");
static_assert(std::is_trivially_copy_constructible<value_storage_select_impl<int, long>>::value,
"value_storage_select_impl<int, long> is not trivially copy constructible!");
static_assert(std::is_trivially_move_constructible<value_storage_select_impl<int, long>>::value,
"value_storage_select_impl<int, long> is not trivially move constructible!");
static_assert(std::is_trivially_copy_assignable<value_storage_select_impl<int, long>>::value,
"value_storage_select_impl<int, long> is not trivially copy assignable!");
static_assert(std::is_trivially_move_assignable<value_storage_select_impl<int, long>>::value,
"value_storage_select_impl<int, long> is not trivially move assignable!");
// Also check is standard layout
static_assert(std::is_standard_layout<value_storage_select_impl<int, long>>::value, "value_storage_select_impl<int, long> is not a standard layout type!");
#endif
} // namespace detail
OUTCOME_V2_NAMESPACE_END
#endif
OUTCOME_V2_NAMESPACE_EXPORT_BEGIN
namespace detail
{
template <class R, class EC, class NoValuePolicy> class basic_result_storage;
} // namespace detail
namespace hooks
{
template <class R, class S, class NoValuePolicy> constexpr inline uint16_t spare_storage(const detail::basic_result_storage<R, S, NoValuePolicy> *r) noexcept;
template <class R, class S, class NoValuePolicy>
constexpr inline void set_spare_storage(detail::basic_result_storage<R, S, NoValuePolicy> *r, uint16_t v) noexcept;
} // namespace hooks
namespace policy
{
struct base;
} // namespace policy
namespace detail
{
template <class R, class EC, class NoValuePolicy> //
class basic_result_storage
{
static_assert(trait::type_can_be_used_in_basic_result<R>, "The type R cannot be used in a basic_result");
static_assert(trait::type_can_be_used_in_basic_result<EC>, "The type S cannot be used in a basic_result");
friend struct policy::base;
template <class T, class U, class V> //
friend class basic_result_storage;
template <class T, class U, class V> friend class basic_result_final;
template <class T, class U, class V>
friend constexpr inline uint16_t hooks::spare_storage(const detail::basic_result_storage<T, U, V> *r) noexcept; // NOLINT
template <class T, class U, class V>
friend constexpr inline void hooks::set_spare_storage(detail::basic_result_storage<T, U, V> *r, uint16_t v) noexcept; // NOLINT
struct disable_in_place_value_type
{
};
struct disable_in_place_error_type
{
};
protected:
using _value_type = std::conditional_t<std::is_same<R, EC>::value, disable_in_place_value_type, R>;
using _error_type = std::conditional_t<std::is_same<R, EC>::value, disable_in_place_error_type, EC>;
using _state_type = value_storage_select_impl<_value_type, _error_type>;
_state_type _state;
public:
// Used by iostream support to access state
_state_type &_iostreams_state() { return _state; }
const _state_type &_iostreams_state() const { return _state; }
protected:
basic_result_storage() = default;
basic_result_storage(const basic_result_storage &) = default; // NOLINT
basic_result_storage(basic_result_storage &&) = default; // NOLINT
basic_result_storage &operator=(const basic_result_storage &) = default; // NOLINT
basic_result_storage &operator=(basic_result_storage &&) = default; // NOLINT
~basic_result_storage() = default;
template <class... Args>
constexpr explicit basic_result_storage(in_place_type_t<_value_type> _,
Args &&... args) noexcept(detail::is_nothrow_constructible<_value_type, Args...>)
: _state{_, static_cast<Args &&>(args)...}
{
}
template <class U, class... Args>
constexpr basic_result_storage(in_place_type_t<_value_type> _, std::initializer_list<U> il,
Args &&... args) noexcept(detail::is_nothrow_constructible<_value_type, std::initializer_list<U>, Args...>)
: _state{_, il, static_cast<Args &&>(args)...}
{
}
template <class... Args>
constexpr explicit basic_result_storage(in_place_type_t<_error_type> _,
Args &&... args) noexcept(detail::is_nothrow_constructible<_error_type, Args...>)
: _state{_, static_cast<Args &&>(args)...}
{
}
template <class U, class... Args>
constexpr basic_result_storage(in_place_type_t<_error_type> _, std::initializer_list<U> il,
Args &&... args) noexcept(detail::is_nothrow_constructible<_error_type, std::initializer_list<U>, Args...>)
: _state{_, il, static_cast<Args &&>(args)...}
{
}
struct compatible_conversion_tag
{
};
template <class T, class U, class V>
constexpr basic_result_storage(compatible_conversion_tag /*unused*/, const basic_result_storage<T, U, V> &o) noexcept(
detail::is_nothrow_constructible<_value_type, T> &&detail::is_nothrow_constructible<_error_type, U>)
: _state(o._state)
{
}
template <class T, class U, class V>
constexpr basic_result_storage(compatible_conversion_tag /*unused*/, basic_result_storage<T, U, V> &&o) noexcept(
detail::is_nothrow_constructible<_value_type, T> &&detail::is_nothrow_constructible<_error_type, U>)
: _state(static_cast<decltype(o._state) &&>(o._state))
{
}
struct make_error_code_compatible_conversion_tag
{
};
template <class T, class U, class V>
constexpr basic_result_storage(make_error_code_compatible_conversion_tag /*unused*/, const basic_result_storage<T, U, V> &o) noexcept(
detail::is_nothrow_constructible<_value_type, T> &&noexcept(make_error_code(std::declval<U>())))
: _state(o._state._status.have_value() ? _state_type(in_place_type<_value_type>, o._state._value) :
_state_type(in_place_type<_error_type>, make_error_code(o._state._error)))
{
}
template <class T, class U, class V>
constexpr basic_result_storage(make_error_code_compatible_conversion_tag /*unused*/, basic_result_storage<T, U, V> &&o) noexcept(
detail::is_nothrow_constructible<_value_type, T> &&noexcept(make_error_code(std::declval<U>())))
: _state(o._state._status.have_value() ? _state_type(in_place_type<_value_type>, static_cast<T &&>(o._state._value)) :
_state_type(in_place_type<_error_type>, make_error_code(static_cast<U &&>(o._state._error))))
{
}
struct make_exception_ptr_compatible_conversion_tag
{
};
template <class T, class U, class V>
constexpr basic_result_storage(make_exception_ptr_compatible_conversion_tag /*unused*/, const basic_result_storage<T, U, V> &o) noexcept(
detail::is_nothrow_constructible<_value_type, T> &&noexcept(make_exception_ptr(std::declval<U>())))
: _state(o._state._status.have_value() ? _state_type(in_place_type<_value_type>, o._state._value) :
_state_type(in_place_type<_error_type>, make_exception_ptr(o._state._error)))
{
}
template <class T, class U, class V>
constexpr basic_result_storage(make_exception_ptr_compatible_conversion_tag /*unused*/, basic_result_storage<T, U, V> &&o) noexcept(
detail::is_nothrow_constructible<_value_type, T> &&noexcept(make_exception_ptr(std::declval<U>())))
: _state(o._state._status.have_value() ? _state_type(in_place_type<_value_type>, static_cast<T &&>(o._state._value)) :
_state_type(in_place_type<_error_type>, make_exception_ptr(static_cast<U &&>(o._state._error))))
{
}
};
} // namespace detail
OUTCOME_V2_NAMESPACE_END
#endif
OUTCOME_V2_NAMESPACE_EXPORT_BEGIN
namespace concepts
{
#if defined(__cpp_concepts)
#if (defined(_MSC_VER) || defined(__clang__) || (defined(__GNUC__) && __cpp_concepts >= 201707) || OUTCOME_FORCE_STD_CXX_CONCEPTS) && !OUTCOME_FORCE_LEGACY_GCC_CXX_CONCEPTS
#define OUTCOME_GCC6_CONCEPT_BOOL
#else
#ifndef OUTCOME_SUPPRESS_LEGACY_CONCEPTS_WARNING
#warning "WARNING: Legacy GCC concepts are known to fail to compile in a number of important situations!"
#endif
#define OUTCOME_GCC6_CONCEPT_BOOL bool
#endif
namespace detail
{
template <class T, class U>
concept OUTCOME_GCC6_CONCEPT_BOOL SameHelper = std::is_same<T, U>::value;
template <class T, class U>
concept OUTCOME_GCC6_CONCEPT_BOOL same_as = detail::SameHelper<T, U> && detail::SameHelper<U, T>;
template <class T, class U>
concept OUTCOME_GCC6_CONCEPT_BOOL convertible = std::is_convertible<T, U>::value;
template <class T, class U>
concept OUTCOME_GCC6_CONCEPT_BOOL base_of = std::is_base_of<T, U>::value;
} // namespace detail
/* The `value_or_none` concept.
\requires That `U::value_type` exists and that `std::declval<U>().has_value()` returns a `bool` and `std::declval<U>().value()` exists.
*/
template <class U>
concept OUTCOME_GCC6_CONCEPT_BOOL value_or_none = requires(U a) {
{
a.has_value()
} -> detail::same_as<bool>;
{
a.value()
};
};
/* The `value_or_error` concept.
\requires That `U::value_type` and `U::error_type` exist;
that `std::declval<U>().has_value()` returns a `bool`, `std::declval<U>().value()` and `std::declval<U>().error()` exists.
*/
template <class U>
concept OUTCOME_GCC6_CONCEPT_BOOL value_or_error = requires(U a) {
{
a.has_value()
} -> detail::same_as<bool>;
{
a.value()
};
{
a.error()
};
};
#else
namespace detail
{
struct no_match
{
};
inline no_match match_value_or_none(...);
inline no_match match_value_or_error(...);
OUTCOME_TEMPLATE(class U)
OUTCOME_TREQUIRES(OUTCOME_TEXPR(std::declval<U>().has_value()), OUTCOME_TEXPR(std::declval<U>().value()))
inline U match_value_or_none(U &&);
OUTCOME_TEMPLATE(class U)
OUTCOME_TREQUIRES(OUTCOME_TEXPR(std::declval<U>().has_value()), OUTCOME_TEXPR(std::declval<U>().value()), OUTCOME_TEXPR(std::declval<U>().error()))
inline U match_value_or_error(U &&);
template <class U>
static constexpr bool value_or_none =
!std::is_same<no_match, decltype(match_value_or_none(std::declval<OUTCOME_V2_NAMESPACE::detail::devoid<U>>()))>::value;
template <class U>
static constexpr bool value_or_error =
!std::is_same<no_match, decltype(match_value_or_error(std::declval<OUTCOME_V2_NAMESPACE::detail::devoid<U>>()))>::value;
} // namespace detail
/* The `value_or_none` concept.
\requires That `U::value_type` exists and that `std::declval<U>().has_value()` returns a `bool` and `std::declval<U>().value()` exists.
*/
template <class U> static constexpr bool value_or_none = detail::value_or_none<U>;
/* The `value_or_error` concept.
\requires That `U::value_type` and `U::error_type` exist;
that `std::declval<U>().has_value()` returns a `bool`, `std::declval<U>().value()` and `std::declval<U>().error()` exists.
*/
template <class U> static constexpr bool value_or_error = detail::value_or_error<U>;
#endif
} // namespace concepts
namespace convert
{
#if OUTCOME_ENABLE_LEGACY_SUPPORT_FOR < 220
#if defined(__cpp_concepts)
template <class U>
concept OUTCOME_GCC6_CONCEPT_BOOL ValueOrNone = concepts::value_or_none<U>;
template <class U>
concept OUTCOME_GCC6_CONCEPT_BOOL ValueOrError = concepts::value_or_error<U>;
#else
template <class U> static constexpr bool ValueOrNone = concepts::value_or_none<U>;
template <class U> static constexpr bool ValueOrError = concepts::value_or_error<U>;
#endif
#endif
namespace detail
{
template <class T, class X> struct make_type
{
template <class U> static constexpr T value(U &&v) { return T{in_place_type<typename T::value_type>, static_cast<U &&>(v).value()}; }
template <class U> static constexpr T error(U &&v) { return T{in_place_type<typename T::error_type>, static_cast<U &&>(v).error()}; }
static constexpr T error() { return T{in_place_type<typename T::error_type>}; }
};
template <class T> struct make_type<T, void>
{
template <class U> static constexpr T value(U && /*unused*/) { return T{in_place_type<typename T::value_type>}; }
template <class U> static constexpr T error(U && /*unused*/) { return T{in_place_type<typename T::error_type>}; }
static constexpr T error() { return T{in_place_type<typename T::error_type>}; }
};
} // namespace detail
/*! AWAITING HUGO JSON CONVERSION TOOL
type definition value_or_error. Potential doc page: NOT FOUND
*/
template <class T, class U> struct value_or_error
{
static constexpr bool enable_result_inputs = false;
static constexpr bool enable_outcome_inputs = false;
OUTCOME_TEMPLATE(class X)
OUTCOME_TREQUIRES(
OUTCOME_TPRED(std::is_same<U, std::decay_t<X>>::value //
&&concepts::value_or_error<U> //
&& (std::is_void<typename std::decay_t<X>::value_type>::value ||
OUTCOME_V2_NAMESPACE::detail::is_explicitly_constructible<typename T::value_type, typename std::decay_t<X>::value_type>) //
&&(std::is_void<typename std::decay_t<X>::error_type>::value ||
OUTCOME_V2_NAMESPACE::detail::is_explicitly_constructible<typename T::error_type, typename std::decay_t<X>::error_type>) ))
constexpr T operator()(X &&v)
{
return v.has_value() ? detail::make_type<T, typename T::value_type>::value(static_cast<X &&>(v)) :
detail::make_type<T, typename U::error_type>::error(static_cast<X &&>(v));
}
};
} // namespace convert
OUTCOME_V2_NAMESPACE_END
#endif
/* Finaliser for a very simple result type
(C) 2017-2019 Niall Douglas <http://www.nedproductions.biz/> (5 commits)
File Created: Oct 2017
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License in the accompanying file
Licence.txt or at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Distributed under the Boost Software License, Version 1.0.
(See accompanying file Licence.txt or copy at
http://www.boost.org/LICENSE_1_0.txt)
*/
#ifndef OUTCOME_BASIC_RESULT_FINAL_HPP
#define OUTCOME_BASIC_RESULT_FINAL_HPP
/* Error observers for a very simple basic_result type
(C) 2017-2019 Niall Douglas <http://www.nedproductions.biz/> (2 commits)
File Created: Oct 2017
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License in the accompanying file
Licence.txt or at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Distributed under the Boost Software License, Version 1.0.
(See accompanying file Licence.txt or copy at
http://www.boost.org/LICENSE_1_0.txt)
*/
#ifndef OUTCOME_BASIC_RESULT_ERROR_OBSERVERS_HPP
#define OUTCOME_BASIC_RESULT_ERROR_OBSERVERS_HPP
OUTCOME_V2_NAMESPACE_EXPORT_BEGIN
namespace detail
{
template <class Base, class EC, class NoValuePolicy> class basic_result_error_observers : public Base
{
public:
using error_type = EC;
using Base::Base;
constexpr error_type &assume_error() & noexcept
{
NoValuePolicy::narrow_error_check(static_cast<basic_result_error_observers &>(*this));
return this->_state._error;
}
constexpr const error_type &assume_error() const & noexcept
{
NoValuePolicy::narrow_error_check(static_cast<const basic_result_error_observers &>(*this));
return this->_state._error;
}
constexpr error_type &&assume_error() && noexcept
{
NoValuePolicy::narrow_error_check(static_cast<basic_result_error_observers &&>(*this));
return static_cast<error_type &&>(this->_state._error);
}
constexpr const error_type &&assume_error() const && noexcept
{
NoValuePolicy::narrow_error_check(static_cast<const basic_result_error_observers &&>(*this));
return static_cast<const error_type &&>(this->_state._error);
}
constexpr error_type &error() &
{
NoValuePolicy::wide_error_check(static_cast<basic_result_error_observers &>(*this));
return this->_state._error;
}
constexpr const error_type &error() const &
{
NoValuePolicy::wide_error_check(static_cast<const basic_result_error_observers &>(*this));
return this->_state._error;
}
constexpr error_type &&error() &&
{
NoValuePolicy::wide_error_check(static_cast<basic_result_error_observers &&>(*this));
return static_cast<error_type &&>(this->_state._error);
}
constexpr const error_type &&error() const &&
{
NoValuePolicy::wide_error_check(static_cast<const basic_result_error_observers &&>(*this));
return static_cast<const error_type &&>(this->_state._error);
}
};
template <class Base, class NoValuePolicy> class basic_result_error_observers<Base, void, NoValuePolicy> : public Base
{
public:
using Base::Base;
constexpr void assume_error() & noexcept { NoValuePolicy::narrow_error_check(static_cast<basic_result_error_observers &>(*this)); }
constexpr void assume_error() const & noexcept { NoValuePolicy::narrow_error_check(static_cast<const basic_result_error_observers &>(*this)); }
constexpr void assume_error() && noexcept { NoValuePolicy::narrow_error_check(static_cast<basic_result_error_observers &&>(*this)); }
constexpr void assume_error() const && noexcept { NoValuePolicy::narrow_error_check(static_cast<const basic_result_error_observers &&>(*this)); }
constexpr void error() & { NoValuePolicy::wide_error_check(static_cast<basic_result_error_observers &>(*this)); }
constexpr void error() const & { NoValuePolicy::wide_error_check(static_cast<const basic_result_error_observers &>(*this)); }
constexpr void error() && { NoValuePolicy::wide_error_check(static_cast<basic_result_error_observers &&>(*this)); }
constexpr void error() const && { NoValuePolicy::wide_error_check(static_cast<const basic_result_error_observers &&>(*this)); }
};
} // namespace detail
OUTCOME_V2_NAMESPACE_END
#endif
/* Value observers for a very simple basic_result type
(C) 2017-2019 Niall Douglas <http://www.nedproductions.biz/> (2 commits)
File Created: Oct 2017
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License in the accompanying file
Licence.txt or at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Distributed under the Boost Software License, Version 1.0.
(See accompanying file Licence.txt or copy at
http://www.boost.org/LICENSE_1_0.txt)
*/
#ifndef OUTCOME_RESULT_VALUE_OBSERVERS_HPP
#define OUTCOME_RESULT_VALUE_OBSERVERS_HPP
OUTCOME_V2_NAMESPACE_EXPORT_BEGIN
namespace detail
{
template <class Base, class R, class NoValuePolicy> class basic_result_value_observers : public Base
{
public:
using value_type = R;
using Base::Base;
constexpr value_type &assume_value() & noexcept
{
NoValuePolicy::narrow_value_check(static_cast<basic_result_value_observers &>(*this));
return this->_state._value; // NOLINT
}
constexpr const value_type &assume_value() const & noexcept
{
NoValuePolicy::narrow_value_check(static_cast<const basic_result_value_observers &>(*this));
return this->_state._value; // NOLINT
}
constexpr value_type &&assume_value() && noexcept
{
NoValuePolicy::narrow_value_check(static_cast<basic_result_value_observers &&>(*this));
return static_cast<value_type &&>(this->_state._value); // NOLINT
}
constexpr const value_type &&assume_value() const && noexcept
{
NoValuePolicy::narrow_value_check(static_cast<const basic_result_value_observers &&>(*this));
return static_cast<const value_type &&>(this->_state._value); // NOLINT
}
constexpr value_type &value() &
{
NoValuePolicy::wide_value_check(static_cast<basic_result_value_observers &>(*this));
return this->_state._value; // NOLINT
}
constexpr const value_type &value() const &
{
NoValuePolicy::wide_value_check(static_cast<const basic_result_value_observers &>(*this));
return this->_state._value; // NOLINT
}
constexpr value_type &&value() &&
{
NoValuePolicy::wide_value_check(static_cast<basic_result_value_observers &&>(*this));
return static_cast<value_type &&>(this->_state._value); // NOLINT
}
constexpr const value_type &&value() const &&
{
NoValuePolicy::wide_value_check(static_cast<const basic_result_value_observers &&>(*this));
return static_cast<const value_type &&>(this->_state._value); // NOLINT
}
};
template <class Base, class NoValuePolicy> class basic_result_value_observers<Base, void, NoValuePolicy> : public Base
{
public:
using Base::Base;
constexpr void assume_value() & noexcept { NoValuePolicy::narrow_value_check(static_cast<basic_result_value_observers &>(*this)); }
constexpr void assume_value() const & noexcept { NoValuePolicy::narrow_value_check(static_cast<const basic_result_value_observers &>(*this)); }
constexpr void assume_value() && noexcept { NoValuePolicy::narrow_value_check(static_cast<basic_result_value_observers &&>(*this)); }
constexpr void assume_value() const && noexcept { NoValuePolicy::narrow_value_check(static_cast<const basic_result_value_observers &&>(*this)); }
constexpr void value() & { NoValuePolicy::wide_value_check(static_cast<basic_result_value_observers &>(*this)); }
constexpr void value() const & { NoValuePolicy::wide_value_check(static_cast<const basic_result_value_observers &>(*this)); }
constexpr void value() && { NoValuePolicy::wide_value_check(static_cast<basic_result_value_observers &&>(*this)); }
constexpr void value() const && { NoValuePolicy::wide_value_check(static_cast<const basic_result_value_observers &&>(*this)); }
};
} // namespace detail
OUTCOME_V2_NAMESPACE_END
#endif
OUTCOME_V2_NAMESPACE_EXPORT_BEGIN
namespace detail
{
template <class R, class EC, class NoValuePolicy> using select_basic_result_impl = basic_result_error_observers<basic_result_value_observers<basic_result_storage<R, EC, NoValuePolicy>, R, NoValuePolicy>, EC, NoValuePolicy>;
template <class R, class S, class NoValuePolicy>
class basic_result_final
: public select_basic_result_impl<R, S, NoValuePolicy>
{
using base = select_basic_result_impl<R, S, NoValuePolicy>;
public:
using base::base;
constexpr explicit operator bool() const noexcept { return this->_state._status.have_value(); }
constexpr bool has_value() const noexcept { return this->_state._status.have_value(); }
constexpr bool has_error() const noexcept { return this->_state._status.have_error(); }
constexpr bool has_exception() const noexcept { return this->_state._status.have_exception(); }
constexpr bool has_lost_consistency() const noexcept { return this->_state._status.have_lost_consistency(); }
constexpr bool has_failure() const noexcept { return this->_state._status.have_error() || this->_state._status.have_exception(); }
OUTCOME_TEMPLATE(class T, class U, class V)
OUTCOME_TREQUIRES(OUTCOME_TEXPR(std::declval<detail::devoid<R>>() == std::declval<detail::devoid<T>>()), //
OUTCOME_TEXPR(std::declval<detail::devoid<S>>() == std::declval<detail::devoid<U>>()))
constexpr bool operator==(const basic_result_final<T, U, V> &o) const noexcept( //
noexcept(std::declval<detail::devoid<R>>() == std::declval<detail::devoid<T>>()) && noexcept(std::declval<detail::devoid<S>>() == std::declval<detail::devoid<U>>()))
{
if(this->_state._status.have_value() && o._state._status.have_value())
{
return this->_state._value == o._state._value; // NOLINT
}
if(this->_state._status.have_error() && o._state._status.have_error())
{
return this->_state._error == o._state._error;
}
return false;
}
OUTCOME_TEMPLATE(class T)
OUTCOME_TREQUIRES(OUTCOME_TEXPR(std::declval<R>() == std::declval<T>()))
constexpr bool operator==(const success_type<T> &o) const noexcept( //
noexcept(std::declval<R>() == std::declval<T>()))
{
if(this->_state._status.have_value())
{
return this->_state._value == o.value();
}
return false;
}
constexpr bool operator==(const success_type<void> &o) const noexcept
{
(void) o;
return this->_state._status.have_value();
}
OUTCOME_TEMPLATE(class T)
OUTCOME_TREQUIRES(OUTCOME_TEXPR(std::declval<S>() == std::declval<T>()))
constexpr bool operator==(const failure_type<T, void> &o) const noexcept( //
noexcept(std::declval<S>() == std::declval<T>()))
{
if(this->_state._status.have_error())
{
return this->_state._error == o.error();
}
return false;
}
OUTCOME_TEMPLATE(class T, class U, class V)
OUTCOME_TREQUIRES(OUTCOME_TEXPR(std::declval<detail::devoid<R>>() != std::declval<detail::devoid<T>>()), //
OUTCOME_TEXPR(std::declval<detail::devoid<S>>() != std::declval<detail::devoid<U>>()))
constexpr bool operator!=(const basic_result_final<T, U, V> &o) const noexcept( //
noexcept(std::declval<detail::devoid<R>>() != std::declval<detail::devoid<T>>()) && noexcept(std::declval<detail::devoid<S>>() != std::declval<detail::devoid<U>>()))
{
if(this->_state._status.have_value() && o._state._status.have_value())
{
return this->_state._value != o._state._value;
}
if(this->_state._status.have_error() && o._state._status.have_error())
{
return this->_state._error != o._state._error;
}
return true;
}
OUTCOME_TEMPLATE(class T)
OUTCOME_TREQUIRES(OUTCOME_TEXPR(std::declval<R>() != std::declval<T>()))
constexpr bool operator!=(const success_type<T> &o) const noexcept( //
noexcept(std::declval<R>() != std::declval<T>()))
{
if(this->_state._status.have_value())
{
return this->_state._value != o.value();
}
return false;
}
constexpr bool operator!=(const success_type<void> &o) const noexcept
{
(void) o;
return !this->_state._status.have_value();
}
OUTCOME_TEMPLATE(class T)
OUTCOME_TREQUIRES(OUTCOME_TEXPR(std::declval<S>() != std::declval<T>()))
constexpr bool operator!=(const failure_type<T, void> &o) const noexcept( //
noexcept(std::declval<S>() != std::declval<T>()))
{
if(this->_state._status.have_error())
{
return this->_state._error != o.error();
}
return true;
}
};
template <class T, class U, class V, class W> constexpr inline bool operator==(const success_type<W> &a, const basic_result_final<T, U, V> &b) noexcept(noexcept(b == a)) { return b == a; }
template <class T, class U, class V, class W> constexpr inline bool operator==(const failure_type<W, void> &a, const basic_result_final<T, U, V> &b) noexcept(noexcept(b == a)) { return b == a; }
template <class T, class U, class V, class W> constexpr inline bool operator!=(const success_type<W> &a, const basic_result_final<T, U, V> &b) noexcept(noexcept(b == a)) { return b != a; }
template <class T, class U, class V, class W> constexpr inline bool operator!=(const failure_type<W, void> &a, const basic_result_final<T, U, V> &b) noexcept(noexcept(b == a)) { return b != a; }
} // namespace detail
OUTCOME_V2_NAMESPACE_END
#endif
/* Inline GDB pretty printer for result
(C) 2024 Niall Douglas <http://www.nedproductions.biz/> (6 commits)
File Created: Jun 2024
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License in the accompanying file
Licence.txt or at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Distributed under the Boost Software License, Version 1.0.
(See accompanying file Licence.txt or copy at
http://www.boost.org/LICENSE_1_0.txt)
*/
#ifndef OUTCOME_INLINE_GDB_PRETTY_PRINTER_H
#define OUTCOME_INLINE_GDB_PRETTY_PRINTER_H
#ifndef OUTCOME_DISABLE_INLINE_GDB_PRETTY_PRINTERS
#if defined(__ELF__)
#ifdef __clang__
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Woverlength-strings"
#endif
__asm__(".pushsection \".debug_gdb_scripts\", \"MS\",@progbits,1\n"
".byte 4 /* Python Text */\n"
".ascii \"gdb.inlined-script\\n\"\n"
".ascii \"import gdb.printing\\n\"\n"
".ascii \"import os\\n\"\n"
".ascii \"def synthesise_gdb_value_from_string(s):\\n\"\n"
".ascii \" '''For when you want to return a synthetic string from children()'''\\n\"\n"
".ascii \" return gdb.Value(s + '\\0').cast(gdb.lookup_type('char').pointer())\\n\"\n"
".ascii \"class OutcomeBasicOutcomePrinter(object):\\n\"\n"
".ascii \" '''Print an outcome::basic_outcome<T> and outcome::basic_result<T>'''\\n\"\n"
".ascii \" def __init__(self, val):\\n\"\n"
".ascii \" self.val = val\\n\"\n"
".ascii \" def children(self):\\n\"\n"
".ascii \" if self.val['_state']['_status']['status_value'] & 1 == 1:\\n\"\n"
".ascii \" yield ('value', self.val['_state']['_value'])\\n\"\n"
".ascii \" if self.val['_state']['_status']['status_value'] & 2 == 2:\\n\"\n"
".ascii \" yield ('error', self.val['_state']['_error'])\\n\"\n"
".ascii \" if self.val['_state']['_status']['status_value'] & 4 == 4:\\n\"\n"
".ascii \" yield ('exception', self.val['_ptr'])\\n\"\n"
".ascii \" def display_hint(self):\\n\"\n"
".ascii \" return None\\n\"\n"
".ascii \" def to_string(self):\\n\"\n"
".ascii \" if self.val['_state']['_status']['status_value'] & 54 == 54:\\n\"\n"
".ascii \" return 'errored (errno, moved from) + exceptioned'\\n\"\n"
".ascii \" if self.val['_state']['_status']['status_value'] & 50 == 50:\\n\"\n"
".ascii \" return 'errored (errno, moved from)'\\n\"\n"
".ascii \" if self.val['_state']['_status']['status_value'] & 38 == 38:\\n\"\n"
".ascii \" return 'errored + exceptioned (moved from)'\\n\"\n"
".ascii \" if self.val['_state']['_status']['status_value'] & 36 == 36:\\n\"\n"
".ascii \" return 'exceptioned (moved from)'\\n\"\n"
".ascii \" if self.val['_state']['_status']['status_value'] & 35 == 35:\\n\"\n"
".ascii \" return 'errored (moved from)'\\n\"\n"
".ascii \" if self.val['_state']['_status']['status_value'] & 33 == 33:\\n\"\n"
".ascii \" return 'valued (moved from)'\\n\"\n"
".ascii \" if self.val['_state']['_status']['status_value'] & 22 == 22:\\n\"\n"
".ascii \" return 'errored (errno) + exceptioned'\\n\"\n"
".ascii \" if self.val['_state']['_status']['status_value'] & 18 == 18:\\n\"\n"
".ascii \" return 'errored (errno)'\\n\"\n"
".ascii \" if self.val['_state']['_status']['status_value'] & 6 == 6:\\n\"\n"
".ascii \" return 'errored + exceptioned'\\n\"\n"
".ascii \" if self.val['_state']['_status']['status_value'] & 4 == 4:\\n\"\n"
".ascii \" return 'exceptioned'\\n\"\n"
".ascii \" if self.val['_state']['_status']['status_value'] & 2 == 2:\\n\"\n"
".ascii \" return 'errored'\\n\"\n"
".ascii \" if self.val['_state']['_status']['status_value'] & 1 == 1:\\n\"\n"
".ascii \" return 'valued'\\n\"\n"
".ascii \" if self.val['_state']['_status']['status_value'] & 0xff == 0:\\n\"\n"
".ascii \" return 'empty'\\n\"\n"
".ascii \"class OutcomeCResultStatusPrinter(object):\\n\"\n"
".ascii \" '''Print a C result'''\\n\"\n"
".ascii \" def __init__(self, val):\\n\"\n"
".ascii \" self.val = val\\n\"\n"
".ascii \" def children(self):\\n\"\n"
".ascii \" if self.val['flags'] & 1 == 1:\\n\"\n"
".ascii \" yield ('value', self.val['value'])\\n\"\n"
".ascii \" if self.val['flags'] & 2 == 2:\\n\"\n"
".ascii \" yield ('error', self.val['error'])\\n\"\n"
".ascii \" def display_hint(self):\\n\"\n"
".ascii \" return None\\n\"\n"
".ascii \" def to_string(self):\\n\"\n"
".ascii \" if self.val['flags'] & 50 == 50:\\n\"\n"
".ascii \" return 'errored (errno, moved from)'\\n\"\n"
".ascii \" if self.val['flags'] & 35 == 35:\\n\"\n"
".ascii \" return 'errored (moved from)'\\n\"\n"
".ascii \" if self.val['flags'] & 33 == 33:\\n\"\n"
".ascii \" return 'valued (moved from)'\\n\"\n"
".ascii \" if self.val['flags'] & 18 == 18:\\n\"\n"
".ascii \" return 'errored (errno)'\\n\"\n"
".ascii \" if self.val['flags'] & 2 == 2:\\n\"\n"
".ascii \" return 'errored'\\n\"\n"
".ascii \" if self.val['flags'] & 1 == 1:\\n\"\n"
".ascii \" return 'valued'\\n\"\n"
".ascii \" if self.val['flags'] & 0xff == 0:\\n\"\n"
".ascii \" return 'empty'\\n\"\n"
".ascii \"class OutcomeCStatusCodePrinter(object):\\n\"\n"
".ascii \" '''Print a C status code'''\\n\"\n"
".ascii \" def __init__(self, val):\\n\"\n"
".ascii \" self.val = val\\n\"\n"
".ascii \" def children(self):\\n\"\n"
".ascii \" yield ('domain', self.val['domain'])\\n\"\n"
".ascii \" yield ('value', self.val['value'])\\n\"\n"
".ascii \" def display_hint(self):\\n\"\n"
".ascii \" return None\\n\"\n"
".ascii \" def to_string(self):\\n\"\n"
".ascii \" s = str(self.val['domain'])\\n\"\n"
".ascii \" if 'posix_code_domain' in s or 'generic_code_domain' in s:\\n\"\n"
".ascii \" return str(self.val['value']) + ' (' + os.strerror(int(self.val['value'])) + ')'\\n\"\n"
".ascii \" else:\\n\"\n"
".ascii \" return self.val['value']\\n\"\n"
".ascii \"def build_pretty_printer():\\n\"\n"
".ascii \" pp = gdb.printing.RegexpCollectionPrettyPrinter('outcome_v2')\\n\"\n"
".ascii \" pp.add_printer('outcome_v2::basic_result', '^(boost::)?outcome_v2[_0-9a-f]*::basic_result<.*>$', OutcomeBasicOutcomePrinter)\\n\"\n"
".ascii \" pp.add_printer('outcome_v2::basic_outcome', '^(boost::)?outcome_v2[_0-9a-f]*::basic_outcome<.*>$', OutcomeBasicOutcomePrinter)\\n\"\n"
".ascii \" pp.add_printer('cxx_result_status_code_*', '^cxx_result_status_code_.*$', OutcomeCResultStatusPrinter)\\n\"\n"
".ascii \" pp.add_printer('cxx_status_code_*', '^cxx_status_code_.*$', OutcomeCStatusCodePrinter)\\n\"\n"
".ascii \" return pp\\n\"\n"
".ascii \"def register_printers(obj = None):\\n\"\n"
".ascii \" gdb.printing.register_pretty_printer(obj, build_pretty_printer(), replace = True)\\n\"\n"
".ascii \"register_printers(gdb.current_objfile())\\n\"\n"
".byte 0\n"
".popsection\n");
#ifdef __clang__
#pragma clang diagnostic pop
#endif
#endif
#endif
#endif
/* Policies for result and outcome
(C) 2017-2019 Niall Douglas <http://www.nedproductions.biz/> (13 commits)
File Created: Oct 2017
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License in the accompanying file
Licence.txt or at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Distributed under the Boost Software License, Version 1.0.
(See accompanying file Licence.txt or copy at
http://www.boost.org/LICENSE_1_0.txt)
*/
#ifndef OUTCOME_POLICY_ALL_NARROW_HPP
#define OUTCOME_POLICY_ALL_NARROW_HPP
/* Policies for result and outcome
(C) 2017-2020 Niall Douglas <http://www.nedproductions.biz/> (6 commits) and Andrzej Krzemieński <[email protected]> (1 commit)
File Created: Oct 2017
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License in the accompanying file
Licence.txt or at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Distributed under the Boost Software License, Version 1.0.
(See accompanying file Licence.txt or copy at
http://www.boost.org/LICENSE_1_0.txt)
*/
#ifndef OUTCOME_POLICY_BASE_HPP
#define OUTCOME_POLICY_BASE_HPP
OUTCOME_V2_NAMESPACE_EXPORT_BEGIN
#if OUTCOME_ENABLE_LEGACY_SUPPORT_FOR < 220
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
namespace hooks
{
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
template <class T, class U> constexpr inline void hook_result_construction(T * /*unused*/, U && /*unused*/) noexcept {}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
template <class T, class U> constexpr inline void hook_result_copy_construction(T * /*unused*/, U && /*unused*/) noexcept {}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
template <class T, class U> constexpr inline void hook_result_move_construction(T * /*unused*/, U && /*unused*/) noexcept {}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
template <class T, class U, class... Args>
constexpr inline void hook_result_in_place_construction(T * /*unused*/, in_place_type_t<U> /*unused*/, Args &&... /*unused*/) noexcept
{
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
template <class T, class... U> constexpr inline void hook_outcome_construction(T * /*unused*/, U &&... /*unused*/) noexcept {}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
template <class T, class U> constexpr inline void hook_outcome_copy_construction(T * /*unused*/, U && /*unused*/) noexcept {}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
template <class T, class U> constexpr inline void hook_outcome_move_construction(T * /*unused*/, U && /*unused*/) noexcept {}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
template <class T, class U, class... Args>
constexpr inline void hook_outcome_in_place_construction(T * /*unused*/, in_place_type_t<U> /*unused*/, Args &&... /*unused*/) noexcept
{
}
} // namespace hooks
#endif
namespace policy
{
namespace detail
{
using OUTCOME_V2_NAMESPACE::detail::make_ub;
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
struct base
{
template <class... Args> static constexpr void _silence_unused(Args &&... /*unused*/) noexcept {}
protected:
template <class Impl> static constexpr void _make_ub(Impl &&self) noexcept { return detail::make_ub(static_cast<Impl &&>(self)); }
template <class Impl> static constexpr bool _has_value(Impl &&self) noexcept { return self._state._status.have_value(); }
template <class Impl> static constexpr bool _has_error(Impl &&self) noexcept { return self._state._status.have_error(); }
template <class Impl> static constexpr bool _has_exception(Impl &&self) noexcept { return self._state._status.have_exception(); }
template <class Impl> static constexpr bool _has_error_is_errno(Impl &&self) noexcept { return self._state._status.have_error_is_errno(); }
template <class Impl> static constexpr void _set_has_value(Impl &&self, bool v) noexcept { self._state._status.set_have_value(v); }
template <class Impl> static constexpr void _set_has_error(Impl &&self, bool v) noexcept { self._state._status.set_have_error(v); }
template <class Impl> static constexpr void _set_has_exception(Impl &&self, bool v) noexcept { self._state._status.set_have_exception(v); }
template <class Impl> static constexpr void _set_has_error_is_errno(Impl &&self, bool v) noexcept { self._state._status.set_have_error_is_errno(v); }
template <class Impl> static constexpr auto &&_value(Impl &&self) noexcept { return static_cast<Impl &&>(self)._state._value; }
template <class Impl> static constexpr auto &&_error(Impl &&self) noexcept { return static_cast<Impl &&>(self)._state._error; }
public:
template <class R, class S, class P, class NoValuePolicy, class Impl> static inline constexpr auto &&_exception(Impl &&self) noexcept;
template <class T, class U> static constexpr inline void on_result_construction(T *inst, U &&v) noexcept
{
#if OUTCOME_ENABLE_LEGACY_SUPPORT_FOR < 220
using namespace hooks;
hook_result_construction(inst, static_cast<U &&>(v));
#else
(void) inst;
(void) v;
#endif
}
template <class T, class U> static constexpr inline void on_result_copy_construction(T *inst, U &&v) noexcept
{
#if OUTCOME_ENABLE_LEGACY_SUPPORT_FOR < 220
using namespace hooks;
hook_result_copy_construction(inst, static_cast<U &&>(v));
#else
(void) inst;
(void) v;
#endif
}
template <class T, class U> static constexpr inline void on_result_move_construction(T *inst, U &&v) noexcept
{
#if OUTCOME_ENABLE_LEGACY_SUPPORT_FOR < 220
using namespace hooks;
hook_result_move_construction(inst, static_cast<U &&>(v));
#else
(void) inst;
(void) v;
#endif
}
template <class T, class U, class... Args>
static constexpr inline void on_result_in_place_construction(T *inst, in_place_type_t<U> _, Args &&... args) noexcept
{
#if OUTCOME_ENABLE_LEGACY_SUPPORT_FOR < 220
using namespace hooks;
hook_result_in_place_construction(inst, _, static_cast<Args &&>(args)...);
#else
(void) inst;
(void) _;
_silence_unused(static_cast<Args &&>(args)...);
#endif
}
template <class T, class... U> static constexpr inline void on_outcome_construction(T *inst, U &&... args) noexcept
{
#if OUTCOME_ENABLE_LEGACY_SUPPORT_FOR < 220
using namespace hooks;
hook_outcome_construction(inst, static_cast<U &&>(args)...);
#else
(void) inst;
_silence_unused(static_cast<U &&>(args)...);
#endif
}
template <class T, class U> static constexpr inline void on_outcome_copy_construction(T *inst, U &&v) noexcept
{
#if OUTCOME_ENABLE_LEGACY_SUPPORT_FOR < 220
using namespace hooks;
hook_outcome_copy_construction(inst, static_cast<U &&>(v));
#else
(void) inst;
(void) v;
#endif
}
template <class T, class U> static constexpr inline void on_outcome_move_construction(T *inst, U &&v) noexcept
{
#if OUTCOME_ENABLE_LEGACY_SUPPORT_FOR < 220
using namespace hooks;
hook_outcome_move_construction(inst, static_cast<U &&>(v));
#else
(void) inst;
(void) v;
#endif
}
template <class T, class U, class... Args>
static constexpr inline void on_outcome_in_place_construction(T *inst, in_place_type_t<U> _, Args &&... args) noexcept
{
#if OUTCOME_ENABLE_LEGACY_SUPPORT_FOR < 220
using namespace hooks;
hook_outcome_in_place_construction(inst, _, static_cast<Args &&>(args)...);
#else
(void) inst;
(void) _;
_silence_unused(static_cast<Args &&>(args)...);
#endif
}
template <class Impl> static constexpr void narrow_value_check(Impl &&self) noexcept
{
if(!_has_value(self))
{
_make_ub(self);
}
}
template <class Impl> static constexpr void narrow_error_check(Impl &&self) noexcept
{
if(!_has_error(self))
{
_make_ub(self);
}
}
template <class Impl> static constexpr void narrow_exception_check(Impl &&self) noexcept
{
if(!_has_exception(self))
{
_make_ub(self);
}
}
};
} // namespace policy
OUTCOME_V2_NAMESPACE_END
#endif
OUTCOME_V2_NAMESPACE_EXPORT_BEGIN
namespace policy
{
/*! AWAITING HUGO JSON CONVERSION TOOL
type definition all_narrow. Potential doc page: `all_narrow`
*/
struct all_narrow : base
{
template <class Impl> static constexpr void wide_value_check(Impl &&self) { base::narrow_value_check(static_cast<Impl &&>(self)); }
template <class Impl> static constexpr void wide_error_check(Impl &&self) { base::narrow_error_check(static_cast<Impl &&>(self)); }
template <class Impl> static constexpr void wide_exception_check(Impl &&self) { base::narrow_exception_check(static_cast<Impl &&>(self)); }
};
} // namespace policy
OUTCOME_V2_NAMESPACE_END
#endif
/* Policies for result and outcome
(C) 2017-2019 Niall Douglas <http://www.nedproductions.biz/> (12 commits)
File Created: Oct 2017
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License in the accompanying file
Licence.txt or at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Distributed under the Boost Software License, Version 1.0.
(See accompanying file Licence.txt or copy at
http://www.boost.org/LICENSE_1_0.txt)
*/
#ifndef OUTCOME_POLICY_TERMINATE_HPP
#define OUTCOME_POLICY_TERMINATE_HPP
#include <cstdlib>
OUTCOME_V2_NAMESPACE_EXPORT_BEGIN
namespace policy
{
/*! AWAITING HUGO JSON CONVERSION TOOL
type definition terminate. Potential doc page: `terminate`
*/
struct terminate : base
{
template <class Impl> static constexpr void wide_value_check(Impl &&self)
{
if(!base::_has_value(static_cast<Impl &&>(self)))
{
std::abort();
}
}
template <class Impl> static constexpr void wide_error_check(Impl &&self) noexcept
{
if(!base::_has_error(static_cast<Impl &&>(self)))
{
std::abort();
}
}
template <class Impl> static constexpr void wide_exception_check(Impl &&self)
{
if(!base::_has_exception(static_cast<Impl &&>(self)))
{
std::abort();
}
}
};
} // namespace policy
OUTCOME_V2_NAMESPACE_END
#endif
#ifdef __clang__
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdocumentation" // Standardese markup confuses clang
#endif
OUTCOME_V2_NAMESPACE_EXPORT_BEGIN
template <class R, class S, class NoValuePolicy> //
class basic_result;
namespace detail
{
// These are reused by basic_outcome to save load on the compiler
template <class value_type, class error_type> struct result_predicates
{
// Predicate for the implicit constructors to be available. Weakened to allow result<int, C enum>.
static constexpr bool implicit_constructors_enabled = //
!(trait::is_error_type<std::decay_t<value_type>>::value &&
trait::is_error_type<std::decay_t<error_type>>::value) // both value and error types are not whitelisted error types
&& ((!detail::is_implicitly_constructible<value_type, error_type> &&
!detail::is_implicitly_constructible<error_type, value_type>) // if value and error types cannot be constructed into one another
|| (trait::is_error_type<std::decay_t<error_type>>::value // if error type is a whitelisted error type
&& !detail::is_implicitly_constructible<error_type, value_type> // AND which cannot be constructed from the value type
&& std::is_integral<value_type>::value)); // AND the value type is some integral type
// Predicate for the value converting constructor to be available. Weakened to allow result<int, C enum>.
template <class T>
static constexpr bool enable_value_converting_constructor = //
implicit_constructors_enabled //
&& !is_in_place_type_t<std::decay_t<T>>::value // not in place construction
&& !trait::is_error_type_enum<error_type, std::decay_t<T>>::value // not an enum valid for my error type
&& ((detail::is_implicitly_constructible<value_type, T> && !detail::is_implicitly_constructible<error_type, T>) // is unambiguously for value type
|| (std::is_same<value_type, std::decay_t<T>>::value // OR is my value type exactly
&& detail::is_implicitly_constructible<value_type, T>) ); // and my value type is constructible from this ref form of T
// Predicate for the error converting constructor to be available. Weakened to allow result<int, C enum>.
template <class T>
static constexpr bool enable_error_converting_constructor = //
implicit_constructors_enabled //
&& !is_in_place_type_t<std::decay_t<T>>::value // not in place construction
&& !trait::is_error_type_enum<error_type, std::decay_t<T>>::value // not an enum valid for my error type
&& ((!detail::is_implicitly_constructible<value_type, T> && detail::is_implicitly_constructible<error_type, T>) // is unambiguously for error type
|| (std::is_same<error_type, std::decay_t<T>>::value // OR is my error type exactly
&& detail::is_implicitly_constructible<error_type, T>) ); // and my error type is constructible from this ref form of T
// Predicate for the error condition converting constructor to be available.
template <class ErrorCondEnum>
static constexpr bool enable_error_condition_converting_constructor = //
!is_in_place_type_t<std::decay_t<ErrorCondEnum>>::value // not in place construction
&& trait::is_error_type_enum<error_type, std::decay_t<ErrorCondEnum>>::value // is an error condition enum
/*&& !detail::is_implicitly_constructible<value_type, ErrorCondEnum> && !detail::is_implicitly_constructible<error_type, ErrorCondEnum>*/; // not
// constructible
// via any other
// means
// Predicate for the converting constructor from a compatible input to be available.
template <class T, class U, class V>
static constexpr bool enable_compatible_conversion = //
(std::is_void<T>::value ||
detail::is_explicitly_constructible<value_type, typename basic_result<T, U, V>::value_type>) // if our value types are constructible
&&(std::is_void<U>::value ||
detail::is_explicitly_constructible<error_type, typename basic_result<T, U, V>::error_type>) // if our error types are constructible
;
// Predicate for the converting constructor from a make_error_code() of the input to be available.
template <class T, class U, class V>
static constexpr bool enable_make_error_code_compatible_conversion = //
trait::is_error_code_available<std::decay_t<error_type>>::value // if error type has an error code
&& !enable_compatible_conversion<T, U, V> // and the normal compatible conversion is not available
&& (std::is_void<T>::value ||
detail::is_explicitly_constructible<value_type, typename basic_result<T, U, V>::value_type>) // and if our value types are constructible
&&detail::is_explicitly_constructible<error_type,
typename trait::is_error_code_available<U>::type>; // and our error type is constructible from a make_error_code()
// Predicate for the converting constructor from a make_exception_ptr() of the input to be available.
template <class T, class U, class V>
static constexpr bool enable_make_exception_ptr_compatible_conversion = //
trait::is_exception_ptr_available<std::decay_t<error_type>>::value // if error type has an exception ptr
&& !enable_compatible_conversion<T, U, V> // and the normal compatible conversion is not available
&& (std::is_void<T>::value ||
detail::is_explicitly_constructible<value_type, typename basic_result<T, U, V>::value_type>) // and if our value types are constructible
&&detail::is_explicitly_constructible<error_type, typename trait::is_exception_ptr_available<U>::type>; // and our error type is constructible from a
// make_exception_ptr()
// Predicate for the implicit converting inplace constructor from a compatible input to be available.
struct disable_inplace_value_error_constructor;
template <class... Args>
using choose_inplace_value_error_constructor = std::conditional_t< //
detail::is_constructible<value_type, Args...> && detail::is_constructible<error_type, Args...>, //
disable_inplace_value_error_constructor, //
std::conditional_t< //
detail::is_constructible<value_type, Args...>, //
value_type, //
std::conditional_t< //
detail::is_constructible<error_type, Args...>, //
error_type, //
disable_inplace_value_error_constructor>>>;
template <class... Args>
static constexpr bool enable_inplace_value_error_constructor =
implicit_constructors_enabled //
&& !std::is_same<choose_inplace_value_error_constructor<Args...>, disable_inplace_value_error_constructor>::value;
};
template <class T, class U> constexpr inline const U &extract_value_from_success(const success_type<U> &v)
{
return v.value();
}
template <class T, class U> constexpr inline U &&extract_value_from_success(success_type<U> &&v)
{
return static_cast<success_type<U> &&>(v).value();
}
template <class T> constexpr inline T extract_value_from_success(const success_type<void> & /*unused*/)
{
return T{};
}
template <class T, class U, class V> constexpr inline const U &extract_error_from_failure(const failure_type<U, V> &v)
{
return v.error();
}
template <class T, class U, class V> constexpr inline U &&extract_error_from_failure(failure_type<U, V> &&v)
{
return static_cast<failure_type<U, V> &&>(v).error();
}
template <class T, class V> constexpr inline T extract_error_from_failure(const failure_type<void, V> & /*unused*/)
{
return T{};
}
template <class T> struct is_basic_result
{
static constexpr bool value = false;
};
template <class R, class S, class T> struct is_basic_result<basic_result<R, S, T>>
{
static constexpr bool value = true;
};
} // namespace detail
/*! AWAITING HUGO JSON CONVERSION TOOL
type alias template <class T> is_basic_result. Potential doc page: `is_basic_result<T>`
*/
template <class T> using is_basic_result = detail::is_basic_result<std::decay_t<T>>;
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
template <class T> static constexpr bool is_basic_result_v = detail::is_basic_result<std::decay_t<T>>::value;
namespace concepts
{
#if defined(__cpp_concepts)
/* The `basic_result` concept.
\requires That `U` matches a `basic_result`.
*/
template <class U>
concept OUTCOME_GCC6_CONCEPT_BOOL basic_result =
OUTCOME_V2_NAMESPACE::is_basic_result<U>::value ||
(requires(U v) { OUTCOME_V2_NAMESPACE::basic_result<typename U::value_type, typename U::error_type, typename U::no_value_policy_type>(v); } && //
detail::convertible<U, OUTCOME_V2_NAMESPACE::basic_result<typename U::value_type, typename U::error_type, typename U::no_value_policy_type>> && //
detail::base_of<OUTCOME_V2_NAMESPACE::basic_result<typename U::value_type, typename U::error_type, typename U::no_value_policy_type>, U>);
#else
namespace detail
{
inline no_match match_basic_result(...);
template <class R, class S, class NVP, class T, //
typename = typename T::value_type, //
typename = typename T::error_type, //
typename = typename T::no_value_policy_type, //
typename std::enable_if_t<std::is_convertible<T, OUTCOME_V2_NAMESPACE::basic_result<R, S, NVP>>::value && //
std::is_base_of<OUTCOME_V2_NAMESPACE::basic_result<R, S, NVP>, T>::value,
bool> = true>
inline OUTCOME_V2_NAMESPACE::basic_result<R, S, NVP> match_basic_result(OUTCOME_V2_NAMESPACE::basic_result<R, S, NVP> &&, T &&);
template <class U>
static constexpr bool basic_result = OUTCOME_V2_NAMESPACE::is_basic_result<U>::value ||
!std::is_same<no_match, decltype(match_basic_result(std::declval<OUTCOME_V2_NAMESPACE::detail::devoid<U>>(),
std::declval<OUTCOME_V2_NAMESPACE::detail::devoid<U>>()))>::value;
} // namespace detail
/* The `basic_result` concept.
\requires That `U` matches a `basic_result`.
*/
template <class U> static constexpr bool basic_result = detail::basic_result<U>;
#endif
} // namespace concepts
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
namespace hooks
{
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
template <class R, class S, class NoValuePolicy> constexpr inline uint16_t spare_storage(const detail::basic_result_storage<R, S, NoValuePolicy> *r) noexcept
{
return r->_state._status.spare_storage_value;
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
template <class R, class S, class NoValuePolicy>
constexpr inline void set_spare_storage(detail::basic_result_storage<R, S, NoValuePolicy> *r, uint16_t v) noexcept
{
r->_state._status.spare_storage_value = v;
}
} // namespace hooks
/*! AWAITING HUGO JSON CONVERSION TOOL
type definition template <class R, class S, class NoValuePolicy> basic_result. Potential doc page: `basic_result<T, E, NoValuePolicy>`
*/
template <class R, class S, class NoValuePolicy> //
class OUTCOME_NODISCARD basic_result : public detail::basic_result_final<R, S, NoValuePolicy>
{
static_assert(trait::type_can_be_used_in_basic_result<R>, "The type R cannot be used in a basic_result");
static_assert(trait::type_can_be_used_in_basic_result<S>, "The type S cannot be used in a basic_result");
using base = detail::basic_result_final<R, S, NoValuePolicy>;
struct implicit_constructors_disabled_tag
{
};
struct value_converting_constructor_tag
{
};
struct error_converting_constructor_tag
{
};
struct error_condition_converting_constructor_tag
{
};
struct explicit_valueornone_converting_constructor_tag
{
};
struct explicit_valueorerror_converting_constructor_tag
{
};
struct explicit_compatible_copy_conversion_tag
{
};
struct explicit_compatible_move_conversion_tag
{
};
struct explicit_make_error_code_compatible_copy_conversion_tag
{
};
struct explicit_make_error_code_compatible_move_conversion_tag
{
};
struct explicit_make_exception_ptr_compatible_copy_conversion_tag
{
};
struct explicit_make_exception_ptr_compatible_move_conversion_tag
{
};
public:
using value_type = R;
using error_type = S;
using no_value_policy_type = NoValuePolicy;
using value_type_if_enabled = typename base::_value_type;
using error_type_if_enabled = typename base::_error_type;
template <class T, class U = S, class V = NoValuePolicy> using rebind = basic_result<T, U, V>;
protected:
// Requirement predicates for result.
struct predicate
{
using base = detail::result_predicates<value_type, error_type>;
// Predicate for any constructors to be available at all
static constexpr bool constructors_enabled = !std::is_same<std::decay_t<value_type>, std::decay_t<error_type>>::value;
// Predicate for implicit constructors to be available at all
static constexpr bool implicit_constructors_enabled = constructors_enabled && base::implicit_constructors_enabled;
// Predicate for the value converting constructor to be available.
template <class T>
static constexpr bool enable_value_converting_constructor = //
constructors_enabled //
&& !std::is_same<std::decay_t<T>, basic_result>::value // not my type
&& base::template enable_value_converting_constructor<T>;
// Predicate for the error converting constructor to be available.
template <class T>
static constexpr bool enable_error_converting_constructor = //
constructors_enabled //
&& !std::is_same<std::decay_t<T>, basic_result>::value // not my type
&& base::template enable_error_converting_constructor<T>;
// Predicate for the error condition converting constructor to be available.
template <class ErrorCondEnum>
static constexpr bool enable_error_condition_converting_constructor = //
constructors_enabled //
&& !std::is_same<std::decay_t<ErrorCondEnum>, basic_result>::value // not my type
&& base::template enable_error_condition_converting_constructor<ErrorCondEnum>;
// Predicate for the converting constructor from a compatible input to be available.
template <class T, class U, class V>
static constexpr bool enable_compatible_conversion = //
constructors_enabled //
&& !std::is_same<basic_result<T, U, V>, basic_result>::value // not my type
&& base::template enable_compatible_conversion<T, U, V>;
// Predicate for the converting constructor from a make_error_code() of the input to be available.
template <class T, class U, class V>
static constexpr bool enable_make_error_code_compatible_conversion = //
constructors_enabled //
&& !std::is_same<basic_result<T, U, V>, basic_result>::value // not my type
&& base::template enable_make_error_code_compatible_conversion<T, U, V>;
// Predicate for the converting constructor from a make_exception_ptr() of the input to be available.
template <class T, class U, class V>
static constexpr bool enable_make_exception_ptr_compatible_conversion = //
constructors_enabled //
&& !std::is_same<basic_result<T, U, V>, basic_result>::value // not my type
&& base::template enable_make_exception_ptr_compatible_conversion<T, U, V>;
// Predicate for the inplace construction of value to be available.
template <class... Args>
static constexpr bool enable_inplace_value_constructor = //
constructors_enabled //
&& (std::is_void<value_type>::value //
|| detail::is_constructible<value_type, Args...>);
// Predicate for the inplace construction of error to be available.
template <class... Args>
static constexpr bool enable_inplace_error_constructor = //
constructors_enabled //
&& (std::is_void<error_type>::value //
|| detail::is_constructible<error_type, Args...>);
// Predicate for the implicit converting inplace constructor to be available.
template <class... Args>
static constexpr bool enable_inplace_value_error_constructor = //
constructors_enabled //
&& base::template enable_inplace_value_error_constructor<Args...>;
template <class... Args> using choose_inplace_value_error_constructor = typename base::template choose_inplace_value_error_constructor<Args...>;
};
public:
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
basic_result() = delete;
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
basic_result(basic_result && /*unused*/) = default; // NOLINT
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
basic_result(const basic_result & /*unused*/) = default;
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
basic_result &operator=(basic_result && /*unused*/) = default; // NOLINT
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
basic_result &operator=(const basic_result & /*unused*/) = default;
~basic_result() = default;
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class Arg, class... Args)
OUTCOME_TREQUIRES(OUTCOME_TPRED(!predicate::constructors_enabled && (sizeof...(Args) >= 0)))
basic_result(Arg && /*unused*/, Args &&.../*unused*/) = delete; // NOLINT basic_result<T, T> is NOT SUPPORTED, see docs!
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class T)
OUTCOME_TREQUIRES(OUTCOME_TPRED((predicate::constructors_enabled && !predicate::implicit_constructors_enabled //
&& (detail::is_implicitly_constructible<value_type, T> || detail::is_implicitly_constructible<error_type, T>) )))
basic_result(T && /*unused*/, implicit_constructors_disabled_tag /*unused*/ = implicit_constructors_disabled_tag()) =
delete; // NOLINT Implicit constructors disabled, use explicit in_place_type<T>, success() or failure(). see docs!
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class T)
OUTCOME_TREQUIRES(OUTCOME_TPRED(predicate::template enable_value_converting_constructor<T>))
constexpr basic_result(T &&t, value_converting_constructor_tag /*unused*/ = value_converting_constructor_tag()) noexcept(
detail::is_nothrow_constructible<value_type, T>) // NOLINT
: base{in_place_type<typename base::value_type>, static_cast<T &&>(t)}
{
no_value_policy_type::on_result_construction(this, static_cast<T &&>(t));
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class T)
OUTCOME_TREQUIRES(OUTCOME_TPRED(predicate::template enable_error_converting_constructor<T>))
constexpr basic_result(T &&t, error_converting_constructor_tag /*unused*/ = error_converting_constructor_tag()) noexcept(
detail::is_nothrow_constructible<error_type, T>) // NOLINT
: base{in_place_type<typename base::error_type>, static_cast<T &&>(t)}
{
no_value_policy_type::on_result_construction(this, static_cast<T &&>(t));
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class ErrorCondEnum)
OUTCOME_TREQUIRES(OUTCOME_TEXPR(error_type(make_error_code(ErrorCondEnum()))), //
OUTCOME_TPRED(predicate::template enable_error_condition_converting_constructor<ErrorCondEnum>))
constexpr basic_result(ErrorCondEnum &&t, error_condition_converting_constructor_tag /*unused*/ = error_condition_converting_constructor_tag()) noexcept(
noexcept(error_type(make_error_code(static_cast<ErrorCondEnum &&>(t))))) // NOLINT
: base{in_place_type<typename base::error_type>, make_error_code(t)}
{
no_value_policy_type::on_result_construction(this, static_cast<ErrorCondEnum &&>(t));
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class T)
OUTCOME_TREQUIRES(OUTCOME_TPRED(convert::value_or_error<basic_result, std::decay_t<T>>::enable_result_inputs || !concepts::basic_result<T>), //
OUTCOME_TEXPR(convert::value_or_error<basic_result, std::decay_t<T>>{}(std::declval<T>())))
constexpr explicit basic_result(T &&o,
explicit_valueorerror_converting_constructor_tag /*unused*/ = explicit_valueorerror_converting_constructor_tag()) // NOLINT
: basic_result{convert::value_or_error<basic_result, std::decay_t<T>>{}(static_cast<T &&>(o))}
{
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class T, class U, class V)
OUTCOME_TREQUIRES(OUTCOME_TPRED(predicate::template enable_compatible_conversion<T, U, V>))
constexpr explicit basic_result(
const basic_result<T, U, V> &o,
explicit_compatible_copy_conversion_tag /*unused*/ = explicit_compatible_copy_conversion_tag()) noexcept(detail::is_nothrow_constructible<value_type, T> &&
detail::is_nothrow_constructible<error_type, U>)
: base{typename base::compatible_conversion_tag(), o}
{
no_value_policy_type::on_result_copy_construction(this, o);
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class T, class U, class V)
OUTCOME_TREQUIRES(OUTCOME_TPRED(predicate::template enable_compatible_conversion<T, U, V>))
constexpr explicit basic_result(
basic_result<T, U, V> &&o,
explicit_compatible_move_conversion_tag /*unused*/ = explicit_compatible_move_conversion_tag()) noexcept(detail::is_nothrow_constructible<value_type, T> &&
detail::is_nothrow_constructible<error_type, U>)
: base{typename base::compatible_conversion_tag(), static_cast<basic_result<T, U, V> &&>(o)}
{
no_value_policy_type::on_result_move_construction(this, static_cast<basic_result<T, U, V> &&>(o));
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class T, class U, class V)
OUTCOME_TREQUIRES(OUTCOME_TPRED(predicate::template enable_make_error_code_compatible_conversion<T, U, V>))
constexpr explicit basic_result(const basic_result<T, U, V> &o,
explicit_make_error_code_compatible_copy_conversion_tag /*unused*/ =
explicit_make_error_code_compatible_copy_conversion_tag()) noexcept(detail::is_nothrow_constructible<value_type, T> &&
noexcept(make_error_code(std::declval<U>())))
: base{typename base::make_error_code_compatible_conversion_tag(), o}
{
no_value_policy_type::on_result_copy_construction(this, o);
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class T, class U, class V)
OUTCOME_TREQUIRES(OUTCOME_TPRED(predicate::template enable_make_error_code_compatible_conversion<T, U, V>))
constexpr explicit basic_result(basic_result<T, U, V> &&o,
explicit_make_error_code_compatible_move_conversion_tag /*unused*/ =
explicit_make_error_code_compatible_move_conversion_tag()) noexcept(detail::is_nothrow_constructible<value_type, T> &&
noexcept(make_error_code(std::declval<U>())))
: base{typename base::make_error_code_compatible_conversion_tag(), static_cast<basic_result<T, U, V> &&>(o)}
{
no_value_policy_type::on_result_move_construction(this, static_cast<basic_result<T, U, V> &&>(o));
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class T, class U, class V)
OUTCOME_TREQUIRES(OUTCOME_TPRED(predicate::template enable_make_exception_ptr_compatible_conversion<T, U, V>))
constexpr explicit basic_result(const basic_result<T, U, V> &o,
explicit_make_exception_ptr_compatible_copy_conversion_tag /*unused*/ =
explicit_make_exception_ptr_compatible_copy_conversion_tag()) noexcept(detail::is_nothrow_constructible<value_type, T> &&
noexcept(make_exception_ptr(std::declval<U>())))
: base{typename base::make_exception_ptr_compatible_conversion_tag(), o}
{
no_value_policy_type::on_result_copy_construction(this, o);
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class T, class U, class V)
OUTCOME_TREQUIRES(OUTCOME_TPRED(predicate::template enable_make_exception_ptr_compatible_conversion<T, U, V>))
constexpr explicit basic_result(basic_result<T, U, V> &&o,
explicit_make_exception_ptr_compatible_move_conversion_tag /*unused*/ =
explicit_make_exception_ptr_compatible_move_conversion_tag()) noexcept(detail::is_nothrow_constructible<value_type, T> &&
noexcept(make_exception_ptr(std::declval<U>())))
: base{typename base::make_exception_ptr_compatible_conversion_tag(), static_cast<basic_result<T, U, V> &&>(o)}
{
no_value_policy_type::on_result_move_construction(this, static_cast<basic_result<T, U, V> &&>(o));
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class... Args)
OUTCOME_TREQUIRES(OUTCOME_TPRED(predicate::template enable_inplace_value_constructor<Args...>))
constexpr explicit basic_result(in_place_type_t<value_type_if_enabled> _, Args &&...args) noexcept(detail::is_nothrow_constructible<value_type, Args...>)
: base{_, static_cast<Args &&>(args)...}
{
no_value_policy_type::on_result_in_place_construction(this, in_place_type<value_type>, static_cast<Args &&>(args)...);
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class U, class... Args)
OUTCOME_TREQUIRES(OUTCOME_TPRED(predicate::template enable_inplace_value_constructor<std::initializer_list<U>, Args...>))
constexpr explicit basic_result(in_place_type_t<value_type_if_enabled> _, std::initializer_list<U> il,
Args &&...args) noexcept(detail::is_nothrow_constructible<value_type, std::initializer_list<U>, Args...>)
: base{_, il, static_cast<Args &&>(args)...}
{
no_value_policy_type::on_result_in_place_construction(this, in_place_type<value_type>, il, static_cast<Args &&>(args)...);
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class... Args)
OUTCOME_TREQUIRES(OUTCOME_TPRED(predicate::template enable_inplace_error_constructor<Args...>))
constexpr explicit basic_result(in_place_type_t<error_type_if_enabled> _, Args &&...args) noexcept(detail::is_nothrow_constructible<error_type, Args...>)
: base{_, static_cast<Args &&>(args)...}
{
no_value_policy_type::on_result_in_place_construction(this, in_place_type<error_type>, static_cast<Args &&>(args)...);
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class U, class... Args)
OUTCOME_TREQUIRES(OUTCOME_TPRED(predicate::template enable_inplace_error_constructor<std::initializer_list<U>, Args...>))
constexpr explicit basic_result(in_place_type_t<error_type_if_enabled> _, std::initializer_list<U> il,
Args &&...args) noexcept(detail::is_nothrow_constructible<error_type, std::initializer_list<U>, Args...>)
: base{_, il, static_cast<Args &&>(args)...}
{
no_value_policy_type::on_result_in_place_construction(this, in_place_type<error_type>, il, static_cast<Args &&>(args)...);
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class A1, class A2, class... Args)
OUTCOME_TREQUIRES(OUTCOME_TPRED(predicate::template enable_inplace_value_error_constructor<A1, A2, Args...>))
constexpr basic_result(A1 &&a1, A2 &&a2, Args &&...args) noexcept(noexcept(
typename predicate::template choose_inplace_value_error_constructor<A1, A2, Args...>(std::declval<A1>(), std::declval<A2>(), std::declval<Args>()...)))
: basic_result(in_place_type<typename predicate::template choose_inplace_value_error_constructor<A1, A2, Args...>>, static_cast<A1 &&>(a1),
static_cast<A2 &&>(a2), static_cast<Args &&>(args)...)
{
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
constexpr basic_result(const success_type<void> &o) noexcept(std::is_nothrow_default_constructible<value_type>::value) // NOLINT
: base{in_place_type<value_type_if_enabled>}
{
hooks::set_spare_storage(this, o.spare_storage());
no_value_policy_type::on_result_copy_construction(this, o);
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class T)
OUTCOME_TREQUIRES(OUTCOME_TPRED(predicate::template enable_compatible_conversion<T, void, void>))
constexpr basic_result(const success_type<T> &o) noexcept(detail::is_nothrow_constructible<value_type, T>) // NOLINT
: base{in_place_type<value_type_if_enabled>, detail::extract_value_from_success<value_type>(o)}
{
hooks::set_spare_storage(this, o.spare_storage());
no_value_policy_type::on_result_copy_construction(this, o);
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class T)
OUTCOME_TREQUIRES(OUTCOME_TPRED(!std::is_void<T>::value && predicate::template enable_compatible_conversion<T, void, void>))
constexpr basic_result(success_type<T> &&o) noexcept(detail::is_nothrow_constructible<value_type, T>) // NOLINT
: base{in_place_type<value_type_if_enabled>, detail::extract_value_from_success<value_type>(static_cast<success_type<T> &&>(o))}
{
hooks::set_spare_storage(this, o.spare_storage());
no_value_policy_type::on_result_move_construction(this, static_cast<success_type<T> &&>(o));
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class T)
OUTCOME_TREQUIRES(OUTCOME_TPRED(predicate::template enable_compatible_conversion<void, T, void>))
constexpr basic_result(const failure_type<T> &o, explicit_compatible_copy_conversion_tag /*unused*/ = explicit_compatible_copy_conversion_tag()) noexcept(
detail::is_nothrow_constructible<error_type, T>) // NOLINT
: base{in_place_type<error_type_if_enabled>, detail::extract_error_from_failure<error_type>(o)}
{
hooks::set_spare_storage(this, o.spare_storage());
no_value_policy_type::on_result_copy_construction(this, o);
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class T)
OUTCOME_TREQUIRES(OUTCOME_TPRED(predicate::template enable_compatible_conversion<void, T, void>))
constexpr basic_result(failure_type<T> &&o, explicit_compatible_move_conversion_tag /*unused*/ = explicit_compatible_move_conversion_tag()) noexcept(
detail::is_nothrow_constructible<error_type, T>) // NOLINT
: base{in_place_type<error_type_if_enabled>, detail::extract_error_from_failure<error_type>(static_cast<failure_type<T> &&>(o))}
{
hooks::set_spare_storage(this, o.spare_storage());
no_value_policy_type::on_result_move_construction(this, static_cast<failure_type<T> &&>(o));
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class T)
OUTCOME_TREQUIRES(OUTCOME_TPRED(predicate::template enable_make_error_code_compatible_conversion<void, T, void>))
constexpr basic_result(const failure_type<T> &o,
explicit_make_error_code_compatible_copy_conversion_tag /*unused*/ =
explicit_make_error_code_compatible_copy_conversion_tag()) noexcept(noexcept(make_error_code(std::declval<T>()))) // NOLINT
: base{in_place_type<error_type_if_enabled>, make_error_code(detail::extract_error_from_failure<error_type>(o))}
{
hooks::set_spare_storage(this, o.spare_storage());
no_value_policy_type::on_result_copy_construction(this, o);
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class T)
OUTCOME_TREQUIRES(OUTCOME_TPRED(predicate::template enable_make_error_code_compatible_conversion<void, T, void>))
constexpr basic_result(failure_type<T> &&o,
explicit_make_error_code_compatible_move_conversion_tag /*unused*/ =
explicit_make_error_code_compatible_move_conversion_tag()) noexcept(noexcept(make_error_code(std::declval<T>()))) // NOLINT
: base{in_place_type<error_type_if_enabled>, make_error_code(detail::extract_error_from_failure<error_type>(static_cast<failure_type<T> &&>(o)))}
{
hooks::set_spare_storage(this, o.spare_storage());
no_value_policy_type::on_result_move_construction(this, static_cast<failure_type<T> &&>(o));
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class T)
OUTCOME_TREQUIRES(OUTCOME_TPRED(predicate::template enable_make_exception_ptr_compatible_conversion<void, T, void>))
constexpr basic_result(const failure_type<T> &o,
explicit_make_exception_ptr_compatible_copy_conversion_tag /*unused*/ =
explicit_make_exception_ptr_compatible_copy_conversion_tag()) noexcept(noexcept(make_exception_ptr(std::declval<T>()))) // NOLINT
: base{in_place_type<error_type_if_enabled>, make_exception_ptr(detail::extract_error_from_failure<error_type>(o))}
{
hooks::set_spare_storage(this, o.spare_storage());
no_value_policy_type::on_result_copy_construction(this, o);
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class T)
OUTCOME_TREQUIRES(OUTCOME_TPRED(predicate::template enable_make_exception_ptr_compatible_conversion<void, T, void>))
constexpr basic_result(failure_type<T> &&o,
explicit_make_exception_ptr_compatible_move_conversion_tag /*unused*/ =
explicit_make_exception_ptr_compatible_move_conversion_tag()) noexcept(noexcept(make_exception_ptr(std::declval<T>()))) // NOLINT
: base{in_place_type<error_type_if_enabled>, make_exception_ptr(detail::extract_error_from_failure<error_type>(static_cast<failure_type<T> &&>(o)))}
{
hooks::set_spare_storage(this, o.spare_storage());
no_value_policy_type::on_result_move_construction(this, static_cast<failure_type<T> &&>(o));
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
constexpr void swap(basic_result &o) noexcept((std::is_void<value_type>::value || detail::is_nothrow_swappable<value_type>::value) //
&& (std::is_void<error_type>::value || detail::is_nothrow_swappable<error_type>::value))
{
this->_state.swap(o._state);
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
auto as_failure() const & { return failure(this->assume_error(), hooks::spare_storage(this)); }
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
auto as_failure() &&
{
this->_state._status.set_have_moved_from(true);
return failure(static_cast<basic_result &&>(*this).assume_error(), hooks::spare_storage(this));
}
#ifdef __APPLE__
failure_type<error_type> _xcode_workaround_as_failure() &&;
#endif
};
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
template <class R, class S, class P> inline void swap(basic_result<R, S, P> &a, basic_result<R, S, P> &b) noexcept(noexcept(a.swap(b)))
{
a.swap(b);
}
#if !defined(NDEBUG)
// Check is trivial in all ways except default constructibility
// static_assert(std::is_trivial<basic_result<int, long, policy::all_narrow>>::value, "result<int> is not trivial!");
// static_assert(std::is_trivially_default_constructible<basic_result<int, long, policy::all_narrow>>::value, "result<int> is not trivially default
// constructible!");
static_assert(std::is_trivially_copyable<basic_result<int, long, policy::all_narrow>>::value, "result<int> is not trivially copyable!");
static_assert(std::is_trivially_assignable<basic_result<int, long, policy::all_narrow>, basic_result<int, long, policy::all_narrow>>::value,
"result<int> is not trivially assignable!");
static_assert(std::is_trivially_destructible<basic_result<int, long, policy::all_narrow>>::value, "result<int> is not trivially destructible!");
static_assert(std::is_trivially_copy_constructible<basic_result<int, long, policy::all_narrow>>::value, "result<int> is not trivially copy constructible!");
static_assert(std::is_trivially_move_constructible<basic_result<int, long, policy::all_narrow>>::value, "result<int> is not trivially move constructible!");
static_assert(std::is_trivially_copy_assignable<basic_result<int, long, policy::all_narrow>>::value, "result<int> is not trivially copy assignable!");
static_assert(std::is_trivially_move_assignable<basic_result<int, long, policy::all_narrow>>::value, "result<int> is not trivially move assignable!");
// Also check is standard layout
static_assert(std::is_standard_layout<basic_result<int, long, policy::all_narrow>>::value, "result<int> is not a standard layout type!");
#endif
OUTCOME_V2_NAMESPACE_END
#ifdef __clang__
#pragma clang diagnostic pop
#endif
#endif
/* Exception observers for outcome type
(C) 2017-2019 Niall Douglas <http://www.nedproductions.biz/> (3 commits)
File Created: Oct 2017
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License in the accompanying file
Licence.txt or at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Distributed under the Boost Software License, Version 1.0.
(See accompanying file Licence.txt or copy at
http://www.boost.org/LICENSE_1_0.txt)
*/
#ifndef OUTCOME_BASIC_OUTCOME_EXCEPTION_OBSERVERS_HPP
#define OUTCOME_BASIC_OUTCOME_EXCEPTION_OBSERVERS_HPP
OUTCOME_V2_NAMESPACE_EXPORT_BEGIN
namespace detail
{
template <class Base, class R, class S, class P, class NoValuePolicy> class basic_outcome_exception_observers : public Base
{
public:
using exception_type = P;
using Base::Base;
constexpr inline exception_type &assume_exception() & noexcept;
constexpr inline const exception_type &assume_exception() const & noexcept;
constexpr inline exception_type &&assume_exception() && noexcept;
constexpr inline const exception_type &&assume_exception() const && noexcept;
constexpr inline exception_type &exception() &;
constexpr inline const exception_type &exception() const &;
constexpr inline exception_type &&exception() &&;
constexpr inline const exception_type &&exception() const &&;
};
// Exception observers not present
template <class Base, class R, class S, class NoValuePolicy> class basic_outcome_exception_observers<Base, R, S, void, NoValuePolicy> : public Base
{
public:
using Base::Base;
constexpr void assume_exception() & noexcept { NoValuePolicy::narrow_exception_check(*this); }
constexpr void assume_exception() const & noexcept { NoValuePolicy::narrow_exception_check(*this); }
constexpr void assume_exception() && noexcept { NoValuePolicy::narrow_exception_check(std::move(*this)); }
constexpr void assume_exception() const && noexcept { NoValuePolicy::narrow_exception_check(std::move(*this)); }
constexpr void exception() & { NoValuePolicy::wide_exception_check(*this); }
constexpr void exception() const & { NoValuePolicy::wide_exception_check(*this); }
constexpr void exception() && { NoValuePolicy::wide_exception_check(std::move(*this)); }
constexpr void exception() const && { NoValuePolicy::wide_exception_check(std::move(*this)); }
};
} // namespace detail
OUTCOME_V2_NAMESPACE_END
#endif
/* Failure observers for outcome type
(C) 2017-2019 Niall Douglas <http://www.nedproductions.biz/> (7 commits)
File Created: Oct 2017
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License in the accompanying file
Licence.txt or at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Distributed under the Boost Software License, Version 1.0.
(See accompanying file Licence.txt or copy at
http://www.boost.org/LICENSE_1_0.txt)
*/
#ifndef OUTCOME_BASIC_OUTCOME_FAILURE_OBSERVERS_HPP
#define OUTCOME_BASIC_OUTCOME_FAILURE_OBSERVERS_HPP
#include <exception>
OUTCOME_V2_NAMESPACE_EXPORT_BEGIN
namespace detail
{
namespace adl
{
struct search_detail_adl
{
};
// Do NOT use template requirements here!
template <class S, typename = decltype(basic_outcome_failure_exception_from_error(std::declval<S>()))>
inline auto _delayed_lookup_basic_outcome_failure_exception_from_error(const S &ec, search_detail_adl /*unused*/)
{
// ADL discovered
return basic_outcome_failure_exception_from_error(ec);
}
} // namespace adl
#if defined(_MSC_VER) && _MSC_VER <= 1923 // VS2019
// VS2017 and VS2019 with /permissive- chokes on the correct form due to over eager early instantiation.
template <class S, class P> inline void _delayed_lookup_basic_outcome_failure_exception_from_error(...) { static_assert(sizeof(S) == 0, "No specialisation for these error and exception types available!"); }
#else
template <class S, class P> inline void _delayed_lookup_basic_outcome_failure_exception_from_error(...) = delete; // NOLINT No specialisation for these error and exception types available!
#endif
template <class exception_type> inline exception_type current_exception_or_fatal(std::exception_ptr e) { std::rethrow_exception(e); }
template <> inline std::exception_ptr current_exception_or_fatal<std::exception_ptr>(std::exception_ptr e) { return e; }
template <class Base, class R, class S, class P, class NoValuePolicy> class basic_outcome_failure_observers : public Base
{
public:
using exception_type = P;
using Base::Base;
exception_type failure() const noexcept
{
#ifdef __cpp_exceptions
try
#endif
{
if(this->_state._status.have_exception())
{
return this->assume_exception();
}
if(this->_state._status.have_error())
{
return _delayed_lookup_basic_outcome_failure_exception_from_error(this->assume_error(), adl::search_detail_adl());
}
return exception_type();
}
#ifdef __cpp_exceptions
catch(...)
{
// Return the failure if exception_type is std::exception_ptr,
// otherwise terminate same as throwing an exception inside noexcept
return current_exception_or_fatal<exception_type>(std::current_exception());
}
#endif
}
};
} // namespace detail
OUTCOME_V2_NAMESPACE_END
#endif
#ifdef __clang__
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdocumentation" // Standardese markup confuses clang
#endif
OUTCOME_V2_NAMESPACE_EXPORT_BEGIN
template <class R, class S, class P, class NoValuePolicy> //
class basic_outcome;
namespace detail
{
// May be reused by basic_outcome subclasses to save load on the compiler
template <class value_type, class error_type, class exception_type> struct outcome_predicates
{
using result = result_predicates<value_type, error_type>;
// Predicate for the implicit constructors to be available
static constexpr bool implicit_constructors_enabled = //
result::implicit_constructors_enabled //
&& !detail::is_implicitly_constructible<value_type, exception_type> //
&& !detail::is_implicitly_constructible<error_type, exception_type> //
&& !detail::is_implicitly_constructible<exception_type, value_type> //
&& !detail::is_implicitly_constructible<exception_type, error_type>;
// Predicate for the value converting constructor to be available.
template <class T>
static constexpr bool enable_value_converting_constructor = //
implicit_constructors_enabled //
&& result::template enable_value_converting_constructor<T> //
&& !detail::is_implicitly_constructible<exception_type, T>; // deliberately less tolerant of ambiguity than result's edition
// Predicate for the error converting constructor to be available.
template <class T>
static constexpr bool enable_error_converting_constructor = //
implicit_constructors_enabled //
&& result::template enable_error_converting_constructor<T> //
&& !detail::is_implicitly_constructible<exception_type, T>; // deliberately less tolerant of ambiguity than result's edition
// Predicate for the error condition converting constructor to be available.
template <class ErrorCondEnum>
static constexpr bool enable_error_condition_converting_constructor = result::template enable_error_condition_converting_constructor<ErrorCondEnum> //
&& !detail::is_implicitly_constructible<exception_type, ErrorCondEnum>;
// Predicate for the exception converting constructor to be available.
template <class T>
static constexpr bool enable_exception_converting_constructor = //
implicit_constructors_enabled //
&& !is_in_place_type_t<std::decay_t<T>>::value // not in place construction
&& !detail::is_implicitly_constructible<value_type, T> && !detail::is_implicitly_constructible<error_type, T> &&
detail::is_implicitly_constructible<exception_type, T>;
// Predicate for the error + exception converting constructor to be available.
template <class T, class U>
static constexpr bool enable_error_exception_converting_constructor = //
implicit_constructors_enabled //
&& !is_in_place_type_t<std::decay_t<T>>::value // not in place construction
&& !detail::is_implicitly_constructible<value_type, T> && detail::is_implicitly_constructible<error_type, T> //
&& !detail::is_implicitly_constructible<value_type, U> && detail::is_implicitly_constructible<exception_type, U>;
// Predicate for the converting copy constructor from a compatible outcome to be available.
template <class T, class U, class V, class W>
static constexpr bool enable_compatible_conversion = //
(std::is_void<T>::value ||
detail::is_explicitly_constructible<value_type, typename basic_outcome<T, U, V, W>::value_type>) // if our value types are constructible
&&(std::is_void<U>::value ||
detail::is_explicitly_constructible<error_type, typename basic_outcome<T, U, V, W>::error_type>) // if our error types are constructible
&&(std::is_void<V>::value ||
detail::is_explicitly_constructible<exception_type, typename basic_outcome<T, U, V, W>::exception_type>) // if our exception types are constructible
;
// Predicate for the converting constructor from a make_error_code() of the input to be available.
template <class T, class U, class V, class W>
static constexpr bool enable_make_error_code_compatible_conversion = //
trait::is_error_code_available<std::decay_t<error_type>>::value // if error type has an error code
&& !enable_compatible_conversion<T, U, V, W> // and the normal compatible conversion is not available
&& (std::is_void<T>::value ||
detail::is_explicitly_constructible<value_type, typename basic_outcome<T, U, V, W>::value_type>) // and if our value types are constructible
&&detail::is_explicitly_constructible<error_type,
typename trait::is_error_code_available<U>::type> // and our error type is constructible from a make_error_code()
&& (std::is_void<V>::value ||
detail::is_explicitly_constructible<exception_type, typename basic_outcome<T, U, V, W>::exception_type>); // and our exception types are constructible
// Predicate for the implicit converting inplace constructor from a compatible input to be available.
struct disable_inplace_value_error_exception_constructor;
template <class... Args>
using choose_inplace_value_error_exception_constructor = std::conditional_t< //
((static_cast<int>(detail::is_constructible<value_type, Args...>) + static_cast<int>(detail::is_constructible<error_type, Args...>) +
static_cast<int>(detail::is_constructible<exception_type, Args...>)) > 1), //
disable_inplace_value_error_exception_constructor, //
std::conditional_t< //
detail::is_constructible<value_type, Args...>, //
value_type, //
std::conditional_t< //
detail::is_constructible<error_type, Args...>, //
error_type, //
std::conditional_t< //
detail::is_constructible<exception_type, Args...>, //
exception_type, //
disable_inplace_value_error_exception_constructor>>>>;
template <class... Args>
static constexpr bool enable_inplace_value_error_exception_constructor = //
implicit_constructors_enabled &&
!std::is_same<choose_inplace_value_error_exception_constructor<Args...>, disable_inplace_value_error_exception_constructor>::value;
};
// Select whether to use basic_outcome_failure_observers or not
template <class Base, class R, class S, class P, class NoValuePolicy>
using select_basic_outcome_failure_observers = //
std::conditional_t<trait::is_error_code_available<S>::value && trait::is_exception_ptr_available<P>::value,
basic_outcome_failure_observers<Base, R, S, P, NoValuePolicy>, Base>;
template <class T, class U, class V> constexpr inline const V &extract_exception_from_failure(const failure_type<U, V> &v)
{
return v.exception();
}
template <class T, class U, class V> constexpr inline V &&extract_exception_from_failure(failure_type<U, V> &&v)
{
return static_cast<failure_type<U, V> &&>(v).exception();
}
template <class T, class U> constexpr inline const U &extract_exception_from_failure(const failure_type<U, void> &v)
{
return v.error();
}
template <class T, class U> constexpr inline U &&extract_exception_from_failure(failure_type<U, void> &&v)
{
return static_cast<failure_type<U, void> &&>(v).error();
}
template <class T> struct is_basic_outcome
{
static constexpr bool value = false;
};
template <class R, class S, class T, class N> struct is_basic_outcome<basic_outcome<R, S, T, N>>
{
static constexpr bool value = true;
};
} // namespace detail
/*! AWAITING HUGO JSON CONVERSION TOOL
type alias template <class T> is_basic_outcome. Potential doc page: `is_basic_outcome<T>`
*/
template <class T> using is_basic_outcome = detail::is_basic_outcome<std::decay_t<T>>;
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
template <class T> static constexpr bool is_basic_outcome_v = detail::is_basic_outcome<std::decay_t<T>>::value;
namespace concepts
{
#if defined(__cpp_concepts)
/* The `basic_outcome` concept.
\requires That `U` matches a `basic_outcome`.
*/
template <class U>
concept OUTCOME_GCC6_CONCEPT_BOOL basic_outcome =
OUTCOME_V2_NAMESPACE::is_basic_outcome<U>::value ||
(requires(U v) {
OUTCOME_V2_NAMESPACE::basic_outcome<typename U::value_type, typename U::error_type, typename U::exception_type, typename U::no_value_policy_type>(v);
} && //
detail::convertible<
U, OUTCOME_V2_NAMESPACE::basic_outcome<typename U::value_type, typename U::error_type, typename U::exception_type, typename U::no_value_policy_type>> && //
detail::base_of<
OUTCOME_V2_NAMESPACE::basic_outcome<typename U::value_type, typename U::error_type, typename U::exception_type, typename U::no_value_policy_type>, U>);
#else
namespace detail
{
inline no_match match_basic_outcome(...);
template <class R, class S, class P, class NVP, class T, //
typename = typename T::value_type, //
typename = typename T::error_type, //
typename = typename T::exception_type, //
typename = typename T::no_value_policy_type, //
typename std::enable_if_t<std::is_convertible<T, OUTCOME_V2_NAMESPACE::basic_outcome<R, S, P, NVP>>::value && //
std::is_base_of<OUTCOME_V2_NAMESPACE::basic_outcome<R, S, P, NVP>, T>::value,
bool> = true>
inline OUTCOME_V2_NAMESPACE::basic_outcome<R, S, P, NVP> match_basic_outcome(OUTCOME_V2_NAMESPACE::basic_outcome<R, S, P, NVP> &&, T &&);
template <class U>
static constexpr bool basic_outcome =
OUTCOME_V2_NAMESPACE::is_basic_outcome<U>::value ||
!std::is_same<no_match, decltype(match_basic_outcome(std::declval<OUTCOME_V2_NAMESPACE::detail::devoid<U>>(),
std::declval<OUTCOME_V2_NAMESPACE::detail::devoid<U>>()))>::value;
} // namespace detail
/* The `basic_outcome` concept.
\requires That `U` matches a `basic_outcome`.
*/
template <class U> static constexpr bool basic_outcome = detail::basic_outcome<U>;
#endif
} // namespace concepts
namespace hooks
{
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
template <class R, class S, class P, class NoValuePolicy, class U>
constexpr inline void override_outcome_exception(basic_outcome<R, S, P, NoValuePolicy> *o, U &&v) noexcept;
} // namespace hooks
/*! AWAITING HUGO JSON CONVERSION TOOL
type definition template <class R, class S, class P, class NoValuePolicy> basic_outcome. Potential doc page: `basic_outcome<T, EC, EP, NoValuePolicy>`
*/
template <class R, class S, class P, class NoValuePolicy> //
class OUTCOME_NODISCARD basic_outcome
: public detail::select_basic_outcome_failure_observers<
detail::basic_outcome_exception_observers<detail::basic_result_final<R, S, NoValuePolicy>, R, S, P, NoValuePolicy>, R, S, P, NoValuePolicy>
{
static_assert(trait::type_can_be_used_in_basic_result<P>, "The exception_type cannot be used");
static_assert(std::is_void<P>::value || std::is_default_constructible<P>::value, "exception_type must be void or default constructible");
using base = detail::select_basic_outcome_failure_observers<
detail::basic_outcome_exception_observers<detail::basic_result_final<R, S, NoValuePolicy>, R, S, P, NoValuePolicy>, R, S, P, NoValuePolicy>;
friend struct policy::base;
template <class T, class U, class V, class W> //
friend class basic_outcome;
template <class T, class U, class V, class W, class X>
friend constexpr inline void hooks::override_outcome_exception(basic_outcome<T, U, V, W> *o, X &&v) noexcept; // NOLINT
struct implicit_constructors_disabled_tag
{
};
struct value_converting_constructor_tag
{
};
struct error_converting_constructor_tag
{
};
struct error_condition_converting_constructor_tag
{
};
struct exception_converting_constructor_tag
{
};
struct error_exception_converting_constructor_tag
{
};
struct explicit_valueorerror_converting_constructor_tag
{
};
struct explicit_compatible_copy_conversion_tag
{
};
struct explicit_compatible_move_conversion_tag
{
};
struct explicit_make_error_code_compatible_copy_conversion_tag
{
};
struct explicit_make_error_code_compatible_move_conversion_tag
{
};
struct error_failure_tag
{
};
struct exception_failure_tag
{
};
struct disable_in_place_value_type
{
};
struct disable_in_place_error_type
{
};
struct disable_in_place_exception_type
{
};
public:
using value_type = R;
using error_type = S;
using exception_type = P;
using no_value_policy_type = NoValuePolicy;
template <class T, class U = S, class V = P, class W = NoValuePolicy> using rebind = basic_outcome<T, U, V, W>;
protected:
// Requirement predicates for outcome.
struct predicate
{
using base = detail::outcome_predicates<value_type, error_type, exception_type>;
// Predicate for any constructors to be available at all
static constexpr bool constructors_enabled =
(!std::is_same<std::decay_t<value_type>, std::decay_t<error_type>>::value || (std::is_void<value_type>::value && std::is_void<error_type>::value)) //
&& (!std::is_same<std::decay_t<value_type>, std::decay_t<exception_type>>::value ||
(std::is_void<value_type>::value && std::is_void<exception_type>::value)) //
&& (!std::is_same<std::decay_t<error_type>, std::decay_t<exception_type>>::value ||
(std::is_void<error_type>::value && std::is_void<exception_type>::value)) //
;
// Predicate for implicit constructors to be available at all
static constexpr bool implicit_constructors_enabled = constructors_enabled && base::implicit_constructors_enabled;
// Predicate for the value converting constructor to be available.
template <class T>
static constexpr bool enable_value_converting_constructor = //
constructors_enabled //
&& !std::is_same<std::decay_t<T>, basic_outcome>::value // not my type
&& base::template enable_value_converting_constructor<T>;
// Predicate for the error converting constructor to be available.
template <class T>
static constexpr bool enable_error_converting_constructor = //
constructors_enabled //
&& !std::is_same<std::decay_t<T>, basic_outcome>::value // not my type
&& base::template enable_error_converting_constructor<T>;
// Predicate for the error condition converting constructor to be available.
template <class ErrorCondEnum>
static constexpr bool enable_error_condition_converting_constructor = //
constructors_enabled //
&& !std::is_same<std::decay_t<ErrorCondEnum>, basic_outcome>::value // not my type
&& base::template enable_error_condition_converting_constructor<ErrorCondEnum>;
// Predicate for the exception converting constructor to be available.
template <class T>
static constexpr bool enable_exception_converting_constructor = //
constructors_enabled //
&& !std::is_same<std::decay_t<T>, basic_outcome>::value // not my type
&& base::template enable_exception_converting_constructor<T>;
// Predicate for the error + exception converting constructor to be available.
template <class T, class U>
static constexpr bool enable_error_exception_converting_constructor = //
constructors_enabled //
&& !std::is_same<std::decay_t<T>, basic_outcome>::value // not my type
&& base::template enable_error_exception_converting_constructor<T, U>;
// Predicate for the converting constructor from a compatible input to be available.
template <class T, class U, class V, class W>
static constexpr bool enable_compatible_conversion = //
constructors_enabled //
&& !std::is_same<basic_outcome<T, U, V, W>, basic_outcome>::value // not my type
&& base::template enable_compatible_conversion<T, U, V, W>;
// Predicate for the converting constructor from a make_error_code() of the input to be available.
template <class T, class U, class V, class W>
static constexpr bool enable_make_error_code_compatible_conversion = //
constructors_enabled //
&& !std::is_same<basic_outcome<T, U, V, W>, basic_outcome>::value // not my type
&& base::template enable_make_error_code_compatible_conversion<T, U, V, W>;
// Predicate for the inplace construction of value to be available.
template <class... Args>
static constexpr bool enable_inplace_value_constructor = //
constructors_enabled //
&& (std::is_void<value_type>::value //
|| detail::is_constructible<value_type, Args...>);
// Predicate for the inplace construction of error to be available.
template <class... Args>
static constexpr bool enable_inplace_error_constructor = //
constructors_enabled //
&& (std::is_void<error_type>::value //
|| detail::is_constructible<error_type, Args...>);
// Predicate for the inplace construction of exception to be available.
template <class... Args>
static constexpr bool enable_inplace_exception_constructor = //
constructors_enabled //
&& (std::is_void<exception_type>::value //
|| detail::is_constructible<exception_type, Args...>);
// Predicate for the implicit converting inplace constructor to be available.
template <class... Args>
static constexpr bool enable_inplace_value_error_exception_constructor = //
constructors_enabled //
&& base::template enable_inplace_value_error_exception_constructor<Args...>;
template <class... Args>
using choose_inplace_value_error_exception_constructor = typename base::template choose_inplace_value_error_exception_constructor<Args...>;
};
public:
using value_type_if_enabled =
std::conditional_t<std::is_same<value_type, error_type>::value || std::is_same<value_type, exception_type>::value, disable_in_place_value_type, value_type>;
using error_type_if_enabled =
std::conditional_t<std::is_same<error_type, value_type>::value || std::is_same<error_type, exception_type>::value, disable_in_place_error_type, error_type>;
using exception_type_if_enabled = std::conditional_t<std::is_same<exception_type, value_type>::value || std::is_same<exception_type, error_type>::value,
disable_in_place_exception_type, exception_type>;
protected:
detail::devoid<exception_type> _ptr;
public:
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class Arg, class... Args)
OUTCOME_TREQUIRES(OUTCOME_TPRED((!predicate::constructors_enabled && sizeof...(Args) >= 0)))
basic_outcome(Arg && /*unused*/, Args &&.../*unused*/) = delete; // NOLINT basic_outcome<> with any of the same type is NOT SUPPORTED, see docs!
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class T)
OUTCOME_TREQUIRES(OUTCOME_TPRED((predicate::constructors_enabled && !predicate::implicit_constructors_enabled //
&& (detail::is_implicitly_constructible<value_type, T> || detail::is_implicitly_constructible<error_type, T> ||
detail::is_implicitly_constructible<exception_type, T>) )))
basic_outcome(T && /*unused*/, implicit_constructors_disabled_tag /*unused*/ = implicit_constructors_disabled_tag()) =
delete; // NOLINT Implicit constructors disabled, use explicit in_place_type<T>, success() or failure(). see docs!
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class T)
OUTCOME_TREQUIRES(OUTCOME_TPRED(predicate::template enable_value_converting_constructor<T>))
constexpr basic_outcome(T &&t, value_converting_constructor_tag /*unused*/ = value_converting_constructor_tag()) noexcept(
detail::is_nothrow_constructible<value_type, T>) // NOLINT
: base{in_place_type<typename base::_value_type>, static_cast<T &&>(t)}
, _ptr()
{
no_value_policy_type::on_outcome_construction(this, static_cast<T &&>(t));
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class T)
OUTCOME_TREQUIRES(OUTCOME_TPRED(predicate::template enable_error_converting_constructor<T>))
constexpr basic_outcome(T &&t, error_converting_constructor_tag /*unused*/ = error_converting_constructor_tag()) noexcept(
detail::is_nothrow_constructible<error_type, T>) // NOLINT
: base{in_place_type<typename base::_error_type>, static_cast<T &&>(t)}
, _ptr()
{
no_value_policy_type::on_outcome_construction(this, static_cast<T &&>(t));
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class ErrorCondEnum)
OUTCOME_TREQUIRES(OUTCOME_TEXPR(error_type(make_error_code(ErrorCondEnum()))), //
OUTCOME_TPRED(predicate::template enable_error_condition_converting_constructor<ErrorCondEnum>))
constexpr basic_outcome(ErrorCondEnum &&t, error_condition_converting_constructor_tag /*unused*/ = error_condition_converting_constructor_tag()) noexcept(
noexcept(error_type(make_error_code(static_cast<ErrorCondEnum &&>(t))))) // NOLINT
: base{in_place_type<typename base::_error_type>, make_error_code(t)}
{
no_value_policy_type::on_outcome_construction(this, static_cast<ErrorCondEnum &&>(t));
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class T)
OUTCOME_TREQUIRES(OUTCOME_TPRED(predicate::template enable_exception_converting_constructor<T>))
constexpr basic_outcome(T &&t, exception_converting_constructor_tag /*unused*/ = exception_converting_constructor_tag()) noexcept(
detail::is_nothrow_constructible<exception_type, T>) // NOLINT
: base()
, _ptr(static_cast<T &&>(t))
{
this->_state._status.set_have_exception(true);
no_value_policy_type::on_outcome_construction(this, static_cast<T &&>(t));
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class T, class U)
OUTCOME_TREQUIRES(OUTCOME_TPRED(predicate::template enable_error_exception_converting_constructor<T, U>))
constexpr basic_outcome(T &&a, U &&b, error_exception_converting_constructor_tag /*unused*/ = error_exception_converting_constructor_tag()) noexcept(
detail::is_nothrow_constructible<error_type, T> && detail::is_nothrow_constructible<exception_type, U>) // NOLINT
: base{in_place_type<typename base::_error_type>, static_cast<T &&>(a)}
, _ptr(static_cast<U &&>(b))
{
this->_state._status.set_have_exception(true);
no_value_policy_type::on_outcome_construction(this, static_cast<T &&>(a), static_cast<U &&>(b));
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class T)
OUTCOME_TREQUIRES(OUTCOME_TPRED(convert::value_or_error<basic_outcome, std::decay_t<T>>::enable_result_inputs || !concepts::basic_result<T>), //
OUTCOME_TPRED(convert::value_or_error<basic_outcome, std::decay_t<T>>::enable_outcome_inputs || !concepts::basic_outcome<T>), //
OUTCOME_TEXPR(convert::value_or_error<basic_outcome, std::decay_t<T>>{}(std::declval<T>())))
constexpr explicit basic_outcome(T &&o,
explicit_valueorerror_converting_constructor_tag /*unused*/ = explicit_valueorerror_converting_constructor_tag()) // NOLINT
: basic_outcome{convert::value_or_error<basic_outcome, std::decay_t<T>>{}(static_cast<T &&>(o))}
{
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class T, class U, class V, class W)
OUTCOME_TREQUIRES(OUTCOME_TPRED(predicate::template enable_compatible_conversion<T, U, V, W>))
constexpr explicit basic_outcome(
const basic_outcome<T, U, V, W> &o,
explicit_compatible_copy_conversion_tag /*unused*/ = explicit_compatible_copy_conversion_tag()) noexcept(detail::is_nothrow_constructible<value_type, T> &&
detail::is_nothrow_constructible<error_type, U> &&
detail::is_nothrow_constructible<exception_type, V>)
: base{typename base::compatible_conversion_tag(), o}
, _ptr(o._ptr)
{
no_value_policy_type::on_outcome_copy_construction(this, o);
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class T, class U, class V, class W)
OUTCOME_TREQUIRES(OUTCOME_TPRED(predicate::template enable_compatible_conversion<T, U, V, W>))
constexpr explicit basic_outcome(
basic_outcome<T, U, V, W> &&o,
explicit_compatible_move_conversion_tag /*unused*/ = explicit_compatible_move_conversion_tag()) noexcept(detail::is_nothrow_constructible<value_type, T> &&
detail::is_nothrow_constructible<error_type, U> &&
detail::is_nothrow_constructible<exception_type, V>)
: base{typename base::compatible_conversion_tag(), static_cast<basic_outcome<T, U, V, W> &&>(o)}
, _ptr(static_cast<typename basic_outcome<T, U, V, W>::exception_type &&>(o._ptr))
{
no_value_policy_type::on_outcome_move_construction(this, static_cast<basic_outcome<T, U, V, W> &&>(o));
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class T, class U, class V)
OUTCOME_TREQUIRES(OUTCOME_TPRED(detail::result_predicates<value_type, error_type>::template enable_compatible_conversion<T, U, V>))
constexpr explicit basic_outcome(
const basic_result<T, U, V> &o,
explicit_compatible_copy_conversion_tag /*unused*/ = explicit_compatible_copy_conversion_tag()) noexcept(detail::is_nothrow_constructible<value_type, T> &&
detail::is_nothrow_constructible<error_type, U> &&
detail::is_nothrow_constructible<exception_type>)
: base{typename base::compatible_conversion_tag(), o}
, _ptr()
{
no_value_policy_type::on_outcome_copy_construction(this, o);
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class T, class U, class V)
OUTCOME_TREQUIRES(OUTCOME_TPRED(detail::result_predicates<value_type, error_type>::template enable_compatible_conversion<T, U, V>))
constexpr explicit basic_outcome(
basic_result<T, U, V> &&o,
explicit_compatible_move_conversion_tag /*unused*/ = explicit_compatible_move_conversion_tag()) noexcept(detail::is_nothrow_constructible<value_type, T> &&
detail::is_nothrow_constructible<error_type, U> &&
detail::is_nothrow_constructible<exception_type>)
: base{typename base::compatible_conversion_tag(), static_cast<basic_result<T, U, V> &&>(o)}
, _ptr()
{
no_value_policy_type::on_outcome_move_construction(this, static_cast<basic_result<T, U, V> &&>(o));
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class T, class U, class V)
OUTCOME_TREQUIRES(OUTCOME_TPRED(detail::result_predicates<value_type, error_type>::template enable_make_error_code_compatible_conversion<T, U, V>))
constexpr explicit basic_outcome(const basic_result<T, U, V> &o,
explicit_make_error_code_compatible_copy_conversion_tag /*unused*/ =
explicit_make_error_code_compatible_copy_conversion_tag()) noexcept(detail::is_nothrow_constructible<value_type, T> &&
noexcept(make_error_code(std::declval<U>())) &&
detail::is_nothrow_constructible<exception_type>)
: base{typename base::make_error_code_compatible_conversion_tag(), o}
, _ptr()
{
no_value_policy_type::on_outcome_copy_construction(this, o);
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class T, class U, class V)
OUTCOME_TREQUIRES(OUTCOME_TPRED(detail::result_predicates<value_type, error_type>::template enable_make_error_code_compatible_conversion<T, U, V>))
constexpr explicit basic_outcome(basic_result<T, U, V> &&o,
explicit_make_error_code_compatible_move_conversion_tag /*unused*/ =
explicit_make_error_code_compatible_move_conversion_tag()) noexcept(detail::is_nothrow_constructible<value_type, T> &&
noexcept(make_error_code(std::declval<U>())) &&
detail::is_nothrow_constructible<exception_type>)
: base{typename base::make_error_code_compatible_conversion_tag(), static_cast<basic_result<T, U, V> &&>(o)}
, _ptr()
{
no_value_policy_type::on_outcome_move_construction(this, static_cast<basic_result<T, U, V> &&>(o));
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class... Args)
OUTCOME_TREQUIRES(OUTCOME_TPRED(predicate::template enable_inplace_value_constructor<Args...>))
constexpr explicit basic_outcome(in_place_type_t<value_type_if_enabled> _, Args &&...args) noexcept(detail::is_nothrow_constructible<value_type, Args...>)
: base{_, static_cast<Args &&>(args)...}
, _ptr()
{
no_value_policy_type::on_outcome_in_place_construction(this, in_place_type<value_type>, static_cast<Args &&>(args)...);
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class U, class... Args)
OUTCOME_TREQUIRES(OUTCOME_TPRED(predicate::template enable_inplace_value_constructor<std::initializer_list<U>, Args...>))
constexpr explicit basic_outcome(in_place_type_t<value_type_if_enabled> _, std::initializer_list<U> il,
Args &&...args) noexcept(detail::is_nothrow_constructible<value_type, std::initializer_list<U>, Args...>)
: base{_, il, static_cast<Args &&>(args)...}
, _ptr()
{
no_value_policy_type::on_outcome_in_place_construction(this, in_place_type<value_type>, il, static_cast<Args &&>(args)...);
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class... Args)
OUTCOME_TREQUIRES(OUTCOME_TPRED(predicate::template enable_inplace_error_constructor<Args...>))
constexpr explicit basic_outcome(in_place_type_t<error_type_if_enabled> _, Args &&...args) noexcept(detail::is_nothrow_constructible<error_type, Args...>)
: base{_, static_cast<Args &&>(args)...}
, _ptr()
{
no_value_policy_type::on_outcome_in_place_construction(this, in_place_type<error_type>, static_cast<Args &&>(args)...);
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class U, class... Args)
OUTCOME_TREQUIRES(OUTCOME_TPRED(predicate::template enable_inplace_error_constructor<std::initializer_list<U>, Args...>))
constexpr explicit basic_outcome(in_place_type_t<error_type_if_enabled> _, std::initializer_list<U> il,
Args &&...args) noexcept(detail::is_nothrow_constructible<error_type, std::initializer_list<U>, Args...>)
: base{_, il, static_cast<Args &&>(args)...}
, _ptr()
{
no_value_policy_type::on_outcome_in_place_construction(this, in_place_type<error_type>, il, static_cast<Args &&>(args)...);
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class... Args)
OUTCOME_TREQUIRES(OUTCOME_TPRED(predicate::template enable_inplace_exception_constructor<Args...>))
constexpr explicit basic_outcome(in_place_type_t<exception_type_if_enabled> /*unused*/,
Args &&...args) noexcept(detail::is_nothrow_constructible<exception_type, Args...>)
: base()
, _ptr(static_cast<Args &&>(args)...)
{
this->_state._status.set_have_exception(true);
no_value_policy_type::on_outcome_in_place_construction(this, in_place_type<exception_type>, static_cast<Args &&>(args)...);
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class U, class... Args)
OUTCOME_TREQUIRES(OUTCOME_TPRED(predicate::template enable_inplace_exception_constructor<std::initializer_list<U>, Args...>))
constexpr explicit basic_outcome(in_place_type_t<exception_type_if_enabled> /*unused*/, std::initializer_list<U> il,
Args &&...args) noexcept(detail::is_nothrow_constructible<exception_type, std::initializer_list<U>, Args...>)
: base()
, _ptr(il, static_cast<Args &&>(args)...)
{
this->_state._status.set_have_exception(true);
no_value_policy_type::on_outcome_in_place_construction(this, in_place_type<exception_type>, il, static_cast<Args &&>(args)...);
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class A1, class A2, class... Args)
OUTCOME_TREQUIRES(OUTCOME_TPRED(predicate::template enable_inplace_value_error_exception_constructor<A1, A2, Args...>))
constexpr basic_outcome(A1 &&a1, A2 &&a2, Args &&...args) noexcept(
noexcept(typename predicate::template choose_inplace_value_error_exception_constructor<A1, A2, Args...>(std::declval<A1>(), std::declval<A2>(),
std::declval<Args>()...)))
: basic_outcome(in_place_type<typename predicate::template choose_inplace_value_error_exception_constructor<A1, A2, Args...>>, static_cast<A1 &&>(a1),
static_cast<A2 &&>(a2), static_cast<Args &&>(args)...)
{
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
constexpr basic_outcome(const success_type<void> &o) noexcept(std::is_nothrow_default_constructible<value_type>::value) // NOLINT
: base{in_place_type<typename base::_value_type>}
{
hooks::set_spare_storage(this, o.spare_storage());
no_value_policy_type::on_outcome_copy_construction(this, o);
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class T)
OUTCOME_TREQUIRES(OUTCOME_TPRED(!std::is_void<T>::value && predicate::template enable_compatible_conversion<T, void, void, void>))
constexpr basic_outcome(const success_type<T> &o) noexcept(detail::is_nothrow_constructible<value_type, T>) // NOLINT
: base{in_place_type<typename base::_value_type>, detail::extract_value_from_success<value_type>(o)}
{
hooks::set_spare_storage(this, o.spare_storage());
no_value_policy_type::on_outcome_copy_construction(this, o);
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class T)
OUTCOME_TREQUIRES(OUTCOME_TPRED(!std::is_void<T>::value && predicate::template enable_compatible_conversion<T, void, void, void>))
constexpr basic_outcome(success_type<T> &&o) noexcept(detail::is_nothrow_constructible<value_type, T>) // NOLINT
: base{in_place_type<typename base::_value_type>, detail::extract_value_from_success<value_type>(static_cast<success_type<T> &&>(o))}
{
hooks::set_spare_storage(this, o.spare_storage());
no_value_policy_type::on_outcome_move_construction(this, static_cast<success_type<T> &&>(o));
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class T)
OUTCOME_TREQUIRES(OUTCOME_TPRED(!std::is_void<T>::value && predicate::template enable_compatible_conversion<void, T, void, void>))
constexpr basic_outcome(const failure_type<T> &o,
error_failure_tag /*unused*/ = error_failure_tag()) noexcept(detail::is_nothrow_constructible<error_type, T>) // NOLINT
: base{in_place_type<typename base::_error_type>, detail::extract_error_from_failure<error_type>(o)}
, _ptr()
{
hooks::set_spare_storage(this, o.spare_storage());
no_value_policy_type::on_outcome_copy_construction(this, o);
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class T)
OUTCOME_TREQUIRES(OUTCOME_TPRED(!std::is_void<T>::value && predicate::template enable_compatible_conversion<void, void, T, void>))
constexpr basic_outcome(const failure_type<T> &o,
exception_failure_tag /*unused*/ = exception_failure_tag()) noexcept(detail::is_nothrow_constructible<exception_type, T>) // NOLINT
: base()
, _ptr(detail::extract_exception_from_failure<exception_type>(o))
{
this->_state._status.set_have_exception(true);
hooks::set_spare_storage(this, o.spare_storage());
no_value_policy_type::on_outcome_copy_construction(this, o);
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class T)
OUTCOME_TREQUIRES(OUTCOME_TPRED(!std::is_void<T>::value && predicate::template enable_make_error_code_compatible_conversion<void, T, void, void>))
constexpr basic_outcome(const failure_type<T> &o,
explicit_make_error_code_compatible_copy_conversion_tag /*unused*/ =
explicit_make_error_code_compatible_copy_conversion_tag()) noexcept(noexcept(make_error_code(std::declval<T>()))) // NOLINT
: base{in_place_type<typename base::_error_type>, make_error_code(detail::extract_error_from_failure<error_type>(o))}
, _ptr()
{
hooks::set_spare_storage(this, o.spare_storage());
no_value_policy_type::on_outcome_copy_construction(this, o);
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class T, class U)
OUTCOME_TREQUIRES(OUTCOME_TPRED(!std::is_void<U>::value && predicate::template enable_compatible_conversion<void, T, U, void>))
constexpr basic_outcome(const failure_type<T, U> &o, explicit_compatible_copy_conversion_tag /*unused*/ = explicit_compatible_copy_conversion_tag()) noexcept(
detail::is_nothrow_constructible<error_type, T> && detail::is_nothrow_constructible<exception_type, U>) // NOLINT
: base{in_place_type<typename base::_error_type>, detail::extract_error_from_failure<error_type>(o)}
, _ptr(detail::extract_exception_from_failure<exception_type>(o))
{
if(!o.has_error())
{
this->_state._status.set_have_error(false);
}
if(o.has_exception())
{
this->_state._status.set_have_exception(true);
}
hooks::set_spare_storage(this, o.spare_storage());
no_value_policy_type::on_outcome_copy_construction(this, o);
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class T)
OUTCOME_TREQUIRES(OUTCOME_TPRED(!std::is_void<T>::value && predicate::template enable_compatible_conversion<void, T, void, void>))
constexpr basic_outcome(failure_type<T> &&o,
error_failure_tag /*unused*/ = error_failure_tag()) noexcept(detail::is_nothrow_constructible<error_type, T>) // NOLINT
: base{in_place_type<typename base::_error_type>, detail::extract_error_from_failure<error_type>(static_cast<failure_type<T> &&>(o))}
, _ptr()
{
hooks::set_spare_storage(this, o.spare_storage());
no_value_policy_type::on_outcome_copy_construction(this, o);
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class T)
OUTCOME_TREQUIRES(OUTCOME_TPRED(!std::is_void<T>::value && predicate::template enable_compatible_conversion<void, void, T, void>))
constexpr basic_outcome(failure_type<T> &&o,
exception_failure_tag /*unused*/ = exception_failure_tag()) noexcept(detail::is_nothrow_constructible<exception_type, T>) // NOLINT
: base()
, _ptr(detail::extract_exception_from_failure<exception_type>(static_cast<failure_type<T> &&>(o)))
{
this->_state._status.set_have_exception(true);
hooks::set_spare_storage(this, o.spare_storage());
no_value_policy_type::on_outcome_copy_construction(this, o);
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class T)
OUTCOME_TREQUIRES(OUTCOME_TPRED(!std::is_void<T>::value && predicate::template enable_make_error_code_compatible_conversion<void, T, void, void>))
constexpr basic_outcome(failure_type<T> &&o,
explicit_make_error_code_compatible_move_conversion_tag /*unused*/ =
explicit_make_error_code_compatible_move_conversion_tag()) noexcept(noexcept(make_error_code(std::declval<T>()))) // NOLINT
: base{in_place_type<typename base::_error_type>, make_error_code(detail::extract_error_from_failure<error_type>(static_cast<failure_type<T> &&>(o)))}
, _ptr()
{
hooks::set_spare_storage(this, o.spare_storage());
no_value_policy_type::on_outcome_copy_construction(this, o);
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class T, class U)
OUTCOME_TREQUIRES(OUTCOME_TPRED(!std::is_void<U>::value && predicate::template enable_compatible_conversion<void, T, U, void>))
constexpr basic_outcome(failure_type<T, U> &&o, explicit_compatible_move_conversion_tag /*unused*/ = explicit_compatible_move_conversion_tag()) noexcept(
detail::is_nothrow_constructible<error_type, T> && detail::is_nothrow_constructible<exception_type, U>) // NOLINT
: base{in_place_type<typename base::_error_type>, detail::extract_error_from_failure<error_type>(static_cast<failure_type<T, U> &&>(o))}
, _ptr(detail::extract_exception_from_failure<exception_type>(static_cast<failure_type<T, U> &&>(o)))
{
if(!o.has_error())
{
this->_state._status.set_have_error(false);
}
if(o.has_exception())
{
this->_state._status.set_have_exception(true);
}
hooks::set_spare_storage(this, o.spare_storage());
no_value_policy_type::on_outcome_move_construction(this, static_cast<failure_type<T, U> &&>(o));
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
using base::operator==;
using base::operator!=;
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class T, class U, class V, class W)
OUTCOME_TREQUIRES(OUTCOME_TEXPR(std::declval<detail::devoid<value_type>>() == std::declval<detail::devoid<T>>()), //
OUTCOME_TEXPR(std::declval<detail::devoid<error_type>>() == std::declval<detail::devoid<U>>()), //
OUTCOME_TEXPR(std::declval<detail::devoid<exception_type>>() == std::declval<detail::devoid<V>>()))
constexpr bool operator==(const basic_outcome<T, U, V, W> &o) const noexcept( //
noexcept(std::declval<detail::devoid<value_type>>() == std::declval<detail::devoid<T>>()) //
&& noexcept(std::declval<detail::devoid<error_type>>() == std::declval<detail::devoid<U>>()) //
&& noexcept(std::declval<detail::devoid<exception_type>>() == std::declval<detail::devoid<V>>()))
{
if(this->_state._status.have_value() && o._state._status.have_value())
{
return this->_state._value == o._state._value; // NOLINT
}
if(this->_state._status.have_error() && o._state._status.have_error() //
&& this->_state._status.have_exception() && o._state._status.have_exception())
{
return this->_state._error == o._state._error && this->_ptr == o._ptr;
}
if(this->_state._status.have_error() && o._state._status.have_error())
{
return this->_state._error == o._state._error;
}
if(this->_state._status.have_exception() && o._state._status.have_exception())
{
return this->_ptr == o._ptr;
}
return false;
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class T, class U)
OUTCOME_TREQUIRES(OUTCOME_TEXPR(std::declval<error_type>() == std::declval<T>()), //
OUTCOME_TEXPR(std::declval<exception_type>() == std::declval<U>()))
constexpr bool operator==(const failure_type<T, U> &o) const noexcept( //
noexcept(std::declval<error_type>() == std::declval<T>()) && noexcept(std::declval<exception_type>() == std::declval<U>()))
{
if(this->_state._status.have_error() && o._state._status.have_error() //
&& this->_state._status.have_exception() && o._state._status.have_exception())
{
return this->_state._error == o.error() && this->_ptr == o.exception();
}
if(this->_state._status.have_error() && o._state._status.have_error())
{
return this->_state._error == o.error();
}
if(this->_state._status.have_exception() && o._state._status.have_exception())
{
return this->_ptr == o.exception();
}
return false;
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class T, class U, class V, class W)
OUTCOME_TREQUIRES(OUTCOME_TEXPR(std::declval<detail::devoid<value_type>>() != std::declval<detail::devoid<T>>()), //
OUTCOME_TEXPR(std::declval<detail::devoid<error_type>>() != std::declval<detail::devoid<U>>()), //
OUTCOME_TEXPR(std::declval<detail::devoid<exception_type>>() != std::declval<detail::devoid<V>>()))
constexpr bool operator!=(const basic_outcome<T, U, V, W> &o) const noexcept( //
noexcept(std::declval<detail::devoid<value_type>>() != std::declval<detail::devoid<T>>()) //
&& noexcept(std::declval<detail::devoid<error_type>>() != std::declval<detail::devoid<U>>()) //
&& noexcept(std::declval<detail::devoid<exception_type>>() != std::declval<detail::devoid<V>>()))
{
if(this->_state._status.have_value() && o._state._status.have_value())
{
return this->_state._value != o._state._value; // NOLINT
}
if(this->_state._status.have_error() && o._state._status.have_error() //
&& this->_state._status.have_exception() && o._state._status.have_exception())
{
return this->_state._error != o._state._error || this->_ptr != o._ptr;
}
if(this->_state._status.have_error() && o._state._status.have_error())
{
return this->_state._error != o._state._error;
}
if(this->_state._status.have_exception() && o._state._status.have_exception())
{
return this->_ptr != o._ptr;
}
return true;
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class T, class U)
OUTCOME_TREQUIRES(OUTCOME_TEXPR(std::declval<error_type>() != std::declval<T>()), //
OUTCOME_TEXPR(std::declval<exception_type>() != std::declval<U>()))
constexpr bool operator!=(const failure_type<T, U> &o) const noexcept( //
noexcept(std::declval<error_type>() == std::declval<T>()) && noexcept(std::declval<exception_type>() == std::declval<U>()))
{
if(this->_state._status.have_error() && o._state._status.have_error() //
&& this->_state._status.have_exception() && o._state._status.have_exception())
{
return this->_state._error != o.error() || this->_ptr != o.exception();
}
if(this->_state._status.have_error() && o._state._status.have_error())
{
return this->_state._error != o.error();
}
if(this->_state._status.have_exception() && o._state._status.have_exception())
{
return this->_ptr != o.exception();
}
return true;
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
constexpr void swap(basic_outcome &o) noexcept((std::is_void<value_type>::value || detail::is_nothrow_swappable<value_type>::value) //
&& (std::is_void<error_type>::value || detail::is_nothrow_swappable<error_type>::value) //
&& (std::is_void<exception_type>::value || detail::is_nothrow_swappable<exception_type>::value))
{
#ifdef __cpp_exceptions
constexpr bool value_throws = !std::is_void<value_type>::value && !detail::is_nothrow_swappable<value_type>::value;
constexpr bool error_throws = !std::is_void<error_type>::value && !detail::is_nothrow_swappable<error_type>::value;
constexpr bool exception_throws = !std::is_void<exception_type>::value && !detail::is_nothrow_swappable<exception_type>::value;
#ifdef _MSC_VER
#pragma warning(push)
#pragma warning(disable : 4127) // conditional expression is constant
#endif
if(!exception_throws && !value_throws && !error_throws)
{
// Simples
this->_state.swap(o._state);
using std::swap;
swap(this->_ptr, o._ptr);
return;
}
struct some_type
{
basic_outcome &a, &b;
bool exceptioned{false};
bool all_good{false};
~some_type()
{
if(!this->all_good)
{
// We lost one of the values
this->a._state._status.set_have_lost_consistency(true);
this->b._state._status.set_have_lost_consistency(true);
return;
}
if(this->exceptioned)
{
// The value + error swap threw an exception. Try to swap back _ptr
try
{
strong_swap(this->all_good, this->a._ptr, this->b._ptr);
}
catch(...)
{
// We lost one of the values
this->a._state._status.set_have_lost_consistency(true);
this->b._state._status.set_have_lost_consistency(true);
// throw away second exception
}
// Prevent has_value() == has_error() or has_value() == has_exception()
auto check = [](basic_outcome *t)
{
if(t->has_value() && (t->has_error() || t->has_exception()))
{
t->_state._status.set_have_error(false).set_have_exception(false);
t->_state._status.set_have_lost_consistency(true);
}
if(!t->has_value() && !(t->has_error() || t->has_exception()))
{
// Choose error, for no particular reason
t->_state._status.set_have_error(true).set_have_lost_consistency(true);
}
};
check(&this->a);
check(&this->b);
}
}
} some_type_value{*this, o};
strong_swap(some_type_value.all_good, this->_ptr, o._ptr);
some_type_value.exceptioned = true;
this->_state.swap(o._state);
some_type_value.exceptioned = false;
#ifdef _MSC_VER
#pragma warning(pop)
#endif
#else
this->_state.swap(o._state);
using std::swap;
swap(this->_ptr, o._ptr);
#endif
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
failure_type<error_type, exception_type> as_failure() const &
{
if(this->has_error() && this->has_exception())
{
return failure_type<error_type, exception_type>(this->assume_error(), this->assume_exception(), hooks::spare_storage(this));
}
if(this->has_exception())
{
return failure_type<error_type, exception_type>(in_place_type<exception_type>, this->assume_exception(), hooks::spare_storage(this));
}
return failure_type<error_type, exception_type>(in_place_type<error_type>, this->assume_error(), hooks::spare_storage(this));
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
failure_type<error_type, exception_type> as_failure() &&
{
this->_state._status.set_have_moved_from(true);
if(this->has_error() && this->has_exception())
{
return failure_type<error_type, exception_type>(static_cast<S &&>(this->assume_error()), static_cast<P &&>(this->assume_exception()),
hooks::spare_storage(this));
}
if(this->has_exception())
{
return failure_type<error_type, exception_type>(in_place_type<exception_type>, static_cast<P &&>(this->assume_exception()), hooks::spare_storage(this));
}
return failure_type<error_type, exception_type>(in_place_type<error_type>, static_cast<S &&>(this->assume_error()), hooks::spare_storage(this));
}
#ifdef __APPLE__
failure_type<error_type, exception_type> _xcode_workaround_as_failure() &&;
#endif
};
// C++ 20 operator== rewriting should take care of this for us, indeed
// if we don't disable it, we cause Concept recursion to infinity!
#if __cplusplus < 202000L && !_HAS_CXX20
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class T, class U, class V, //
class R, class S, class P, class N)
OUTCOME_TREQUIRES(OUTCOME_TEXPR(std::declval<basic_outcome<R, S, P, N>>() == std::declval<basic_result<T, U, V>>()))
constexpr inline bool operator==(const basic_result<T, U, V> &a, const basic_outcome<R, S, P, N> &b) noexcept( //
noexcept(std::declval<basic_outcome<R, S, P, N>>() == std::declval<basic_result<T, U, V>>()))
{
return b == a;
}
#endif
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class T, class U, class V, //
class R, class S, class P, class N)
OUTCOME_TREQUIRES(OUTCOME_TEXPR(std::declval<basic_outcome<R, S, P, N>>() != std::declval<basic_result<T, U, V>>()))
constexpr inline bool operator!=(const basic_result<T, U, V> &a, const basic_outcome<R, S, P, N> &b) noexcept( //
noexcept(std::declval<basic_outcome<R, S, P, N>>() != std::declval<basic_result<T, U, V>>()))
{
return b != a;
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
template <class R, class S, class P, class N> inline void swap(basic_outcome<R, S, P, N> &a, basic_outcome<R, S, P, N> &b) noexcept(noexcept(a.swap(b)))
{
a.swap(b);
}
namespace hooks
{
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
template <class R, class S, class P, class NoValuePolicy, class U>
constexpr inline void override_outcome_exception(basic_outcome<R, S, P, NoValuePolicy> *o, U &&v) noexcept
{
o->_ptr = static_cast<U &&>(v); // NOLINT
o->_state._status.set_have_exception(true);
}
} // namespace hooks
OUTCOME_V2_NAMESPACE_END
#ifdef __clang__
#pragma clang diagnostic pop
#endif
/* Exception observers for outcome type
(C) 2017-2019 Niall Douglas <http://www.nedproductions.biz/> (6 commits)
File Created: Oct 2017
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License in the accompanying file
Licence.txt or at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Distributed under the Boost Software License, Version 1.0.
(See accompanying file Licence.txt or copy at
http://www.boost.org/LICENSE_1_0.txt)
*/
#ifndef OUTCOME_BASIC_OUTCOME_EXCEPTION_OBSERVERS_IMPL_HPP
#define OUTCOME_BASIC_OUTCOME_EXCEPTION_OBSERVERS_IMPL_HPP
OUTCOME_V2_NAMESPACE_EXPORT_BEGIN
namespace policy
{
template <class R, class S, class P, class NoValuePolicy, class Impl> inline constexpr auto &&base::_exception(Impl &&self) noexcept
{
// Impl will be some internal implementation class which has no knowledge of the _ptr stored
// beneath it. So statically cast, preserving rvalue and constness, to the derived class.
using Outcome = OUTCOME_V2_NAMESPACE::detail::rebind_type<basic_outcome<R, S, P, NoValuePolicy>, decltype(self)>;
#if defined(_MSC_VER) && _MSC_VER < 1920
// VS2017 tries a copy construction in the correct implementation despite that Outcome is always a rvalue or lvalue ref! :(
basic_outcome<R, S, P, NoValuePolicy> &_self = (basic_outcome<R, S, P, NoValuePolicy> &) (self); // NOLINT
#else
Outcome _self = static_cast<Outcome>(self); // NOLINT
#endif
return static_cast<Outcome>(_self)._ptr;
}
} // namespace policy
namespace detail
{
template <class Base, class R, class S, class P, class NoValuePolicy> inline constexpr typename basic_outcome_exception_observers<Base, R, S, P, NoValuePolicy>::exception_type &basic_outcome_exception_observers<Base, R, S, P, NoValuePolicy>::assume_exception() & noexcept
{
NoValuePolicy::narrow_exception_check(*this);
return NoValuePolicy::template _exception<R, S, P, NoValuePolicy>(*this);
}
template <class Base, class R, class S, class P, class NoValuePolicy> inline constexpr const typename basic_outcome_exception_observers<Base, R, S, P, NoValuePolicy>::exception_type &basic_outcome_exception_observers<Base, R, S, P, NoValuePolicy>::assume_exception() const &noexcept
{
NoValuePolicy::narrow_exception_check(*this);
return NoValuePolicy::template _exception<R, S, P, NoValuePolicy>(*this);
}
template <class Base, class R, class S, class P, class NoValuePolicy> inline constexpr typename basic_outcome_exception_observers<Base, R, S, P, NoValuePolicy>::exception_type &&basic_outcome_exception_observers<Base, R, S, P, NoValuePolicy>::assume_exception() && noexcept
{
NoValuePolicy::narrow_exception_check(std::move(*this));
return NoValuePolicy::template _exception<R, S, P, NoValuePolicy>(std::move(*this));
}
template <class Base, class R, class S, class P, class NoValuePolicy> inline constexpr const typename basic_outcome_exception_observers<Base, R, S, P, NoValuePolicy>::exception_type &&basic_outcome_exception_observers<Base, R, S, P, NoValuePolicy>::assume_exception() const &&noexcept
{
NoValuePolicy::narrow_exception_check(std::move(*this));
return NoValuePolicy::template _exception<R, S, P, NoValuePolicy>(std::move(*this));
}
template <class Base, class R, class S, class P, class NoValuePolicy> inline constexpr typename basic_outcome_exception_observers<Base, R, S, P, NoValuePolicy>::exception_type &basic_outcome_exception_observers<Base, R, S, P, NoValuePolicy>::exception() &
{
NoValuePolicy::wide_exception_check(*this);
return NoValuePolicy::template _exception<R, S, P, NoValuePolicy>(*this);
}
template <class Base, class R, class S, class P, class NoValuePolicy> inline constexpr const typename basic_outcome_exception_observers<Base, R, S, P, NoValuePolicy>::exception_type &basic_outcome_exception_observers<Base, R, S, P, NoValuePolicy>::exception() const &
{
NoValuePolicy::wide_exception_check(*this);
return NoValuePolicy::template _exception<R, S, P, NoValuePolicy>(*this);
}
template <class Base, class R, class S, class P, class NoValuePolicy> inline constexpr typename basic_outcome_exception_observers<Base, R, S, P, NoValuePolicy>::exception_type &&basic_outcome_exception_observers<Base, R, S, P, NoValuePolicy>::exception() &&
{
NoValuePolicy::wide_exception_check(std::move(*this));
return NoValuePolicy::template _exception<R, S, P, NoValuePolicy>(std::move(*this));
}
template <class Base, class R, class S, class P, class NoValuePolicy> inline constexpr const typename basic_outcome_exception_observers<Base, R, S, P, NoValuePolicy>::exception_type &&basic_outcome_exception_observers<Base, R, S, P, NoValuePolicy>::exception() const &&
{
NoValuePolicy::wide_exception_check(std::move(*this));
return NoValuePolicy::template _exception<R, S, P, NoValuePolicy>(std::move(*this));
}
} // namespace detail
OUTCOME_V2_NAMESPACE_END
#endif
#if !defined(NDEBUG)
OUTCOME_V2_NAMESPACE_BEGIN
// Check is trivial in all ways except default constructibility and standard layout
// static_assert(std::is_trivial<basic_outcome<int, long, double, policy::all_narrow>>::value, "outcome<int> is not trivial!");
// static_assert(std::is_trivially_default_constructible<basic_outcome<int, long, double, policy::all_narrow>>::value, "outcome<int> is not trivially default
// constructible!");
static_assert(std::is_trivially_copyable<basic_outcome<int, long, double, policy::all_narrow>>::value, "outcome<int> is not trivially copyable!");
static_assert(std::is_trivially_assignable<basic_outcome<int, long, double, policy::all_narrow>, basic_outcome<int, long, double, policy::all_narrow>>::value,
"outcome<int> is not trivially assignable!");
static_assert(std::is_trivially_destructible<basic_outcome<int, long, double, policy::all_narrow>>::value, "outcome<int> is not trivially destructible!");
static_assert(std::is_trivially_copy_constructible<basic_outcome<int, long, double, policy::all_narrow>>::value,
"outcome<int> is not trivially copy constructible!");
static_assert(std::is_trivially_move_constructible<basic_outcome<int, long, double, policy::all_narrow>>::value,
"outcome<int> is not trivially move constructible!");
static_assert(std::is_trivially_copy_assignable<basic_outcome<int, long, double, policy::all_narrow>>::value, "outcome<int> is not trivially copy assignable!");
static_assert(std::is_trivially_move_assignable<basic_outcome<int, long, double, policy::all_narrow>>::value, "outcome<int> is not trivially move assignable!");
// Can't be standard layout as non-static member data is defined in more than one inherited class
// static_assert(std::is_standard_layout<basic_outcome<int, long, double, policy::all_narrow>>::value, "outcome<int> is not a standard layout type!");
OUTCOME_V2_NAMESPACE_END
#endif
#endif
/* Traits for Outcome
(C) 2018-2019 Niall Douglas <http://www.nedproductions.biz/> (3 commits)
File Created: March 2018
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License in the accompanying file
Licence.txt or at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Distributed under the Boost Software License, Version 1.0.
(See accompanying file Licence.txt or copy at
http://www.boost.org/LICENSE_1_0.txt)
*/
#ifndef OUTCOME_TRAIT_STD_EXCEPTION_HPP
#define OUTCOME_TRAIT_STD_EXCEPTION_HPP
#include <exception>
OUTCOME_V2_NAMESPACE_BEGIN
namespace policy
{
namespace detail
{
/* Pass through `make_exception_ptr` function for `std::exception_ptr`.
*/
inline std::exception_ptr make_exception_ptr(std::exception_ptr v) { return v; }
// Try ADL, if not use fall backs above
template <class T> constexpr inline decltype(auto) exception_ptr(T &&v) { return make_exception_ptr(std::forward<T>(v)); }
} // namespace detail
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
template <class T> constexpr inline decltype(auto) exception_ptr(T &&v) { return detail::exception_ptr(std::forward<T>(v)); }
namespace detail
{
template <bool has_error_payload> struct _rethrow_exception
{
template <class Exception> explicit _rethrow_exception(Exception && /*unused*/) // NOLINT
{
}
};
template <> struct _rethrow_exception<true>
{
template <class Exception> explicit _rethrow_exception(Exception &&excpt) // NOLINT
{
// ADL
rethrow_exception(policy::exception_ptr(std::forward<Exception>(excpt)));
}
};
} // namespace detail
} // namespace policy
namespace trait
{
namespace detail
{
// Shortcut this for lower build impact
template <> struct _is_exception_ptr_available<std::exception_ptr>
{
static constexpr bool value = true;
using type = std::exception_ptr;
};
} // namespace detail
// std::exception_ptr is an error type
template <> struct is_error_type<std::exception_ptr>
{
static constexpr bool value = true;
};
} // namespace trait
OUTCOME_V2_NAMESPACE_END
#endif
/* A very simple result type
(C) 2018-2020 Niall Douglas <http://www.nedproductions.biz/> (11 commits)
File Created: Apr 2018
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License in the accompanying file
Licence.txt or at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Distributed under the Boost Software License, Version 1.0.
(See accompanying file Licence.txt or copy at
http://www.boost.org/LICENSE_1_0.txt)
*/
#ifndef OUTCOME_EXPERIMENTAL_STATUS_RESULT_HPP
#define OUTCOME_EXPERIMENTAL_STATUS_RESULT_HPP
/* Policies for result and outcome
(C) 2018-2019 Niall Douglas <http://www.nedproductions.biz/> (4 commits)
File Created: Sep 2018
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License in the accompanying file
Licence.txt or at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Distributed under the Boost Software License, Version 1.0.
(See accompanying file Licence.txt or copy at
http://www.boost.org/LICENSE_1_0.txt)
*/
#ifndef OUTCOME_POLICY_FAIL_TO_COMPILE_OBSERVERS_HPP
#define OUTCOME_POLICY_FAIL_TO_COMPILE_OBSERVERS_HPP
OUTCOME_V2_NAMESPACE_EXPORT_BEGIN
#define OUTCOME_FAIL_TO_COMPILE_OBSERVERS_MESSAGE "Attempt to wide observe value, error or " "exception for a basic_result/basic_outcome given an EC or EP type which is not void, and for whom " "trait::is_error_code_available<EC>, trait::is_exception_ptr_available<EC>, and trait::is_exception_ptr_available<EP> " "are all false. Please specify a NoValuePolicy to tell basic_result/basic_outcome what to do, or else use " "a more specific convenience type alias such as unchecked<T, E> to indicate you want the wide " "observers to be narrow, or checked<T, E> to indicate you always want an exception throw etc."
namespace policy
{
struct fail_to_compile_observers : base
{
template <class Impl> static constexpr void wide_value_check(Impl && /* unused */) { static_assert(!std::is_same<Impl, Impl>::value, "Attempt to wide observe value, error or " "exception for a basic_result/basic_outcome given an EC or EP type which is not void, and for whom " "trait::is_error_code_available<EC>, trait::is_exception_ptr_available<EC>, and trait::is_exception_ptr_available<EP> " "are all false. Please specify a NoValuePolicy to tell basic_result/basic_outcome what to do, or else use " "a more specific convenience type alias such as unchecked<T, E> to indicate you want the wide " "observers to be narrow, or checked<T, E> to indicate you always want an exception throw etc."); }
template <class Impl> static constexpr void wide_error_check(Impl && /* unused */) { static_assert(!std::is_same<Impl, Impl>::value, "Attempt to wide observe value, error or " "exception for a basic_result/basic_outcome given an EC or EP type which is not void, and for whom " "trait::is_error_code_available<EC>, trait::is_exception_ptr_available<EC>, and trait::is_exception_ptr_available<EP> " "are all false. Please specify a NoValuePolicy to tell basic_result/basic_outcome what to do, or else use " "a more specific convenience type alias such as unchecked<T, E> to indicate you want the wide " "observers to be narrow, or checked<T, E> to indicate you always want an exception throw etc."); }
template <class Impl> static constexpr void wide_exception_check(Impl && /* unused */) { static_assert(!std::is_same<Impl, Impl>::value, "Attempt to wide observe value, error or " "exception for a basic_result/basic_outcome given an EC or EP type which is not void, and for whom " "trait::is_error_code_available<EC>, trait::is_exception_ptr_available<EC>, and trait::is_exception_ptr_available<EP> " "are all false. Please specify a NoValuePolicy to tell basic_result/basic_outcome what to do, or else use " "a more specific convenience type alias such as unchecked<T, E> to indicate you want the wide " "observers to be narrow, or checked<T, E> to indicate you always want an exception throw etc."); }
};
} // namespace policy
#undef OUTCOME_FAIL_TO_COMPILE_OBSERVERS_MESSAGE
OUTCOME_V2_NAMESPACE_END
#endif
#ifndef SYSTEM_ERROR2_USE_STD_ADDRESSOF
#if OUTCOME_USE_STD_ADDRESSOF
#define SYSTEM_ERROR2_USE_STD_ADDRESSOF 1
#endif
#endif
/* Proposed SG14 status_code
(C) 2018 Niall Douglas <http://www.nedproductions.biz/> (5 commits)
File Created: Feb 2018
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License in the accompanying file
Licence.txt or at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Distributed under the Boost Software License, Version 1.0.
(See accompanying file Licence.txt or copy at
http://www.boost.org/LICENSE_1_0.txt)
*/
#ifndef SYSTEM_ERROR2_HPP
#define SYSTEM_ERROR2_HPP
/* Proposed SG14 status_code
(C) 2018 Niall Douglas <http://www.nedproductions.biz/> (5 commits)
File Created: Feb 2018
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License in the accompanying file
Licence.txt or at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Distributed under the Boost Software License, Version 1.0.
(See accompanying file Licence.txt or copy at
http://www.boost.org/LICENSE_1_0.txt)
*/
#ifndef SYSTEM_ERROR2_ERROR_HPP
#define SYSTEM_ERROR2_ERROR_HPP
/* Proposed SG14 status_code
(C) 2018 Niall Douglas <http://www.nedproductions.biz/> (5 commits)
File Created: Jun 2018
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License in the accompanying file
Licence.txt or at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Distributed under the Boost Software License, Version 1.0.
(See accompanying file Licence.txt or copy at
http://www.boost.org/LICENSE_1_0.txt)
*/
#ifndef SYSTEM_ERROR2_ERRORED_STATUS_CODE_HPP
#define SYSTEM_ERROR2_ERRORED_STATUS_CODE_HPP
/* Proposed SG14 status_code
(C) 2018 - 2020 Niall Douglas <http://www.nedproductions.biz/> (5 commits)
File Created: May 2020
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License in the accompanying file
Licence.txt or at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Distributed under the Boost Software License, Version 1.0.
(See accompanying file Licence.txt or copy at
http://www.boost.org/LICENSE_1_0.txt)
*/
#ifndef SYSTEM_ERROR2_QUICK_STATUS_CODE_FROM_ENUM_HPP
#define SYSTEM_ERROR2_QUICK_STATUS_CODE_FROM_ENUM_HPP
#ifndef SYSTEM_ERROR2_QUICK_STATUS_CODE_FROM_ENUM_ASSERT_ON_MISSING_MAPPING_TABLE_ENTRIES
#define SYSTEM_ERROR2_QUICK_STATUS_CODE_FROM_ENUM_ASSERT_ON_MISSING_MAPPING_TABLE_ENTRIES 1
#endif
/* Proposed SG14 status_code
(C) 2018 - 2020 Niall Douglas <http://www.nedproductions.biz/> (5 commits)
File Created: Feb 2018
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License in the accompanying file
Licence.txt or at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Distributed under the Boost Software License, Version 1.0.
(See accompanying file Licence.txt or copy at
http://www.boost.org/LICENSE_1_0.txt)
*/
#ifndef SYSTEM_ERROR2_GENERIC_CODE_HPP
#define SYSTEM_ERROR2_GENERIC_CODE_HPP
/* Proposed SG14 status_code
(C) 2018 - 2022 Niall Douglas <http://www.nedproductions.biz/> (5 commits)
File Created: Feb 2018
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License in the accompanying file
Licence.txt or at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Distributed under the Boost Software License, Version 1.0.
(See accompanying file Licence.txt or copy at
http://www.boost.org/LICENSE_1_0.txt)
*/
#ifndef SYSTEM_ERROR2_STATUS_ERROR_HPP
#define SYSTEM_ERROR2_STATUS_ERROR_HPP
/* Proposed SG14 status_code
(C) 2018 - 2023 Niall Douglas <http://www.nedproductions.biz/> (5 commits)
File Created: Feb 2018
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License in the accompanying file
Licence.txt or at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Distributed under the Boost Software License, Version 1.0.
(See accompanying file Licence.txt or copy at
http://www.boost.org/LICENSE_1_0.txt)
*/
#ifndef SYSTEM_ERROR2_STATUS_CODE_HPP
#define SYSTEM_ERROR2_STATUS_CODE_HPP
/* Proposed SG14 status_code
(C) 2018 Niall Douglas <http://www.nedproductions.biz/> (5 commits)
File Created: Feb 2018
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License in the accompanying file
Licence.txt or at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Distributed under the Boost Software License, Version 1.0.
(See accompanying file Licence.txt or copy at
http://www.boost.org/LICENSE_1_0.txt)
*/
#ifndef SYSTEM_ERROR2_STATUS_CODE_DOMAIN_HPP
#define SYSTEM_ERROR2_STATUS_CODE_DOMAIN_HPP
/* Proposed SG14 status_code
(C) 2018 - 2021 Niall Douglas <http://www.nedproductions.biz/> (5 commits)
File Created: Feb 2018
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License in the accompanying file
Licence.txt or at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Distributed under the Boost Software License, Version 1.0.
(See accompanying file Licence.txt or copy at
http://www.boost.org/LICENSE_1_0.txt)
*/
#ifndef SYSTEM_ERROR2_CONFIG_HPP
#define SYSTEM_ERROR2_CONFIG_HPP
// < 0.1 each
#include <cassert>
#include <cstddef> // for size_t
#include <cstdlib> // for free
// 0.22
#include <type_traits>
// 0.29
#include <atomic>
// 0.28 (0.15 of which is exception_ptr)
#include <exception> // for std::exception
// <new> includes <exception>, <exception> includes <new>
#include <new>
// 0.01
#include <initializer_list>
#ifndef SYSTEM_ERROR2_HAVE_BIT_CAST
#ifdef __has_include
#if __has_include(<bit>) && (__cplusplus >= 202002L || _HAS_CXX20)
#define SYSTEM_ERROR2_HAVE_BIT_CAST 1
#endif
#elif __cplusplus >= 202002L
#define SYSTEM_ERROR2_HAVE_BIT_CAST 1
#endif
#ifndef SYSTEM_ERROR2_HAVE_BIT_CAST
#define SYSTEM_ERROR2_HAVE_BIT_CAST 0
#endif
#endif
#if SYSTEM_ERROR2_HAVE_BIT_CAST
#include <bit>
#if __cpp_lib_bit_cast < 201806L
#undef SYSTEM_ERROR2_HAVE_BIT_CAST
#define SYSTEM_ERROR2_HAVE_BIT_CAST 0
#endif
#endif
#if SYSTEM_ERROR2_USE_STD_ADDRESSOF
#include <memory> // for std::addressof
#define SYSTEM_ERROR2_ADDRESS_OF(...) std::addressof(__VA_ARGS__)
#else
#define SYSTEM_ERROR2_ADDRESS_OF(...) (&__VA_ARGS__)
#endif
#ifndef SYSTEM_ERROR2_CONSTEXPR14
#if 0L || __cplusplus >= 201400 || _MSC_VER >= 1910 /* VS2017 */
//! Defined to be `constexpr` when on C++ 14 or better compilers. Usually automatic, can be overriden.
#define SYSTEM_ERROR2_CONSTEXPR14 constexpr
#else
#define SYSTEM_ERROR2_CONSTEXPR14
#endif
#endif
#ifndef SYSTEM_ERROR2_CONSTEXPR20
#if 0L || __cplusplus >= 202000 || _HAS_CXX20
//! Defined to be `constexpr` when on C++ 20 or better compilers. Usually automatic, can be overriden.
#define SYSTEM_ERROR2_CONSTEXPR20 constexpr
#else
#define SYSTEM_ERROR2_CONSTEXPR20
#endif
#endif
#ifndef SYSTEM_ERROR2_NORETURN
#if 0L || (_HAS_CXX17 && _MSC_VER >= 1911 /* VS2017.3 */)
#define SYSTEM_ERROR2_NORETURN [[noreturn]]
#endif
#endif
#if !defined(SYSTEM_ERROR2_NORETURN)
#ifdef __has_cpp_attribute
#if __has_cpp_attribute(noreturn)
#define SYSTEM_ERROR2_NORETURN [[noreturn]]
#endif
#endif
#endif
#if !defined(SYSTEM_ERROR2_NORETURN)
#if defined(_MSC_VER)
#define SYSTEM_ERROR2_NORETURN __declspec(noreturn)
#elif defined(__GNUC__)
#define SYSTEM_ERROR2_NORETURN __attribute__((__noreturn__))
#else
#define SYSTEM_ERROR2_NORETURN
#endif
#endif
// GCCs before 7 don't grok [[noreturn]] virtual functions, and warn annoyingly
#if defined(__GNUC__) && !defined(__clang__) && __GNUC__ < 7
#undef SYSTEM_ERROR2_NORETURN
#define SYSTEM_ERROR2_NORETURN
#endif
#ifndef SYSTEM_ERROR2_NODISCARD
#if 0L || (_HAS_CXX17 && _MSC_VER >= 1911 /* VS2017.3 */)
#define SYSTEM_ERROR2_NODISCARD [[nodiscard]]
#endif
#endif
#ifndef SYSTEM_ERROR2_NODISCARD
#ifdef __has_cpp_attribute
#if __has_cpp_attribute(nodiscard)
#define SYSTEM_ERROR2_NODISCARD [[nodiscard]]
#endif
#elif defined(__clang__)
#define SYSTEM_ERROR2_NODISCARD __attribute__((warn_unused_result))
#elif defined(_MSC_VER)
// _Must_inspect_result_ expands into this
#define SYSTEM_ERROR2_NODISCARD __declspec( "SAL_name" "(" "\"_Must_inspect_result_\"" "," "\"\"" "," "\"2\"" ")") __declspec("SAL_begin") __declspec("SAL_post") __declspec("SAL_mustInspect") __declspec("SAL_post") __declspec("SAL_checkReturn") __declspec("SAL_end")
#endif
#endif
#ifndef SYSTEM_ERROR2_NODISCARD
#define SYSTEM_ERROR2_NODISCARD
#endif
#ifndef SYSTEM_ERROR2_TRIVIAL_ABI
#if 0L || (__clang_major__ >= 7 && !defined(__APPLE__))
//! Defined to be `[[clang::trivial_abi]]` when on a new enough clang compiler. Usually automatic, can be overriden.
#define SYSTEM_ERROR2_TRIVIAL_ABI [[clang::trivial_abi]]
#else
#define SYSTEM_ERROR2_TRIVIAL_ABI
#endif
#endif
#if defined(__cpp_concepts) && !defined(SYSTEM_ERROR2_DISABLE_CONCEPTS_SUPPORT)
#define SYSTEM_ERROR2_GLUE(x, y) x y
#define SYSTEM_ERROR2_RETURN_ARG_COUNT(_1_, _2_, _3_, _4_, _5_, _6_, _7_, _8_, count, ...) count
#define SYSTEM_ERROR2_EXPAND_ARGS(args) SYSTEM_ERROR2_RETURN_ARG_COUNT args
#define SYSTEM_ERROR2_COUNT_ARGS_MAX8(...) SYSTEM_ERROR2_EXPAND_ARGS((__VA_ARGS__, 8, 7, 6, 5, 4, 3, 2, 1, 0))
#define SYSTEM_ERROR2_OVERLOAD_MACRO2(name, count) name##count
#define SYSTEM_ERROR2_OVERLOAD_MACRO1(name, count) SYSTEM_ERROR2_OVERLOAD_MACRO2(name, count)
#define SYSTEM_ERROR2_OVERLOAD_MACRO(name, count) SYSTEM_ERROR2_OVERLOAD_MACRO1(name, count)
#define SYSTEM_ERROR2_CALL_OVERLOAD(name, ...) SYSTEM_ERROR2_GLUE(SYSTEM_ERROR2_OVERLOAD_MACRO(name, SYSTEM_ERROR2_COUNT_ARGS_MAX8(__VA_ARGS__)), (__VA_ARGS__))
#define SYSTEM_ERROR2_TREQUIRES_EXPAND8(a, b, c, d, e, f, g, h) a &&SYSTEM_ERROR2_TREQUIRES_EXPAND7(b, c, d, e, f, g, h)
#define SYSTEM_ERROR2_TREQUIRES_EXPAND7(a, b, c, d, e, f, g) a &&SYSTEM_ERROR2_TREQUIRES_EXPAND6(b, c, d, e, f, g)
#define SYSTEM_ERROR2_TREQUIRES_EXPAND6(a, b, c, d, e, f) a &&SYSTEM_ERROR2_TREQUIRES_EXPAND5(b, c, d, e, f)
#define SYSTEM_ERROR2_TREQUIRES_EXPAND5(a, b, c, d, e) a &&SYSTEM_ERROR2_TREQUIRES_EXPAND4(b, c, d, e)
#define SYSTEM_ERROR2_TREQUIRES_EXPAND4(a, b, c, d) a &&SYSTEM_ERROR2_TREQUIRES_EXPAND3(b, c, d)
#define SYSTEM_ERROR2_TREQUIRES_EXPAND3(a, b, c) a &&SYSTEM_ERROR2_TREQUIRES_EXPAND2(b, c)
#define SYSTEM_ERROR2_TREQUIRES_EXPAND2(a, b) a &&SYSTEM_ERROR2_TREQUIRES_EXPAND1(b)
#define SYSTEM_ERROR2_TREQUIRES_EXPAND1(a) a
//! Expands into a && b && c && ...
#define SYSTEM_ERROR2_TREQUIRES(...) requires SYSTEM_ERROR2_CALL_OVERLOAD(SYSTEM_ERROR2_TREQUIRES_EXPAND, __VA_ARGS__)
#define SYSTEM_ERROR2_TEMPLATE(...) template <__VA_ARGS__>
#define SYSTEM_ERROR2_TEXPR(...) requires { (__VA_ARGS__); }
#define SYSTEM_ERROR2_TPRED(...) (__VA_ARGS__)
#if !defined(_MSC_VER) || _MSC_FULL_VER >= 192400000 // VS 2019 16.3 is broken here
#define SYSTEM_ERROR2_REQUIRES(...) requires(__VA_ARGS__)
#else
#define SYSTEM_ERROR2_REQUIRES(...)
#endif
#else
#define SYSTEM_ERROR2_TEMPLATE(...) template <__VA_ARGS__
#define SYSTEM_ERROR2_TREQUIRES(...) , __VA_ARGS__ >
#define SYSTEM_ERROR2_TEXPR(...) typename = decltype(__VA_ARGS__)
#ifdef _MSC_VER
// MSVC gives an error if every specialisation of a template is always ill-formed, so
// the more powerful SFINAE form below causes pukeage :(
#define SYSTEM_ERROR2_TPRED(...) typename = typename std::enable_if<(__VA_ARGS__)>::type
#else
#define SYSTEM_ERROR2_TPRED(...) typename std::enable_if<(__VA_ARGS__), bool>::type = true
#endif
#define SYSTEM_ERROR2_REQUIRES(...)
#endif
#ifndef SYSTEM_ERROR2_NAMESPACE
//! The system_error2 namespace name.
#define SYSTEM_ERROR2_NAMESPACE system_error2
//! Begins the system_error2 namespace.
#define SYSTEM_ERROR2_NAMESPACE_BEGIN namespace system_error2 {
//! Ends the system_error2 namespace.
#define SYSTEM_ERROR2_NAMESPACE_END }
#endif
//! Namespace for the library
SYSTEM_ERROR2_NAMESPACE_BEGIN
//! Namespace for user specialised traits
namespace traits
{
/*! Specialise to true if you guarantee that a type is move bitcopying (i.e.
its move constructor equals copying bits from old to new, old is left in a
default constructed state, and calling the destructor on a default constructed
instance is trivial). All trivially copyable types are move bitcopying by
definition, and that is the unspecialised implementation.
*/
template <class T> struct is_move_bitcopying
{
static constexpr bool value = std::is_trivially_copyable<T>::value;
};
} // namespace traits
namespace detail
{
#if __cplusplus >= 201400 || _MSC_VER >= 1910 /* VS2017 */
inline constexpr size_t cstrlen(const char *str)
{
const char *end = nullptr;
for(end = str; *end != 0; ++end) // NOLINT
;
return end - str;
}
#else
inline constexpr size_t cstrlen_(const char *str, size_t acc) { return (str[0] == 0) ? acc : cstrlen_(str + 1, acc + 1); }
inline constexpr size_t cstrlen(const char *str) { return cstrlen_(str, 0); }
#endif
#if (__cplusplus >= 202002L || _MSVC_LANG >= 202002L) && __cpp_lib_remove_cvref >= 201711L
template <class T> using remove_cvref = std::remove_cvref<T>;
#else
template <class T> struct remove_cvref
{
using type = typename std::remove_cv<typename std::remove_reference<T>::type>::type;
};
#endif
/* A partially compliant implementation of C++20's std::bit_cast function contributed
by Jesse Towner.
Our bit_cast is only guaranteed to be constexpr when both the input and output
arguments are either integrals or enums. However, this covers most use cases
since the vast majority of status_codes have an underlying type that is either
an integral or enum. We still attempt a constexpr union-based type pun for non-array
input types, which some compilers accept. For array inputs, we fall back to
non-constexpr memmove.
*/
template <class T> using is_integral_or_enum = std::integral_constant<bool, std::is_integral<T>::value || std::is_enum<T>::value>;
template <class To, class From> using is_static_castable = std::integral_constant<bool, is_integral_or_enum<To>::value && is_integral_or_enum<From>::value>;
template <class To, class From>
using is_union_castable = std::integral_constant<bool, !is_static_castable<To, From>::value && !std::is_array<To>::value && !std::is_array<From>::value>;
template <class To, class From>
using is_bit_castable =
std::integral_constant<bool, sizeof(To) == sizeof(From) && traits::is_move_bitcopying<To>::value && traits::is_move_bitcopying<From>::value>;
template <class To, class From> union bit_cast_union
{
From source;
To target;
};
#if SYSTEM_ERROR2_HAVE_BIT_CAST
using std::bit_cast; // available for all trivially copyable types
// For move bit copying types
template <class To, class From>
requires(is_bit_castable<To, From>::value //
&&is_union_castable<To, From>::value //
&& (!std::is_trivially_copyable_v<From> //
|| !std::is_trivially_copyable_v<To>) ) //
constexpr To bit_cast(const From &from) noexcept
{
return bit_cast_union<To, From>{from}.target;
}
template <class To, class From>
requires(is_bit_castable<To, From>::value //
&& !is_union_castable<To, From>::value //
&& (!std::is_trivially_copyable_v<From> //
|| !std::is_trivially_copyable_v<To>) ) //
To bit_cast(const From &from)
noexcept
{
bit_cast_union<To, From> ret;
memmove(&ret.source, &from, sizeof(ret.source));
return ret.target;
}
#else
SYSTEM_ERROR2_TEMPLATE(class To, class From, int = 5)
SYSTEM_ERROR2_TREQUIRES(SYSTEM_ERROR2_TPRED(is_bit_castable<To, From>::value //
&&is_static_castable<To, From>::value //
&& !is_union_castable<To, From>::value))
constexpr To bit_cast(const From &from) noexcept { return static_cast<To>(from); }
#if defined(__GNUC__) && !defined(__clang__)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
#endif
SYSTEM_ERROR2_TEMPLATE(class To, class From, long = 5)
SYSTEM_ERROR2_TREQUIRES(SYSTEM_ERROR2_TPRED(is_bit_castable<To, From>::value //
&& !is_static_castable<To, From>::value //
&& is_union_castable<To, From>::value))
constexpr To bit_cast(const From &from) noexcept { return bit_cast_union<To, From>{from}.target; }
#if defined(__GNUC__) && !defined(__clang__)
#pragma GCC diagnostic pop
#endif
SYSTEM_ERROR2_TEMPLATE(class To, class From, short = 5)
SYSTEM_ERROR2_TREQUIRES(SYSTEM_ERROR2_TPRED(is_bit_castable<To, From>::value //
&& !is_static_castable<To, From>::value //
&& !is_union_castable<To, From>::value))
To bit_cast(const From &from) noexcept
{
bit_cast_union<To, From> ret;
memmove(&ret.source, &from, sizeof(ret.source));
return ret.target;
}
#endif
/* erasure_cast performs a bit_cast with additional rules to handle types
of differing sizes. For integral & enum types, it may perform a narrowing
or widing conversion with static_cast if necessary, before doing the final
conversion with bit_cast. When casting to or from non-integral, non-enum
types it may insert the value into another object with extra padding bytes
to satisfy bit_cast's preconditions that both types have the same size. */
template <class To, class From>
using is_erasure_castable = std::integral_constant<bool, traits::is_move_bitcopying<To>::value && traits::is_move_bitcopying<From>::value>;
template <class T, bool = std::is_enum<T>::value> struct identity_or_underlying_type
{
using type = T;
};
template <class T> struct identity_or_underlying_type<T, true>
{
using type = typename std::underlying_type<T>::type;
};
template <class OfSize, class OfSign>
using erasure_integer_type = typename std::conditional<std::is_signed<typename identity_or_underlying_type<OfSign>::type>::value,
typename std::make_signed<typename identity_or_underlying_type<OfSize>::type>::type,
typename std::make_unsigned<typename identity_or_underlying_type<OfSize>::type>::type>::type;
template <class ErasedType, std::size_t N> struct padded_erasure_object
{
static_assert(traits::is_move_bitcopying<ErasedType>::value, "ErasedType must be TriviallyCopyable or MoveBitcopying");
static_assert(alignof(ErasedType) <= sizeof(ErasedType), "ErasedType must not be over-aligned");
ErasedType value;
char padding[N];
constexpr explicit padded_erasure_object(const ErasedType &v) noexcept
: value(v)
, padding{}
{
}
};
SYSTEM_ERROR2_TEMPLATE(class To, class From)
SYSTEM_ERROR2_TREQUIRES(SYSTEM_ERROR2_TPRED(is_erasure_castable<To, From>::value && (sizeof(To) == sizeof(From))))
constexpr To erasure_cast(const From &from) noexcept { return bit_cast<To>(from); }
#if defined(_WIN32) || defined(__APPLE__) || __LITTLE_ENDIAN__ || (defined(__BYTE_ORDER) && defined(__LITTLE_ENDIAN) && __BYTE_ORDER == __LITTLE_ENDIAN)
// We can avoid the type pun on little endian architectures which can aid optimisation
SYSTEM_ERROR2_TEMPLATE(class To, class From, long = 5)
SYSTEM_ERROR2_TREQUIRES(SYSTEM_ERROR2_TPRED(is_erasure_castable<To, From>::value &&is_static_castable<To, From>::value && (sizeof(To) < sizeof(From))))
constexpr To erasure_cast(const From &from) noexcept { return static_cast<To>(bit_cast<erasure_integer_type<From, To>>(from)); }
SYSTEM_ERROR2_TEMPLATE(class To, class From, int = 5)
SYSTEM_ERROR2_TREQUIRES(SYSTEM_ERROR2_TPRED(is_erasure_castable<To, From>::value &&is_static_castable<To, From>::value && (sizeof(To) > sizeof(From))))
constexpr To erasure_cast(const From &from) noexcept { return bit_cast<To>(static_cast<erasure_integer_type<To, From>>(from)); }
SYSTEM_ERROR2_TEMPLATE(class To, class From, short = 5)
SYSTEM_ERROR2_TREQUIRES(SYSTEM_ERROR2_TPRED(is_erasure_castable<To, From>::value && !is_static_castable<To, From>::value && (sizeof(To) < sizeof(From))))
constexpr To erasure_cast(const From &from) noexcept { return bit_cast<padded_erasure_object<To, sizeof(From) - sizeof(To)>>(from).value; }
SYSTEM_ERROR2_TEMPLATE(class To, class From, char = 5)
SYSTEM_ERROR2_TREQUIRES(SYSTEM_ERROR2_TPRED(is_erasure_castable<To, From>::value && !is_static_castable<To, From>::value && (sizeof(To) > sizeof(From))))
constexpr To erasure_cast(const From &from) noexcept { return bit_cast<To>(padded_erasure_object<From, sizeof(To) - sizeof(From)>{from}); }
#else
SYSTEM_ERROR2_TEMPLATE(class To, class From, short = 5)
SYSTEM_ERROR2_TREQUIRES(SYSTEM_ERROR2_TPRED(is_erasure_castable<To, From>::value && (sizeof(To) < sizeof(From))))
constexpr To erasure_cast(const From &from) noexcept { return bit_cast<padded_erasure_object<To, sizeof(From) - sizeof(To)>>(from).value; }
SYSTEM_ERROR2_TEMPLATE(class To, class From, char = 5)
SYSTEM_ERROR2_TREQUIRES(SYSTEM_ERROR2_TPRED(is_erasure_castable<To, From>::value && (sizeof(To) > sizeof(From))))
constexpr To erasure_cast(const From &from) noexcept { return bit_cast<To>(padded_erasure_object<From, sizeof(To) - sizeof(From)>{from}); }
#endif
} // namespace detail
SYSTEM_ERROR2_NAMESPACE_END
#ifndef SYSTEM_ERROR2_FATAL
#ifdef SYSTEM_ERROR2_NOT_POSIX
#error If SYSTEM_ERROR2_NOT_POSIX is defined, you must define your own SYSTEM_ERROR2_FATAL implementation!
#endif
#include <cstdlib> // for abort
#ifdef __APPLE__
#include <unistd.h> // for write
#endif
SYSTEM_ERROR2_NAMESPACE_BEGIN
namespace detail
{
namespace avoid_stdio_include
{
#if !defined(__APPLE__) && !defined(_MSC_VER)
extern "C" ptrdiff_t write(int, const void *, size_t);
#elif defined(_MSC_VER)
extern ptrdiff_t write(int, const void *, size_t);
#if (defined(__x86_64__) || defined(_M_X64)) || (defined(__aarch64__) || defined(_M_ARM64)) || (defined(__arm__) || defined(_M_ARM))
#pragma comment(linker, "/alternatename:?write@avoid_stdio_include@detail@system_error2@@YA_JHPEBX_K@Z=write")
#elif defined(__x86__) || defined(_M_IX86) || defined(__i386__)
#pragma comment(linker, "/alternatename:?write@avoid_stdio_include@detail@system_error2@@YAHHPBXI@Z=_write")
#else
#error Unknown architecture
#endif
#endif
} // namespace avoid_stdio_include
inline void do_fatal_exit(const char *msg)
{
using namespace avoid_stdio_include;
write(2 /*stderr*/, msg, cstrlen(msg));
write(2 /*stderr*/, "\n", 1);
abort();
}
} // namespace detail
SYSTEM_ERROR2_NAMESPACE_END
//! Prints msg to stderr, and calls `std::terminate()`. Can be overriden via predefinition.
#define SYSTEM_ERROR2_FATAL(msg) ::SYSTEM_ERROR2_NAMESPACE::detail::do_fatal_exit(msg)
#endif
#endif
#include <cstring> // for strchr
SYSTEM_ERROR2_NAMESPACE_BEGIN
/*! The main workhorse of the system_error2 library, can be typed (`status_code<DomainType>`), erased-immutable (`status_code<void>`) or erased-mutable
(`status_code<erased<T>>`).
Be careful of placing these into containers! Equality and inequality operators are
*semantic* not exact. Therefore two distinct items will test true! To help prevent
surprise on this, `operator<` and `std::hash<>` are NOT implemented in order to
trap potential incorrectness. Define your own custom comparison functions for your
container which perform exact comparisons.
*/
template <class DomainType> class status_code;
class _generic_code_domain;
//! The generic code is a status code with the generic code domain, which is that of `errc` (POSIX).
using generic_code = status_code<_generic_code_domain>;
namespace detail
{
template <class StatusCode, class Allocator> class indirecting_domain;
/* We are severely limited by needing to retain C++ 11 compatibility when doing
constexpr string parsing. MSVC lets you throw exceptions within a constexpr
evaluation context when exceptions are globally disabled, but won't let you
divide by zero, even if never evaluated, ever in constexpr. GCC and clang won't
let you throw exceptions, ever, if exceptions are globally disabled. So let's
use the trick of divide by zero in constexpr on GCC and clang if and only if
exceptions are globally disabled.
*/
#ifdef __GNUC__
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdiv-by-zero"
#endif
#if defined(__cpp_exceptions) || (defined(_MSC_VER) && !defined(__clang__))
#define SYSTEM_ERROR2_FAIL_CONSTEXPR(msg) throw msg
#else
#define SYSTEM_ERROR2_FAIL_CONSTEXPR(msg) ((void) msg, 1 / 0)
#endif
constexpr inline unsigned long long parse_hex_byte(char c)
{
return ('0' <= c && c <= '9') ? (c - '0') :
('a' <= c && c <= 'f') ? (10 + c - 'a') :
('A' <= c && c <= 'F') ? (10 + c - 'A') :
SYSTEM_ERROR2_FAIL_CONSTEXPR("Invalid character in UUID");
}
constexpr inline unsigned long long parse_uuid2(const char *s)
{
return ((parse_hex_byte(s[0]) << 0) | (parse_hex_byte(s[1]) << 4) | (parse_hex_byte(s[2]) << 8) | (parse_hex_byte(s[3]) << 12) |
(parse_hex_byte(s[4]) << 16) | (parse_hex_byte(s[5]) << 20) | (parse_hex_byte(s[6]) << 24) | (parse_hex_byte(s[7]) << 28) |
(parse_hex_byte(s[9]) << 32) | (parse_hex_byte(s[10]) << 36) | (parse_hex_byte(s[11]) << 40) | (parse_hex_byte(s[12]) << 44) |
(parse_hex_byte(s[14]) << 48) | (parse_hex_byte(s[15]) << 52) | (parse_hex_byte(s[16]) << 56) | (parse_hex_byte(s[17]) << 60)) //
^ //
((parse_hex_byte(s[19]) << 0) | (parse_hex_byte(s[20]) << 4) | (parse_hex_byte(s[21]) << 8) | (parse_hex_byte(s[22]) << 12) |
(parse_hex_byte(s[24]) << 16) | (parse_hex_byte(s[25]) << 20) | (parse_hex_byte(s[26]) << 24) | (parse_hex_byte(s[27]) << 28) |
(parse_hex_byte(s[28]) << 32) | (parse_hex_byte(s[29]) << 36) | (parse_hex_byte(s[30]) << 40) | (parse_hex_byte(s[31]) << 44) |
(parse_hex_byte(s[32]) << 48) | (parse_hex_byte(s[33]) << 52) | (parse_hex_byte(s[34]) << 56) | (parse_hex_byte(s[35]) << 60));
}
template <size_t N> constexpr inline unsigned long long parse_uuid_from_array(const char (&uuid)[N])
{
return (N == 37) ? parse_uuid2(uuid) : ((N == 39) ? parse_uuid2(uuid + 1) : SYSTEM_ERROR2_FAIL_CONSTEXPR("UUID does not have correct length"));
}
template <size_t N> constexpr inline unsigned long long parse_uuid_from_pointer(const char *uuid)
{
return (N == 36) ? parse_uuid2(uuid) : ((N == 38) ? parse_uuid2(uuid + 1) : SYSTEM_ERROR2_FAIL_CONSTEXPR("UUID does not have correct length"));
}
#ifdef __GNUC__
#pragma GCC diagnostic pop
#endif
static constexpr unsigned long long test_uuid_parse = parse_uuid_from_array("430f1201-94fc-06c7-430f-120194fc06c7");
// static constexpr unsigned long long test_uuid_parse2 = parse_uuid_from_array("x30f1201-94fc-06c7-430f-120194fc06c7");
} // namespace detail
/*! Abstract base class for a coding domain of a status code.
*/
class status_code_domain
{
template <class DomainType> friend class status_code;
template <class StatusCode, class Allocator> friend class detail::indirecting_domain;
public:
//! Type of the unique id for this domain.
using unique_id_type = unsigned long long;
/*! (Potentially thread safe) Reference to a message string.
Be aware that you cannot add payload to implementations of this class.
You get exactly the `void *[3]` array to keep state, this is usually
sufficient for a `std::shared_ptr<>` or a `std::string`.
You can install a handler to be called when this object is copied,
moved and destructed. This takes the form of a C function pointer.
*/
class string_ref
{
public:
//! The value type
using value_type = const char;
//! The size type
using size_type = size_t;
//! The pointer type
using pointer = const char *;
//! The const pointer type
using const_pointer = const char *;
//! The iterator type
using iterator = const char *;
//! The const iterator type
using const_iterator = const char *;
protected:
//! The operation occurring
enum class _thunk_op
{
copy,
move,
destruct
};
//! The prototype of the handler function. Copies can throw, moves and destructs cannot.
using _thunk_spec = void (*)(string_ref *dest, const string_ref *src, _thunk_op op);
#ifndef NDEBUG
private:
static void _checking_string_thunk(string_ref *dest, const string_ref *src, _thunk_op /*unused*/) noexcept
{
(void) dest;
(void) src;
assert(dest->_thunk == _checking_string_thunk); // NOLINT
assert(src == nullptr || src->_thunk == _checking_string_thunk); // NOLINT
// do nothing
}
protected:
#endif
//! Pointers to beginning and end of character range
pointer _begin{}, _end{};
//! Three `void*` of state
void *_state[3]{}; // at least the size of a shared_ptr
//! Handler for when operations occur
const _thunk_spec _thunk{nullptr};
constexpr explicit string_ref(_thunk_spec thunk) noexcept
: _thunk(thunk)
{
}
public:
//! Construct from a C string literal
SYSTEM_ERROR2_CONSTEXPR14 explicit string_ref(const char *str, size_type len = static_cast<size_type>(-1), void *state0 = nullptr, void *state1 = nullptr,
void *state2 = nullptr,
#ifndef NDEBUG
_thunk_spec thunk = _checking_string_thunk
#else
_thunk_spec thunk = nullptr
#endif
) noexcept
: _begin(str)
, _end((len == static_cast<size_type>(-1)) ? (str + detail::cstrlen(str)) : (str + len))
, // NOLINT
_state{state0, state1, state2}
, _thunk(thunk)
{
}
//! Copy construct the derived implementation.
SYSTEM_ERROR2_CONSTEXPR20 string_ref(const string_ref &o)
: _begin(o._begin)
, _end(o._end)
, _state{o._state[0], o._state[1], o._state[2]}
, _thunk(o._thunk)
{
if(_thunk != nullptr)
{
_thunk(this, &o, _thunk_op::copy);
}
}
//! Move construct the derived implementation.
SYSTEM_ERROR2_CONSTEXPR20 string_ref(string_ref &&o) noexcept
: _begin(o._begin)
, _end(o._end)
, _state{o._state[0], o._state[1], o._state[2]}
, _thunk(o._thunk)
{
if(_thunk != nullptr)
{
_thunk(this, &o, _thunk_op::move);
}
}
//! Copy assignment
SYSTEM_ERROR2_CONSTEXPR20 string_ref &operator=(const string_ref &o)
{
if(this != &o)
{
#if defined(__cpp_exceptions) || defined(__EXCEPTIONS) || defined(_CPPUNWIND)
string_ref temp(static_cast<string_ref &&>(*this));
this->~string_ref();
try
{
new(this) string_ref(o); // may throw
}
catch(...)
{
new(this) string_ref(static_cast<string_ref &&>(temp));
throw;
}
#else
this->~string_ref();
new(this) string_ref(o);
#endif
}
return *this;
}
//! Move assignment
SYSTEM_ERROR2_CONSTEXPR20 string_ref &operator=(string_ref &&o) noexcept
{
if(this != &o)
{
this->~string_ref();
new(this) string_ref(static_cast<string_ref &&>(o));
}
return *this;
}
//! Destruction
SYSTEM_ERROR2_CONSTEXPR20 ~string_ref()
{
if(_thunk != nullptr)
{
_thunk(this, nullptr, _thunk_op::destruct);
}
_begin = _end = nullptr;
}
//! Returns whether the reference is empty or not
SYSTEM_ERROR2_NODISCARD constexpr bool empty() const noexcept { return _begin == _end; }
//! Returns the size of the string
constexpr size_type size() const noexcept { return _end - _begin; }
//! Returns a null terminated C string
constexpr const_pointer c_str() const noexcept { return _begin; }
//! Returns a null terminated C string
constexpr const_pointer data() const noexcept { return _begin; }
//! Returns the beginning of the string
SYSTEM_ERROR2_CONSTEXPR14 iterator begin() noexcept { return _begin; }
//! Returns the beginning of the string
SYSTEM_ERROR2_CONSTEXPR14 const_iterator begin() const noexcept { return _begin; }
//! Returns the beginning of the string
constexpr const_iterator cbegin() const noexcept { return _begin; }
//! Returns the end of the string
SYSTEM_ERROR2_CONSTEXPR14 iterator end() noexcept { return _end; }
//! Returns the end of the string
SYSTEM_ERROR2_CONSTEXPR14 const_iterator end() const noexcept { return _end; }
//! Returns the end of the string
constexpr const_iterator cend() const noexcept { return _end; }
};
/*! A reference counted, threadsafe reference to a message string.
*/
class atomic_refcounted_string_ref : public string_ref
{
struct _allocated_msg
{
mutable std::atomic<unsigned> count{1};
};
_allocated_msg *&_msg() noexcept { return reinterpret_cast<_allocated_msg *&>(this->_state[0]); } // NOLINT
const _allocated_msg *_msg() const noexcept { return reinterpret_cast<const _allocated_msg *>(this->_state[0]); } // NOLINT
static SYSTEM_ERROR2_CONSTEXPR20 void _refcounted_string_thunk(string_ref *_dest, const string_ref *_src, _thunk_op op) noexcept
{
auto dest = static_cast<atomic_refcounted_string_ref *>(_dest); // NOLINT
auto src = static_cast<const atomic_refcounted_string_ref *>(_src); // NOLINT
(void) src;
assert(dest->_thunk == _refcounted_string_thunk); // NOLINT
assert(src == nullptr || src->_thunk == _refcounted_string_thunk); // NOLINT
switch(op)
{
case _thunk_op::copy:
{
if(dest->_msg() != nullptr)
{
auto count = dest->_msg()->count.fetch_add(1, std::memory_order_relaxed);
(void) count;
assert(count != 0); // NOLINT
}
return;
}
case _thunk_op::move:
{
assert(src); // NOLINT
auto msrc = const_cast<atomic_refcounted_string_ref *>(src); // NOLINT
msrc->_begin = msrc->_end = nullptr;
msrc->_state[0] = msrc->_state[1] = msrc->_state[2] = nullptr;
return;
}
case _thunk_op::destruct:
{
if(dest->_msg() != nullptr)
{
auto count = dest->_msg()->count.fetch_sub(1, std::memory_order_release);
if(count == 1)
{
std::atomic_thread_fence(std::memory_order_acquire);
free((void *) dest->_begin); // NOLINT
delete dest->_msg(); // NOLINT
}
}
}
}
}
public:
//! Construct from a C string literal allocated using `malloc()`.
explicit atomic_refcounted_string_ref(const char *str, size_type len = static_cast<size_type>(-1), void *state1 = nullptr, void *state2 = nullptr) noexcept
: string_ref(str, len, new(std::nothrow) _allocated_msg, state1, state2, _refcounted_string_thunk)
{
if(_msg() == nullptr)
{
free((void *) this->_begin); // NOLINT
_msg() = nullptr; // disabled
this->_begin = "failed to get message from system";
this->_end = strchr(this->_begin, 0);
return;
}
}
};
private:
unique_id_type _id;
protected:
/*! Use [https://www.random.org/cgi-bin/randbyte?nbytes=8&format=h](https://www.random.org/cgi-bin/randbyte?nbytes=8&format=h) to get a random 64 bit id.
Do NOT make up your own value. Do NOT use zero.
*/
constexpr explicit status_code_domain(unique_id_type id) noexcept
: _id(id)
{
}
/*! UUID constructor, where input is constexpr parsed into a `unique_id_type`.
*/
template <size_t N>
constexpr explicit status_code_domain(const char (&uuid)[N]) noexcept
: _id(detail::parse_uuid_from_array<N>(uuid))
{
}
template <size_t N> struct _uuid_size
{
};
//! Alternative UUID constructor
template <size_t N>
constexpr explicit status_code_domain(const char *uuid, _uuid_size<N> /*unused*/) noexcept
: _id(detail::parse_uuid_from_pointer<N>(uuid))
{
}
//! No public copying at type erased level
status_code_domain(const status_code_domain &) = default;
//! No public moving at type erased level
status_code_domain(status_code_domain &&) = default;
//! No public assignment at type erased level
status_code_domain &operator=(const status_code_domain &) = default;
//! No public assignment at type erased level
status_code_domain &operator=(status_code_domain &&) = default;
//! No public destruction at type erased level
~status_code_domain() = default;
public:
//! True if the unique ids match.
constexpr bool operator==(const status_code_domain &o) const noexcept { return _id == o._id; }
//! True if the unique ids do not match.
constexpr bool operator!=(const status_code_domain &o) const noexcept { return _id != o._id; }
//! True if this unique is lower than the other's unique id.
constexpr bool operator<(const status_code_domain &o) const noexcept { return _id < o._id; }
//! Returns the unique id used to identify identical category instances.
constexpr unique_id_type id() const noexcept { return _id; }
//! Name of this category.
SYSTEM_ERROR2_CONSTEXPR20 virtual string_ref name() const noexcept = 0;
//! Information about the payload of the code for this domain
struct payload_info_t
{
size_t payload_size{0}; //!< The payload size in bytes
size_t total_size{0}; //!< The total status code size in bytes (includes domain pointer and mixins state)
size_t total_alignment{1}; //!< The total status code alignment in bytes
payload_info_t() = default;
constexpr payload_info_t(size_t _payload_size, size_t _total_size, size_t _total_alignment)
: payload_size(_payload_size)
, total_size(_total_size)
, total_alignment(_total_alignment)
{
}
};
//! Information about this domain's payload
SYSTEM_ERROR2_CONSTEXPR20 virtual payload_info_t payload_info() const noexcept = 0;
protected:
//! True if code means failure.
SYSTEM_ERROR2_CONSTEXPR20 virtual bool _do_failure(const status_code<void> &code) const noexcept = 0;
//! True if code is (potentially non-transitively) equivalent to another code in another domain.
SYSTEM_ERROR2_CONSTEXPR20 virtual bool _do_equivalent(const status_code<void> &code1, const status_code<void> &code2) const noexcept = 0;
//! Returns the generic code closest to this code, if any.
SYSTEM_ERROR2_CONSTEXPR20 virtual generic_code _generic_code(const status_code<void> &code) const noexcept = 0;
//! Return a reference to a string textually representing a code.
SYSTEM_ERROR2_CONSTEXPR20 virtual string_ref _do_message(const status_code<void> &code) const noexcept = 0;
#if defined(_CPPUNWIND) || defined(__EXCEPTIONS) || 0L
//! Throw a code as a C++ exception.
SYSTEM_ERROR2_NORETURN SYSTEM_ERROR2_CONSTEXPR20 virtual void _do_throw_exception(const status_code<void> &code) const = 0;
#else
// Keep a vtable slot for binary compatibility
SYSTEM_ERROR2_NORETURN virtual void _do_throw_exception(const status_code<void> & /*code*/) const { abort(); }
#endif
// For a `status_code<erased<T>>` only, copy from `src` to `dst`. Default implementation uses `memcpy()`. You should return false here if your payload is not
// trivially copyable or would not fit.
virtual bool _do_erased_copy(status_code<void> &dst, const status_code<void> &src, payload_info_t dstinfo) const
{
// Note that dst may not have its domain set
const auto srcinfo = payload_info();
if(dstinfo.total_size < srcinfo.total_size)
{
return false;
}
const auto tocopy = (dstinfo.total_size > srcinfo.total_size) ? srcinfo.total_size : dstinfo.total_size;
memcpy(&dst, &src, tocopy);
return true;
} // NOLINT
// For a `status_code<erased<T>>` only, destroy the erased value type. Default implementation does nothing.
SYSTEM_ERROR2_CONSTEXPR20 virtual void _do_erased_destroy(status_code<void> &code, payload_info_t info) const noexcept // NOLINT
{
(void) code;
(void) info;
}
};
SYSTEM_ERROR2_NAMESPACE_END
#endif
#if (__cplusplus >= 201700 || _HAS_CXX17) && !defined(SYSTEM_ERROR2_DISABLE_STD_IN_PLACE)
// 0.26
#include <utility> // for in_place
SYSTEM_ERROR2_NAMESPACE_BEGIN
using in_place_t = std::in_place_t;
using std::in_place;
SYSTEM_ERROR2_NAMESPACE_END
#else
SYSTEM_ERROR2_NAMESPACE_BEGIN
//! Aliases `std::in_place_t` if on C++ 17 or later, else defined locally.
struct in_place_t
{
explicit in_place_t() = default;
};
//! Aliases `std::in_place` if on C++ 17 or later, else defined locally.
constexpr in_place_t in_place{};
SYSTEM_ERROR2_NAMESPACE_END
#endif
SYSTEM_ERROR2_NAMESPACE_BEGIN
//! Namespace for user injected mixins
namespace mixins
{
template <class Base, class T> struct mixin : public Base
{
using Base::Base;
};
} // namespace mixins
namespace detail
{
SYSTEM_ERROR2_TEMPLATE(class ErasedType) //
SYSTEM_ERROR2_TREQUIRES(SYSTEM_ERROR2_TPRED(traits::is_move_bitcopying<ErasedType>::value))
struct erased
{
using value_type = ErasedType;
};
} // namespace detail
/*! The tag type used to specialise erased editions of `status_code<D>`.
Available only if `ErasedType` satisfies `traits::is_move_bitcopying<ErasedType>::value`.
*/
template <class ErasedType> //
using status_code_erased_tag_type = detail::erased<ErasedType>;
/*! Specialise this template to quickly wrap a third party enumeration into a
custom status code domain.
Use like this:
```c++
SYSTEM_ERROR2_NAMESPACE_BEGIN
template <> struct quick_status_code_from_enum<AnotherCode> : quick_status_code_from_enum_defaults<AnotherCode>
{
// Text name of the enum
static constexpr const auto domain_name = "Another Code";
// Unique UUID for the enum. PLEASE use https://www.random.org/cgi-bin/randbyte?nbytes=16&format=h
static constexpr const auto domain_uuid = "{be201f65-3962-dd0e-1266-a72e63776a42}";
// Map of each enum value to its text string, and list of semantically equivalent errc's
static const std::initializer_list<mapping> &value_mappings()
{
static const std::initializer_list<mapping<AnotherCode>> v = {
// Format is: { enum value, "string representation", { list of errc mappings ... } }
{AnotherCode::success1, "Success 1", {errc::success}}, //
{AnotherCode::goaway, "Go away", {errc::permission_denied}}, //
{AnotherCode::success2, "Success 2", {errc::success}}, //
{AnotherCode::error2, "Error 2", {}}, //
};
return v;
}
// Completely optional definition of mixin for the status code synthesised from `Enum`. It can be omitted.
template <class Base> struct mixin : Base
{
using Base::Base;
constexpr int custom_method() const { return 42; }
};
};
SYSTEM_ERROR2_NAMESPACE_END
```
Note that if the `errc` mapping contains `errc::success`, then
the enumeration value is considered to be a successful value.
Otherwise it is considered to be a failure value.
The first value in the `errc` mapping is the one chosen as the
`generic_code` conversion. Other values are used during equivalence
comparisons.
*/
template <class Enum> struct quick_status_code_from_enum;
namespace detail
{
template <class T> struct is_status_code
{
static constexpr bool value = false;
};
template <class T> struct is_status_code<status_code<T>>
{
static constexpr bool value = true;
};
template <class T> struct is_erased_status_code
{
static constexpr bool value = false;
};
template <class T> struct is_erased_status_code<status_code<detail::erased<T>>>
{
static constexpr bool value = true;
};
#if !defined(__GNUC__) || defined(__clang__) || __GNUC__ >= 8
// From http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2015/n4436.pdf
namespace impl
{
template <typename... Ts> struct make_void
{
using type = void;
};
template <typename... Ts> using void_t = typename make_void<Ts...>::type;
template <class...> struct types
{
using type = types;
};
template <template <class...> class T, class types, class = void> struct test_apply
{
using type = void;
};
template <template <class...> class T, class... Ts> struct test_apply<T, types<Ts...>, void_t<T<Ts...>>>
{
using type = T<Ts...>;
};
} // namespace impl
template <template <class...> class T, class... Ts> using test_apply = impl::test_apply<T, impl::types<Ts...>>;
template <class T, class... Args> using get_make_status_code_result = decltype(make_status_code(std::declval<T>(), std::declval<Args>()...));
template <class... Args> using safe_get_make_status_code_result = test_apply<get_make_status_code_result, Args...>;
#else
// ICE avoidance form for GCCs before 8. Note this form doesn't prevent recursive make_status_code ADL instantation,
// so in certain corner cases this will break. On the other hand, more useful than an ICE.
namespace impl
{
template <typename... Ts> struct make_void
{
using type = void;
};
template <typename... Ts> using void_t = typename make_void<Ts...>::type;
template <class...> struct types
{
using type = types;
};
template <typename Types, typename = void> struct make_status_code_rettype
{
using type = void;
};
template <typename... Args> using get_make_status_code_result = decltype(make_status_code(std::declval<Args>()...));
template <typename... Args> struct make_status_code_rettype<types<Args...>, void_t<get_make_status_code_result<Args...>>>
{
using type = get_make_status_code_result<Args...>;
};
} // namespace impl
template <class... Args> struct safe_get_make_status_code_result
{
using type = typename impl::make_status_code_rettype<impl::types<Args...>>::type;
};
#endif
} // namespace detail
//! Trait returning true if the type is a status code.
template <class T> struct is_status_code
{
static constexpr bool value =
detail::is_status_code<typename std::decay<T>::type>::value || detail::is_erased_status_code<typename std::decay<T>::type>::value;
};
/*! A type erased lightweight status code reflecting empty, success, or failure.
Differs from `status_code<erased<>>` by being always available irrespective of
the domain's value type, but cannot be copied, moved, nor destructed. Thus one
always passes this around by const lvalue reference.
*/
template <> class SYSTEM_ERROR2_TRIVIAL_ABI status_code<void>
{
template <class T> friend class status_code;
public:
//! The type of the domain.
using domain_type = void;
//! The type of the status code.
using value_type = void;
//! The type of a reference to a message string.
using string_ref = typename status_code_domain::string_ref;
protected:
const status_code_domain *_domain{nullptr};
protected:
//! No default construction at type erased level
status_code() = default;
//! No public copying at type erased level
status_code(const status_code &) = default;
//! No public moving at type erased level
status_code(status_code &&) = default;
//! No public assignment at type erased level
status_code &operator=(const status_code &) = default;
//! No public assignment at type erased level
status_code &operator=(status_code &&) = default;
//! No public destruction at type erased level
~status_code() = default;
//! Used to construct a non-empty type erased status code
constexpr explicit status_code(const status_code_domain *v) noexcept
: _domain(v)
{
}
// Used to work around triggering a ubsan failure. Do NOT remove!
constexpr const status_code_domain *_domain_ptr() const noexcept { return _domain; }
public:
//! Return the status code domain.
constexpr const status_code_domain &domain() const noexcept { return *_domain; }
//! True if the status code is empty.
SYSTEM_ERROR2_NODISCARD constexpr bool empty() const noexcept { return _domain == nullptr; }
//! Return a reference to a string textually representing a code.
SYSTEM_ERROR2_CONSTEXPR20 string_ref message() const noexcept
{
// Avoid MSVC's buggy ternary operator for expensive to destruct things
if(_domain != nullptr)
{
return _domain->_do_message(*this);
}
return string_ref("(empty)");
}
//! True if code means success.
SYSTEM_ERROR2_CONSTEXPR20 bool success() const noexcept { return (_domain != nullptr) ? !_domain->_do_failure(*this) : false; }
//! True if code means failure.
SYSTEM_ERROR2_CONSTEXPR20 bool failure() const noexcept { return (_domain != nullptr) ? _domain->_do_failure(*this) : false; }
/*! True if code is strictly (and potentially non-transitively) semantically equivalent to another code in another domain.
Note that usually non-semantic i.e. pure value comparison is used when the other status code has the same domain.
As `equivalent()` will try mapping to generic code, this usually captures when two codes have the same semantic
meaning in `equivalent()`.
*/
template <class T> SYSTEM_ERROR2_CONSTEXPR14 bool strictly_equivalent(const status_code<T> &o) const noexcept
{
if(_domain && o._domain)
{
return _domain->_do_equivalent(*this, o);
}
// If we are both empty, we are equivalent
if(!_domain && !o._domain)
{
return true; // NOLINT
}
// Otherwise not equivalent
return false;
}
/*! True if code is equivalent, by any means, to another code in another domain (guaranteed transitive).
Firstly `strictly_equivalent()` is run in both directions. If neither succeeds, each domain is asked
for the equivalent generic code and those are compared.
*/
template <class T> SYSTEM_ERROR2_CONSTEXPR14 inline bool equivalent(const status_code<T> &o) const noexcept;
#if defined(_CPPUNWIND) || defined(__EXCEPTIONS) || 0L
//! Throw a code as a C++ exception.
SYSTEM_ERROR2_NORETURN void throw_exception() const
{
_domain->_do_throw_exception(*this);
abort(); // suppress buggy GCC warning
}
#endif
};
namespace detail
{
template <class DomainType> struct get_domain_value_type
{
using domain_type = DomainType;
using value_type = typename domain_type::value_type;
};
template <class ErasedType> struct get_domain_value_type<erased<ErasedType>>
{
using domain_type = status_code_domain;
using value_type = ErasedType;
};
template <class DomainType> class SYSTEM_ERROR2_TRIVIAL_ABI status_code_storage : public status_code<void>
{
static_assert(!std::is_void<DomainType>::value, "status_code_storage<void> should never occur!");
using _base = status_code<void>;
public:
//! The type of the domain.
using domain_type = typename get_domain_value_type<DomainType>::domain_type;
//! The type of the status code.
using value_type = typename get_domain_value_type<DomainType>::value_type;
//! The type of a reference to a message string.
using string_ref = typename domain_type::string_ref;
#ifndef NDEBUG
static_assert(std::is_move_constructible<value_type>::value || std::is_copy_constructible<value_type>::value,
"DomainType::value_type is neither move nor copy constructible!");
static_assert(!std::is_default_constructible<value_type>::value || std::is_nothrow_default_constructible<value_type>::value,
"DomainType::value_type is not nothrow default constructible!");
static_assert(!std::is_move_constructible<value_type>::value || std::is_nothrow_move_constructible<value_type>::value,
"DomainType::value_type is not nothrow move constructible!");
static_assert(std::is_nothrow_destructible<value_type>::value, "DomainType::value_type is not nothrow destructible!");
#endif
// Replace the type erased implementations with type aware implementations for better codegen
//! Return the status code domain.
constexpr const domain_type &domain() const noexcept { return *static_cast<const domain_type *>(this->_domain); }
//! Reset the code to empty.
SYSTEM_ERROR2_CONSTEXPR14 void clear() noexcept
{
this->_value.~value_type();
this->_domain = nullptr;
new(std::addressof(this->_value)) value_type();
}
#if __cplusplus >= 201400 || _MSC_VER >= 1910 /* VS2017 */
//! Return a reference to the `value_type`.
constexpr value_type &value() & noexcept { return this->_value; }
//! Return a reference to the `value_type`.
constexpr value_type &&value() && noexcept { return static_cast<value_type &&>(this->_value); }
#endif
//! Return a reference to the `value_type`.
constexpr const value_type &value() const & noexcept { return this->_value; }
//! Return a reference to the `value_type`.
constexpr const value_type &&value() const && noexcept { return static_cast<const value_type &&>(this->_value); }
protected:
status_code_storage() = default;
status_code_storage(const status_code_storage &) = default;
SYSTEM_ERROR2_CONSTEXPR14 status_code_storage(status_code_storage &&o) noexcept
: _base(static_cast<status_code_storage &&>(o))
, _value(static_cast<status_code_storage &&>(o)._value)
{
o._domain = nullptr;
}
status_code_storage &operator=(const status_code_storage &) = default;
SYSTEM_ERROR2_CONSTEXPR14 status_code_storage &operator=(status_code_storage &&o) noexcept
{
this->~status_code_storage();
new(this) status_code_storage(static_cast<status_code_storage &&>(o));
return *this;
}
~status_code_storage() = default;
value_type _value{};
struct _value_type_constructor
{
};
template <class... Args>
constexpr status_code_storage(_value_type_constructor /*unused*/, const status_code_domain *v, Args &&...args)
: _base(v)
, _value(static_cast<Args &&>(args)...)
{
}
};
template <class DomainType> struct has_stateful_mixin
{
static constexpr bool value = (sizeof(status_code_storage<DomainType>) != sizeof(mixins::mixin<status_code_storage<DomainType>, DomainType>));
};
template <class ToDomain, class FromDomain> struct domain_value_type_erasure_is_safe
{
using to_value_type = typename get_domain_value_type<ToDomain>::value_type;
using from_value_type = typename get_domain_value_type<FromDomain>::value_type;
static constexpr bool value = traits::is_move_bitcopying<to_value_type>::value //
&& traits::is_move_bitcopying<from_value_type>::value //
&& sizeof(status_code_storage<FromDomain>) <= sizeof(status_code_storage<ToDomain>) //
&& !has_stateful_mixin<FromDomain>::value;
};
template <class ToDomain> struct domain_value_type_erasure_is_safe<ToDomain, void>
{
static constexpr bool value = false;
};
} // namespace detail
namespace traits
{
//! Determines whether the mixin contained in `StatusCode` contains non-static member variables.
template <class StatusCode> using has_stateful_mixin = detail::has_stateful_mixin<typename detail::remove_cvref<StatusCode>::type::value_type>;
//! Determines whether the status code `From` can be type erased into the status code `To`.
template <class To, class From>
using is_type_erasable_to =
detail::domain_value_type_erasure_is_safe<typename detail::remove_cvref<To>::type::domain_type, typename detail::remove_cvref<From>::type::domain_type>;
} // namespace traits
/*! A lightweight, typed, status code reflecting empty, success, or failure.
This is the main workhorse of the system_error2 library. Its characteristics reflect the value type
set by its domain type, so if that value type is move-only or trivial, so is this.
An ADL discovered helper function `make_status_code(T, Args...)` is looked up by one of the constructors.
If it is found, and it generates a status code compatible with this status code, implicit construction
is made available.
You may mix in custom member functions and member function overrides by injecting a specialisation of
`mixins::mixin<Base, YourDomainType>`. Your mixin must inherit from `Base`. Your mixin can carry state,
but if it does, it will no longer be possible to construct erased status codes from such unerased status
codes.
*/
template <class DomainType> class SYSTEM_ERROR2_TRIVIAL_ABI status_code : public mixins::mixin<detail::status_code_storage<DomainType>, DomainType>
{
template <class T> friend class status_code;
using _base = mixins::mixin<detail::status_code_storage<DomainType>, DomainType>;
public:
//! The type of the domain.
using domain_type = DomainType;
//! The type of the status code.
using value_type = typename domain_type::value_type;
//! The type of a reference to a message string.
using string_ref = typename domain_type::string_ref;
protected:
using _base::_base;
public:
//! Default construction to empty
status_code() = default;
//! Copy constructor
status_code(const status_code &) = default;
//! Move constructor
status_code(status_code &&) = default; // NOLINT
//! Copy assignment
status_code &operator=(const status_code &) = default;
//! Move assignment
status_code &operator=(status_code &&) = default; // NOLINT
~status_code() = default;
//! Return a copy of the code.
SYSTEM_ERROR2_CONSTEXPR14 status_code clone() const { return *this; }
/***** KEEP THESE IN SYNC WITH ERRORED_STATUS_CODE *****/
//! Implicit construction from any type where an ADL discovered `make_status_code(T, Args ...)` returns a `status_code`.
SYSTEM_ERROR2_TEMPLATE(
class T, class... Args, //
class MakeStatusCodeResult =
typename detail::safe_get_make_status_code_result<T, Args...>::type) // Safe ADL lookup of make_status_code(), returns void if not found
SYSTEM_ERROR2_TREQUIRES(SYSTEM_ERROR2_TPRED(!std::is_same<typename std::decay<T>::type, status_code>::value // not copy/move of self
&& !std::is_same<typename std::decay<T>::type, in_place_t>::value // not in_place_t
&& is_status_code<MakeStatusCodeResult>::value // ADL makes a status code
&& std::is_constructible<status_code, MakeStatusCodeResult>::value)) // ADLed status code is compatible
constexpr status_code(T &&v, Args &&...args) noexcept(noexcept(make_status_code(std::declval<T>(), std::declval<Args>()...))) // NOLINT
: status_code(make_status_code(static_cast<T &&>(v), static_cast<Args &&>(args)...))
{
}
//! Implicit construction from any `quick_status_code_from_enum<Enum>` enumerated type.
SYSTEM_ERROR2_TEMPLATE(class Enum, //
class QuickStatusCodeType = typename quick_status_code_from_enum<Enum>::code_type) // Enumeration has been activated
SYSTEM_ERROR2_TREQUIRES(SYSTEM_ERROR2_TPRED(std::is_constructible<status_code, QuickStatusCodeType>::value)) // Its status code is compatible
constexpr status_code(Enum &&v) noexcept(std::is_nothrow_constructible<status_code, QuickStatusCodeType>::value) // NOLINT
: status_code(QuickStatusCodeType(static_cast<Enum &&>(v)))
{
}
//! Explicit in-place construction. Disables if `domain_type::get()` is not a valid expression.
template <class... Args>
constexpr explicit status_code(in_place_t /*unused */, Args &&...args) noexcept(std::is_nothrow_constructible<value_type, Args &&...>::value)
: _base(typename _base::_value_type_constructor{}, &domain_type::get(), static_cast<Args &&>(args)...)
{
}
//! Explicit in-place construction from initialiser list. Disables if `domain_type::get()` is not a valid expression.
template <class T, class... Args>
constexpr explicit status_code(in_place_t /*unused */, std::initializer_list<T> il,
Args &&...args) noexcept(std::is_nothrow_constructible<value_type, std::initializer_list<T>, Args &&...>::value)
: _base(typename _base::_value_type_constructor{}, &domain_type::get(), il, static_cast<Args &&>(args)...)
{
}
//! Explicit copy construction from a `value_type`. Disables if `domain_type::get()` is not a valid expression.
constexpr explicit status_code(const value_type &v) noexcept(std::is_nothrow_copy_constructible<value_type>::value)
: _base(typename _base::_value_type_constructor{}, &domain_type::get(), v)
{
}
//! Explicit move construction from a `value_type`. Disables if `domain_type::get()` is not a valid expression.
constexpr explicit status_code(value_type &&v) noexcept(std::is_nothrow_move_constructible<value_type>::value)
: _base(typename _base::_value_type_constructor{}, &domain_type::get(), static_cast<value_type &&>(v))
{
}
/*! Explicit construction from an erased status code. Available only if
`value_type` is trivially copyable or move bitcopying, and `sizeof(status_code) <= sizeof(status_code<erased<>>)`.
Does not check if domains are equal.
*/
SYSTEM_ERROR2_TEMPLATE(class ErasedType) //
SYSTEM_ERROR2_TREQUIRES(SYSTEM_ERROR2_TPRED(detail::domain_value_type_erasure_is_safe<domain_type, detail::erased<ErasedType>>::value))
constexpr explicit status_code(const status_code<detail::erased<ErasedType>> &v) noexcept(std::is_nothrow_copy_constructible<value_type>::value)
: status_code(detail::erasure_cast<value_type>(v.value()))
{
#if __cplusplus >= 201400
assert(v.domain() == this->domain());
#endif
}
//! Return a reference to a string textually representing a code.
SYSTEM_ERROR2_CONSTEXPR20 string_ref message() const noexcept
{
// Avoid MSVC's buggy ternary operator for expensive to destruct things
if(this->_domain != nullptr)
{
return string_ref(this->domain()._do_message(*this));
}
return string_ref("(empty)");
}
};
namespace traits
{
template <class DomainType> struct is_move_bitcopying<status_code<DomainType>>
{
static constexpr bool value = is_move_bitcopying<typename DomainType::value_type>::value;
};
} // namespace traits
/*! Type erased, move-only status_code, unlike `status_code<void>` which cannot be moved nor destroyed. Available
only if `erased<>` is available, which is when the domain's type is trivially
copyable or is move relocatable, and if the size of the domain's typed error code is less than or equal to
this erased error code. Copy construction is disabled, but if you want a copy call `.clone()`.
An ADL discovered helper function `make_status_code(T, Args...)` is looked up by one of the constructors.
If it is found, and it generates a status code compatible with this status code, implicit construction
is made available.
*/
template <class ErasedType>
class SYSTEM_ERROR2_TRIVIAL_ABI status_code<detail::erased<ErasedType>>
: public mixins::mixin<detail::status_code_storage<detail::erased<ErasedType>>, detail::erased<ErasedType>>
{
template <class T> friend class status_code;
using _base = mixins::mixin<detail::status_code_storage<detail::erased<ErasedType>>, detail::erased<ErasedType>>;
public:
//! The type of the domain (void, as it is erased).
using domain_type = void;
//! The type of the erased status code.
using value_type = ErasedType;
//! The type of a reference to a message string.
using string_ref = typename _base::string_ref;
public:
//! Default construction to empty
status_code() = default;
//! Copy constructor
status_code(const status_code &) = delete;
//! Move constructor
status_code(status_code &&) = default; // NOLINT
//! Copy assignment
status_code &operator=(const status_code &) = delete;
//! Move assignment
status_code &operator=(status_code &&) = default; // NOLINT
SYSTEM_ERROR2_CONSTEXPR20 ~status_code()
{
if(nullptr != this->_domain)
{
status_code_domain::payload_info_t info{sizeof(value_type), sizeof(status_code), alignof(status_code)};
this->_domain->_do_erased_destroy(*this, info);
}
}
//! Return a copy of the erased code by asking the domain to perform the erased copy.
SYSTEM_ERROR2_CONSTEXPR20 status_code clone() const
{
if(nullptr == this->_domain)
{
return {};
}
status_code x;
if(!this->_domain->_do_erased_copy(x, *this, this->_domain->payload_info()))
{
abort(); // should not be possible
}
return x;
}
/***** KEEP THESE IN SYNC WITH ERRORED_STATUS_CODE *****/
//! Implicit copy construction from any other status code if its value type is trivially copyable, it would fit into our storage, and it is not an erased
//! status code.
SYSTEM_ERROR2_TEMPLATE(class DomainType) //
SYSTEM_ERROR2_TREQUIRES(SYSTEM_ERROR2_TPRED(detail::domain_value_type_erasure_is_safe<detail::erased<ErasedType>, DomainType>::value),
SYSTEM_ERROR2_TPRED(!detail::is_erased_status_code<status_code<typename std::decay<DomainType>::type>>::value))
constexpr status_code(const status_code<DomainType> &v) noexcept // NOLINT
: _base(typename _base::_value_type_constructor{}, v._domain_ptr(), detail::erasure_cast<value_type>(v.value()))
{
}
//! Implicit move construction from any other status code if its value type is trivially copyable or move bitcopying and it would fit into our storage
SYSTEM_ERROR2_TEMPLATE(class DomainType) //
SYSTEM_ERROR2_TREQUIRES(SYSTEM_ERROR2_TPRED(detail::domain_value_type_erasure_is_safe<detail::erased<ErasedType>, DomainType>::value))
SYSTEM_ERROR2_CONSTEXPR14 status_code(status_code<DomainType> &&v) noexcept // NOLINT
: _base(typename _base::_value_type_constructor{}, v._domain_ptr(), detail::erasure_cast<value_type>(v.value()))
{
alignas(alignof(typename DomainType::value_type)) char buffer[sizeof(typename DomainType::value_type)];
new(buffer) typename DomainType::value_type(static_cast<status_code<DomainType> &&>(v).value());
// deliberately do not destruct value moved into buffer
(void) buffer;
v._domain = nullptr;
}
//! Implicit construction from any type where an ADL discovered `make_status_code(T, Args ...)` returns a `status_code`.
SYSTEM_ERROR2_TEMPLATE(
class T, class... Args, //
class MakeStatusCodeResult =
typename detail::safe_get_make_status_code_result<T, Args...>::type) // Safe ADL lookup of make_status_code(), returns void if not found
SYSTEM_ERROR2_TREQUIRES(SYSTEM_ERROR2_TPRED(!std::is_same<typename std::decay<T>::type, status_code>::value // not copy/move of self
&& !std::is_same<typename std::decay<T>::type, value_type>::value // not copy/move of value type
&& is_status_code<MakeStatusCodeResult>::value // ADL makes a status code
&& std::is_constructible<status_code, MakeStatusCodeResult>::value)) // ADLed status code is compatible
constexpr status_code(T &&v, Args &&...args) noexcept(noexcept(make_status_code(std::declval<T>(), std::declval<Args>()...))) // NOLINT
: status_code(make_status_code(static_cast<T &&>(v), static_cast<Args &&>(args)...))
{
}
//! Implicit construction from any `quick_status_code_from_enum<Enum>` enumerated type.
SYSTEM_ERROR2_TEMPLATE(class Enum, //
class QuickStatusCodeType = typename quick_status_code_from_enum<Enum>::code_type) // Enumeration has been activated
SYSTEM_ERROR2_TREQUIRES(SYSTEM_ERROR2_TPRED(std::is_constructible<status_code, QuickStatusCodeType>::value)) // Its status code is compatible
constexpr status_code(Enum &&v) noexcept(std::is_nothrow_constructible<status_code, QuickStatusCodeType>::value) // NOLINT
: status_code(QuickStatusCodeType(static_cast<Enum &&>(v)))
{
}
#if defined(_CPPUNWIND) || defined(__EXCEPTIONS) || 0L
//! Explicit copy construction from an unknown status code. Note that this will throw an exception if its value type is not trivially copyable or would not
//! fit into our storage or the source domain's `_do_erased_copy()` refused the copy.
explicit SYSTEM_ERROR2_CONSTEXPR14 status_code(in_place_t, const status_code<void> &v) // NOLINT
: _base(typename _base::_value_type_constructor{}, v._domain_ptr(), value_type{})
{
status_code_domain::payload_info_t info{sizeof(value_type), sizeof(status_code), alignof(status_code)};
if(this->_domain->_do_erased_copy(*this, v, info))
{
return;
}
struct _ final : public std::exception
{
virtual const char *what() const noexcept override { return "status_code: source domain's erased copy function returned failure or refusal"; }
};
throw _{};
}
#endif
//! Tagged copy construction from an unknown status code. Note that this will be empty if its value type is not trivially copyable or would not fit into our
//! storage or the source domain's `_do_erased_copy()` refused the copy.
SYSTEM_ERROR2_CONSTEXPR20 status_code(std::nothrow_t, const status_code<void> &v) noexcept // NOLINT
: _base(typename _base::_value_type_constructor{}, v._domain_ptr(), value_type{})
{
#if defined(_CPPUNWIND) || defined(__EXCEPTIONS) || 0L
try
#endif
{
status_code_domain::payload_info_t info{sizeof(value_type), sizeof(status_code), alignof(status_code)};
if(this->_domain->_do_erased_copy(*this, v, info))
{
return;
}
this->_domain = nullptr;
}
#if defined(_CPPUNWIND) || defined(__EXCEPTIONS) || 0L
catch(...)
{
this->_domain = nullptr;
}
#endif
}
/**** By rights ought to be removed in any formal standard ****/
//! Reset the code to empty.
SYSTEM_ERROR2_CONSTEXPR14 void clear() noexcept { *this = status_code(); }
//! Return the erased `value_type` by value.
constexpr value_type value() const noexcept { return this->_value; }
};
/*! An erased type specialisation of `status_code<D>`.
Available only if `ErasedType` satisfies `traits::is_move_bitcopying<ErasedType>::value`.
*/
template <class ErasedType> using erased_status_code = status_code<detail::erased<ErasedType>>;
namespace traits
{
template <class ErasedType> struct is_move_bitcopying<status_code<detail::erased<ErasedType>>>
{
static constexpr bool value = true;
};
} // namespace traits
SYSTEM_ERROR2_NAMESPACE_END
#ifndef SYSTEM_ERROR2_DISABLE_INLINE_GDB_PRETTY_PRINTERS
#if defined(__ELF__)
__asm__(
".pushsection \".debug_gdb_scripts\", \"MS\",@progbits,1\n"
".byte 4 /* Python Text */\n"
".ascii \"gdb.inlined-script\\n\"\n"
".ascii \"import gdb.printing\\n\"\n"
".ascii \"import gdb\\n\"\n"
".ascii \"import os\\n\"\n"
".ascii \"def synthesise_gdb_value_from_string(s):\\n\"\n"
".ascii \" '''For when you want to return a synthetic string from children()'''\\n\"\n"
".ascii \" return gdb.Value(s + '\\0').cast(gdb.lookup_type('char').pointer())\\n\"\n"
".ascii \"class StatusCodePrinter(object):\\n\"\n"
".ascii \" '''Print a system_error2::status_code<T>'''\\n\"\n"
".ascii \" def __init__(self, val):\\n\"\n"
".ascii \" self.val = val\\n\"\n"
".ascii \" def children(self):\\n\"\n"
".ascii \" s = str(self.val['_domain'])\\n\"\n"
".ascii \" if 'posix_code_domain' in s or 'generic_code_domain' in s:\\n\"\n"
".ascii \" yield ('msg', synthesise_gdb_value_from_string(str(self.val['_value']) + ' (' + os.strerror(int(self.val['_value'])) + ')'))\\n\"\n"
".ascii \" yield ('domain', self.val['_domain'])\\n\"\n"
".ascii \" yield ('value', self.val['_value'])\\n\"\n"
".ascii \" def display_hint(self):\\n\"\n"
".ascii \" return None\\n\"\n"
".ascii \" def to_string(self):\\n\"\n"
".ascii \" s = str(self.val['_domain'])\\n\"\n"
".ascii \" if 'posix_code_domain' in s or 'generic_code_domain' in s:\\n\"\n"
".ascii \" return str(self.val['_value']) + ' (' + os.strerror(int(self.val['_value'])) + ')'\\n\"\n"
".ascii \" else:\\n\"\n"
".ascii \" return self.val['_value']\\n\"\n"
".ascii \"def build_pretty_printer():\\n\"\n"
".ascii \" pp = gdb.printing.RegexpCollectionPrettyPrinter('system_error2')\\n\"\n"
".ascii \" pp.add_printer('system_error2::status_code', '^(boost::)?system_error2::status_code<.*>$', StatusCodePrinter)\\n\"\n"
".ascii \" return pp\\n\"\n"
".ascii \"def register_printers(obj = None):\\n\"\n"
".ascii \" gdb.printing.register_pretty_printer(obj, build_pretty_printer(), replace = True)\\n\"\n"
".ascii \"register_printers(gdb.current_objfile())\\n\"\n"
".byte 0\n"
".popsection\n");
#endif
#endif
#endif
#include <exception> // for std::exception
SYSTEM_ERROR2_NAMESPACE_BEGIN
/*! Exception type representing a thrown status_code
*/
template <class DomainType> class status_error;
/*! The erased type edition of status_error.
*/
template <> class status_error<void> : public std::exception
{
protected:
//! Constructs an instance. Not publicly available.
status_error() = default;
//! Copy constructor. Not publicly available
status_error(const status_error &) = default;
//! Move constructor. Not publicly available
status_error(status_error &&) = default;
//! Copy assignment. Not publicly available
status_error &operator=(const status_error &) = default;
//! Move assignment. Not publicly available
status_error &operator=(status_error &&) = default;
//! Destructor. Not publicly available.
~status_error() override = default;
virtual const status_code<void> &_do_code() const noexcept = 0;
public:
//! The type of the status domain
using domain_type = void;
//! The type of the status code
using status_code_type = status_code<void>;
public:
//! The erased status code which generated this exception instance.
const status_code<void> &code() const noexcept { return _do_code(); }
};
/*! Exception type representing a thrown status_code
*/
template <class DomainType> class status_error : public status_error<void>
{
status_code<DomainType> _code;
typename DomainType::string_ref _msgref;
virtual const status_code<void> &_do_code() const noexcept override final { return _code; }
public:
//! The type of the status domain
using domain_type = DomainType;
//! The type of the status code
using status_code_type = status_code<DomainType>;
//! Constructs an instance
explicit status_error(status_code<DomainType> code)
: _code(static_cast<status_code<DomainType> &&>(code))
, _msgref(_code.message())
{
}
//! Return an explanatory string
virtual const char *what() const noexcept override { return _msgref.c_str(); } // NOLINT
//! Returns a reference to the code
const status_code_type &code() const & { return _code; }
//! Returns a reference to the code
status_code_type &code() & { return _code; }
//! Returns a reference to the code
const status_code_type &&code() const && { return _code; }
//! Returns a reference to the code
status_code_type &&code() && { return _code; }
};
/*! Exception type representing a thrown erased status_code
*/
template <class ErasedType> class status_error<detail::erased<ErasedType>> : public status_error<void>
{
status_code<detail::erased<ErasedType>> _code;
typename status_code_domain::string_ref _msgref;
virtual const status_code<detail::erased<ErasedType>> &_do_code() const noexcept override final { return _code; }
public:
//! The type of the status domain
using domain_type = void;
//! The type of the status code
using status_code_type = status_code<detail::erased<ErasedType>>;
//! Constructs an instance
explicit status_error(status_code<detail::erased<ErasedType>> code)
: _code(static_cast<status_code<detail::erased<ErasedType>> &&>(code))
, _msgref(_code.message())
{
}
//! Return an explanatory string
virtual const char *what() const noexcept override { return _msgref.c_str(); } // NOLINT
//! Returns a reference to the code
const status_code_type &code() const & { return _code; }
//! Returns a reference to the code
status_code_type &code() & { return _code; }
//! Returns a reference to the code
const status_code_type &&code() const && { return _code; }
//! Returns a reference to the code
status_code_type &&code() && { return _code; }
};
SYSTEM_ERROR2_NAMESPACE_END
#endif
#include <cerrno> // for error constants
SYSTEM_ERROR2_NAMESPACE_BEGIN
//! The generic error coding (POSIX)
enum class errc : int
{
success = 0,
unknown = -1,
address_family_not_supported = EAFNOSUPPORT,
address_in_use = EADDRINUSE,
address_not_available = EADDRNOTAVAIL,
already_connected = EISCONN,
argument_list_too_long = E2BIG,
argument_out_of_domain = EDOM,
bad_address = EFAULT,
bad_file_descriptor = EBADF,
bad_message = EBADMSG,
broken_pipe = EPIPE,
connection_aborted = ECONNABORTED,
connection_already_in_progress = EALREADY,
connection_refused = ECONNREFUSED,
connection_reset = ECONNRESET,
cross_device_link = EXDEV,
destination_address_required = EDESTADDRREQ,
device_or_resource_busy = EBUSY,
directory_not_empty = ENOTEMPTY,
executable_format_error = ENOEXEC,
file_exists = EEXIST,
file_too_large = EFBIG,
filename_too_long = ENAMETOOLONG,
function_not_supported = ENOSYS,
host_unreachable = EHOSTUNREACH,
identifier_removed = EIDRM,
illegal_byte_sequence = EILSEQ,
inappropriate_io_control_operation = ENOTTY,
interrupted = EINTR,
invalid_argument = EINVAL,
invalid_seek = ESPIPE,
io_error = EIO,
is_a_directory = EISDIR,
message_size = EMSGSIZE,
network_down = ENETDOWN,
network_reset = ENETRESET,
network_unreachable = ENETUNREACH,
no_buffer_space = ENOBUFS,
no_child_process = ECHILD,
no_link = ENOLINK,
no_lock_available = ENOLCK,
no_message = ENOMSG,
no_protocol_option = ENOPROTOOPT,
no_space_on_device = ENOSPC,
no_stream_resources = ENOSR,
no_such_device_or_address = ENXIO,
no_such_device = ENODEV,
no_such_file_or_directory = ENOENT,
no_such_process = ESRCH,
not_a_directory = ENOTDIR,
not_a_socket = ENOTSOCK,
not_a_stream = ENOSTR,
not_connected = ENOTCONN,
not_enough_memory = ENOMEM,
not_supported = ENOTSUP,
operation_canceled = ECANCELED,
operation_in_progress = EINPROGRESS,
operation_not_permitted = EPERM,
operation_not_supported = EOPNOTSUPP,
operation_would_block = EWOULDBLOCK,
owner_dead = EOWNERDEAD,
permission_denied = EACCES,
protocol_error = EPROTO,
protocol_not_supported = EPROTONOSUPPORT,
read_only_file_system = EROFS,
resource_deadlock_would_occur = EDEADLK,
resource_unavailable_try_again = EAGAIN,
result_out_of_range = ERANGE,
state_not_recoverable = ENOTRECOVERABLE,
stream_timeout = ETIME,
text_file_busy = ETXTBSY,
timed_out = ETIMEDOUT,
too_many_files_open_in_system = ENFILE,
too_many_files_open = EMFILE,
too_many_links = EMLINK,
too_many_symbolic_link_levels = ELOOP,
value_too_large = EOVERFLOW,
wrong_protocol_type = EPROTOTYPE
};
namespace detail
{
SYSTEM_ERROR2_CONSTEXPR14 inline const char *generic_code_message(errc code) noexcept
{
switch(code)
{
case errc::success:
return "Success";
case errc::address_family_not_supported:
return "Address family not supported by protocol";
case errc::address_in_use:
return "Address already in use";
case errc::address_not_available:
return "Cannot assign requested address";
case errc::already_connected:
return "Transport endpoint is already connected";
case errc::argument_list_too_long:
return "Argument list too long";
case errc::argument_out_of_domain:
return "Numerical argument out of domain";
case errc::bad_address:
return "Bad address";
case errc::bad_file_descriptor:
return "Bad file descriptor";
case errc::bad_message:
return "Bad message";
case errc::broken_pipe:
return "Broken pipe";
case errc::connection_aborted:
return "Software caused connection abort";
case errc::connection_already_in_progress:
return "Operation already in progress";
case errc::connection_refused:
return "Connection refused";
case errc::connection_reset:
return "Connection reset by peer";
case errc::cross_device_link:
return "Invalid cross-device link";
case errc::destination_address_required:
return "Destination address required";
case errc::device_or_resource_busy:
return "Device or resource busy";
case errc::directory_not_empty:
return "Directory not empty";
case errc::executable_format_error:
return "Exec format error";
case errc::file_exists:
return "File exists";
case errc::file_too_large:
return "File too large";
case errc::filename_too_long:
return "File name too long";
case errc::function_not_supported:
return "Function not implemented";
case errc::host_unreachable:
return "No route to host";
case errc::identifier_removed:
return "Identifier removed";
case errc::illegal_byte_sequence:
return "Invalid or incomplete multibyte or wide character";
case errc::inappropriate_io_control_operation:
return "Inappropriate ioctl for device";
case errc::interrupted:
return "Interrupted system call";
case errc::invalid_argument:
return "Invalid argument";
case errc::invalid_seek:
return "Illegal seek";
case errc::io_error:
return "Input/output error";
case errc::is_a_directory:
return "Is a directory";
case errc::message_size:
return "Message too long";
case errc::network_down:
return "Network is down";
case errc::network_reset:
return "Network dropped connection on reset";
case errc::network_unreachable:
return "Network is unreachable";
case errc::no_buffer_space:
return "No buffer space available";
case errc::no_child_process:
return "No child processes";
case errc::no_link:
return "Link has been severed";
case errc::no_lock_available:
return "No locks available";
case errc::no_message:
return "No message of desired type";
case errc::no_protocol_option:
return "Protocol not available";
case errc::no_space_on_device:
return "No space left on device";
case errc::no_stream_resources:
return "Out of streams resources";
case errc::no_such_device_or_address:
return "No such device or address";
case errc::no_such_device:
return "No such device";
case errc::no_such_file_or_directory:
return "No such file or directory";
case errc::no_such_process:
return "No such process";
case errc::not_a_directory:
return "Not a directory";
case errc::not_a_socket:
return "Socket operation on non-socket";
case errc::not_a_stream:
return "Device not a stream";
case errc::not_connected:
return "Transport endpoint is not connected";
case errc::not_enough_memory:
return "Cannot allocate memory";
#if ENOTSUP != EOPNOTSUPP
case errc::not_supported:
return "Operation not supported";
#endif
case errc::operation_canceled:
return "Operation canceled";
case errc::operation_in_progress:
return "Operation now in progress";
case errc::operation_not_permitted:
return "Operation not permitted";
case errc::operation_not_supported:
return "Operation not supported";
#if EAGAIN != EWOULDBLOCK
case errc::operation_would_block:
return "Resource temporarily unavailable";
#endif
case errc::owner_dead:
return "Owner died";
case errc::permission_denied:
return "Permission denied";
case errc::protocol_error:
return "Protocol error";
case errc::protocol_not_supported:
return "Protocol not supported";
case errc::read_only_file_system:
return "Read-only file system";
case errc::resource_deadlock_would_occur:
return "Resource deadlock avoided";
case errc::resource_unavailable_try_again:
return "Resource temporarily unavailable";
case errc::result_out_of_range:
return "Numerical result out of range";
case errc::state_not_recoverable:
return "State not recoverable";
case errc::stream_timeout:
return "Timer expired";
case errc::text_file_busy:
return "Text file busy";
case errc::timed_out:
return "Connection timed out";
case errc::too_many_files_open_in_system:
return "Too many open files in system";
case errc::too_many_files_open:
return "Too many open files";
case errc::too_many_links:
return "Too many links";
case errc::too_many_symbolic_link_levels:
return "Too many levels of symbolic links";
case errc::value_too_large:
return "Value too large for defined data type";
case errc::wrong_protocol_type:
return "Protocol wrong type for socket";
default:
return "unknown";
}
}
} // namespace detail
/*! The implementation of the domain for generic status codes, those mapped by `errc` (POSIX).
*/
class _generic_code_domain : public status_code_domain
{
template <class> friend class status_code;
using _base = status_code_domain;
public:
//! The value type of the generic code, which is an `errc` as per POSIX.
using value_type = errc;
using string_ref = _base::string_ref;
public:
//! Default constructor
constexpr explicit _generic_code_domain(typename _base::unique_id_type id = 0x746d6354f4f733e9) noexcept
: _base(id)
{
}
_generic_code_domain(const _generic_code_domain &) = default;
_generic_code_domain(_generic_code_domain &&) = default;
_generic_code_domain &operator=(const _generic_code_domain &) = default;
_generic_code_domain &operator=(_generic_code_domain &&) = default;
~_generic_code_domain() = default;
//! Constexpr singleton getter. Returns the constexpr generic_code_domain variable.
static inline constexpr const _generic_code_domain &get();
virtual _base::string_ref name() const noexcept override { return string_ref("generic domain"); } // NOLINT
virtual payload_info_t payload_info() const noexcept override
{
return {sizeof(value_type), sizeof(status_code_domain *) + sizeof(value_type),
(alignof(value_type) > alignof(status_code_domain *)) ? alignof(value_type) : alignof(status_code_domain *)};
}
protected:
virtual bool _do_failure(const status_code<void> &code) const noexcept override // NOLINT
{
assert(code.domain() == *this); // NOLINT
return static_cast<const generic_code &>(code).value() != errc::success; // NOLINT
}
virtual bool _do_equivalent(const status_code<void> &code1, const status_code<void> &code2) const noexcept override // NOLINT
{
assert(code1.domain() == *this); // NOLINT
const auto &c1 = static_cast<const generic_code &>(code1); // NOLINT
if(code2.domain() == *this)
{
const auto &c2 = static_cast<const generic_code &>(code2); // NOLINT
return c1.value() == c2.value();
}
return false;
}
virtual generic_code _generic_code(const status_code<void> &code) const noexcept override // NOLINT
{
assert(code.domain() == *this); // NOLINT
return static_cast<const generic_code &>(code); // NOLINT
}
virtual _base::string_ref _do_message(const status_code<void> &code) const noexcept override // NOLINT
{
assert(code.domain() == *this); // NOLINT
const auto &c = static_cast<const generic_code &>(code); // NOLINT
return string_ref(detail::generic_code_message(c.value()));
}
#if defined(_CPPUNWIND) || defined(__EXCEPTIONS) || 0L
SYSTEM_ERROR2_NORETURN virtual void _do_throw_exception(const status_code<void> &code) const override // NOLINT
{
assert(code.domain() == *this); // NOLINT
const auto &c = static_cast<const generic_code &>(code); // NOLINT
throw status_error<_generic_code_domain>(c);
}
#endif
};
//! A specialisation of `status_error` for the generic code domain.
using generic_error = status_error<_generic_code_domain>;
//! A constexpr source variable for the generic code domain, which is that of `errc` (POSIX). Returned by `_generic_code_domain::get()`.
constexpr _generic_code_domain generic_code_domain;
inline constexpr const _generic_code_domain &_generic_code_domain::get()
{
return generic_code_domain;
}
// Enable implicit construction of generic_code from errc
SYSTEM_ERROR2_CONSTEXPR14 inline generic_code make_status_code(errc c) noexcept
{
return generic_code(in_place, c);
}
/*************************************************************************************************************/
template <class T> inline SYSTEM_ERROR2_CONSTEXPR14 bool status_code<void>::equivalent(const status_code<T> &o) const noexcept
{
if(_domain && o._domain)
{
if(_domain->_do_equivalent(*this, o))
{
return true;
}
if(o._domain->_do_equivalent(o, *this))
{
return true;
}
generic_code c1 = o._domain->_generic_code(o);
if(c1.value() != errc::unknown && _domain->_do_equivalent(*this, c1))
{
return true;
}
generic_code c2 = _domain->_generic_code(*this);
if(c2.value() != errc::unknown && o._domain->_do_equivalent(o, c2))
{
return true;
}
}
// If we are both empty, we are equivalent, otherwise not equivalent
return (!_domain && !o._domain);
}
//! True if the status code's are semantically equal via `equivalent()`.
template <class DomainType1, class DomainType2>
SYSTEM_ERROR2_CONSTEXPR14 inline bool operator==(const status_code<DomainType1> &a, const status_code<DomainType2> &b) noexcept
{
return a.equivalent(b);
}
//! True if the status code's are not semantically equal via `equivalent()`.
template <class DomainType1, class DomainType2>
SYSTEM_ERROR2_CONSTEXPR14 inline bool operator!=(const status_code<DomainType1> &a, const status_code<DomainType2> &b) noexcept
{
return !a.equivalent(b);
}
//! True if the status code's are semantically equal via `equivalent()` to `make_status_code(T)`.
SYSTEM_ERROR2_TEMPLATE(class DomainType1, class T, //
class MakeStatusCodeResult =
typename detail::safe_get_make_status_code_result<const T &>::type) // Safe ADL lookup of make_status_code(), returns void if not found
SYSTEM_ERROR2_TREQUIRES(SYSTEM_ERROR2_TPRED(is_status_code<MakeStatusCodeResult>::value)) // ADL makes a status code
SYSTEM_ERROR2_CONSTEXPR14 inline bool operator==(const status_code<DomainType1> &a, const T &b)
{
return a.equivalent(make_status_code(b));
}
//! True if the status code's are semantically equal via `equivalent()` to `make_status_code(T)`.
SYSTEM_ERROR2_TEMPLATE(class T, class DomainType1, //
class MakeStatusCodeResult =
typename detail::safe_get_make_status_code_result<const T &>::type) // Safe ADL lookup of make_status_code(), returns void if not found
SYSTEM_ERROR2_TREQUIRES(SYSTEM_ERROR2_TPRED(is_status_code<MakeStatusCodeResult>::value)) // ADL makes a status code
SYSTEM_ERROR2_CONSTEXPR14 inline bool operator==(const T &a, const status_code<DomainType1> &b)
{
return b.equivalent(make_status_code(a));
}
//! True if the status code's are not semantically equal via `equivalent()` to `make_status_code(T)`.
SYSTEM_ERROR2_TEMPLATE(class DomainType1, class T, //
class MakeStatusCodeResult =
typename detail::safe_get_make_status_code_result<const T &>::type) // Safe ADL lookup of make_status_code(), returns void if not found
SYSTEM_ERROR2_TREQUIRES(SYSTEM_ERROR2_TPRED(is_status_code<MakeStatusCodeResult>::value)) // ADL makes a status code
SYSTEM_ERROR2_CONSTEXPR14 inline bool operator!=(const status_code<DomainType1> &a, const T &b)
{
return !a.equivalent(make_status_code(b));
}
//! True if the status code's are semantically equal via `equivalent()` to `make_status_code(T)`.
SYSTEM_ERROR2_TEMPLATE(class T, class DomainType1, //
class MakeStatusCodeResult =
typename detail::safe_get_make_status_code_result<const T &>::type) // Safe ADL lookup of make_status_code(), returns void if not found
SYSTEM_ERROR2_TREQUIRES(SYSTEM_ERROR2_TPRED(is_status_code<MakeStatusCodeResult>::value)) // ADL makes a status code
SYSTEM_ERROR2_CONSTEXPR14 inline bool operator!=(const T &a, const status_code<DomainType1> &b)
{
return !b.equivalent(make_status_code(a));
}
//! True if the status code's are semantically equal via `equivalent()` to `quick_status_code_from_enum<T>::code_type(b)`.
template <class DomainType1, class T, //
class QuickStatusCodeType = typename quick_status_code_from_enum<T>::code_type // Enumeration has been activated
>
SYSTEM_ERROR2_CONSTEXPR14 inline bool operator==(const status_code<DomainType1> &a, const T &b)
{
return a.equivalent(QuickStatusCodeType(b));
}
//! True if the status code's are semantically equal via `equivalent()` to `quick_status_code_from_enum<T>::code_type(a)`.
template <class T, class DomainType1, //
class QuickStatusCodeType = typename quick_status_code_from_enum<T>::code_type // Enumeration has been activated
>
SYSTEM_ERROR2_CONSTEXPR14 inline bool operator==(const T &a, const status_code<DomainType1> &b)
{
return b.equivalent(QuickStatusCodeType(a));
}
//! True if the status code's are not semantically equal via `equivalent()` to `quick_status_code_from_enum<T>::code_type(b)`.
template <class DomainType1, class T, //
class QuickStatusCodeType = typename quick_status_code_from_enum<T>::code_type // Enumeration has been activated
>
SYSTEM_ERROR2_CONSTEXPR14 inline bool operator!=(const status_code<DomainType1> &a, const T &b)
{
return !a.equivalent(QuickStatusCodeType(b));
}
//! True if the status code's are not semantically equal via `equivalent()` to `quick_status_code_from_enum<T>::code_type(a)`.
template <class T, class DomainType1, //
class QuickStatusCodeType = typename quick_status_code_from_enum<T>::code_type // Enumeration has been activated
>
SYSTEM_ERROR2_CONSTEXPR14 inline bool operator!=(const T &a, const status_code<DomainType1> &b)
{
return !b.equivalent(QuickStatusCodeType(a));
}
SYSTEM_ERROR2_NAMESPACE_END
#endif
SYSTEM_ERROR2_NAMESPACE_BEGIN
template <class Enum> class _quick_status_code_from_enum_domain;
//! A status code wrapping `Enum` generated from `quick_status_code_from_enum`.
template <class Enum> using quick_status_code_from_enum_code = status_code<_quick_status_code_from_enum_domain<Enum>>;
//! Defaults for an implementation of `quick_status_code_from_enum<Enum>`
template <class Enum> struct quick_status_code_from_enum_defaults
{
//! The type of the resulting code
using code_type = quick_status_code_from_enum_code<Enum>;
//! Used within `quick_status_code_from_enum` to define a mapping of enumeration value with its status code
struct mapping
{
//! The enumeration type
using enumeration_type = Enum;
//! The value being mapped
const Enum value;
//! A string representation for this enumeration value
const char *message;
//! A list of `errc` equivalents for this enumeration value
const std::initializer_list<errc> code_mappings;
};
//! Used within `quick_status_code_from_enum` to define mixins for the status code wrapping `Enum`
template <class Base> struct mixin : Base
{
using Base::Base;
};
};
/*! The implementation of the domain for status codes wrapping `Enum` generated from `quick_status_code_from_enum`.
*/
template <class Enum> class _quick_status_code_from_enum_domain : public status_code_domain
{
template <class DomainType> friend class status_code;
using _base = status_code_domain;
using _src = quick_status_code_from_enum<Enum>;
public:
//! The value type of the quick status code from enum
using value_type = Enum;
using _base::string_ref;
constexpr _quick_status_code_from_enum_domain()
: status_code_domain(_src::domain_uuid, _uuid_size<detail::cstrlen(_src::domain_uuid)>())
{
}
_quick_status_code_from_enum_domain(const _quick_status_code_from_enum_domain &) = default;
_quick_status_code_from_enum_domain(_quick_status_code_from_enum_domain &&) = default;
_quick_status_code_from_enum_domain &operator=(const _quick_status_code_from_enum_domain &) = default;
_quick_status_code_from_enum_domain &operator=(_quick_status_code_from_enum_domain &&) = default;
~_quick_status_code_from_enum_domain() = default;
#if __cplusplus < 201402L && !defined(_MSC_VER)
static inline const _quick_status_code_from_enum_domain &get()
{
static _quick_status_code_from_enum_domain v;
return v;
}
#else
static inline constexpr const _quick_status_code_from_enum_domain &get();
#endif
virtual string_ref name() const noexcept override { return string_ref(_src::domain_name); }
virtual payload_info_t payload_info() const noexcept override
{
return {sizeof(value_type), sizeof(status_code_domain *) + sizeof(value_type),
(alignof(value_type) > alignof(status_code_domain *)) ? alignof(value_type) : alignof(status_code_domain *)};
}
protected:
// Not sure if a hash table is worth it here, most enumerations won't be long enough to be worth it
// Also, until C++ 20's consteval, the hash table would get emitted into the binary, bloating it
static SYSTEM_ERROR2_CONSTEXPR14 const typename _src::mapping *_find_mapping(value_type v) noexcept
{
for(const auto &i : _src::value_mappings())
{
if(i.value == v)
{
return &i;
}
}
return nullptr;
}
virtual bool _do_failure(const status_code<void> &code) const noexcept override
{
assert(code.domain() == *this); // NOLINT
// If `errc::success` is in the generic code mapping, it is not a failure
const auto *mapping = _find_mapping(static_cast<const quick_status_code_from_enum_code<value_type> &>(code).value());
#if SYSTEM_ERROR2_QUICK_STATUS_CODE_FROM_ENUM_ASSERT_ON_MISSING_MAPPING_TABLE_ENTRIES
assert(mapping != nullptr); // if this fires, you forgot to add the enum to the mapping table
#endif
if(mapping != nullptr)
{
for(errc ec : mapping->code_mappings)
{
if(ec == errc::success)
{
return false;
}
}
}
return true;
}
virtual bool _do_equivalent(const status_code<void> &code1, const status_code<void> &code2) const noexcept override
{
assert(code1.domain() == *this); // NOLINT
const auto &c1 = static_cast<const quick_status_code_from_enum_code<value_type> &>(code1); // NOLINT
if(code2.domain() == *this)
{
const auto &c2 = static_cast<const quick_status_code_from_enum_code<value_type> &>(code2); // NOLINT
return c1.value() == c2.value();
}
if(code2.domain() == generic_code_domain)
{
const auto &c2 = static_cast<const generic_code &>(code2); // NOLINT
const auto *mapping = _find_mapping(c1.value());
#if SYSTEM_ERROR2_QUICK_STATUS_CODE_FROM_ENUM_ASSERT_ON_MISSING_MAPPING_TABLE_ENTRIES
assert(mapping != nullptr); // if this fires, you forgot to add the enum to the mapping table
#endif
if(mapping != nullptr)
{
for(errc ec : mapping->code_mappings)
{
if(ec == c2.value())
{
return true;
}
}
}
}
return false;
}
virtual generic_code _generic_code(const status_code<void> &code) const noexcept override
{
assert(code.domain() == *this); // NOLINT
const auto *mapping = _find_mapping(static_cast<const quick_status_code_from_enum_code<value_type> &>(code).value());
#if SYSTEM_ERROR2_QUICK_STATUS_CODE_FROM_ENUM_ASSERT_ON_MISSING_MAPPING_TABLE_ENTRIES
assert(mapping != nullptr); // if this fires, you forgot to add the enum to the mapping table
#endif
if(mapping != nullptr)
{
if(mapping->code_mappings.size() > 0)
{
return *mapping->code_mappings.begin();
}
}
return errc::unknown;
}
virtual string_ref _do_message(const status_code<void> &code) const noexcept override
{
assert(code.domain() == *this); // NOLINT
const auto *mapping = _find_mapping(static_cast<const quick_status_code_from_enum_code<value_type> &>(code).value());
#if SYSTEM_ERROR2_QUICK_STATUS_CODE_FROM_ENUM_ASSERT_ON_MISSING_MAPPING_TABLE_ENTRIES
assert(mapping != nullptr); // if this fires, you forgot to add the enum to the mapping table
#endif
if(mapping != nullptr)
{
return string_ref(mapping->message);
}
return string_ref("unknown");
}
#if defined(_CPPUNWIND) || defined(__EXCEPTIONS) || 0L
SYSTEM_ERROR2_NORETURN virtual void _do_throw_exception(const status_code<void> &code) const override
{
assert(code.domain() == *this); // NOLINT
const auto &c = static_cast<const quick_status_code_from_enum_code<value_type> &>(code); // NOLINT
throw status_error<_quick_status_code_from_enum_domain>(c);
}
#endif
};
#if __cplusplus >= 201402L || defined(_MSC_VER)
template <class Enum> constexpr _quick_status_code_from_enum_domain<Enum> quick_status_code_from_enum_domain = {};
template <class Enum> inline constexpr const _quick_status_code_from_enum_domain<Enum> &_quick_status_code_from_enum_domain<Enum>::get()
{
return quick_status_code_from_enum_domain<Enum>;
}
#endif
namespace mixins
{
template <class Base, class Enum>
struct mixin<Base, _quick_status_code_from_enum_domain<Enum>> : public quick_status_code_from_enum<Enum>::template mixin<Base>
{
using quick_status_code_from_enum<Enum>::template mixin<Base>::mixin;
};
} // namespace mixins
SYSTEM_ERROR2_NAMESPACE_END
#endif
SYSTEM_ERROR2_NAMESPACE_BEGIN
/*! A `status_code` which is always a failure. The closest equivalent to
`std::error_code`, except it cannot be modified, and is templated.
Differences from `status_code`:
- Never successful (this contract is checked on construction, if fails then it
terminates the process).
- Is immutable.
*/
template <class DomainType> class errored_status_code : public status_code<DomainType>
{
using _base = status_code<DomainType>;
using _base::clear;
using _base::success;
void _check()
{
if(_base::success())
{
std::terminate();
}
}
public:
//! The type of the domain.
using typename _base::domain_type;
//! The type of the error code.
using typename _base::value_type;
//! The type of a reference to a message string.
using typename _base::string_ref;
//! Default constructor.
errored_status_code() = default;
//! Copy constructor.
errored_status_code(const errored_status_code &) = default;
//! Move constructor.
errored_status_code(errored_status_code &&) = default; // NOLINT
//! Copy assignment.
errored_status_code &operator=(const errored_status_code &) = default;
//! Move assignment.
errored_status_code &operator=(errored_status_code &&) = default; // NOLINT
~errored_status_code() = default;
//! Explicitly construct from any similarly erased status code
explicit errored_status_code(const _base &o) noexcept(std::is_nothrow_copy_constructible<_base>::value)
: _base(o)
{
_check();
}
//! Explicitly construct from any similarly erased status code
explicit errored_status_code(_base &&o) noexcept(std::is_nothrow_move_constructible<_base>::value)
: _base(static_cast<_base &&>(o))
{
_check();
}
/***** KEEP THESE IN SYNC WITH STATUS_CODE *****/
//! Implicit construction from any type where an ADL discovered `make_status_code(T, Args ...)` returns a `status_code`.
SYSTEM_ERROR2_TEMPLATE(
class T, class... Args, //
class MakeStatusCodeResult =
typename detail::safe_get_make_status_code_result<T, Args...>::type) // Safe ADL lookup of make_status_code(), returns void if not found
SYSTEM_ERROR2_TREQUIRES(SYSTEM_ERROR2_TPRED(!std::is_same<typename std::decay<T>::type, errored_status_code>::value // not copy/move of self
&& !std::is_same<typename std::decay<T>::type, in_place_t>::value // not in_place_t
&& is_status_code<MakeStatusCodeResult>::value // ADL makes a status code
&& std::is_constructible<errored_status_code, MakeStatusCodeResult>::value)) // ADLed status code is compatible
errored_status_code(T &&v, Args &&...args) noexcept(noexcept(make_status_code(std::declval<T>(), std::declval<Args>()...))) // NOLINT
: errored_status_code(make_status_code(static_cast<T &&>(v), static_cast<Args &&>(args)...))
{
_check();
}
//! Implicit construction from any `quick_status_code_from_enum<Enum>` enumerated type.
SYSTEM_ERROR2_TEMPLATE(class Enum, //
class QuickStatusCodeType = typename quick_status_code_from_enum<Enum>::code_type) // Enumeration has been activated
SYSTEM_ERROR2_TREQUIRES(SYSTEM_ERROR2_TPRED(std::is_constructible<errored_status_code, QuickStatusCodeType>::value)) // Its status code is compatible
errored_status_code(Enum &&v) noexcept(std::is_nothrow_constructible<errored_status_code, QuickStatusCodeType>::value) // NOLINT
: errored_status_code(QuickStatusCodeType(static_cast<Enum &&>(v)))
{
_check();
}
//! Explicit in-place construction.
template <class... Args>
explicit errored_status_code(in_place_t _, Args &&...args) noexcept(std::is_nothrow_constructible<value_type, Args &&...>::value)
: _base(_, static_cast<Args &&>(args)...)
{
_check();
}
//! Explicit in-place construction from initialiser list.
template <class T, class... Args>
explicit errored_status_code(in_place_t _, std::initializer_list<T> il,
Args &&...args) noexcept(std::is_nothrow_constructible<value_type, std::initializer_list<T>, Args &&...>::value)
: _base(_, il, static_cast<Args &&>(args)...)
{
_check();
}
//! Explicit copy construction from a `value_type`.
explicit errored_status_code(const value_type &v) noexcept(std::is_nothrow_copy_constructible<value_type>::value)
: _base(v)
{
_check();
}
//! Explicit move construction from a `value_type`.
explicit errored_status_code(value_type &&v) noexcept(std::is_nothrow_move_constructible<value_type>::value)
: _base(static_cast<value_type &&>(v))
{
_check();
}
/*! Explicit construction from an erased status code. Available only if
`value_type` is trivially copyable or move bitcopying, and `sizeof(status_code) <= sizeof(status_code<erased<>>)`.
Does not check if domains are equal.
*/
SYSTEM_ERROR2_TEMPLATE(class ErasedType) //
SYSTEM_ERROR2_TREQUIRES(SYSTEM_ERROR2_TPRED(detail::domain_value_type_erasure_is_safe<domain_type, detail::erased<ErasedType>>::value))
explicit errored_status_code(const status_code<detail::erased<ErasedType>> &v) noexcept(std::is_nothrow_copy_constructible<value_type>::value)
: errored_status_code(detail::erasure_cast<value_type>(v.value())) // NOLINT
{
assert(v.domain() == this->domain()); // NOLINT
_check();
}
//! Always false (including at compile time), as errored status codes are never successful.
constexpr bool success() const noexcept { return false; }
//! Return a const reference to the `value_type`.
constexpr const value_type &value() const & noexcept { return this->_value; }
};
namespace traits
{
template <class DomainType> struct is_move_bitcopying<errored_status_code<DomainType>>
{
static constexpr bool value = is_move_bitcopying<typename DomainType::value_type>::value;
};
} // namespace traits
template <class ErasedType> class errored_status_code<detail::erased<ErasedType>> : public status_code<detail::erased<ErasedType>>
{
using _base = status_code<detail::erased<ErasedType>>;
using _base::success;
void _check()
{
if(_base::success())
{
std::terminate();
}
}
public:
using domain_type = typename _base::domain_type;
using value_type = typename _base::value_type;
using string_ref = typename _base::string_ref;
//! Default construction to empty
errored_status_code() = default;
//! Copy constructor
errored_status_code(const errored_status_code &) = default;
//! Move constructor
errored_status_code(errored_status_code &&) = default; // NOLINT
//! Copy assignment
errored_status_code &operator=(const errored_status_code &) = default;
//! Move assignment
errored_status_code &operator=(errored_status_code &&) = default; // NOLINT
~errored_status_code() = default;
//! Explicitly construct from any similarly erased status code
explicit errored_status_code(const _base &o) noexcept(std::is_nothrow_copy_constructible<_base>::value)
: _base(o)
{
_check();
}
//! Explicitly construct from any similarly erased status code
explicit errored_status_code(_base &&o) noexcept(std::is_nothrow_move_constructible<_base>::value)
: _base(static_cast<_base &&>(o))
{
_check();
}
/***** KEEP THESE IN SYNC WITH STATUS_CODE *****/
//! Implicit copy construction from any other status code if its value type is trivially copyable, it would fit into our storage, and it is not an erased
//! status code.
SYSTEM_ERROR2_TEMPLATE(class DomainType) //
SYSTEM_ERROR2_TREQUIRES(SYSTEM_ERROR2_TPRED(detail::domain_value_type_erasure_is_safe<detail::erased<ErasedType>, DomainType>::value),
SYSTEM_ERROR2_TPRED(!detail::is_erased_status_code<status_code<typename std::decay<DomainType>::type>>::value))
errored_status_code(const status_code<DomainType> &v) noexcept
: _base(v) // NOLINT
{
_check();
}
//! Implicit copy construction from any other status code if its value type is trivially copyable and it would fit into our storage, and it is not an erased
//! status code.
SYSTEM_ERROR2_TEMPLATE(class DomainType) //
SYSTEM_ERROR2_TREQUIRES(SYSTEM_ERROR2_TPRED(detail::domain_value_type_erasure_is_safe<detail::erased<ErasedType>, DomainType>::value),
SYSTEM_ERROR2_TPRED(!detail::is_erased_status_code<status_code<typename std::decay<DomainType>::type>>::value))
errored_status_code(const errored_status_code<DomainType> &v) noexcept
: _base(static_cast<const status_code<DomainType> &>(v)) // NOLINT
{
_check();
}
//! Implicit move construction from any other status code if its value type is trivially copyable or move bitcopying and it would fit into our storage
SYSTEM_ERROR2_TEMPLATE(class DomainType) //
SYSTEM_ERROR2_TREQUIRES(SYSTEM_ERROR2_TPRED(detail::domain_value_type_erasure_is_safe<detail::erased<ErasedType>, DomainType>::value))
errored_status_code(status_code<DomainType> &&v) noexcept
: _base(static_cast<status_code<DomainType> &&>(v)) // NOLINT
{
_check();
}
//! Implicit move construction from any other status code if its value type is trivially copyable or move bitcopying and it would fit into our storage
SYSTEM_ERROR2_TEMPLATE(class DomainType) //
SYSTEM_ERROR2_TREQUIRES(SYSTEM_ERROR2_TPRED(detail::domain_value_type_erasure_is_safe<detail::erased<ErasedType>, DomainType>::value))
errored_status_code(errored_status_code<DomainType> &&v) noexcept
: _base(static_cast<status_code<DomainType> &&>(v)) // NOLINT
{
_check();
}
//! Implicit construction from any type where an ADL discovered `make_status_code(T, Args ...)` returns a `status_code`.
SYSTEM_ERROR2_TEMPLATE(
class T, class... Args, //
class MakeStatusCodeResult =
typename detail::safe_get_make_status_code_result<T, Args...>::type) // Safe ADL lookup of make_status_code(), returns void if not found
SYSTEM_ERROR2_TREQUIRES(SYSTEM_ERROR2_TPRED(!std::is_same<typename std::decay<T>::type, errored_status_code>::value // not copy/move of self
&& !std::is_same<typename std::decay<T>::type, value_type>::value // not copy/move of value type
&& is_status_code<MakeStatusCodeResult>::value // ADL makes a status code
&& std::is_constructible<errored_status_code, MakeStatusCodeResult>::value)) // ADLed status code is compatible
errored_status_code(T &&v, Args &&...args) noexcept(noexcept(make_status_code(std::declval<T>(), std::declval<Args>()...))) // NOLINT
: errored_status_code(make_status_code(static_cast<T &&>(v), static_cast<Args &&>(args)...))
{
_check();
}
//! Implicit construction from any `quick_status_code_from_enum<Enum>` enumerated type.
SYSTEM_ERROR2_TEMPLATE(class Enum, //
class QuickStatusCodeType = typename quick_status_code_from_enum<Enum>::code_type) // Enumeration has been activated
SYSTEM_ERROR2_TREQUIRES(SYSTEM_ERROR2_TPRED(std::is_constructible<errored_status_code, QuickStatusCodeType>::value)) // Its status code is compatible
errored_status_code(Enum &&v) noexcept(std::is_nothrow_constructible<errored_status_code, QuickStatusCodeType>::value) // NOLINT
: errored_status_code(QuickStatusCodeType(static_cast<Enum &&>(v)))
{
_check();
}
#if defined(_CPPUNWIND) || defined(__EXCEPTIONS) || 0L
//! Explicit copy construction from an unknown status code. Note that this will be empty if its value type is not trivially copyable or would not fit into our
//! storage or the source domain's `_do_erased_copy()` refused the copy.
explicit errored_status_code(in_place_t _, const status_code<void> &v) // NOLINT
: _base(_, v)
{
_check();
}
#endif
//! Always false (including at compile time), as errored status codes are never successful.
constexpr bool success() const noexcept { return false; }
//! Return the erased `value_type` by value.
constexpr value_type value() const noexcept { return this->_value; }
};
/*! An erased type specialisation of `errored_status_code<D>`.
Available only if `ErasedType` satisfies `traits::is_move_bitcopying<ErasedType>::value`.
*/
template <class ErasedType> using erased_errored_status_code = errored_status_code<detail::erased<ErasedType>>;
namespace traits
{
template <class ErasedType> struct is_move_bitcopying<errored_status_code<detail::erased<ErasedType>>>
{
static constexpr bool value = true;
};
} // namespace traits
//! True if the status code's are semantically equal via `equivalent()`.
template <class DomainType1, class DomainType2>
inline bool operator==(const errored_status_code<DomainType1> &a, const errored_status_code<DomainType2> &b) noexcept
{
return a.equivalent(static_cast<const status_code<DomainType2> &>(b));
}
//! True if the status code's are semantically equal via `equivalent()`.
template <class DomainType1, class DomainType2> inline bool operator==(const status_code<DomainType1> &a, const errored_status_code<DomainType2> &b) noexcept
{
return a.equivalent(static_cast<const status_code<DomainType2> &>(b));
}
//! True if the status code's are semantically equal via `equivalent()`.
template <class DomainType1, class DomainType2> inline bool operator==(const errored_status_code<DomainType1> &a, const status_code<DomainType2> &b) noexcept
{
return static_cast<const status_code<DomainType1> &>(a).equivalent(b);
}
//! True if the status code's are not semantically equal via `equivalent()`.
template <class DomainType1, class DomainType2>
inline bool operator!=(const errored_status_code<DomainType1> &a, const errored_status_code<DomainType2> &b) noexcept
{
return !a.equivalent(static_cast<const status_code<DomainType2> &>(b));
}
//! True if the status code's are not semantically equal via `equivalent()`.
template <class DomainType1, class DomainType2> inline bool operator!=(const status_code<DomainType1> &a, const errored_status_code<DomainType2> &b) noexcept
{
return !a.equivalent(static_cast<const status_code<DomainType2> &>(b));
}
//! True if the status code's are not semantically equal via `equivalent()`.
template <class DomainType1, class DomainType2> inline bool operator!=(const errored_status_code<DomainType1> &a, const status_code<DomainType2> &b) noexcept
{
return !static_cast<const status_code<DomainType1> &>(a).equivalent(b);
}
//! True if the status code's are semantically equal via `equivalent()` to `make_status_code(T)`.
SYSTEM_ERROR2_TEMPLATE(class DomainType1, class T, //
class MakeStatusCodeResult =
typename detail::safe_get_make_status_code_result<const T &>::type) // Safe ADL lookup of make_status_code(), returns void if not found
SYSTEM_ERROR2_TREQUIRES(SYSTEM_ERROR2_TPRED(is_status_code<MakeStatusCodeResult>::value)) // ADL makes a status code
inline bool operator==(const errored_status_code<DomainType1> &a, const T &b)
{
return a.equivalent(make_status_code(b));
}
//! True if the status code's are semantically equal via `equivalent()` to `make_status_code(T)`.
SYSTEM_ERROR2_TEMPLATE(class T, class DomainType1, //
class MakeStatusCodeResult =
typename detail::safe_get_make_status_code_result<const T &>::type) // Safe ADL lookup of make_status_code(), returns void if not found
SYSTEM_ERROR2_TREQUIRES(SYSTEM_ERROR2_TPRED(is_status_code<MakeStatusCodeResult>::value)) // ADL makes a status code
inline bool operator==(const T &a, const errored_status_code<DomainType1> &b)
{
return b.equivalent(make_status_code(a));
}
//! True if the status code's are not semantically equal via `equivalent()` to `make_status_code(T)`.
SYSTEM_ERROR2_TEMPLATE(class DomainType1, class T, //
class MakeStatusCodeResult =
typename detail::safe_get_make_status_code_result<const T &>::type) // Safe ADL lookup of make_status_code(), returns void if not found
SYSTEM_ERROR2_TREQUIRES(SYSTEM_ERROR2_TPRED(is_status_code<MakeStatusCodeResult>::value)) // ADL makes a status code
inline bool operator!=(const errored_status_code<DomainType1> &a, const T &b)
{
return !a.equivalent(make_status_code(b));
}
//! True if the status code's are semantically equal via `equivalent()` to `make_status_code(T)`.
SYSTEM_ERROR2_TEMPLATE(class T, class DomainType1, //
class MakeStatusCodeResult =
typename detail::safe_get_make_status_code_result<const T &>::type) // Safe ADL lookup of make_status_code(), returns void if not found
SYSTEM_ERROR2_TREQUIRES(SYSTEM_ERROR2_TPRED(is_status_code<MakeStatusCodeResult>::value)) // ADL makes a status code
inline bool operator!=(const T &a, const errored_status_code<DomainType1> &b)
{
return !b.equivalent(make_status_code(a));
}
//! True if the status code's are semantically equal via `equivalent()` to `quick_status_code_from_enum<T>::code_type(b)`.
template <class DomainType1, class T, //
class QuickStatusCodeType = typename quick_status_code_from_enum<T>::code_type // Enumeration has been activated
>
inline bool operator==(const errored_status_code<DomainType1> &a, const T &b)
{
return a.equivalent(QuickStatusCodeType(b));
}
//! True if the status code's are semantically equal via `equivalent()` to `quick_status_code_from_enum<T>::code_type(a)`.
template <class T, class DomainType1, //
class QuickStatusCodeType = typename quick_status_code_from_enum<T>::code_type // Enumeration has been activated
>
inline bool operator==(const T &a, const errored_status_code<DomainType1> &b)
{
return b.equivalent(QuickStatusCodeType(a));
}
//! True if the status code's are not semantically equal via `equivalent()` to `quick_status_code_from_enum<T>::code_type(b)`.
template <class DomainType1, class T, //
class QuickStatusCodeType = typename quick_status_code_from_enum<T>::code_type // Enumeration has been activated
>
inline bool operator!=(const errored_status_code<DomainType1> &a, const T &b)
{
return !a.equivalent(QuickStatusCodeType(b));
}
//! True if the status code's are not semantically equal via `equivalent()` to `quick_status_code_from_enum<T>::code_type(a)`.
template <class T, class DomainType1, //
class QuickStatusCodeType = typename quick_status_code_from_enum<T>::code_type // Enumeration has been activated
>
inline bool operator!=(const T &a, const errored_status_code<DomainType1> &b)
{
return !b.equivalent(QuickStatusCodeType(a));
}
namespace detail
{
template <class T> struct is_errored_status_code
{
static constexpr bool value = false;
};
template <class T> struct is_errored_status_code<errored_status_code<T>>
{
static constexpr bool value = true;
};
template <class T> struct is_erased_errored_status_code
{
static constexpr bool value = false;
};
template <class T> struct is_erased_errored_status_code<errored_status_code<erased<T>>>
{
static constexpr bool value = true;
};
} // namespace detail
//! Trait returning true if the type is an errored status code.
template <class T> struct is_errored_status_code
{
static constexpr bool value =
detail::is_errored_status_code<typename std::decay<T>::type>::value || detail::is_erased_errored_status_code<typename std::decay<T>::type>::value;
};
SYSTEM_ERROR2_NAMESPACE_END
#endif
/* Proposed SG14 status_code
(C) 2018 Niall Douglas <http://www.nedproductions.biz/> (5 commits)
File Created: Feb 2018
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License in the accompanying file
Licence.txt or at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Distributed under the Boost Software License, Version 1.0.
(See accompanying file Licence.txt or copy at
http://www.boost.org/LICENSE_1_0.txt)
*/
#ifndef SYSTEM_ERROR2_SYSTEM_CODE_HPP
#define SYSTEM_ERROR2_SYSTEM_CODE_HPP
#ifndef SYSTEM_ERROR2_NOT_POSIX
/* Proposed SG14 status_code
(C) 2018-2020 Niall Douglas <http://www.nedproductions.biz/> (5 commits)
File Created: Feb 2018
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License in the accompanying file
Licence.txt or at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Distributed under the Boost Software License, Version 1.0.
(See accompanying file Licence.txt or copy at
http://www.boost.org/LICENSE_1_0.txt)
*/
#ifndef SYSTEM_ERROR2_POSIX_CODE_HPP
#define SYSTEM_ERROR2_POSIX_CODE_HPP
#ifdef SYSTEM_ERROR2_NOT_POSIX
#error <posix_code.hpp> is not includable when SYSTEM_ERROR2_NOT_POSIX is defined!
#endif
#include <cstring> // for strchr and strerror_r
SYSTEM_ERROR2_NAMESPACE_BEGIN
// Fix for issue #48 Issue compiling on arm-none-eabi (newlib) with GNU extensions off
#if !defined(_MSC_VER) && !defined(__APPLE__)
namespace detail
{
namespace avoid_string_include
{
#if defined(__GLIBC__) && !defined(__UCLIBC__)
// This returns int for non-glibc strerror_r, but glibc's is particularly weird so we retain it
extern "C" char *strerror_r(int errnum, char *buf, size_t buflen);
#else
extern "C" int strerror_r(int errnum, char *buf, size_t buflen);
#endif
} // namespace avoid_string_include
} // namespace detail
#endif
class _posix_code_domain;
//! A POSIX error code, those returned by `errno`.
using posix_code = status_code<_posix_code_domain>;
//! A specialisation of `status_error` for the POSIX error code domain.
using posix_error = status_error<_posix_code_domain>;
namespace mixins
{
template <class Base> struct mixin<Base, _posix_code_domain> : public Base
{
using Base::Base;
//! Returns a `posix_code` for the current value of `errno`.
static posix_code current() noexcept;
};
} // namespace mixins
/*! The implementation of the domain for POSIX error codes, those returned by `errno`.
*/
class _posix_code_domain : public status_code_domain
{
template <class DomainType> friend class status_code;
using _base = status_code_domain;
static _base::string_ref _make_string_ref(int c) noexcept
{
char buffer[1024] = "";
#ifdef _WIN32
strerror_s(buffer, sizeof(buffer), c);
#elif defined(__GLIBC__) && !defined(__UCLIBC__) // handle glibc's weird strerror_r()
char *s = detail::avoid_string_include::strerror_r(c, buffer, sizeof(buffer)); // NOLINT
if(s != nullptr)
{
strncpy(buffer, s, sizeof(buffer) - 1); // NOLINT
buffer[1023] = 0;
}
#elif !defined(__APPLE__)
detail::avoid_string_include::strerror_r(c, buffer, sizeof(buffer));
#else
strerror_r(c, buffer, sizeof(buffer));
#endif
size_t length = strlen(buffer); // NOLINT
auto *p = static_cast<char *>(malloc(length + 1)); // NOLINT
if(p == nullptr)
{
return _base::string_ref("failed to get message from system");
}
memcpy(p, buffer, length + 1); // NOLINT
return _base::atomic_refcounted_string_ref(p, length);
}
public:
//! The value type of the POSIX code, which is an `int`
using value_type = int;
using _base::string_ref;
//! Default constructor
constexpr explicit _posix_code_domain(typename _base::unique_id_type id = 0xa59a56fe5f310933) noexcept
: _base(id)
{
}
_posix_code_domain(const _posix_code_domain &) = default;
_posix_code_domain(_posix_code_domain &&) = default;
_posix_code_domain &operator=(const _posix_code_domain &) = default;
_posix_code_domain &operator=(_posix_code_domain &&) = default;
~_posix_code_domain() = default;
//! Constexpr singleton getter. Returns constexpr posix_code_domain variable.
static inline constexpr const _posix_code_domain &get();
virtual string_ref name() const noexcept override { return string_ref("posix domain"); } // NOLINT
virtual payload_info_t payload_info() const noexcept override
{
return {sizeof(value_type), sizeof(status_code_domain *) + sizeof(value_type),
(alignof(value_type) > alignof(status_code_domain *)) ? alignof(value_type) : alignof(status_code_domain *)};
}
protected:
virtual bool _do_failure(const status_code<void> &code) const noexcept override // NOLINT
{
assert(code.domain() == *this); // NOLINT
return static_cast<const posix_code &>(code).value() != 0; // NOLINT
}
virtual bool _do_equivalent(const status_code<void> &code1, const status_code<void> &code2) const noexcept override // NOLINT
{
assert(code1.domain() == *this); // NOLINT
const auto &c1 = static_cast<const posix_code &>(code1); // NOLINT
if(code2.domain() == *this)
{
const auto &c2 = static_cast<const posix_code &>(code2); // NOLINT
return c1.value() == c2.value();
}
if(code2.domain() == generic_code_domain)
{
const auto &c2 = static_cast<const generic_code &>(code2); // NOLINT
if(static_cast<int>(c2.value()) == c1.value())
{
return true;
}
}
return false;
}
virtual generic_code _generic_code(const status_code<void> &code) const noexcept override // NOLINT
{
assert(code.domain() == *this); // NOLINT
const auto &c = static_cast<const posix_code &>(code); // NOLINT
return generic_code(static_cast<errc>(c.value()));
}
virtual string_ref _do_message(const status_code<void> &code) const noexcept override // NOLINT
{
assert(code.domain() == *this); // NOLINT
const auto &c = static_cast<const posix_code &>(code); // NOLINT
return _make_string_ref(c.value());
}
#if defined(_CPPUNWIND) || defined(__EXCEPTIONS) || 0L
SYSTEM_ERROR2_NORETURN virtual void _do_throw_exception(const status_code<void> &code) const override // NOLINT
{
assert(code.domain() == *this); // NOLINT
const auto &c = static_cast<const posix_code &>(code); // NOLINT
throw status_error<_posix_code_domain>(c);
}
#endif
};
//! A constexpr source variable for the POSIX code domain, which is that of `errno`. Returned by `_posix_code_domain::get()`.
constexpr _posix_code_domain posix_code_domain;
inline constexpr const _posix_code_domain &_posix_code_domain::get()
{
return posix_code_domain;
}
namespace mixins
{
template <class Base> inline posix_code mixin<Base, _posix_code_domain>::current() noexcept
{
return posix_code(errno);
}
} // namespace mixins
SYSTEM_ERROR2_NAMESPACE_END
#endif
#else
#endif
#if defined(_WIN32) || 0L
/* Proposed SG14 status_code
(C) 2018 Niall Douglas <http://www.nedproductions.biz/> (5 commits)
File Created: Feb 2018
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License in the accompanying file
Licence.txt or at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Distributed under the Boost Software License, Version 1.0.
(See accompanying file Licence.txt or copy at
http://www.boost.org/LICENSE_1_0.txt)
*/
#ifndef SYSTEM_ERROR2_NT_CODE_HPP
#define SYSTEM_ERROR2_NT_CODE_HPP
#if !defined(_WIN32) && !0L
#error This file should only be included on Windows
#endif
/* Proposed SG14 status_code
(C) 2018 Niall Douglas <http://www.nedproductions.biz/> (5 commits)
File Created: Feb 2018
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License in the accompanying file
Licence.txt or at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Distributed under the Boost Software License, Version 1.0.
(See accompanying file Licence.txt or copy at
http://www.boost.org/LICENSE_1_0.txt)
*/
#ifndef SYSTEM_ERROR2_WIN32_CODE_HPP
#define SYSTEM_ERROR2_WIN32_CODE_HPP
#if !defined(_WIN32) && !0L
#error This file should only be included on Windows
#endif
SYSTEM_ERROR2_NAMESPACE_BEGIN
//! \exclude
namespace win32
{
#ifdef __MINGW32__
extern "C"
{
#endif
// A Win32 DWORD
using DWORD = unsigned long;
// Used to retrieve the current Win32 error code
extern DWORD __stdcall GetLastError();
// Used to retrieve a locale-specific message string for some error code
extern DWORD __stdcall FormatMessageW(DWORD dwFlags, const void *lpSource, DWORD dwMessageId, DWORD dwLanguageId, wchar_t *lpBuffer, DWORD nSize,
void /*va_list*/ *Arguments);
// Converts UTF-16 message string to UTF-8
extern int __stdcall WideCharToMultiByte(unsigned int CodePage, DWORD dwFlags, const wchar_t *lpWideCharStr, int cchWideChar, char *lpMultiByteStr,
int cbMultiByte, const char *lpDefaultChar, int *lpUsedDefaultChar);
#ifdef __MINGW32__
}
#else
#pragma comment(lib, "kernel32.lib")
#if (defined(__x86_64__) || defined(_M_X64)) || (defined(__aarch64__) || defined(_M_ARM64))
#pragma comment(linker, "/alternatename:?GetLastError@win32@system_error2@@YAKXZ=GetLastError")
#pragma comment(linker, "/alternatename:?FormatMessageW@win32@system_error2@@YAKKPEBXKKPEA_WKPEAX@Z=FormatMessageW")
#pragma comment(linker, "/alternatename:?WideCharToMultiByte@win32@system_error2@@YAHIKPEB_WHPEADHPEBDPEAH@Z=WideCharToMultiByte")
#elif defined(__x86__) || defined(_M_IX86) || defined(__i386__)
#pragma comment(linker, "/alternatename:?GetLastError@win32@system_error2@@YGKXZ=_GetLastError@0")
#pragma comment(linker, "/alternatename:?FormatMessageW@win32@system_error2@@YGKKPBXKKPA_WKPAX@Z=_FormatMessageW@28")
#pragma comment(linker, "/alternatename:?WideCharToMultiByte@win32@system_error2@@YGHIKPB_WHPADHPBDPAH@Z=_WideCharToMultiByte@32")
#elif defined(__arm__) || defined(_M_ARM)
#pragma comment(linker, "/alternatename:?GetLastError@win32@system_error2@@YAKXZ=GetLastError")
#pragma comment(linker, "/alternatename:?FormatMessageW@win32@system_error2@@YAKKPBXKKPA_WKPAX@Z=FormatMessageW")
#pragma comment(linker, "/alternatename:?WideCharToMultiByte@win32@system_error2@@YAHIKPB_WHPADHPBDPAH@Z=WideCharToMultiByte")
#else
#error Unknown architecture
#endif
#endif
} // namespace win32
class _win32_code_domain;
class _com_code_domain;
//! (Windows only) A Win32 error code, those returned by `GetLastError()`.
using win32_code = status_code<_win32_code_domain>;
//! (Windows only) A specialisation of `status_error` for the Win32 error code domain.
using win32_error = status_error<_win32_code_domain>;
namespace mixins
{
template <class Base> struct mixin<Base, _win32_code_domain> : public Base
{
using Base::Base;
//! Returns a `win32_code` for the current value of `GetLastError()`.
static inline win32_code current() noexcept;
};
} // namespace mixins
/*! (Windows only) The implementation of the domain for Win32 error codes, those returned by `GetLastError()`.
*/
class _win32_code_domain : public status_code_domain
{
template <class DomainType> friend class status_code;
friend class _com_code_domain;
using _base = status_code_domain;
static int _win32_code_to_errno(win32::DWORD c)
{
switch(c)
{
case 0:
return 0;
case 0x1: return ENOSYS;
case 0x2: return ENOENT;
case 0x3: return ENOENT;
case 0x4: return EMFILE;
case 0x5: return EACCES;
case 0x6: return EINVAL;
case 0x8: return ENOMEM;
case 0xc: return EACCES;
case 0xe: return ENOMEM;
case 0xf: return ENODEV;
case 0x10: return EACCES;
case 0x11: return EXDEV;
case 0x13: return EACCES;
case 0x14: return ENODEV;
case 0x15: return EAGAIN;
case 0x19: return EIO;
case 0x1d: return EIO;
case 0x1e: return EIO;
case 0x20: return EACCES;
case 0x21: return ENOLCK;
case 0x27: return ENOSPC;
case 0x37: return ENODEV;
case 0x50: return EEXIST;
case 0x52: return EACCES;
case 0x57: return EINVAL;
case 0x6e: return EIO;
case 0x6f: return ENAMETOOLONG;
case 0x70: return ENOSPC;
case 0x7b: return EINVAL;
case 0x83: return EINVAL;
case 0x8e: return EBUSY;
case 0x91: return ENOTEMPTY;
case 0xaa: return EBUSY;
case 0xb7: return EEXIST;
case 0xd4: return ENOLCK;
case 0x10b: return EINVAL;
case 0x3e3: return ECANCELED;
case 0x3e6: return EACCES;
case 0x3f3: return EIO;
case 0x3f4: return EIO;
case 0x3f5: return EIO;
case 0x4d5: return EAGAIN;
case 0x961: return EBUSY;
case 0x964: return EBUSY;
case 0x2714: return EINTR;
case 0x2719: return EBADF;
case 0x271d: return EACCES;
case 0x271e: return EFAULT;
case 0x2726: return EINVAL;
case 0x2728: return EMFILE;
case 0x2733: return EWOULDBLOCK;
case 0x2734: return EINPROGRESS;
case 0x2735: return EALREADY;
case 0x2736: return ENOTSOCK;
case 0x2737: return EDESTADDRREQ;
case 0x2738: return EMSGSIZE;
case 0x2739: return EPROTOTYPE;
case 0x273a: return ENOPROTOOPT;
case 0x273b: return EPROTONOSUPPORT;
case 0x273d: return EOPNOTSUPP;
case 0x273f: return EAFNOSUPPORT;
case 0x2740: return EADDRINUSE;
case 0x2741: return EADDRNOTAVAIL;
case 0x2742: return ENETDOWN;
case 0x2743: return ENETUNREACH;
case 0x2744: return ENETRESET;
case 0x2745: return ECONNABORTED;
case 0x2746: return ECONNRESET;
case 0x2747: return ENOBUFS;
case 0x2748: return EISCONN;
case 0x2749: return ENOTCONN;
case 0x274c: return ETIMEDOUT;
case 0x274d: return ECONNREFUSED;
case 0x274f: return ENAMETOOLONG;
case 0x2751: return EHOSTUNREACH;
}
return -1;
}
//! Construct from a Win32 error code
static _base::string_ref _make_string_ref(win32::DWORD c) noexcept
{
wchar_t buffer[32768];
win32::DWORD wlen =
win32::FormatMessageW(0x00001000 /*FORMAT_MESSAGE_FROM_SYSTEM*/ | 0x00000200 /*FORMAT_MESSAGE_IGNORE_INSERTS*/, nullptr, c, 0, buffer, 32768, nullptr);
size_t allocation = wlen + (wlen >> 1);
win32::DWORD bytes;
if(wlen == 0)
{
return _base::string_ref("failed to get message from system");
}
for(;;)
{
auto *p = static_cast<char *>(malloc(allocation)); // NOLINT
if(p == nullptr)
{
return _base::string_ref("failed to get message from system");
}
bytes = win32::WideCharToMultiByte(65001 /*CP_UTF8*/, 0, buffer, (int) (wlen + 1), p, (int) allocation, nullptr, nullptr);
if(bytes != 0)
{
char *end = strchr(p, 0);
while(end[-1] == 10 || end[-1] == 13)
{
--end;
}
*end = 0; // NOLINT
return _base::atomic_refcounted_string_ref(p, end - p);
}
free(p); // NOLINT
if(win32::GetLastError() == 0x7a /*ERROR_INSUFFICIENT_BUFFER*/)
{
allocation += allocation >> 2;
continue;
}
return _base::string_ref("failed to get message from system");
}
}
public:
//! The value type of the win32 code, which is a `win32::DWORD`
using value_type = win32::DWORD;
using _base::string_ref;
public:
//! Default constructor
constexpr explicit _win32_code_domain(typename _base::unique_id_type id = 0x8cd18ee72d680f1b) noexcept
: _base(id)
{
}
_win32_code_domain(const _win32_code_domain &) = default;
_win32_code_domain(_win32_code_domain &&) = default;
_win32_code_domain &operator=(const _win32_code_domain &) = default;
_win32_code_domain &operator=(_win32_code_domain &&) = default;
~_win32_code_domain() = default;
//! Constexpr singleton getter. Returns the constexpr win32_code_domain variable.
static inline constexpr const _win32_code_domain &get();
virtual string_ref name() const noexcept override { return string_ref("win32 domain"); } // NOLINT
virtual payload_info_t payload_info() const noexcept override
{
return {sizeof(value_type), sizeof(status_code_domain *) + sizeof(value_type),
(alignof(value_type) > alignof(status_code_domain *)) ? alignof(value_type) : alignof(status_code_domain *)};
}
protected:
virtual bool _do_failure(const status_code<void> &code) const noexcept override // NOLINT
{
assert(code.domain() == *this);
return static_cast<const win32_code &>(code).value() != 0; // NOLINT
}
virtual bool _do_equivalent(const status_code<void> &code1, const status_code<void> &code2) const noexcept override // NOLINT
{
assert(code1.domain() == *this);
const auto &c1 = static_cast<const win32_code &>(code1); // NOLINT
if(code2.domain() == *this)
{
const auto &c2 = static_cast<const win32_code &>(code2); // NOLINT
return c1.value() == c2.value();
}
if(code2.domain() == generic_code_domain)
{
const auto &c2 = static_cast<const generic_code &>(code2); // NOLINT
if(static_cast<int>(c2.value()) == _win32_code_to_errno(c1.value()))
{
return true;
}
}
return false;
}
virtual generic_code _generic_code(const status_code<void> &code) const noexcept override // NOLINT
{
assert(code.domain() == *this);
const auto &c = static_cast<const win32_code &>(code); // NOLINT
return generic_code(static_cast<errc>(_win32_code_to_errno(c.value())));
}
virtual string_ref _do_message(const status_code<void> &code) const noexcept override // NOLINT
{
assert(code.domain() == *this);
const auto &c = static_cast<const win32_code &>(code); // NOLINT
return _make_string_ref(c.value());
}
#if defined(_CPPUNWIND) || defined(__EXCEPTIONS) || 0L
SYSTEM_ERROR2_NORETURN virtual void _do_throw_exception(const status_code<void> &code) const override // NOLINT
{
assert(code.domain() == *this);
const auto &c = static_cast<const win32_code &>(code); // NOLINT
throw status_error<_win32_code_domain>(c);
}
#endif
};
//! (Windows only) A constexpr source variable for the win32 code domain, which is that of `GetLastError()` (Windows). Returned by
//! `_win32_code_domain::get()`.
constexpr _win32_code_domain win32_code_domain;
inline constexpr const _win32_code_domain &_win32_code_domain::get()
{
return win32_code_domain;
}
namespace mixins
{
template <class Base> inline win32_code mixin<Base, _win32_code_domain>::current() noexcept
{
return win32_code(win32::GetLastError());
}
} // namespace mixins
SYSTEM_ERROR2_NAMESPACE_END
#endif
SYSTEM_ERROR2_NAMESPACE_BEGIN
//! \exclude
namespace win32
{
#ifdef __MINGW32__
extern "C"
{
#endif
// A Win32 NTSTATUS
using NTSTATUS = long;
// A Win32 HMODULE
using HMODULE = void *;
// Used to retrieve where the NTDLL DLL is mapped into memory
extern HMODULE __stdcall GetModuleHandleW(const wchar_t *lpModuleName);
#ifdef __MINGW32__
}
#else
#pragma comment(lib, "kernel32.lib")
#if (defined(__x86_64__) || defined(_M_X64)) || (defined(__aarch64__) || defined(_M_ARM64))
#pragma comment(linker, "/alternatename:?GetModuleHandleW@win32@system_error2@@YAPEAXPEB_W@Z=GetModuleHandleW")
#elif defined(__x86__) || defined(_M_IX86) || defined(__i386__)
#pragma comment(linker, "/alternatename:?GetModuleHandleW@win32@system_error2@@YGPAXPB_W@Z=_GetModuleHandleW@4")
#elif defined(__arm__) || defined(_M_ARM)
#pragma comment(linker, "/alternatename:?GetModuleHandleW@win32@system_error2@@YAPAXPB_W@Z=GetModuleHandleW")
#else
#error Unknown architecture
#endif
#endif
} // namespace win32
class _nt_code_domain;
//! (Windows only) A NT error code, those returned by NT kernel functions.
using nt_code = status_code<_nt_code_domain>;
//! (Windows only) A specialisation of `status_error` for the NT error code domain.
using nt_error = status_error<_nt_code_domain>;
/*! (Windows only) The implementation of the domain for NT error codes, those returned by NT kernel functions.
*/
class _nt_code_domain : public status_code_domain
{
template <class DomainType> friend class status_code;
friend class _com_code_domain;
using _base = status_code_domain;
static int _nt_code_to_errno(win32::NTSTATUS c)
{
if(c >= 0)
{
return 0; // success
}
switch(static_cast<unsigned>(c))
{
case 0x80000002: return EACCES;
case 0x8000000f: return EAGAIN;
case 0x80000010: return EAGAIN;
case 0x80000011: return EBUSY;
case 0xc0000002: return ENOSYS;
case 0xc0000005: return EACCES;
case 0xc0000008: return EINVAL;
case 0xc000000e: return ENOENT;
case 0xc000000f: return ENOENT;
case 0xc0000010: return ENOSYS;
case 0xc0000013: return EAGAIN;
case 0xc0000017: return ENOMEM;
case 0xc000001c: return ENOSYS;
case 0xc000001e: return EACCES;
case 0xc000001f: return EACCES;
case 0xc0000021: return EACCES;
case 0xc0000022: return EACCES;
case 0xc0000024: return EINVAL;
case 0xc0000033: return EINVAL;
case 0xc0000034: return ENOENT;
case 0xc0000035: return EEXIST;
case 0xc0000037: return EINVAL;
case 0xc000003a: return ENOENT;
case 0xc0000040: return ENOMEM;
case 0xc0000041: return EACCES;
case 0xc0000042: return EINVAL;
case 0xc0000043: return EACCES;
case 0xc000004b: return EACCES;
case 0xc0000054: return ENOLCK;
case 0xc0000055: return ENOLCK;
case 0xc0000056: return EACCES;
case 0xc000007f: return ENOSPC;
case 0xc0000087: return ENOMEM;
case 0xc0000097: return ENOMEM;
case 0xc000009b: return ENOENT;
case 0xc000009e: return EAGAIN;
case 0xc00000a2: return EACCES;
case 0xc00000a3: return EAGAIN;
case 0xc00000af: return ENOSYS;
case 0xc00000ba: return EACCES;
case 0xc00000c0: return ENODEV;
case 0xc00000d4: return EXDEV;
case 0xc00000d5: return EACCES;
case 0xc00000fb: return ENOENT;
case 0xc0000101: return ENOTEMPTY;
case 0xc0000103: return EINVAL;
case 0xc0000107: return EBUSY;
case 0xc0000108: return EBUSY;
case 0xc000010a: return EACCES;
case 0xc000011f: return EMFILE;
case 0xc0000120: return ECANCELED;
case 0xc0000121: return EACCES;
case 0xc0000123: return EACCES;
case 0xc0000128: return EINVAL;
case 0xc0000189: return EACCES;
case 0xc00001ad: return ENOMEM;
case 0xc000022d: return EAGAIN;
case 0xc0000235: return EINVAL;
case 0xc000026e: return EAGAIN;
case 0xc000028a: return EACCES;
case 0xc000028b: return EACCES;
case 0xc000028d: return EACCES;
case 0xc000028e: return EACCES;
case 0xc000028f: return EACCES;
case 0xc0000290: return EACCES;
case 0xc000029c: return ENOSYS;
case 0xc00002c5: return EACCES;
case 0xc00002d3: return EAGAIN;
case 0xc00002ea: return EACCES;
case 0xc00002f0: return ENOENT;
case 0xc0000373: return ENOMEM;
case 0xc0000416: return ENOMEM;
case 0xc0000433: return EBUSY;
case 0xc0000434: return EBUSY;
case 0xc0000455: return EINVAL;
case 0xc0000467: return EACCES;
case 0xc0000491: return ENOENT;
case 0xc0000495: return EAGAIN;
case 0xc0000503: return EAGAIN;
case 0xc0000507: return EBUSY;
case 0xc0000512: return EACCES;
case 0xc000070a: return EINVAL;
case 0xc000070b: return EINVAL;
case 0xc000070c: return EINVAL;
case 0xc000070d: return EINVAL;
case 0xc000070e: return EINVAL;
case 0xc000070f: return EINVAL;
case 0xc0000710: return ENOSYS;
case 0xc0000711: return ENOSYS;
case 0xc0000716: return EINVAL;
case 0xc000071b: return ENOSYS;
case 0xc000071d: return ENOSYS;
case 0xc000071e: return ENOSYS;
case 0xc000071f: return ENOSYS;
case 0xc0000720: return ENOSYS;
case 0xc0000721: return ENOSYS;
case 0xc000080f: return EAGAIN;
case 0xc000a203: return EACCES;
}
return -1;
}
static win32::DWORD _nt_code_to_win32_code(win32::NTSTATUS c) // NOLINT
{
if(c >= 0)
{
return 0; // success
}
switch(static_cast<unsigned>(c))
{
case 0x80000002: return 0x3e6;
case 0x80000005: return 0xea;
case 0x80000006: return 0x12;
case 0x80000007: return 0x2a3;
case 0x8000000a: return 0x2a4;
case 0x8000000b: return 0x56f;
case 0x8000000c: return 0x2a8;
case 0x8000000d: return 0x12b;
case 0x8000000e: return 0x1c;
case 0x8000000f: return 0x15;
case 0x80000010: return 0x15;
case 0x80000011: return 0xaa;
case 0x80000012: return 0x103;
case 0x80000013: return 0xfe;
case 0x80000014: return 0xff;
case 0x80000015: return 0xff;
case 0x80000016: return 0x456;
case 0x80000017: return 0x2a5;
case 0x80000018: return 0x2a6;
case 0x8000001a: return 0x103;
case 0x8000001b: return 0x44d;
case 0x8000001c: return 0x456;
case 0x8000001d: return 0x457;
case 0x8000001e: return 0x44c;
case 0x8000001f: return 0x44e;
case 0x80000020: return 0x2a7;
case 0x80000021: return 0x44f;
case 0x80000022: return 0x450;
case 0x80000023: return 0x702;
case 0x80000024: return 0x713;
case 0x80000025: return 0x962;
case 0x80000026: return 0x2aa;
case 0x80000027: return 0x10f4;
case 0x80000028: return 0x2ab;
case 0x80000029: return 0x2ac;
case 0x8000002a: return 0x2ad;
case 0x8000002b: return 0x2ae;
case 0x8000002c: return 0x2af;
case 0x8000002d: return 0x2a9;
case 0x8000002e: return 0x321;
case 0x8000002f: return 0x324;
case 0x80000030: return 0xab;
case 0x80000032: return 0xeb;
case 0x80000288: return 0x48d;
case 0x80000289: return 0x48e;
case 0x80000803: return 0x1abb;
case 0x8000a127: return 0x3bdf;
case 0x8000cf00: return 0x16e;
case 0x8000cf04: return 0x16d;
case 0x8000cf05: return 0x176;
case 0x80130001: return 0x13c5;
case 0x80130002: return 0x13c6;
case 0x80130003: return 0x13c7;
case 0x80130004: return 0x13c8;
case 0x80130005: return 0x13c9;
case 0x80190009: return 0x19e5;
case 0x80190029: return 0x1aa0;
case 0x80190031: return 0x1aa2;
case 0x80190041: return 0x1ab3;
case 0x80190042: return 0x1ab4;
case 0x801c0001: return 0x7a;
case 0xc0000001: return 0x1f;
case 0xc0000002: return 0x1;
case 0xc0000003: return 0x57;
case 0xc0000004: return 0x18;
case 0xc0000005: return 0x3e6;
case 0xc0000006: return 0x3e7;
case 0xc0000007: return 0x5ae;
case 0xc0000008: return 0x6;
case 0xc0000009: return 0x3e9;
case 0xc000000a: return 0xc1;
case 0xc000000b: return 0x57;
case 0xc000000c: return 0x21d;
case 0xc000000d: return 0x57;
case 0xc000000e: return 0x2;
case 0xc000000f: return 0x2;
case 0xc0000010: return 0x1;
case 0xc0000011: return 0x26;
case 0xc0000012: return 0x22;
case 0xc0000013: return 0x15;
case 0xc0000014: return 0x6f9;
case 0xc0000015: return 0x1b;
case 0xc0000016: return 0xea;
case 0xc0000017: return 0x8;
case 0xc0000018: return 0x1e7;
case 0xc0000019: return 0x1e7;
case 0xc000001a: return 0x57;
case 0xc000001b: return 0x57;
case 0xc000001c: return 0x1;
case 0xc000001e: return 0x5;
case 0xc000001f: return 0x5;
case 0xc0000020: return 0xc1;
case 0xc0000021: return 0x5;
case 0xc0000022: return 0x5;
case 0xc0000023: return 0x7a;
case 0xc0000024: return 0x6;
case 0xc0000027: return 0x21e;
case 0xc0000028: return 0x21f;
case 0xc0000029: return 0x220;
case 0xc000002a: return 0x9e;
case 0xc000002c: return 0x1e7;
case 0xc000002d: return 0x1e7;
case 0xc000002e: return 0x221;
case 0xc000002f: return 0x222;
case 0xc0000030: return 0x57;
case 0xc0000031: return 0x223;
case 0xc0000032: return 0x571;
case 0xc0000033: return 0x7b;
case 0xc0000034: return 0x2;
case 0xc0000035: return 0xb7;
case 0xc0000036: return 0x72a;
case 0xc0000037: return 0x6;
case 0xc0000038: return 0x224;
case 0xc0000039: return 0xa1;
case 0xc000003a: return 0x3;
case 0xc000003b: return 0xa1;
case 0xc000003c: return 0x45d;
case 0xc000003d: return 0x45d;
case 0xc000003e: return 0x17;
case 0xc000003f: return 0x17;
case 0xc0000040: return 0x8;
case 0xc0000041: return 0x5;
case 0xc0000042: return 0x6;
case 0xc0000043: return 0x20;
case 0xc0000044: return 0x718;
case 0xc0000045: return 0x57;
case 0xc0000046: return 0x120;
case 0xc0000047: return 0x12a;
case 0xc0000048: return 0x57;
case 0xc0000049: return 0x57;
case 0xc000004a: return 0x9c;
case 0xc000004b: return 0x5;
case 0xc000004c: return 0x57;
case 0xc000004d: return 0x57;
case 0xc000004e: return 0x57;
case 0xc000004f: return 0x11a;
case 0xc0000050: return 0xff;
case 0xc0000051: return 0x570;
case 0xc0000052: return 0x570;
case 0xc0000053: return 0x570;
case 0xc0000054: return 0x21;
case 0xc0000055: return 0x21;
case 0xc0000056: return 0x5;
case 0xc0000057: return 0x32;
case 0xc0000058: return 0x519;
case 0xc0000059: return 0x51a;
case 0xc000005a: return 0x51b;
case 0xc000005b: return 0x51c;
case 0xc000005c: return 0x51d;
case 0xc000005d: return 0x51e;
case 0xc000005e: return 0x51f;
case 0xc000005f: return 0x520;
case 0xc0000060: return 0x521;
case 0xc0000061: return 0x522;
case 0xc0000062: return 0x523;
case 0xc0000063: return 0x524;
case 0xc0000064: return 0x525;
case 0xc0000065: return 0x526;
case 0xc0000066: return 0x527;
case 0xc0000067: return 0x528;
case 0xc0000068: return 0x529;
case 0xc0000069: return 0x52a;
case 0xc000006a: return 0x56;
case 0xc000006b: return 0x52c;
case 0xc000006c: return 0x52d;
case 0xc000006d: return 0x52e;
case 0xc000006e: return 0x52f;
case 0xc000006f: return 0x530;
case 0xc0000070: return 0x531;
case 0xc0000071: return 0x532;
case 0xc0000072: return 0x533;
case 0xc0000073: return 0x534;
case 0xc0000074: return 0x535;
case 0xc0000075: return 0x536;
case 0xc0000076: return 0x537;
case 0xc0000077: return 0x538;
case 0xc0000078: return 0x539;
case 0xc0000079: return 0x53a;
case 0xc000007a: return 0x7f;
case 0xc000007b: return 0xc1;
case 0xc000007c: return 0x3f0;
case 0xc000007d: return 0x53c;
case 0xc000007e: return 0x9e;
case 0xc000007f: return 0x70;
case 0xc0000080: return 0x53d;
case 0xc0000081: return 0x53e;
case 0xc0000082: return 0x44;
case 0xc0000083: return 0x103;
case 0xc0000084: return 0x53f;
case 0xc0000085: return 0x103;
case 0xc0000086: return 0x9a;
case 0xc0000087: return 0xe;
case 0xc0000088: return 0x1e7;
case 0xc0000089: return 0x714;
case 0xc000008a: return 0x715;
case 0xc000008b: return 0x716;
case 0xc0000095: return 0x216;
case 0xc0000097: return 0x8;
case 0xc0000098: return 0x3ee;
case 0xc0000099: return 0x540;
case 0xc000009a: return 0x5aa;
case 0xc000009b: return 0x3;
case 0xc000009c: return 0x17;
case 0xc000009d: return 0x48f;
case 0xc000009e: return 0x15;
case 0xc000009f: return 0x1e7;
case 0xc00000a0: return 0x1e7;
case 0xc00000a1: return 0x5ad;
case 0xc00000a2: return 0x13;
case 0xc00000a3: return 0x15;
case 0xc00000a4: return 0x541;
case 0xc00000a5: return 0x542;
case 0xc00000a6: return 0x543;
case 0xc00000a7: return 0x544;
case 0xc00000a8: return 0x545;
case 0xc00000a9: return 0x57;
case 0xc00000aa: return 0x225;
case 0xc00000ab: return 0xe7;
case 0xc00000ac: return 0xe7;
case 0xc00000ad: return 0xe6;
case 0xc00000ae: return 0xe7;
case 0xc00000af: return 0x1;
case 0xc00000b0: return 0xe9;
case 0xc00000b1: return 0xe8;
case 0xc00000b2: return 0x217;
case 0xc00000b3: return 0x218;
case 0xc00000b4: return 0xe6;
case 0xc00000b5: return 0x79;
case 0xc00000b6: return 0x26;
case 0xc00000b7: return 0x226;
case 0xc00000b8: return 0x227;
case 0xc00000b9: return 0x228;
case 0xc00000ba: return 0x5;
case 0xc00000bb: return 0x32;
case 0xc00000bc: return 0x33;
case 0xc00000bd: return 0x34;
case 0xc00000be: return 0x35;
case 0xc00000bf: return 0x36;
case 0xc00000c0: return 0x37;
case 0xc00000c1: return 0x38;
case 0xc00000c2: return 0x39;
case 0xc00000c3: return 0x3a;
case 0xc00000c4: return 0x3b;
case 0xc00000c5: return 0x3c;
case 0xc00000c6: return 0x3d;
case 0xc00000c7: return 0x3e;
case 0xc00000c8: return 0x3f;
case 0xc00000c9: return 0x40;
case 0xc00000ca: return 0x41;
case 0xc00000cb: return 0x42;
case 0xc00000cc: return 0x43;
case 0xc00000cd: return 0x44;
case 0xc00000ce: return 0x45;
case 0xc00000cf: return 0x46;
case 0xc00000d0: return 0x47;
case 0xc00000d1: return 0x48;
case 0xc00000d2: return 0x58;
case 0xc00000d3: return 0x229;
case 0xc00000d4: return 0x11;
case 0xc00000d5: return 0x5;
case 0xc00000d6: return 0xf0;
case 0xc00000d7: return 0x546;
case 0xc00000d8: return 0x22a;
case 0xc00000d9: return 0xe8;
case 0xc00000da: return 0x547;
case 0xc00000db: return 0x22b;
case 0xc00000dc: return 0x548;
case 0xc00000dd: return 0x549;
case 0xc00000de: return 0x54a;
case 0xc00000df: return 0x54b;
case 0xc00000e0: return 0x54c;
case 0xc00000e1: return 0x54d;
case 0xc00000e2: return 0x12c;
case 0xc00000e3: return 0x12d;
case 0xc00000e4: return 0x54e;
case 0xc00000e5: return 0x54f;
case 0xc00000e6: return 0x550;
case 0xc00000e7: return 0x551;
case 0xc00000e8: return 0x6f8;
case 0xc00000e9: return 0x45d;
case 0xc00000ea: return 0x22c;
case 0xc00000eb: return 0x22d;
case 0xc00000ec: return 0x22e;
case 0xc00000ed: return 0x552;
case 0xc00000ee: return 0x553;
case 0xc00000ef: return 0x57;
case 0xc00000f0: return 0x57;
case 0xc00000f1: return 0x57;
case 0xc00000f2: return 0x57;
case 0xc00000f3: return 0x57;
case 0xc00000f4: return 0x57;
case 0xc00000f5: return 0x57;
case 0xc00000f6: return 0x57;
case 0xc00000f7: return 0x57;
case 0xc00000f8: return 0x57;
case 0xc00000f9: return 0x57;
case 0xc00000fa: return 0x57;
case 0xc00000fb: return 0x3;
case 0xc00000fc: return 0x420;
case 0xc00000fd: return 0x3e9;
case 0xc00000fe: return 0x554;
case 0xc00000ff: return 0x22f;
case 0xc0000100: return 0xcb;
case 0xc0000101: return 0x91;
case 0xc0000102: return 0x570;
case 0xc0000103: return 0x10b;
case 0xc0000104: return 0x555;
case 0xc0000105: return 0x556;
case 0xc0000106: return 0xce;
case 0xc0000107: return 0x961;
case 0xc0000108: return 0x964;
case 0xc000010a: return 0x5;
case 0xc000010b: return 0x557;
case 0xc000010c: return 0x230;
case 0xc000010d: return 0x558;
case 0xc000010e: return 0x420;
case 0xc000010f: return 0x21a;
case 0xc0000110: return 0x21a;
case 0xc0000111: return 0x21a;
case 0xc0000112: return 0x21a;
case 0xc0000113: return 0x21a;
case 0xc0000114: return 0x21a;
case 0xc0000115: return 0x21a;
case 0xc0000116: return 0x21a;
case 0xc0000117: return 0x5a4;
case 0xc0000118: return 0x231;
case 0xc0000119: return 0x233;
case 0xc000011a: return 0x234;
case 0xc000011b: return 0xc1;
case 0xc000011c: return 0x559;
case 0xc000011d: return 0x55a;
case 0xc000011e: return 0x3ee;
case 0xc000011f: return 0x4;
case 0xc0000120: return 0x3e3;
case 0xc0000121: return 0x5;
case 0xc0000122: return 0x4ba;
case 0xc0000123: return 0x5;
case 0xc0000124: return 0x55b;
case 0xc0000125: return 0x55c;
case 0xc0000126: return 0x55d;
case 0xc0000127: return 0x55e;
case 0xc0000128: return 0x6;
case 0xc0000129: return 0x235;
case 0xc000012a: return 0x236;
case 0xc000012b: return 0x55f;
case 0xc000012c: return 0x237;
case 0xc000012d: return 0x5af;
case 0xc000012e: return 0xc1;
case 0xc000012f: return 0xc1;
case 0xc0000130: return 0xc1;
case 0xc0000131: return 0xc1;
case 0xc0000132: return 0x238;
case 0xc0000133: return 0x576;
case 0xc0000134: return 0x239;
case 0xc0000135: return 0x7e;
case 0xc0000136: return 0x23a;
case 0xc0000137: return 0x23b;
case 0xc0000138: return 0xb6;
case 0xc0000139: return 0x7f;
case 0xc000013a: return 0x23c;
case 0xc000013b: return 0x40;
case 0xc000013c: return 0x40;
case 0xc000013d: return 0x33;
case 0xc000013e: return 0x3b;
case 0xc000013f: return 0x3b;
case 0xc0000140: return 0x3b;
case 0xc0000141: return 0x3b;
case 0xc0000142: return 0x45a;
case 0xc0000143: return 0x23d;
case 0xc0000144: return 0x23e;
case 0xc0000145: return 0x23f;
case 0xc0000146: return 0x240;
case 0xc0000147: return 0x242;
case 0xc0000148: return 0x7c;
case 0xc0000149: return 0x56;
case 0xc000014a: return 0x243;
case 0xc000014b: return 0x6d;
case 0xc000014c: return 0x3f1;
case 0xc000014d: return 0x3f8;
case 0xc000014e: return 0x244;
case 0xc000014f: return 0x3ed;
case 0xc0000150: return 0x45e;
case 0xc0000151: return 0x560;
case 0xc0000152: return 0x561;
case 0xc0000153: return 0x562;
case 0xc0000154: return 0x563;
case 0xc0000155: return 0x564;
case 0xc0000156: return 0x565;
case 0xc0000157: return 0x566;
case 0xc0000158: return 0x567;
case 0xc0000159: return 0x3ef;
case 0xc000015a: return 0x568;
case 0xc000015b: return 0x569;
case 0xc000015c: return 0x3f9;
case 0xc000015d: return 0x56a;
case 0xc000015e: return 0x245;
case 0xc000015f: return 0x45d;
case 0xc0000160: return 0x4db;
case 0xc0000161: return 0x246;
case 0xc0000162: return 0x459;
case 0xc0000163: return 0x247;
case 0xc0000164: return 0x248;
case 0xc0000165: return 0x462;
case 0xc0000166: return 0x463;
case 0xc0000167: return 0x464;
case 0xc0000168: return 0x465;
case 0xc0000169: return 0x466;
case 0xc000016a: return 0x467;
case 0xc000016b: return 0x468;
case 0xc000016c: return 0x45f;
case 0xc000016d: return 0x45d;
case 0xc000016e: return 0x249;
case 0xc0000172: return 0x451;
case 0xc0000173: return 0x452;
case 0xc0000174: return 0x453;
case 0xc0000175: return 0x454;
case 0xc0000176: return 0x455;
case 0xc0000177: return 0x469;
case 0xc0000178: return 0x458;
case 0xc000017a: return 0x56b;
case 0xc000017b: return 0x56c;
case 0xc000017c: return 0x3fa;
case 0xc000017d: return 0x3fb;
case 0xc000017e: return 0x56d;
case 0xc000017f: return 0x56e;
case 0xc0000180: return 0x3fc;
case 0xc0000181: return 0x3fd;
case 0xc0000182: return 0x57;
case 0xc0000183: return 0x45d;
case 0xc0000184: return 0x16;
case 0xc0000185: return 0x45d;
case 0xc0000186: return 0x45d;
case 0xc0000187: return 0x24a;
case 0xc0000188: return 0x5de;
case 0xc0000189: return 0x13;
case 0xc000018a: return 0x6fa;
case 0xc000018b: return 0x6fb;
case 0xc000018c: return 0x6fc;
case 0xc000018d: return 0x6fd;
case 0xc000018e: return 0x5dc;
case 0xc000018f: return 0x5dd;
case 0xc0000190: return 0x6fe;
case 0xc0000191: return 0x24b;
case 0xc0000192: return 0x700;
case 0xc0000193: return 0x701;
case 0xc0000194: return 0x46b;
case 0xc0000195: return 0x4c3;
case 0xc0000196: return 0x4c4;
case 0xc0000197: return 0x5df;
case 0xc0000198: return 0x70f;
case 0xc0000199: return 0x710;
case 0xc000019a: return 0x711;
case 0xc000019b: return 0x712;
case 0xc000019c: return 0x24c;
case 0xc000019d: return 0x420;
case 0xc000019e: return 0x130;
case 0xc000019f: return 0x131;
case 0xc00001a0: return 0x132;
case 0xc00001a1: return 0x133;
case 0xc00001a2: return 0x325;
case 0xc00001a3: return 0x134;
case 0xc00001a4: return 0x135;
case 0xc00001a5: return 0x136;
case 0xc00001a6: return 0x137;
case 0xc00001a7: return 0x139;
case 0xc00001a8: return 0x1abb;
case 0xc00001a9: return 0x32;
case 0xc00001aa: return 0x3d54;
case 0xc00001ab: return 0x329;
case 0xc00001ac: return 0x678;
case 0xc00001ad: return 0x8;
case 0xc00001ae: return 0x2f7;
case 0xc00001af: return 0x32d;
case 0xc0000201: return 0x41;
case 0xc0000202: return 0x572;
case 0xc0000203: return 0x3b;
case 0xc0000204: return 0x717;
case 0xc0000205: return 0x46a;
case 0xc0000206: return 0x6f8;
case 0xc0000207: return 0x4be;
case 0xc0000208: return 0x4be;
case 0xc0000209: return 0x44;
case 0xc000020a: return 0x34;
case 0xc000020b: return 0x40;
case 0xc000020c: return 0x40;
case 0xc000020d: return 0x40;
case 0xc000020e: return 0x44;
case 0xc000020f: return 0x3b;
case 0xc0000210: return 0x3b;
case 0xc0000211: return 0x3b;
case 0xc0000212: return 0x3b;
case 0xc0000213: return 0x3b;
case 0xc0000214: return 0x3b;
case 0xc0000215: return 0x3b;
case 0xc0000216: return 0x32;
case 0xc0000217: return 0x32;
case 0xc0000218: return 0x24d;
case 0xc0000219: return 0x24e;
case 0xc000021a: return 0x24f;
case 0xc000021b: return 0x250;
case 0xc000021c: return 0x17e6;
case 0xc000021d: return 0x251;
case 0xc000021e: return 0x252;
case 0xc000021f: return 0x253;
case 0xc0000220: return 0x46c;
case 0xc0000221: return 0xc1;
case 0xc0000222: return 0x254;
case 0xc0000223: return 0x255;
case 0xc0000224: return 0x773;
case 0xc0000225: return 0x490;
case 0xc0000226: return 0x256;
case 0xc0000227: return 0x4ff;
case 0xc0000228: return 0x257;
case 0xc0000229: return 0x57;
case 0xc000022a: return 0x1392;
case 0xc000022b: return 0x1392;
case 0xc000022c: return 0x258;
case 0xc000022d: return 0x4d5;
case 0xc000022e: return 0x259;
case 0xc000022f: return 0x25a;
case 0xc0000230: return 0x492;
case 0xc0000231: return 0x25b;
case 0xc0000232: return 0x25c;
case 0xc0000233: return 0x774;
case 0xc0000234: return 0x775;
case 0xc0000235: return 0x6;
case 0xc0000236: return 0x4c9;
case 0xc0000237: return 0x4ca;
case 0xc0000238: return 0x4cb;
case 0xc0000239: return 0x4cc;
case 0xc000023a: return 0x4cd;
case 0xc000023b: return 0x4ce;
case 0xc000023c: return 0x4cf;
case 0xc000023d: return 0x4d0;
case 0xc000023e: return 0x4d1;
case 0xc000023f: return 0x4d2;
case 0xc0000240: return 0x4d3;
case 0xc0000241: return 0x4d4;
case 0xc0000242: return 0x25d;
case 0xc0000243: return 0x4c8;
case 0xc0000244: return 0x25e;
case 0xc0000245: return 0x25f;
case 0xc0000246: return 0x4d6;
case 0xc0000247: return 0x4d7;
case 0xc0000248: return 0x4d8;
case 0xc0000249: return 0xc1;
case 0xc0000250: return 0x260;
case 0xc0000251: return 0x261;
case 0xc0000252: return 0x262;
case 0xc0000253: return 0x4d4;
case 0xc0000254: return 0x263;
case 0xc0000255: return 0x264;
case 0xc0000256: return 0x265;
case 0xc0000257: return 0x4d0;
case 0xc0000258: return 0x266;
case 0xc0000259: return 0x573;
case 0xc000025a: return 0x267;
case 0xc000025b: return 0x268;
case 0xc000025c: return 0x269;
case 0xc000025e: return 0x422;
case 0xc000025f: return 0x26a;
case 0xc0000260: return 0x26b;
case 0xc0000261: return 0x26c;
case 0xc0000262: return 0xb6;
case 0xc0000263: return 0x7f;
case 0xc0000264: return 0x120;
case 0xc0000265: return 0x476;
case 0xc0000266: return 0x26d;
case 0xc0000267: return 0x10fe;
case 0xc0000268: return 0x26e;
case 0xc0000269: return 0x26f;
case 0xc000026a: return 0x1b8e;
case 0xc000026b: return 0x270;
case 0xc000026c: return 0x7d1;
case 0xc000026d: return 0x4b1;
case 0xc000026e: return 0x15;
case 0xc000026f: return 0x21c;
case 0xc0000270: return 0x21c;
case 0xc0000271: return 0x271;
case 0xc0000272: return 0x491;
case 0xc0000273: return 0x272;
case 0xc0000275: return 0x1126;
case 0xc0000276: return 0x1129;
case 0xc0000277: return 0x112a;
case 0xc0000278: return 0x1128;
case 0xc0000279: return 0x780;
case 0xc000027a: return 0x291;
case 0xc000027b: return 0x54f;
case 0xc000027c: return 0x54f;
case 0xc0000280: return 0x781;
case 0xc0000281: return 0xa1;
case 0xc0000282: return 0x273;
case 0xc0000283: return 0x488;
case 0xc0000284: return 0x489;
case 0xc0000285: return 0x48a;
case 0xc0000286: return 0x48b;
case 0xc0000287: return 0x48c;
case 0xc000028a: return 0x5;
case 0xc000028b: return 0x5;
case 0xc000028c: return 0x284;
case 0xc000028d: return 0x5;
case 0xc000028e: return 0x5;
case 0xc000028f: return 0x5;
case 0xc0000290: return 0x5;
case 0xc0000291: return 0x1777;
case 0xc0000292: return 0x1778;
case 0xc0000293: return 0x1772;
case 0xc0000295: return 0x1068;
case 0xc0000296: return 0x1069;
case 0xc0000297: return 0x106a;
case 0xc0000298: return 0x106b;
case 0xc0000299: return 0x201a;
case 0xc000029a: return 0x201b;
case 0xc000029b: return 0x201c;
case 0xc000029c: return 0x1;
case 0xc000029d: return 0x10ff;
case 0xc000029e: return 0x1100;
case 0xc000029f: return 0x494;
case 0xc00002a0: return 0x274;
case 0xc00002a1: return 0x200a;
case 0xc00002a2: return 0x200b;
case 0xc00002a3: return 0x200c;
case 0xc00002a4: return 0x200d;
case 0xc00002a5: return 0x200e;
case 0xc00002a6: return 0x200f;
case 0xc00002a7: return 0x2010;
case 0xc00002a8: return 0x2011;
case 0xc00002a9: return 0x2012;
case 0xc00002aa: return 0x2013;
case 0xc00002ab: return 0x2014;
case 0xc00002ac: return 0x2015;
case 0xc00002ad: return 0x2016;
case 0xc00002ae: return 0x2017;
case 0xc00002af: return 0x2018;
case 0xc00002b0: return 0x2019;
case 0xc00002b1: return 0x211e;
case 0xc00002b2: return 0x1127;
case 0xc00002b3: return 0x275;
case 0xc00002b4: return 0x276;
case 0xc00002b5: return 0x277;
case 0xc00002b6: return 0x651;
case 0xc00002b7: return 0x49a;
case 0xc00002b8: return 0x49b;
case 0xc00002b9: return 0x278;
case 0xc00002ba: return 0x2047;
case 0xc00002c1: return 0x2024;
case 0xc00002c2: return 0x279;
case 0xc00002c3: return 0x575;
case 0xc00002c4: return 0x27a;
case 0xc00002c5: return 0x3e6;
case 0xc00002c6: return 0x1075;
case 0xc00002c7: return 0x1076;
case 0xc00002c8: return 0x27b;
case 0xc00002c9: return 0x4ed;
case 0xc00002ca: return 0x10e8;
case 0xc00002cb: return 0x2138;
case 0xc00002cc: return 0x4e3;
case 0xc00002cd: return 0x2139;
case 0xc00002ce: return 0x27c;
case 0xc00002cf: return 0x49d;
case 0xc00002d0: return 0x213a;
case 0xc00002d1: return 0x27d;
case 0xc00002d2: return 0x27e;
case 0xc00002d3: return 0x15;
case 0xc00002d4: return 0x2141;
case 0xc00002d5: return 0x2142;
case 0xc00002d6: return 0x2143;
case 0xc00002d7: return 0x2144;
case 0xc00002d8: return 0x2145;
case 0xc00002d9: return 0x2146;
case 0xc00002da: return 0x2147;
case 0xc00002db: return 0x2148;
case 0xc00002dc: return 0x2149;
case 0xc00002dd: return 0x32;
case 0xc00002de: return 0x27f;
case 0xc00002df: return 0x2151;
case 0xc00002e0: return 0x2152;
case 0xc00002e1: return 0x2153;
case 0xc00002e2: return 0x2154;
case 0xc00002e3: return 0x215d;
case 0xc00002e4: return 0x2163;
case 0xc00002e5: return 0x2164;
case 0xc00002e6: return 0x2165;
case 0xc00002e7: return 0x216d;
case 0xc00002e8: return 0x280;
case 0xc00002e9: return 0x577;
case 0xc00002ea: return 0x52;
case 0xc00002eb: return 0x281;
case 0xc00002ec: return 0x2171;
case 0xc00002ed: return 0x2172;
case 0xc00002f0: return 0x2;
case 0xc00002fe: return 0x45b;
case 0xc00002ff: return 0x4e7;
case 0xc0000300: return 0x4e6;
case 0xc0000301: return 0x106f;
case 0xc0000302: return 0x1074;
case 0xc0000303: return 0x106e;
case 0xc0000304: return 0x12e;
case 0xc000030c: return 0x792;
case 0xc000030d: return 0x793;
case 0xc0000320: return 0x4ef;
case 0xc0000321: return 0x4f0;
case 0xc0000350: return 0x4e8;
case 0xc0000352: return 0x177d;
case 0xc0000353: return 0x282;
case 0xc0000354: return 0x504;
case 0xc0000355: return 0x283;
case 0xc0000357: return 0x217c;
case 0xc0000358: return 0x2182;
case 0xc0000359: return 0xc1;
case 0xc000035a: return 0xc1;
case 0xc000035c: return 0x572;
case 0xc000035d: return 0x4eb;
case 0xc000035f: return 0x286;
case 0xc0000361: return 0x4ec;
case 0xc0000362: return 0x4ec;
case 0xc0000363: return 0x4ec;
case 0xc0000364: return 0x4ec;
case 0xc0000365: return 0x287;
case 0xc0000366: return 0x288;
case 0xc0000368: return 0x289;
case 0xc0000369: return 0x28a;
case 0xc000036a: return 0x28b;
case 0xc000036b: return 0x4fb;
case 0xc000036c: return 0x4fb;
case 0xc000036d: return 0x28c;
case 0xc000036e: return 0x28d;
case 0xc000036f: return 0x4fc;
case 0xc0000371: return 0x21ac;
case 0xc0000372: return 0x312;
case 0xc0000373: return 0x8;
case 0xc0000374: return 0x54f;
case 0xc0000388: return 0x4f1;
case 0xc000038e: return 0x28e;
case 0xc0000401: return 0x78c;
case 0xc0000402: return 0x78d;
case 0xc0000403: return 0x78e;
case 0xc0000404: return 0x217b;
case 0xc0000405: return 0x219d;
case 0xc0000406: return 0x219f;
case 0xc0000407: return 0x28f;
case 0xc0000408: return 0x52e;
case 0xc0000409: return 0x502;
case 0xc0000410: return 0x503;
case 0xc0000411: return 0x290;
case 0xc0000412: return 0x505;
case 0xc0000413: return 0x78f;
case 0xc0000414: return 0x506;
case 0xc0000416: return 0x8;
case 0xc0000417: return 0x508;
case 0xc0000418: return 0x791;
case 0xc0000419: return 0x215b;
case 0xc000041a: return 0x21ba;
case 0xc000041b: return 0x21bb;
case 0xc000041c: return 0x21bc;
case 0xc000041d: return 0x2c9;
case 0xc0000420: return 0x29c;
case 0xc0000421: return 0x219;
case 0xc0000423: return 0x300;
case 0xc0000424: return 0x4fb;
case 0xc0000425: return 0x3fa;
case 0xc0000426: return 0x301;
case 0xc0000427: return 0x299;
case 0xc0000428: return 0x241;
case 0xc0000429: return 0x307;
case 0xc000042a: return 0x308;
case 0xc000042b: return 0x50c;
case 0xc000042c: return 0x2e4;
case 0xc0000432: return 0x509;
case 0xc0000433: return 0xaa;
case 0xc0000434: return 0xaa;
case 0xc0000435: return 0x4c8;
case 0xc0000441: return 0x1781;
case 0xc0000442: return 0x1782;
case 0xc0000443: return 0x1783;
case 0xc0000444: return 0x1784;
case 0xc0000445: return 0x1785;
case 0xc0000446: return 0x513;
case 0xc0000450: return 0x50b;
case 0xc0000451: return 0x3b92;
case 0xc0000452: return 0x3bc3;
case 0xc0000453: return 0x5bb;
case 0xc0000454: return 0x5be;
case 0xc0000455: return 0x6;
case 0xc0000456: return 0x57;
case 0xc0000457: return 0x57;
case 0xc0000458: return 0x57;
case 0xc0000459: return 0xbea;
case 0xc0000460: return 0x138;
case 0xc0000461: return 0x13a;
case 0xc0000462: return 0x3cfc;
case 0xc0000463: return 0x13c;
case 0xc0000464: return 0x141;
case 0xc0000465: return 0x13b;
case 0xc0000466: return 0x40;
case 0xc0000467: return 0x20;
case 0xc0000468: return 0x142;
case 0xc0000469: return 0x3d00;
case 0xc000046a: return 0x151;
case 0xc000046b: return 0x152;
case 0xc000046c: return 0x153;
case 0xc000046d: return 0x156;
case 0xc000046e: return 0x157;
case 0xc000046f: return 0x158;
case 0xc0000470: return 0x143;
case 0xc0000471: return 0x144;
case 0xc0000472: return 0x146;
case 0xc0000473: return 0x14b;
case 0xc0000474: return 0x147;
case 0xc0000475: return 0x148;
case 0xc0000476: return 0x149;
case 0xc0000477: return 0x14a;
case 0xc0000478: return 0x14c;
case 0xc0000479: return 0x14d;
case 0xc000047a: return 0x14e;
case 0xc000047b: return 0x14f;
case 0xc000047c: return 0x150;
case 0xc000047d: return 0x5b4;
case 0xc000047e: return 0x3d07;
case 0xc000047f: return 0x3d08;
case 0xc0000480: return 0x40;
case 0xc0000481: return 0x7e;
case 0xc0000482: return 0x7e;
case 0xc0000483: return 0x1e3;
case 0xc0000486: return 0x159;
case 0xc0000487: return 0x1f;
case 0xc0000488: return 0x15a;
case 0xc0000489: return 0x3d0f;
case 0xc000048a: return 0x32a;
case 0xc000048b: return 0x32c;
case 0xc000048c: return 0x15b;
case 0xc000048d: return 0x15c;
case 0xc000048e: return 0x162;
case 0xc000048f: return 0x15d;
case 0xc0000490: return 0x491;
case 0xc0000491: return 0x2;
case 0xc0000492: return 0x490;
case 0xc0000493: return 0x492;
case 0xc0000494: return 0x307;
case 0xc0000495: return 0x15;
case 0xc0000496: return 0x163;
case 0xc0000497: return 0x3d5a;
case 0xc0000499: return 0x167;
case 0xc000049a: return 0x168;
case 0xc000049b: return 0x12e;
case 0xc000049c: return 0x169;
case 0xc000049d: return 0x16f;
case 0xc000049e: return 0x170;
case 0xc000049f: return 0x49f;
case 0xc00004a0: return 0x4a0;
case 0xc00004a1: return 0x18f;
case 0xc0000500: return 0x60e;
case 0xc0000501: return 0x60f;
case 0xc0000502: return 0x610;
case 0xc0000503: return 0x15;
case 0xc0000504: return 0x13f;
case 0xc0000505: return 0x140;
case 0xc0000506: return 0x5bf;
case 0xc0000507: return 0xaa;
case 0xc0000508: return 0x5e0;
case 0xc0000509: return 0x5e1;
case 0xc000050b: return 0x112b;
case 0xc000050e: return 0x115c;
case 0xc000050f: return 0x10d3;
case 0xc0000510: return 0x4df;
case 0xc0000511: return 0x32e;
case 0xc0000512: return 0x5;
case 0xc0000513: return 0x180;
case 0xc0000514: return 0x115d;
case 0xc0000602: return 0x675;
case 0xc0000604: return 0x677;
case 0xc0000606: return 0x679;
case 0xc000060a: return 0x67c;
case 0xc000060b: return 0x67d;
case 0xc0000700: return 0x54f;
case 0xc0000701: return 0x54f;
case 0xc0000702: return 0x57;
case 0xc0000703: return 0x54f;
case 0xc0000704: return 0x32;
case 0xc0000705: return 0x57;
case 0xc0000706: return 0x57;
case 0xc0000707: return 0x32;
case 0xc0000708: return 0x54f;
case 0xc0000709: return 0x30b;
case 0xc000070a: return 0x6;
case 0xc000070b: return 0x6;
case 0xc000070c: return 0x6;
case 0xc000070d: return 0x6;
case 0xc000070e: return 0x6;
case 0xc000070f: return 0x6;
case 0xc0000710: return 0x1;
case 0xc0000711: return 0x1;
case 0xc0000712: return 0x50d;
case 0xc0000713: return 0x310;
case 0xc0000714: return 0x52e;
case 0xc0000715: return 0x5b7;
case 0xc0000716: return 0x7b;
case 0xc0000717: return 0x459;
case 0xc0000718: return 0x54f;
case 0xc0000719: return 0x54f;
case 0xc000071a: return 0x54f;
case 0xc000071b: return 0x1;
case 0xc000071c: return 0x57;
case 0xc000071d: return 0x1;
case 0xc000071e: return 0x1;
case 0xc000071f: return 0x1;
case 0xc0000720: return 0x1;
case 0xc0000721: return 0x1;
case 0xc0000722: return 0x72b;
case 0xc0000723: return 0x1f;
case 0xc0000724: return 0x1f;
case 0xc0000725: return 0x1f;
case 0xc0000726: return 0x1f;
case 0xc0000800: return 0x30c;
case 0xc0000801: return 0x21a4;
case 0xc0000802: return 0x50f;
case 0xc0000804: return 0x510;
case 0xc0000805: return 0x1ac1;
case 0xc0000806: return 0x1ac3;
case 0xc0000808: return 0x319;
case 0xc0000809: return 0x31a;
case 0xc000080a: return 0x31b;
case 0xc000080b: return 0x31c;
case 0xc000080c: return 0x31d;
case 0xc000080d: return 0x31e;
case 0xc000080e: return 0x31f;
case 0xc000080f: return 0x4d5;
case 0xc0000810: return 0x328;
case 0xc0000811: return 0x54f;
case 0xc0000901: return 0xdc;
case 0xc0000902: return 0xdd;
case 0xc0000903: return 0xde;
case 0xc0000904: return 0xdf;
case 0xc0000905: return 0xe0;
case 0xc0000906: return 0xe1;
case 0xc0000907: return 0xe2;
case 0xc0000908: return 0x317;
case 0xc0000909: return 0x322;
case 0xc0000910: return 0x326;
case 0xc0009898: return 0x29e;
case 0xc000a002: return 0x17;
case 0xc000a003: return 0x139f;
case 0xc000a004: return 0x154;
case 0xc000a005: return 0x155;
case 0xc000a006: return 0x32b;
case 0xc000a007: return 0x32;
case 0xc000a010: return 0xea;
case 0xc000a011: return 0xea;
case 0xc000a012: return 0x4d0;
case 0xc000a013: return 0x32;
case 0xc000a014: return 0x4d1;
case 0xc000a080: return 0x314;
case 0xc000a081: return 0x315;
case 0xc000a082: return 0x316;
case 0xc000a083: return 0x5b9;
case 0xc000a084: return 0x5ba;
case 0xc000a085: return 0x5bc;
case 0xc000a086: return 0x5bd;
case 0xc000a087: return 0x21bd;
case 0xc000a088: return 0x21be;
case 0xc000a089: return 0x21c6;
case 0xc000a100: return 0x3bc4;
case 0xc000a101: return 0x3bc5;
case 0xc000a121: return 0x3bd9;
case 0xc000a122: return 0x3bda;
case 0xc000a123: return 0x3bdb;
case 0xc000a124: return 0x3bdc;
case 0xc000a125: return 0x3bdd;
case 0xc000a126: return 0x3bde;
case 0xc000a141: return 0x3c28;
case 0xc000a142: return 0x3c29;
case 0xc000a143: return 0x3c2a;
case 0xc000a145: return 0x3c2b;
case 0xc000a146: return 0x3c2c;
case 0xc000a200: return 0x109a;
case 0xc000a201: return 0x109c;
case 0xc000a202: return 0x109d;
case 0xc000a203: return 0x5;
case 0xc000a281: return 0x1130;
case 0xc000a282: return 0x1131;
case 0xc000a283: return 0x1132;
case 0xc000a284: return 0x1133;
case 0xc000a285: return 0x1134;
case 0xc000a2a1: return 0x1158;
case 0xc000a2a2: return 0x1159;
case 0xc000a2a3: return 0x115a;
case 0xc000a2a4: return 0x115b;
case 0xc000ce01: return 0x171;
case 0xc000ce02: return 0x172;
case 0xc000ce03: return 0x173;
case 0xc000ce04: return 0x174;
case 0xc000ce05: return 0x181;
case 0xc000cf00: return 0x166;
case 0xc000cf01: return 0x16a;
case 0xc000cf02: return 0x16b;
case 0xc000cf03: return 0x16c;
case 0xc000cf06: return 0x177;
case 0xc000cf07: return 0x178;
case 0xc000cf08: return 0x179;
case 0xc000cf09: return 0x17a;
case 0xc000cf0a: return 0x17b;
case 0xc000cf0b: return 0x17c;
case 0xc000cf0c: return 0x17d;
case 0xc000cf0d: return 0x17e;
case 0xc000cf0e: return 0x17f;
case 0xc000cf0f: return 0x182;
case 0xc000cf10: return 0x183;
case 0xc000cf11: return 0x184;
case 0xc000cf12: return 0x185;
case 0xc000cf13: return 0x186;
case 0xc000cf14: return 0x187;
case 0xc000cf15: return 0x188;
case 0xc000cf16: return 0x189;
case 0xc000cf17: return 0x18a;
case 0xc000cf18: return 0x18b;
case 0xc000cf19: return 0x18c;
case 0xc000cf1a: return 0x18d;
case 0xc000cf1b: return 0x18e;
}
return static_cast<win32::DWORD>(-1);
}
//! Construct from a NT error code
static _base::string_ref _make_string_ref(win32::NTSTATUS c) noexcept
{
wchar_t buffer[32768];
static win32::HMODULE ntdll = win32::GetModuleHandleW(L"NTDLL.DLL");
win32::DWORD wlen =
win32::FormatMessageW(0x00000800 /*FORMAT_MESSAGE_FROM_HMODULE*/ | 0x00001000 /*FORMAT_MESSAGE_FROM_SYSTEM*/ | 0x00000200 /*FORMAT_MESSAGE_IGNORE_INSERTS*/,
ntdll, c, (1 << 10) /*MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT)*/, buffer, 32768, nullptr);
size_t allocation = wlen + (wlen >> 1);
win32::DWORD bytes;
if(wlen == 0)
{
return _base::string_ref("failed to get message from system");
}
for(;;)
{
auto *p = static_cast<char *>(malloc(allocation)); // NOLINT
if(p == nullptr)
{
return _base::string_ref("failed to get message from system");
}
bytes = win32::WideCharToMultiByte(65001 /*CP_UTF8*/, 0, buffer, (int) (wlen + 1), p, (int) allocation, nullptr, nullptr);
if(bytes != 0)
{
char *end = strchr(p, 0);
while(end[-1] == 10 || end[-1] == 13)
{
--end;
}
*end = 0; // NOLINT
return _base::atomic_refcounted_string_ref(p, end - p);
}
free(p); // NOLINT
if(win32::GetLastError() == 0x7a /*ERROR_INSUFFICIENT_BUFFER*/)
{
allocation += allocation >> 2;
continue;
}
return _base::string_ref("failed to get message from system");
}
}
public:
//! The value type of the NT code, which is a `win32::NTSTATUS`
using value_type = win32::NTSTATUS;
using _base::string_ref;
public:
//! Default constructor
constexpr explicit _nt_code_domain(typename _base::unique_id_type id = 0x93f3b4487e4af25b) noexcept
: _base(id)
{
}
_nt_code_domain(const _nt_code_domain &) = default;
_nt_code_domain(_nt_code_domain &&) = default;
_nt_code_domain &operator=(const _nt_code_domain &) = default;
_nt_code_domain &operator=(_nt_code_domain &&) = default;
~_nt_code_domain() = default;
//! Constexpr singleton getter. Returns the constexpr nt_code_domain variable.
static inline constexpr const _nt_code_domain &get();
virtual string_ref name() const noexcept override { return string_ref("NT domain"); } // NOLINT
virtual payload_info_t payload_info() const noexcept override
{
return {sizeof(value_type), sizeof(status_code_domain *) + sizeof(value_type),
(alignof(value_type) > alignof(status_code_domain *)) ? alignof(value_type) : alignof(status_code_domain *)};
}
protected:
virtual bool _do_failure(const status_code<void> &code) const noexcept override // NOLINT
{
assert(code.domain() == *this);
return static_cast<const nt_code &>(code).value() < 0; // NOLINT
}
virtual bool _do_equivalent(const status_code<void> &code1, const status_code<void> &code2) const noexcept override // NOLINT
{
assert(code1.domain() == *this);
const auto &c1 = static_cast<const nt_code &>(code1); // NOLINT
if(code2.domain() == *this)
{
const auto &c2 = static_cast<const nt_code &>(code2); // NOLINT
return c1.value() == c2.value();
}
if(code2.domain() == generic_code_domain)
{
const auto &c2 = static_cast<const generic_code &>(code2); // NOLINT
if(static_cast<int>(c2.value()) == _nt_code_to_errno(c1.value()))
{
return true;
}
}
if(code2.domain() == win32_code_domain)
{
const auto &c2 = static_cast<const win32_code &>(code2); // NOLINT
if(c2.value() == _nt_code_to_win32_code(c1.value()))
{
return true;
}
}
return false;
}
virtual generic_code _generic_code(const status_code<void> &code) const noexcept override // NOLINT
{
assert(code.domain() == *this);
const auto &c = static_cast<const nt_code &>(code); // NOLINT
return generic_code(static_cast<errc>(_nt_code_to_errno(c.value())));
}
virtual string_ref _do_message(const status_code<void> &code) const noexcept override // NOLINT
{
assert(code.domain() == *this);
const auto &c = static_cast<const nt_code &>(code); // NOLINT
return _make_string_ref(c.value());
}
#if defined(_CPPUNWIND) || defined(__EXCEPTIONS) || 0L
SYSTEM_ERROR2_NORETURN virtual void _do_throw_exception(const status_code<void> &code) const override // NOLINT
{
assert(code.domain() == *this);
const auto &c = static_cast<const nt_code &>(code); // NOLINT
throw status_error<_nt_code_domain>(c);
}
#endif
};
//! (Windows only) A constexpr source variable for the NT code domain, which is that of NT kernel functions. Returned by `_nt_code_domain::get()`.
constexpr _nt_code_domain nt_code_domain;
inline constexpr const _nt_code_domain &_nt_code_domain::get()
{
return nt_code_domain;
}
SYSTEM_ERROR2_NAMESPACE_END
#endif
// NOT "com_code.hpp"
#endif
SYSTEM_ERROR2_NAMESPACE_BEGIN
/*! An erased-mutable status code suitably large for all the system codes
which can be returned on this system.
For Windows, these might be:
- `com_code` (`HRESULT`) [you need to include "com_code.hpp" explicitly for this]
- `nt_code` (`LONG`)
- `win32_code` (`DWORD`)
For POSIX, `posix_code` is possible.
You are guaranteed that `system_code` can be transported by the compiler
in exactly two CPU registers.
*/
using system_code = erased_status_code<intptr_t>;
#ifndef NDEBUG
static_assert(sizeof(system_code) == 2 * sizeof(void *), "system_code is not exactly two pointers in size!");
static_assert(traits::is_move_bitcopying<system_code>::value, "system_code is not move bitcopying!");
#endif
SYSTEM_ERROR2_NAMESPACE_END
#endif
SYSTEM_ERROR2_NAMESPACE_BEGIN
/*! An errored `system_code` which must be a failure upon copy or move or
non-default construction. The closest equivalent to `std::error_code`, except
it cannot be modified.
This refines `system_code` into an `error` object meeting the requirements of
[P0709 Zero-overhead deterministic exceptions](https://wg21.link/P0709).
Differences from `system_code`:
- Almost always a failure (this is checked at copy or move and non-default
construction, and if not the case, the program is terminated as this is a logic
error)
- Is immutable.
As with `system_code`, it remains guaranteed to be two CPU registers in size,
and move bitcopying.
*/
using error = erased_errored_status_code<system_code::value_type>;
#ifndef NDEBUG
static_assert(sizeof(error) == 2 * sizeof(void *), "error is not exactly two pointers in size!");
static_assert(traits::is_move_bitcopying<error>::value, "error is not move bitcopying!");
#endif
SYSTEM_ERROR2_NAMESPACE_END
#endif
#endif
OUTCOME_V2_NAMESPACE_EXPORT_BEGIN
namespace trait
{
namespace detail
{
// Shortcut this for lower build impact. Used to tell outcome's converting constructors
// that they can do E => EC or E => EP as necessary.
template <class DomainType> struct _is_error_code_available<SYSTEM_ERROR2_NAMESPACE::status_code<DomainType>>
{
static constexpr bool value = true;
using type = SYSTEM_ERROR2_NAMESPACE::status_code<DomainType>;
};
template <class DomainType> struct _is_error_code_available<SYSTEM_ERROR2_NAMESPACE::errored_status_code<DomainType>>
{
static constexpr bool value = true;
using type = SYSTEM_ERROR2_NAMESPACE::errored_status_code<DomainType>;
};
} // namespace detail
template <class DomainType> struct is_move_bitcopying<SYSTEM_ERROR2_NAMESPACE::status_code<DomainType>>
{
static constexpr bool value = SYSTEM_ERROR2_NAMESPACE::traits::is_move_bitcopying<SYSTEM_ERROR2_NAMESPACE::status_code<DomainType>>::value;
};
template <class DomainType> struct is_move_bitcopying<SYSTEM_ERROR2_NAMESPACE::errored_status_code<DomainType>>
{
static constexpr bool value = SYSTEM_ERROR2_NAMESPACE::traits::is_move_bitcopying<SYSTEM_ERROR2_NAMESPACE::errored_status_code<DomainType>>::value;
};
} // namespace trait
namespace detail
{
// Customise _set_error_is_errno
template <class State> constexpr inline void _set_error_is_errno(State &state, const SYSTEM_ERROR2_NAMESPACE::generic_code & /*unused*/)
{
state._status.set_have_error_is_errno(true);
}
#ifndef SYSTEM_ERROR2_NOT_POSIX
template <class State> constexpr inline void _set_error_is_errno(State &state, const SYSTEM_ERROR2_NAMESPACE::posix_code & /*unused*/)
{
state._status.set_have_error_is_errno(true);
}
#endif
template <class State> constexpr inline void _set_error_is_errno(State &state, const SYSTEM_ERROR2_NAMESPACE::errc & /*unused*/)
{
state._status.set_have_error_is_errno(true);
}
} // namespace detail
namespace experimental
{
using namespace SYSTEM_ERROR2_NAMESPACE;
using OUTCOME_V2_NAMESPACE::failure;
using OUTCOME_V2_NAMESPACE::success;
namespace policy
{
using namespace OUTCOME_V2_NAMESPACE::policy;
template <class T, class EC, class E> struct status_code_throw
{
static_assert(!std::is_same<T, T>::value,
"policy::status_code_throw not specialised for these types, did you use status_result<T, status_code<DomainType>, E>?");
};
template <class T, class DomainType> struct status_code_throw<T, status_code<DomainType>, void> : base
{
using _base = base;
template <class Impl> static constexpr void wide_value_check(Impl &&self)
{
if(!base::_has_value(static_cast<Impl &&>(self)))
{
if(base::_has_error(static_cast<Impl &&>(self)))
{
#ifdef __cpp_exceptions
base::_error(static_cast<Impl &&>(self)).throw_exception();
#else
OUTCOME_THROW_EXCEPTION("wide value check failed");
#endif
}
}
}
template <class Impl> static constexpr void wide_error_check(Impl &&self) { _base::narrow_error_check(static_cast<Impl &&>(self)); }
};
template <class T, class DomainType>
struct status_code_throw<T, errored_status_code<DomainType>, void> : status_code_throw<T, status_code<DomainType>, void>
{
status_code_throw() = default;
using status_code_throw<T, status_code<DomainType>, void>::status_code_throw;
};
template <class T, class EC>
using default_status_result_policy = std::conditional_t< //
std::is_void<EC>::value, //
OUTCOME_V2_NAMESPACE::policy::terminate, //
std::conditional_t<is_status_code<EC>::value || is_errored_status_code<EC>::value, //
status_code_throw<T, EC, void>, //
OUTCOME_V2_NAMESPACE::policy::fail_to_compile_observers //
>>;
} // namespace policy
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
template <class R, class S = erased_errored_status_code<typename system_code::value_type>,
class NoValuePolicy = policy::default_status_result_policy<R, S>> //
using status_result = basic_result<R, S, NoValuePolicy>;
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class R, class S, class NoValuePolicy)
OUTCOME_TREQUIRES(OUTCOME_TPRED(std::is_copy_constructible<R>::value && (is_status_code<S>::value || is_errored_status_code<S>::value)))
inline basic_result<R, S, NoValuePolicy> clone(const basic_result<R, S, NoValuePolicy> &v)
{
if(v)
{
return success_type<R>(v.assume_value());
}
return failure_type<S>(v.assume_error().clone(), hooks::spare_storage(&v));
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class S, class NoValuePolicy)
OUTCOME_TREQUIRES(OUTCOME_TPRED(is_status_code<S>::value || is_errored_status_code<S>::value))
inline basic_result<void, S, NoValuePolicy> clone(const basic_result<void, S, NoValuePolicy> &v)
{
if(v)
{
return success_type<void>();
}
return failure_type<S>(v.assume_error().clone(), hooks::spare_storage(&v));
}
} // namespace experimental
OUTCOME_V2_NAMESPACE_END
#endif
// Boost.Outcome #include "boost/exception_ptr.hpp"
SYSTEM_ERROR2_NAMESPACE_BEGIN
template <class DomainType> inline std::exception_ptr basic_outcome_failure_exception_from_error(const status_code<DomainType> &sc)
{
(void) sc;
#ifdef __cpp_exceptions
try
{
sc.throw_exception();
}
catch(...)
{
return std::current_exception();
}
#endif
return {};
}
SYSTEM_ERROR2_NAMESPACE_END
OUTCOME_V2_NAMESPACE_EXPORT_BEGIN
namespace experimental
{
namespace policy
{
template <class T, class EC, class E>
using default_status_outcome_policy = std::conditional_t< //
std::is_void<EC>::value && std::is_void<E>::value, //
OUTCOME_V2_NAMESPACE::policy::terminate, //
std::conditional_t<(is_status_code<EC>::value || is_errored_status_code<EC>::value) &&
(std::is_void<E>::value || OUTCOME_V2_NAMESPACE::trait::is_exception_ptr_available<E>::value), //
status_code_throw<T, EC, E>, //
OUTCOME_V2_NAMESPACE::policy::fail_to_compile_observers //
>>;
} // namespace policy
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
template <class R, class S = erased_errored_status_code<typename system_code::value_type>, class P = std::exception_ptr,
class NoValuePolicy = policy::default_status_outcome_policy<R, S, P>> //
using status_outcome = basic_outcome<R, S, P, NoValuePolicy>;
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class R, class S, class P, class NoValuePolicy)
OUTCOME_TREQUIRES(OUTCOME_TPRED(std::is_copy_constructible<R>::value &&std::is_copy_constructible<P>::value &&
(is_status_code<S>::value || is_errored_status_code<S>::value)))
inline basic_outcome<R, S, P, NoValuePolicy> clone(const basic_outcome<R, S, P, NoValuePolicy> &v)
{
if(v)
{
return success_type<R>(v.assume_value());
}
if(v.has_error() && v.has_exception())
{
return failure_type<S, P>(v.assume_error().clone(), v.assume_exception(), hooks::spare_storage(&v));
}
if(v.has_exception())
{
return failure_type<S, P>(in_place_type<P>, v.assume_exception(), hooks::spare_storage(&v));
}
return failure_type<S, P>(in_place_type<S>, v.assume_error().clone(), hooks::spare_storage(&v));
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class S, class P, class NoValuePolicy)
OUTCOME_TREQUIRES(OUTCOME_TPRED(std::is_copy_constructible<P>::value && (is_status_code<S>::value || is_errored_status_code<S>::value)))
inline basic_outcome<void, S, P, NoValuePolicy> clone(const basic_outcome<void, S, P, NoValuePolicy> &v)
{
if(v)
{
return success_type<void>();
}
if(v.has_error() && v.has_exception())
{
return failure_type<S, P>(v.assume_error().clone(), v.assume_exception(), hooks::spare_storage(&v));
}
if(v.has_exception())
{
return failure_type<S, P>(in_place_type<P>, v.assume_exception(), hooks::spare_storage(&v));
}
return failure_type<S, P>(in_place_type<S>, v.assume_error().clone(), hooks::spare_storage(&v));
}
namespace policy
{
template <class T, class DomainType, class E> struct status_code_throw<T, status_code<DomainType>, E> : base
{
using _base = base;
template <class Impl> static constexpr void wide_value_check(Impl &&self)
{
if(!base::_has_value(static_cast<Impl &&>(self)))
{
if(base::_has_exception(static_cast<Impl &&>(self)))
{
OUTCOME_V2_NAMESPACE::policy::detail::_rethrow_exception<trait::is_exception_ptr_available<E>::value>(
base::_exception<T, status_code<DomainType>, E, status_code_throw>(static_cast<Impl &&>(self))); // NOLINT
}
if(base::_has_error(static_cast<Impl &&>(self)))
{
#ifdef __cpp_exceptions
base::_error(static_cast<Impl &&>(self)).throw_exception();
#else
OUTCOME_THROW_EXCEPTION("wide value check failed");
#endif
}
}
}
template <class Impl> static constexpr void wide_error_check(Impl &&self) { _base::narrow_error_check(static_cast<Impl &&>(self)); }
template <class Impl> static constexpr void wide_exception_check(Impl &&self) { _base::narrow_exception_check(static_cast<Impl &&>(self)); }
};
template <class T, class DomainType, class E>
struct status_code_throw<T, errored_status_code<DomainType>, E> : status_code_throw<T, status_code<DomainType>, E>
{
status_code_throw() = default;
using status_code_throw<T, status_code<DomainType>, E>::status_code_throw;
};
} // namespace policy
} // namespace experimental
OUTCOME_V2_NAMESPACE_END
#endif
/* Pointer to a SG14 status_code
(C) 2018 - 2023 Niall Douglas <http://www.nedproductions.biz/> (5 commits)
File Created: Sep 2018
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License in the accompanying file
Licence.txt or at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Distributed under the Boost Software License, Version 1.0.
(See accompanying file Licence.txt or copy at
http://www.boost.org/LICENSE_1_0.txt)
*/
#ifndef SYSTEM_ERROR2_NESTED_STATUS_CODE_HPP
#define SYSTEM_ERROR2_NESTED_STATUS_CODE_HPP
#include <memory> // for allocator
SYSTEM_ERROR2_NAMESPACE_BEGIN
namespace detail
{
template <class StatusCode, class Allocator> class indirecting_domain : public status_code_domain
{
template <class DomainType> friend class status_code;
using _base = status_code_domain;
public:
struct payload_type
{
using allocator_traits = std::allocator_traits<Allocator>;
union
{
char _uninit[sizeof(StatusCode)];
StatusCode sc;
};
Allocator alloc;
payload_type(StatusCode _sc, Allocator _alloc)
: alloc(static_cast<Allocator &&>(_alloc))
{
allocator_traits::construct(alloc, &sc, static_cast<StatusCode &&>(_sc));
}
payload_type(const payload_type &) = delete;
payload_type(payload_type &&) = delete;
~payload_type() { allocator_traits::destroy(alloc, &sc); }
};
using value_type = payload_type *;
using payload_allocator_traits = typename payload_type::allocator_traits::template rebind_traits<payload_type>;
using _base::string_ref;
constexpr indirecting_domain() noexcept
: _base(0xc44f7bdeb2cc50e9 ^ typename StatusCode::domain_type().id() /* unique-ish based on domain's unique id */)
{
}
indirecting_domain(const indirecting_domain &) = default;
indirecting_domain(indirecting_domain &&) = default; // NOLINT
indirecting_domain &operator=(const indirecting_domain &) = default;
indirecting_domain &operator=(indirecting_domain &&) = default; // NOLINT
~indirecting_domain() = default;
#if __cplusplus < 201402L && !defined(_MSC_VER)
static inline const indirecting_domain &get()
{
static indirecting_domain v;
return v;
}
#else
static inline constexpr const indirecting_domain &get();
#endif
virtual string_ref name() const noexcept override { return typename StatusCode::domain_type().name(); } // NOLINT
virtual payload_info_t payload_info() const noexcept override
{
return {sizeof(value_type), sizeof(status_code_domain *) + sizeof(value_type),
(alignof(value_type) > alignof(status_code_domain *)) ? alignof(value_type) : alignof(status_code_domain *)};
}
protected:
using _mycode = status_code<indirecting_domain>;
virtual bool _do_failure(const status_code<void> &code) const noexcept override // NOLINT
{
assert(code.domain() == *this);
const auto &c = static_cast<const _mycode &>(code); // NOLINT
return static_cast<status_code_domain &&>(typename StatusCode::domain_type())._do_failure(c.value()->sc);
}
virtual bool _do_equivalent(const status_code<void> &code1, const status_code<void> &code2) const noexcept override // NOLINT
{
assert(code1.domain() == *this);
const auto &c1 = static_cast<const _mycode &>(code1); // NOLINT
return static_cast<status_code_domain &&>(typename StatusCode::domain_type())._do_equivalent(c1.value()->sc, code2);
}
virtual generic_code _generic_code(const status_code<void> &code) const noexcept override // NOLINT
{
assert(code.domain() == *this);
const auto &c = static_cast<const _mycode &>(code); // NOLINT
return static_cast<status_code_domain &&>(typename StatusCode::domain_type())._generic_code(c.value()->sc);
}
virtual string_ref _do_message(const status_code<void> &code) const noexcept override // NOLINT
{
assert(code.domain() == *this);
const auto &c = static_cast<const _mycode &>(code); // NOLINT
return static_cast<status_code_domain &&>(typename StatusCode::domain_type())._do_message(c.value()->sc);
}
#if defined(_CPPUNWIND) || defined(__EXCEPTIONS) || 0L
SYSTEM_ERROR2_NORETURN virtual void _do_throw_exception(const status_code<void> &code) const override // NOLINT
{
assert(code.domain() == *this);
const auto &c = static_cast<const _mycode &>(code); // NOLINT
static_cast<status_code_domain &&>(typename StatusCode::domain_type())._do_throw_exception(c.value()->sc);
abort(); // suppress buggy GCC warning
}
#endif
virtual bool _do_erased_copy(status_code<void> &dst, const status_code<void> &src, payload_info_t dstinfo) const override // NOLINT
{
// Note that dst may not have its domain set
const auto srcinfo = payload_info();
assert(src.domain() == *this);
if(dstinfo.total_size < srcinfo.total_size)
{
return false;
}
auto &d = static_cast<_mycode &>(dst); // NOLINT
const auto &_s = static_cast<const _mycode &>(src); // NOLINT
const payload_type &sp = *_s.value();
typename payload_allocator_traits::template rebind_alloc<payload_type> payload_alloc(sp.alloc);
auto *dp = payload_allocator_traits::allocate(payload_alloc, 1);
#if defined(_CPPUNWIND) || defined(__EXCEPTIONS) || 0L
try
#endif
{
payload_allocator_traits::construct(payload_alloc, dp, sp.sc, sp.alloc);
new(SYSTEM_ERROR2_ADDRESS_OF(d)) _mycode(in_place, dp);
}
#if defined(_CPPUNWIND) || defined(__EXCEPTIONS) || 0L
catch(...)
{
payload_allocator_traits::deallocate(payload_alloc, dp, 1);
throw;
}
#endif
return true;
}
virtual void _do_erased_destroy(status_code<void> &code, payload_info_t /*unused*/) const noexcept override // NOLINT
{
assert(code.domain() == *this);
auto &c = static_cast<_mycode &>(code); // NOLINT
payload_type *p = c.value();
typename payload_allocator_traits::template rebind_alloc<payload_type> payload_alloc(p->alloc);
payload_allocator_traits::destroy(payload_alloc, p);
payload_allocator_traits::deallocate(payload_alloc, p, 1);
}
};
#if __cplusplus >= 201402L || defined(_MSC_VER)
template <class StatusCode, class Allocator> constexpr indirecting_domain<StatusCode, Allocator> _indirecting_domain{};
template <class StatusCode, class Allocator>
inline constexpr const indirecting_domain<StatusCode, Allocator> &indirecting_domain<StatusCode, Allocator>::get()
{
return _indirecting_domain<StatusCode, Allocator>;
}
#endif
} // namespace detail
/*! Make an erased status code which indirects to a dynamically allocated status code,
using the allocator `alloc`.
This is useful for shoehorning a rich status code with large value type into a small
erased status code like `system_code`, with which the status code generated by this
function is compatible. Note that this function can throw if the allocator throws.
*/
SYSTEM_ERROR2_TEMPLATE(class T, class Alloc = std::allocator<typename std::decay<T>::type>)
SYSTEM_ERROR2_TREQUIRES(SYSTEM_ERROR2_TPRED(is_status_code<T>::value)) //
inline status_code<detail::erased<typename std::add_pointer<typename std::decay<T>::type>::type>> make_nested_status_code(T &&v, Alloc alloc = {})
{
using status_code_type = typename std::decay<T>::type;
using domain_type = detail::indirecting_domain<status_code_type, typename std::decay<Alloc>::type>;
using payload_allocator_traits = typename domain_type::payload_allocator_traits;
typename payload_allocator_traits::template rebind_alloc<typename domain_type::payload_type> payload_alloc(alloc);
auto *p = payload_allocator_traits::allocate(payload_alloc, 1);
#if defined(_CPPUNWIND) || defined(__EXCEPTIONS) || 0L
try
#endif
{
payload_allocator_traits::construct(payload_alloc, p, static_cast<T &&>(v), static_cast<Alloc &&>(alloc));
return status_code<domain_type>(in_place, p);
}
#if defined(_CPPUNWIND) || defined(__EXCEPTIONS) || 0L
catch(...)
{
payload_allocator_traits::deallocate(payload_alloc, p, 1);
throw;
}
#endif
}
/*! If a status code refers to a `nested_status_code` which indirects to a status
code of type `StatusCode`, return a pointer to that `StatusCode`. Otherwise return null.
*/
SYSTEM_ERROR2_TEMPLATE(class StatusCode, class U)
SYSTEM_ERROR2_TREQUIRES(SYSTEM_ERROR2_TPRED(is_status_code<StatusCode>::value)) inline StatusCode *get_if(status_code<detail::erased<U>> *v) noexcept
{
if((0xc44f7bdeb2cc50e9 ^ typename StatusCode::domain_type().id()) != v->domain().id())
{
return nullptr;
}
union
{
U value;
StatusCode *ret;
};
value = v->value();
return ret;
}
//! \overload Const overload
SYSTEM_ERROR2_TEMPLATE(class StatusCode, class U)
SYSTEM_ERROR2_TREQUIRES(SYSTEM_ERROR2_TPRED(is_status_code<StatusCode>::value))
inline const StatusCode *get_if(const status_code<detail::erased<U>> *v) noexcept
{
if((0xc44f7bdeb2cc50e9 ^ typename StatusCode::domain_type().id()) != v->domain().id())
{
return nullptr;
}
union
{
U value;
const StatusCode *ret;
};
value = v->value();
return ret;
}
/*! If a status code refers to a `nested_status_code`, return the id of the erased
status code's domain. Otherwise return a meaningless number.
*/
template <class U> inline typename status_code_domain::unique_id_type get_id(const status_code<detail::erased<U>> &v) noexcept
{
return 0xc44f7bdeb2cc50e9 ^ v.domain().id();
}
SYSTEM_ERROR2_NAMESPACE_END
#endif
/* Try operation macros
(C) 2017-2021 Niall Douglas <http://www.nedproductions.biz/> (20 commits)
File Created: July 2017
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License in the accompanying file
Licence.txt or at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Distributed under the Boost Software License, Version 1.0.
(See accompanying file Licence.txt or copy at
http://www.boost.org/LICENSE_1_0.txt)
*/
#ifndef OUTCOME_TRY_HPP
#define OUTCOME_TRY_HPP
/* Try operation macros
(C) 2017-2024 Niall Douglas <http://www.nedproductions.biz/> (20 commits)
File Created: July 2017
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License in the accompanying file
Licence.txt or at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Distributed under the Boost Software License, Version 1.0.
(See accompanying file Licence.txt or copy at
http://www.boost.org/LICENSE_1_0.txt)
*/
#ifndef OUTCOME_TRY_H
#define OUTCOME_TRY_H
#if !defined(__clang__) && defined(__GNUC__) && __GNUC__ >= 8
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wparentheses"
#endif
#define OUTCOME_TRY_GLUE2(x, y) x##y
#define OUTCOME_TRY_GLUE(x, y) OUTCOME_TRY_GLUE2(x, y)
#define OUTCOME_TRY_UNIQUE_NAME OUTCOME_TRY_GLUE(_outcome_try_unique_name_temporary, __COUNTER__)
#define OUTCOME_TRY_RETURN_ARG_COUNT(_1_, _2_, _3_, _4_, _5_, _6_, _7_, _8_, count, ...) count
#define OUTCOME_TRY_EXPAND_ARGS(args) OUTCOME_TRY_RETURN_ARG_COUNT args
#define OUTCOME_TRY_COUNT_ARGS_MAX8(...) OUTCOME_TRY_EXPAND_ARGS((__VA_ARGS__, 8, 7, 6, 5, 4, 3, 2, 1, 0))
#define OUTCOME_TRY_OVERLOAD_MACRO2(name, count) name##count
#define OUTCOME_TRY_OVERLOAD_MACRO1(name, count) OUTCOME_TRY_OVERLOAD_MACRO2(name, count)
#define OUTCOME_TRY_OVERLOAD_MACRO(name, count) OUTCOME_TRY_OVERLOAD_MACRO1(name, count)
#define OUTCOME_TRY_OVERLOAD_GLUE(x, y) x y
#define OUTCOME_TRY_CALL_OVERLOAD(name, ...) OUTCOME_TRY_OVERLOAD_GLUE(OUTCOME_TRY_OVERLOAD_MACRO(name, OUTCOME_TRY_COUNT_ARGS_MAX8(__VA_ARGS__)), (__VA_ARGS__))
#define _OUTCOME_TRY_RETURN_ARG_COUNT(_1_, _2_, _3_, _4_, _5_, _6_, _7_, _8_, count, ...) count
#define _OUTCOME_TRY_EXPAND_ARGS(args) _OUTCOME_TRY_RETURN_ARG_COUNT args
#define _OUTCOME_TRY_COUNT_ARGS_MAX8(...) _OUTCOME_TRY_EXPAND_ARGS((__VA_ARGS__, 8, 7, 6, 5, 4, 3, 2, 1, 0))
#define _OUTCOME_TRY_OVERLOAD_MACRO2(name, count) name##count
#define _OUTCOME_TRY_OVERLOAD_MACRO1(name, count) _OUTCOME_TRY_OVERLOAD_MACRO2(name, count)
#define _OUTCOME_TRY_OVERLOAD_MACRO(name, count) _OUTCOME_TRY_OVERLOAD_MACRO1(name, count)
#define _OUTCOME_TRY_OVERLOAD_GLUE(x, y) x y
#define _OUTCOME_TRY_CALL_OVERLOAD(name, ...) _OUTCOME_TRY_OVERLOAD_GLUE(_OUTCOME_TRY_OVERLOAD_MACRO(name, _OUTCOME_TRY_COUNT_ARGS_MAX8(__VA_ARGS__)), (__VA_ARGS__))
#if !defined(OUTCOME_TRY_LIKELY_IF) && defined(__has_cpp_attribute)
#if __has_cpp_attribute(likely)
#define OUTCOME_TRY_LIKELY_IF(...) if(__VA_ARGS__) [[likely]]
#endif
#endif
#ifndef OUTCOME_TRY_LIKELY_IF
#if defined(__clang__) || defined(__GNUC__)
#define OUTCOME_TRY_LIKELY_IF(...) if(__builtin_expect(!!(__VA_ARGS__), 1))
#else
#define OUTCOME_TRY_LIKELY_IF(...) if(__VA_ARGS__)
#endif
#endif
#ifdef __cplusplus
#define OUTCOME_TRYV2_UNIQUE_STORAGE_AUTO(...) auto
#else
#define OUTCOME_TRYV2_UNIQUE_STORAGE_AUTO(...) __typeof__(__VA_ARGS__)
#endif
#define OUTCOME_TRYV2_UNIQUE_STORAGE_UNPACK(...) __VA_ARGS__
#define OUTCOME_TRYV2_UNIQUE_STORAGE_DEDUCE3(unique, ...) OUTCOME_TRYV2_UNIQUE_STORAGE_AUTO(__VA_ARGS__) unique = (__VA_ARGS__)
#define OUTCOME_TRYV2_UNIQUE_STORAGE_DEDUCE2(x) x
#define OUTCOME_TRYV2_UNIQUE_STORAGE_DEDUCE(unique, x, ...) OUTCOME_TRYV2_UNIQUE_STORAGE_DEDUCE2(OUTCOME_TRYV2_UNIQUE_STORAGE_DEDUCE3(unique, __VA_ARGS__))
#define OUTCOME_TRYV2_UNIQUE_STORAGE_SPECIFIED3(unique, x, y, ...) x unique = (__VA_ARGS__)
#define OUTCOME_TRYV2_UNIQUE_STORAGE_SPECIFIED2(x) x
#define OUTCOME_TRYV2_UNIQUE_STORAGE_SPECIFIED(unique, ...) OUTCOME_TRYV2_UNIQUE_STORAGE_SPECIFIED2(OUTCOME_TRYV2_UNIQUE_STORAGE_SPECIFIED3(unique, __VA_ARGS__))
#define OUTCOME_TRYV2_UNIQUE_STORAGE1(...) OUTCOME_TRYV2_UNIQUE_STORAGE_DEDUCE
#define OUTCOME_TRYV2_UNIQUE_STORAGE2(...) OUTCOME_TRYV2_UNIQUE_STORAGE_SPECIFIED
#define OUTCOME_TRYV2_UNIQUE_STORAGE(unique, spec, ...) _OUTCOME_TRY_CALL_OVERLOAD(OUTCOME_TRYV2_UNIQUE_STORAGE, OUTCOME_TRYV2_UNIQUE_STORAGE_UNPACK spec) (unique, OUTCOME_TRYV2_UNIQUE_STORAGE_UNPACK spec, __VA_ARGS__)
#define OUTCOME_TRY2_VAR_SECOND2(x, var) var
#define OUTCOME_TRY2_VAR_SECOND3(x, y, ...) x y
#define OUTCOME_TRY2_VAR(spec) _OUTCOME_TRY_CALL_OVERLOAD(OUTCOME_TRY2_VAR_SECOND, OUTCOME_TRYV2_UNIQUE_STORAGE_UNPACK spec, spec)
#if !defined(__clang__) && defined(__GNUC__) && __GNUC__ >= 8
#pragma GCC diagnostic pop
#endif
#endif
OUTCOME_V2_NAMESPACE_BEGIN
namespace detail
{
struct has_value_overload
{
};
struct as_failure_overload
{
};
struct assume_error_overload
{
};
struct error_overload
{
};
struct assume_value_overload
{
};
struct value_overload
{
};
// #ifdef __APPLE__
// OUTCOME_TEMPLATE(class T, class R = decltype(std::declval<T>()._xcode_workaround_as_failure()))
// #else
OUTCOME_TEMPLATE(class T, class R = decltype(std::declval<T>().as_failure()))
// #endif
OUTCOME_TREQUIRES(OUTCOME_TPRED(OUTCOME_V2_NAMESPACE::is_failure_type<R>))
constexpr inline bool has_as_failure(int /*unused */)
{
return true;
}
template <class T> constexpr inline bool has_as_failure(...)
{
return false;
}
OUTCOME_TEMPLATE(class T)
OUTCOME_TREQUIRES(OUTCOME_TEXPR(std::declval<T>().assume_error()))
constexpr inline bool has_assume_error(int /*unused */)
{
return true;
}
template <class T> constexpr inline bool has_assume_error(...)
{
return false;
}
OUTCOME_TEMPLATE(class T)
OUTCOME_TREQUIRES(OUTCOME_TEXPR(std::declval<T>().error()))
constexpr inline bool has_error(int /*unused */)
{
return true;
}
template <class T> constexpr inline bool has_error(...)
{
return false;
}
OUTCOME_TEMPLATE(class T)
OUTCOME_TREQUIRES(OUTCOME_TEXPR(std::declval<T>().assume_value()))
constexpr inline bool has_assume_value(int /*unused */)
{
return true;
}
template <class T> constexpr inline bool has_assume_value(...)
{
return false;
}
OUTCOME_TEMPLATE(class T)
OUTCOME_TREQUIRES(OUTCOME_TEXPR(std::declval<T>().value()))
constexpr inline bool has_value(int /*unused */)
{
return true;
}
template <class T> constexpr inline bool has_value(...)
{
return false;
}
} // namespace detail
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class T)
OUTCOME_TREQUIRES(OUTCOME_TEXPR(std::declval<T>().has_value()))
constexpr inline bool try_operation_has_value(T &&v, detail::has_value_overload = {})
{
return v.has_value();
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class T)
OUTCOME_TREQUIRES(OUTCOME_TPRED(detail::has_as_failure<T>(5)))
constexpr inline decltype(auto) try_operation_return_as(T &&v, detail::as_failure_overload = {})
{
return static_cast<T &&>(v).as_failure();
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class T)
OUTCOME_TREQUIRES(OUTCOME_TPRED(!detail::has_as_failure<T>(5) && detail::has_assume_error<T>(5)))
constexpr inline decltype(auto) try_operation_return_as(T &&v, detail::assume_error_overload = {})
{
return failure(static_cast<T &&>(v).assume_error());
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class T)
OUTCOME_TREQUIRES(OUTCOME_TPRED(!detail::has_as_failure<T>(5) && !detail::has_assume_error<T>(5) && detail::has_error<T>(5)))
constexpr inline decltype(auto) try_operation_return_as(T &&v, detail::error_overload = {})
{
return failure(static_cast<T &&>(v).error());
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class T)
OUTCOME_TREQUIRES(OUTCOME_TPRED(detail::has_assume_value<T>(5)))
constexpr inline decltype(auto) try_operation_extract_value(T &&v, detail::assume_value_overload = {})
{
return static_cast<T &&>(v).assume_value();
}
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
OUTCOME_TEMPLATE(class T)
OUTCOME_TREQUIRES(OUTCOME_TPRED(!detail::has_assume_value<T>(5) && detail::has_value<T>(5)))
constexpr inline decltype(auto) try_operation_extract_value(T &&v, detail::value_overload = {})
{
return static_cast<T &&>(v).value();
}
OUTCOME_V2_NAMESPACE_END
#if !defined(__clang__) && defined(__GNUC__) && __GNUC__ >= 8
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wparentheses"
#endif
// Use if(!expr); else as some compilers assume else clauses are always unlikely
#define OUTCOME_TRYV2_SUCCESS_LIKELY(unique, retstmt, spec, ...) OUTCOME_TRYV2_UNIQUE_STORAGE(unique, spec, __VA_ARGS__); OUTCOME_TRY_LIKELY_IF(::OUTCOME_V2_NAMESPACE::try_operation_has_value(unique)); else { /* works around ICE in GCC's coroutines implementation */ auto unique##_f(::OUTCOME_V2_NAMESPACE::try_operation_return_as(static_cast<decltype(unique) &&>(unique))); retstmt unique##_f; }
#define OUTCOME_TRYV3_FAILURE_LIKELY(unique, retstmt, spec, ...) OUTCOME_TRYV2_UNIQUE_STORAGE(unique, spec, __VA_ARGS__); OUTCOME_TRY_LIKELY_IF(!OUTCOME_V2_NAMESPACE::try_operation_has_value(unique)) { /* works around ICE in GCC's coroutines implementation */ auto unique##_f(::OUTCOME_V2_NAMESPACE::try_operation_return_as(static_cast<decltype(unique) &&>(unique))); retstmt unique##_f; }
#define OUTCOME_TRY2_SUCCESS_LIKELY(unique, retstmt, var, ...) OUTCOME_TRYV2_SUCCESS_LIKELY(unique, retstmt, var, __VA_ARGS__); OUTCOME_TRY2_VAR(var) = ::OUTCOME_V2_NAMESPACE::try_operation_extract_value(static_cast<decltype(unique) &&>(unique))
#define OUTCOME_TRY2_FAILURE_LIKELY(unique, retstmt, var, ...) OUTCOME_TRYV3_FAILURE_LIKELY(unique, retstmt, var, __VA_ARGS__); OUTCOME_TRY2_VAR(var) = ::OUTCOME_V2_NAMESPACE::try_operation_extract_value(static_cast<decltype(unique) &&>(unique))
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
#define OUTCOME_TRYV(...) OUTCOME_TRYV2_SUCCESS_LIKELY(OUTCOME_TRY_UNIQUE_NAME, return, deduce, __VA_ARGS__)
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
#define OUTCOME_TRYV_FAILURE_LIKELY(...) OUTCOME_TRYV3_FAILURE_LIKELY(OUTCOME_TRY_UNIQUE_NAME, return, deduce, __VA_ARGS__)
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
#define OUTCOME_CO_TRYV(...) OUTCOME_TRYV2_SUCCESS_LIKELY(OUTCOME_TRY_UNIQUE_NAME, co_return, deduce, __VA_ARGS__)
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
#define OUTCOME_CO_TRYV_FAILURE_LIKELY(...) OUTCOME_TRYV3_FAILURE_LIKELY(OUTCOME_TRY_UNIQUE_NAME, co_return, deduce, __VA_ARGS__)
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
#define OUTCOME_TRYV2(s, ...) OUTCOME_TRYV2_SUCCESS_LIKELY(OUTCOME_TRY_UNIQUE_NAME, return, (s, ), __VA_ARGS__)
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
#define OUTCOME_TRYV2_FAILURE_LIKELY(s, ...) OUTCOME_TRYV3_FAILURE_LIKELY(OUTCOME_TRY_UNIQUE_NAME, return, (s, ), __VA_ARGS__)
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
#define OUTCOME_CO_TRYV2(s, ...) OUTCOME_TRYV2_SUCCESS_LIKELY(OUTCOME_TRY_UNIQUE_NAME, co_return, (s, ), __VA_ARGS__)
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
#define OUTCOME_CO_TRYV2_FAILURE_LIKELY(s, ...) OUTCOME_TRYV3_FAILURE_LIKELY(OUTCOME_TRY_UNIQUE_NAME, co_return, s(, ), __VA_ARGS__)
#if defined(__GNUC__) || defined(__clang__)
#define OUTCOME_TRYX2(unique, retstmt, ...) ({ OUTCOME_TRYV2_SUCCESS_LIKELY(unique, retstmt, deduce, __VA_ARGS__); ::OUTCOME_V2_NAMESPACE::try_operation_extract_value(static_cast<decltype(unique) &&>(unique)); })
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
#define OUTCOME_TRYX(...) OUTCOME_TRYX2(OUTCOME_TRY_UNIQUE_NAME, return, __VA_ARGS__)
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
#define OUTCOME_CO_TRYX(...) OUTCOME_TRYX2(OUTCOME_TRY_UNIQUE_NAME, co_return, __VA_ARGS__)
#endif
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
#define OUTCOME_TRYA(v, ...) OUTCOME_TRY2_SUCCESS_LIKELY(OUTCOME_TRY_UNIQUE_NAME, return, v, __VA_ARGS__)
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
#define OUTCOME_TRYA_FAILURE_LIKELY(v, ...) OUTCOME_TRY2_FAILURE_LIKELY(OUTCOME_TRY_UNIQUE_NAME, return, v, __VA_ARGS__)
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
#define OUTCOME_CO_TRYA(v, ...) OUTCOME_TRY2_SUCCESS_LIKELY(OUTCOME_TRY_UNIQUE_NAME, co_return, v, __VA_ARGS__)
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
#define OUTCOME_CO_TRYA_FAILURE_LIKELY(v, ...) OUTCOME_TRY2_FAILURE_LIKELY(OUTCOME_TRY_UNIQUE_NAME, co_return, v, __VA_ARGS__)
#define OUTCOME_TRY_INVOKE_TRY8(a, b, c, d, e, f, g, h) OUTCOME_TRYA(a, b, c, d, e, f, g, h)
#define OUTCOME_TRY_INVOKE_TRY7(a, b, c, d, e, f, g) OUTCOME_TRYA(a, b, c, d, e, f, g)
#define OUTCOME_TRY_INVOKE_TRY6(a, b, c, d, e, f) OUTCOME_TRYA(a, b, c, d, e, f)
#define OUTCOME_TRY_INVOKE_TRY5(a, b, c, d, e) OUTCOME_TRYA(a, b, c, d, e)
#define OUTCOME_TRY_INVOKE_TRY4(a, b, c, d) OUTCOME_TRYA(a, b, c, d)
#define OUTCOME_TRY_INVOKE_TRY3(a, b, c) OUTCOME_TRYA(a, b, c)
#define OUTCOME_TRY_INVOKE_TRY2(a, b) OUTCOME_TRYA(a, b)
#define OUTCOME_TRY_INVOKE_TRY1(a) OUTCOME_TRYV(a)
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
#define OUTCOME_TRY(...) OUTCOME_TRY_CALL_OVERLOAD(OUTCOME_TRY_INVOKE_TRY, __VA_ARGS__)
#define OUTCOME_TRY_FAILURE_LIKELY_INVOKE_TRY8(a, b, c, d, e, f, g, h) OUTCOME_TRYA_FAILURE_LIKELY(a, b, c, d, e, f, g, h)
#define OUTCOME_TRY_FAILURE_LIKELY_INVOKE_TRY7(a, b, c, d, e, f, g) OUTCOME_TRYA_FAILURE_LIKELY(a, b, c, d, e, f, g)
#define OUTCOME_TRY_FAILURE_LIKELY_INVOKE_TRY6(a, b, c, d, e, f) OUTCOME_TRYA_FAILURE_LIKELY(a, b, c, d, e, f)
#define OUTCOME_TRY_FAILURE_LIKELY_INVOKE_TRY5(a, b, c, d, e) OUTCOME_TRYA_FAILURE_LIKELY(a, b, c, d, e)
#define OUTCOME_TRY_FAILURE_LIKELY_INVOKE_TRY4(a, b, c, d) OUTCOME_TRYA_FAILURE_LIKELY(a, b, c, d)
#define OUTCOME_TRY_FAILURE_LIKELY_INVOKE_TRY3(a, b, c) OUTCOME_TRYA_FAILURE_LIKELY(a, b, c)
#define OUTCOME_TRY_FAILURE_LIKELY_INVOKE_TRY2(a, b) OUTCOME_TRYA_FAILURE_LIKELY(a, b)
#define OUTCOME_TRY_FAILURE_LIKELY_INVOKE_TRY1(a) OUTCOME_TRYV_FAILURE_LIKELY(a)
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
#define OUTCOME_TRY_FAILURE_LIKELY(...) OUTCOME_TRY_CALL_OVERLOAD(OUTCOME_TRY_FAILURE_LIKELY_INVOKE_TRY, __VA_ARGS__)
#define OUTCOME_CO_TRY_INVOKE_TRY8(a, b, c, d, e, f, g, h) OUTCOME_CO_TRYA(a, b, c, d, e, f, g, h)
#define OUTCOME_CO_TRY_INVOKE_TRY7(a, b, c, d, e, f, g) OUTCOME_CO_TRYA(a, b, c, d, e, f, g)
#define OUTCOME_CO_TRY_INVOKE_TRY6(a, b, c, d, e, f) OUTCOME_CO_TRYA(a, b, c, d, e, f)
#define OUTCOME_CO_TRY_INVOKE_TRY5(a, b, c, d, e) OUTCOME_CO_TRYA(a, b, c, d, e)
#define OUTCOME_CO_TRY_INVOKE_TRY4(a, b, c, d) OUTCOME_CO_TRYA(a, b, c, d)
#define OUTCOME_CO_TRY_INVOKE_TRY3(a, b, c) OUTCOME_CO_TRYA(a, b, c)
#define OUTCOME_CO_TRY_INVOKE_TRY2(a, b) OUTCOME_CO_TRYA(a, b)
#define OUTCOME_CO_TRY_INVOKE_TRY1(a) OUTCOME_CO_TRYV(a)
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
#define OUTCOME_CO_TRY(...) OUTCOME_TRY_CALL_OVERLOAD(OUTCOME_CO_TRY_INVOKE_TRY, __VA_ARGS__)
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
#define OUTCOME_TRY(...) OUTCOME_TRY_CALL_OVERLOAD(OUTCOME_TRY_INVOKE_TRY, __VA_ARGS__)
#define OUTCOME_CO_TRY_FAILURE_LIKELY_INVOKE_TRY8(a, b, c, d, e, f, g, h) OUTCOME_CO_TRYA_FAILURE_LIKELY(a, b, c, d, e, f, g, h)
#define OUTCOME_CO_TRY_FAILURE_LIKELY_INVOKE_TRY7(a, b, c, d, e, f, g) OUTCOME_CO_TRYA_FAILURE_LIKELY(a, b, c, d, e, f, g)
#define OUTCOME_CO_TRY_FAILURE_LIKELY_INVOKE_TRY6(a, b, c, d, e, f) OUTCOME_CO_TRYA_FAILURE_LIKELY(a, b, c, d, e, f)
#define OUTCOME_CO_TRY_FAILURE_LIKELY_INVOKE_TRY5(a, b, c, d, e) OUTCOME_CO_TRYA_FAILURE_LIKELY(a, b, c, d, e)
#define OUTCOME_CO_TRY_FAILURE_LIKELY_INVOKE_TRY4(a, b, c, d) OUTCOME_CO_TRYA_FAILURE_LIKELY(a, b, c, d)
#define OUTCOME_CO_TRY_FAILURE_LIKELY_INVOKE_TRY3(a, b, c) OUTCOME_CO_TRYA_FAILURE_LIKELY(a, b, c)
#define OUTCOME_CO_TRY_FAILURE_LIKELY_INVOKE_TRY2(a, b) OUTCOME_CO_TRYA_FAILURE_LIKELY(a, b)
#define OUTCOME_CO_TRY_FAILURE_LIKELY_INVOKE_TRY1(a) OUTCOME_CO_TRYV_FAILURE_LIKELY(a)
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
#define OUTCOME_CO_TRY_FAILURE_LIKELY(...) OUTCOME_TRY_CALL_OVERLOAD(OUTCOME_CO_TRY_FAILURE_LIKELY_INVOKE_TRY, __VA_ARGS__)
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
#define OUTCOME21_TRYA(v, ...) OUTCOME_TRY2_SUCCESS_LIKELY(OUTCOME_TRY_UNIQUE_NAME, return, deduce, auto &&v, __VA_ARGS__)
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
#define OUTCOME21_TRYA_FAILURE_LIKELY(v, ...) OUTCOME_TRY2_FAILURE_LIKELY(OUTCOME_TRY_UNIQUE_NAME, return, deduce, auto &&v, __VA_ARGS__)
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
#define OUTCOME21_CO_TRYA(v, ...) OUTCOME_TRY2_FAILURE_LIKELY(OUTCOME_TRY_UNIQUE_NAME, co_return, deduce, auto &&v, __VA_ARGS__)
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
#define OUTCOME21_CO_TRYA_FAILURE_LIKELY(v, ...) OUTCOME_TRY2_FAILURE_LIKELY(OUTCOME_TRY_UNIQUE_NAME, co_retrn, deduce, auto &&v, __VA_ARGS__)
#define OUTCOME21_TRY_INVOKE_TRY8(a, b, c, d, e, f, g, h) OUTCOME21_TRYA(a, b, c, d, e, f, g, h)
#define OUTCOME21_TRY_INVOKE_TRY7(a, b, c, d, e, f, g) OUTCOME21_TRYA(a, b, c, d, e, f, g)
#define OUTCOME21_TRY_INVOKE_TRY6(a, b, c, d, e, f) OUTCOME21_TRYA(a, b, c, d, e, f)
#define OUTCOME21_TRY_INVOKE_TRY5(a, b, c, d, e) OUTCOME21_TRYA(a, b, c, d, e)
#define OUTCOME21_TRY_INVOKE_TRY4(a, b, c, d) OUTCOME21_TRYA(a, b, c, d)
#define OUTCOME21_TRY_INVOKE_TRY3(a, b, c) OUTCOME21_TRYA(a, b, c)
#define OUTCOME21_TRY_INVOKE_TRY2(a, b) OUTCOME21_TRYA(a, b)
#define OUTCOME21_TRY_INVOKE_TRY1(a) OUTCOME_TRYV(a)
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
#define OUTCOME21_TRY(...) OUTCOME_TRY_CALL_OVERLOAD(OUTCOME21_TRY_INVOKE_TRY, __VA_ARGS__)
#define OUTCOME21_TRY_FAILURE_LIKELY_INVOKE_TRY8(a, b, c, d, e, f, g, h) OUTCOME21_TRYA_FAILURE_LIKELY(a, b, c, d, e, f, g, h)
#define OUTCOME21_TRY_FAILURE_LIKELY_INVOKE_TRY7(a, b, c, d, e, f, g) OUTCOME21_TRYA_FAILURE_LIKELY(a, b, c, d, e, f, g)
#define OUTCOME21_TRY_FAILURE_LIKELY_INVOKE_TRY6(a, b, c, d, e, f) OUTCOME21_TRYA_FAILURE_LIKELY(a, b, c, d, e, f)
#define OUTCOME21_TRY_FAILURE_LIKELY_INVOKE_TRY5(a, b, c, d, e) OUTCOME21_TRYA_FAILURE_LIKELY(a, b, c, d, e)
#define OUTCOME21_TRY_FAILURE_LIKELY_INVOKE_TRY4(a, b, c, d) OUTCOME21_TRYA_FAILURE_LIKELY(a, b, c, d)
#define OUTCOME21_TRY_FAILURE_LIKELY_INVOKE_TRY3(a, b, c) OUTCOME21_TRYA_FAILURE_LIKELY(a, b, c)
#define OUTCOME21_TRY_FAILURE_LIKELY_INVOKE_TRY2(a, b) OUTCOME21_TRYA_FAILURE_LIKELY(a, b)
#define OUTCOME21_TRY_FAILURE_LIKELY_INVOKE_TRY1(a) OUTCOME_TRYV_FAILURE_LIKELY(a)
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
#define OUTCOME21_TRY_FAILURE_LIKELY(...) OUTCOME_TRY_CALL_OVERLOAD(OUTCOME21_TRY_FAILURE_LIKELY_INVOKE_TRY, __VA_ARGS__)
#define OUTCOME21_CO_TRY_INVOKE_TRY8(a, b, c, d, e, f, g, h) OUTCOME21_CO_TRYA(a, b, c, d, e, f, g, h)
#define OUTCOME21_CO_TRY_INVOKE_TRY7(a, b, c, d, e, f, g) OUTCOME21_CO_TRYA(a, b, c, d, e, f, g)
#define OUTCOME21_CO_TRY_INVOKE_TRY6(a, b, c, d, e, f) OUTCOME21_CO_TRYA(a, b, c, d, e, f)
#define OUTCOME21_CO_TRY_INVOKE_TRY5(a, b, c, d, e) OUTCOME21_CO_TRYA(a, b, c, d, e)
#define OUTCOME21_CO_TRY_INVOKE_TRY4(a, b, c, d) OUTCOME21_CO_TRYA(a, b, c, d)
#define OUTCOME21_CO_TRY_INVOKE_TRY3(a, b, c) OUTCOME21_CO_TRYA(a, b, c)
#define OUTCOME21_CO_TRY_INVOKE_TRY2(a, b) OUTCOME21_CO_TRYA(a, b)
#define OUTCOME21_CO_TRY_INVOKE_TRY1(a) OUTCOME_CO_TRYV(a)
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
#define OUTCOME21_CO_TRY(...) OUTCOME_TRY_CALL_OVERLOAD(OUTCOME21_CO_TRY_INVOKE_TRY, __VA_ARGS__)
#define OUTCOME21_CO_TRY_FAILURE_LIKELY_INVOKE_TRY8(a, b, c, d, e, f, g, h) OUTCOME21_CO_TRYA_FAILURE_LIKELY(a, b, c, d, e, f, g, h)
#define OUTCOME21_CO_TRY_FAILURE_LIKELY_INVOKE_TRY7(a, b, c, d, e, f, g) OUTCOME21_CO_TRYA_FAILURE_LIKELY(a, b, c, d, e, f, g)
#define OUTCOME21_CO_TRY_FAILURE_LIKELY_INVOKE_TRY6(a, b, c, d, e, f) OUTCOME21_CO_TRYA_FAILURE_LIKELY(a, b, c, d, e, f)
#define OUTCOME21_CO_TRY_FAILURE_LIKELY_INVOKE_TRY5(a, b, c, d, e) OUTCOME21_CO_TRYA_FAILURE_LIKELY(a, b, c, d, e)
#define OUTCOME21_CO_TRY_FAILURE_LIKELY_INVOKE_TRY4(a, b, c, d) OUTCOME21_CO_TRYA_FAILURE_LIKELY(a, b, c, d)
#define OUTCOME21_CO_TRY_FAILURE_LIKELY_INVOKE_TRY3(a, b, c) OUTCOME21_CO_TRYA_FAILURE_LIKELY(a, b, c)
#define OUTCOME21_CO_TRY_FAILURE_LIKELY_INVOKE_TRY2(a, b) OUTCOME21_CO_TRYA_FAILURE_LIKELY(a, b)
#define OUTCOME21_CO_TRY_FAILURE_LIKELY_INVOKE_TRY1(a) OUTCOME_CO_TRYV_FAILURE_LIKELY(a)
/*! AWAITING HUGO JSON CONVERSION TOOL
SIGNATURE NOT RECOGNISED
*/
#define OUTCOME21_CO_TRY_FAILURE_LIKELY(...) OUTCOME_TRY_CALL_OVERLOAD(OUTCOME21_CO_TRY_FAILURE_LIKELY_INVOKE_TRY, __VA_ARGS__)
#if !defined(__clang__) && defined(__GNUC__) && __GNUC__ >= 8
#pragma GCC diagnostic pop
#endif
#endif
|
0 | repos/outcome | repos/outcome/benchmark/timing.h | /* Benchmark test runner
(C) 2017-2019 Niall Douglas <http://www.nedproductions.biz/> (3 commits)
File Created: Mar 2017
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License in the accompanying file
Licence.txt or at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Distributed under the Boost Software License, Version 1.0.
(See accompanying file Licence.txt or copy at
http://www.boost.org/LICENSE_1_0.txt)
*/
#ifndef TIMING_H
#define TIMING_H
#include <stdint.h>
#ifdef _WIN32
#define WIN32_LEAN_AND_MEAN
#include <intrin.h>
#include <windows.h>
typedef unsigned __int64 usCount;
inline usCount GetUsCount()
{
static LARGE_INTEGER ticksPerSec;
static double scalefactor;
LARGE_INTEGER val;
if(!scalefactor)
{
if(QueryPerformanceFrequency(&ticksPerSec))
scalefactor = ticksPerSec.QuadPart / 1000000000000.0;
else
scalefactor = 1;
}
if(!QueryPerformanceCounter(&val))
return (usCount) GetTickCount() * 1000000000;
return (usCount)(val.QuadPart / scalefactor);
}
#else
#include <sys/time.h>
#include <time.h>
typedef unsigned long long usCount;
inline usCount GetUsCount()
{
#ifdef CLOCK_MONOTONIC
struct timespec ts;
clock_gettime(CLOCK_MONOTONIC, &ts);
return ((usCount) ts.tv_sec * 1000000000000LL) + ts.tv_nsec * 1000LL;
#else
struct timeval tv;
gettimeofday(&tv, 0);
return ((usCount) tv.tv_sec * 1000000000000LL) + tv.tv_usec * 1000000LL;
#endif
}
#endif
inline uint64_t ticksclock()
{
#ifdef _MSC_VER
auto rdtscp = [] {
unsigned x;
return (uint64_t) __rdtscp(&x);
};
#else
#if defined(__x86_64__)
auto rdtscp = [] {
unsigned lo, hi, aux;
asm volatile("rdtscp" : "=a"(lo), "=d"(hi), "=c"(aux));
return (uint64_t) lo | ((uint64_t) hi << 32);
};
#elif defined(__i386__)
auto rdtscp = [] {
unsigned lo, hi, aux;
asm volatile("rdtscp" : "=a"(lo), "=d"(hi), "=c"(aux));
return (uint64_t) lo | ((uint64_t) hi << 32);
};
#endif
#if __ARM_ARCH >= 6
auto rdtscp = [] {
unsigned count;
asm volatile("MRC p15, 0, %0, c9, c13, 0" : "=r"(count));
return (uint64_t) count * 64;
};
#endif
#endif
return rdtscp();
}
#if defined(__cplusplus) && 0
#include <chrono>
#include <iostream>
inline uint64_t nanoclock()
{
static double ticks_per_sec;
static uint64_t offset;
if(ticks_per_sec == 0)
{
auto end = std::chrono::high_resolution_clock::now(), begin = std::chrono::high_resolution_clock::now();
uint64_t _begin = ticksclock(), _end;
do
{
end = std::chrono::high_resolution_clock::now();
} while(std::chrono::duration_cast<std::chrono::seconds>(end - begin).count() < 1);
_end = ticksclock();
double x = (double) (_end - _begin);
ticks_per_sec = x / 1000000000.0;
volatile uint64_t a = ticksclock();
volatile uint64_t b = ticksclock();
offset = b - a;
#if 1
std::cout << "There are " << ticks_per_sec << " TSCs in 1 nanosecond and it takes " << offset << " ticks per nanoclock()." << std::endl;
#endif
}
return (uint64_t)((ticksclock() - offset) / ticks_per_sec);
}
#endif
#endif
|
0 | repos/outcome | repos/outcome/benchmark/runner.cpp | /* Benchmark test runner
(C) 2017-2020 Niall Douglas <http://www.nedproductions.biz/> (7 commits)
File Created: Mar 2017
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License in the accompanying file
Licence.txt or at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Distributed under the Boost Software License, Version 1.0.
(See accompanying file Licence.txt or copy at
http://www.boost.org/LICENSE_1_0.txt)
*/
#include "timing.h"
#include <stdio.h>
#include "function.h"
#if defined(_CPPUNWIND) || defined(__EXCEPTIONS)
#include <exception>
#endif
#define ITERATIONS 100000
extern volatile int counter;
volatile int counter, forcereturn;
int main(void)
{
#ifdef _WIN32
SetThreadAffinityMask(GetCurrentThread(), 2ULL);
#endif
{
usCount start=GetUsCount();
while(GetUsCount()-start<1*1000000000000LL);
}
auto start = ticksclock();
for(int n=0; n<ITERATIONS; n++)
{
#if !defined(_CPPUNWIND) && !defined(__EXCEPTIONS)
forcereturn += !FUNCTION(n);
#else
try
{
forcereturn += !FUNCTION(n);
}
catch(const std::exception &)
{
}
#endif
}
auto end = ticksclock();
double ticks=end-start;
ticks/=ITERATIONS;
printf("%f\n", ticks);
return 0;
}
|
0 | repos/outcome | repos/outcome/benchmark/benchmark.py | #!/usr/bin/python
# Benchmark Outcome against other stuff
# (C) 2017 - 2020 Niall Douglas http://www.nedproductions.biz/
# Created: Mar 2017
from __future__ import print_function
import sys, os, subprocess, shlex, time
# Some Python 3 compatibility shims
if sys.version_info.major < 3:
clock = time.clock
else:
clock = time.perf_counter
class ErrorHandlingSystem(object):
"Base class for an error handling system"
def __init__(self):
pass
def preamble(self, idx):
"Preamble written out before each source file"
return ''
def function_cont(self, name):
"Function signature"
return 'extern int %s(int par)' % name
def function_final(self):
"Function implementation for final function zero"
return r'''{ return par ? -1 : 0; }'''
def generate_sources(self, no):
"Generate no source files calling into one another"
for n in range(0, no):
with open("source%04d.cpp" % n, 'wt') as oh:
oh.write(self.preamble(n))
oh.write(r'''extern volatile int counter;
struct RAII { RAII() { ++counter; } ~RAII() { --counter; } };
''')
if n:
oh.write(self.function_cont("funct%04d" % (n-1)) + ';\n')
oh.write(self.function_cont("funct%04d" % n))
if n:
oh.write(r'''
{
RAII raii;
return ''' + ("funct%04d" % (n-1)) + r'''(par + 1);
}
''')
else:
oh.write(self.function_final())
with open("function.h", 'wt') as oh:
oh.write(self.preamble(no-1))
oh.write(self.function_cont("funct%04d" % (no-1)) + ';\n')
oh.write("#define FUNCTION funct%04d\n" % (no-1))
oh.write("#define NESTING %d\n" % (no))
class ExceptionThrow(ErrorHandlingSystem):
def preamble(self, idx):
return '#include <exception>\n' if idx == 0 else ''
def function_final(self):
return r'''{ throw std::exception(); }'''
class ResultErrorValue(ErrorHandlingSystem):
def preamble(self, idx):
return '#include "../include/outcome/result.hpp"\n'
def function_cont(self, name):
return 'extern OUTCOME_V2_NAMESPACE::result<int> %s(int par)' % name
def function_final(self):
return r'''{ return par; }'''
class ResultErrorError(ResultErrorValue):
def function_final(self):
return r'''{ return std::error_code(5, std::generic_category()); }'''
class ResultExceptionValue(ResultErrorValue):
def function_cont(self, name):
return 'extern OUTCOME_V2_NAMESPACE::result<int, std::exception_ptr> %s(int par)' % name
def function_final(self):
return r'''{ return par; }'''
class ResultExceptionError(ResultExceptionValue):
def function_cont(self, name):
return 'extern OUTCOME_V2_NAMESPACE::result<int, std::exception_ptr> %s(int par)' % name
def function_final(self):
return r'''{ return std::make_exception_ptr(std::exception()); }'''
class ResultExperimentalValue(ErrorHandlingSystem):
def preamble(self, idx):
return '#include "../include/outcome/experimental/status_result.hpp"\n'
def function_cont(self, name):
return 'extern OUTCOME_V2_NAMESPACE::experimental::status_result<int> %s(int par)' % name
def function_final(self):
return r'''{ return par; }'''
class ResultExperimentalError(ResultExperimentalValue):
def function_final(self):
return r'''{ return OUTCOME_V2_NAMESPACE::experimental::errc::io_error; }'''
matrix = [
('integer-returns', ErrorHandlingSystem),
('exception-throw', ExceptionThrow),
('result-error-value', ResultErrorValue),
('result-error-error', ResultErrorError),
('result-excpt-value', ResultExceptionValue),
('result-excpt-error', ResultExceptionError),
('result-exper-value', ResultExperimentalValue),
('result-exper-error', ResultExperimentalError),
]
if sys.platform == 'win32':
compilers = [
('msvc1924-noexcept', r'cl /nologo /std:c++17 /O2 /Gy /MD /Fe%s /I..\\.. /I..\\..\\quickcpplib\\include'),
('msvc1924', r'cl /nologo /std:c++17 /O2 /Gy /MD /EHsc /Fe%s /I..\\.. /I..\\..\\quickcpplib\\include'),
('msvc1924-ltcg', r'cl /nologo /std:c++17 /O2 /Gy /GL /MD /EHsc /Fe%s /I..\\.. /I..\\..\\quickcpplib\\include'),
]
elif sys.platform == 'darwin':
compilers = [
('xcode82', r'clang++ -std=c++14 -O3 -g -o %s -I../.. -I../../quickcpplib/include'),
]
else:
compilers = [
('gcc92-noexcept', r'g++-9 -std=c++17 -fno-exceptions -O3 -g -o %s -I../.. -I../../quickcpplib/include'),
('gcc92', r'g++-9 -std=c++17 -O3 -g -o %s -I../.. -I../../quickcpplib/include'),
('gcc92-lto', r'g++-9 -std=c++17 -O3 -g -flto -o %s -I../.. -I../../quickcpplib/include'),
('clang90', r'clang++-9 -std=c++17 -O3 -g -o %s -I../.. -I../../quickcpplib/include'),
('clang90-lto', r'clang++-9 -std=c++17 -O3 -g -flto -o %s -I../.. -I../../quickcpplib/include'),
]
SOURCES=10
if len(sys.argv)>1:
SOURCES = int(sys.argv[1])
with open('results-'+sys.platform+'.csv', 'wt') as resultsh:
resultsh.write('"Compiler"')
for m in matrix:
resultsh.write(',"'+m[0]+'"')
resultsh.write('\n')
for compiler in compilers:
resultsh.write('"'+compiler[0]+'"')
for m in matrix:
if 'noexcept' in compiler[0] and m[0] == 'exception-throw':
resultsh.write(',')
continue
instance = m[1]()
try:
exename = m[0]+'_'+compiler[0]
print("\nGenerating sources for", exename, "...")
instance.generate_sources(SOURCES)
args = shlex.split(compiler[1] % exename)
args.append("runner.cpp")
for n in range(0, SOURCES):
args.append("source%04d.cpp" % n)
if sys.platform == 'win32':
args.append("/link")
args.append("/OPT:REF,ICF")
#print(' '.join(args))
try:
print("Compiling", exename, "...")
compile_begin = clock()
print(subprocess.check_output(args))
compile_end = clock()
print("Compile took", compile_end-compile_begin, "secs. Running executable ...")
except subprocess.CalledProcessError as e:
print(e.output)
raise
finally:
for n in range(0, SOURCES):
if os.path.exists("source%04d.cpp" % n):
os.remove("source%04d.cpp" % n)
if os.path.exists("source%04d.obj" % n):
os.remove("source%04d.obj" % n)
os.remove("function.h")
#if os.path.exists(exename):
# os.remove(exename)
#if os.path.exists(exename+'.exe'):
# os.remove(exename+'.exe')
if os.path.exists("runner.obj"):
os.remove("runner.obj")
if sys.platform != 'win32':
exename = './' + exename
result = subprocess.check_output([exename]).decode('utf-8')
resultsh.write(',' + result.rstrip())
resultsh.flush()
resultsh.write('\n')
|
0 | repos/outcome | repos/outcome/conan/conanfile.py | from conans import ConanFile, tools
class OutcomeConan(ConanFile):
name = "Outcome"
version = "master"
license = "Apache-2.0"
description = "Provides very lightweight outcome<T> and result<T>"
repo_url = "https://github.com/ned14/outcome"
build_policy = "always"
def source(self):
file_url = "https://raw.githubusercontent.com/ned14/outcome/master/"
tools.download(file_url + "single-header/outcome.hpp", filename="outcome.hpp")
tools.download(file_url + "Licence.txt", filename="LICENCE")
def package(self):
self.copy("outcome.hpp", dst="include")
self.copy("LICENCE", dst="licenses")
def package_id(self):
self.info.header_only()
|
0 | repos/outcome/conan | repos/outcome/conan/test_package/example.cpp | #include <outcome.hpp>
namespace outcome = OUTCOME_V2_NAMESPACE;
outcome::result<int> test2(int x)
{
return x;
}
outcome::result<int> test1(int x)
{
OUTCOME_TRY(test2(x));
return 0;
}
int main(void)
{
return test1(5).value();
}
|
0 | repos/outcome/conan | repos/outcome/conan/test_package/CMakeLists.txt | project(OutcomePackageTest CXX)
cmake_minimum_required(VERSION 3.1 FATAL_ERROR)
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_EXTENSIONS OFF)
include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup(TARGETS)
add_executable(example example.cpp)
target_link_libraries(example CONAN_PKG::Outcome)
|
0 | repos/outcome/conan | repos/outcome/conan/test_package/conanfile.py | from conans import ConanFile, CMake
import os
class OutcomeTestConan(ConanFile):
settings = "os", "compiler", "build_type", "arch"
generators = "cmake"
# def requirements(self):
# if self.settings.compiler == "clang" and float(str(self.settings.compiler.version)) < 4.0:
# raise Exception("clang >= 4.0 is required, %s is being used" % self.settings.compiler.version)
# if self.settings.compiler == "gcc" and float(str(self.settings.compiler.version)) < 5.0:
# raise Exception("GCC >= 5.0 is required, %s is being used" % self.settings.compiler.version)
# if self.settings.compiler == "Visual Studio" and float(str(self.settings.compiler.version)) < 15:
# raise Exception("Visual Studio >= 15 is required, %s is being used" % self.settings.compiler.version)
def build(self):
cmake = CMake(self)
# Current dir is "test_package/build/<build_id>" and CMakeLists.txt is in "test_package"
cmake.configure(source_dir=self.conanfile_directory, build_dir="./")
cmake.build()
def test(self):
os.chdir("bin")
self.run(".%sexample" % os.sep)
|
0 | repos/outcome | repos/outcome/abi-compliance/check-abi.sh | #!/bin/sh
rm -rf abi_dumps/Outcome/test-gcc7-cxx14/binary_only.dump
rm -rf abi_dumps/Outcome/test-gcc9-cxx17/binary_only.dump
sh ./dump-abi.sh test || exit 1
cd abi_dumps/Outcome
tar xf $1.tar.bz2
cd ../..
RETCODE=0
abi-compliance-checker -l Outcome -old abi_dumps/Outcome/$1-gcc7-cxx14/binary_only.dump -new abi_dumps/Outcome/test-gcc7-cxx14/binary_only.dump || RETCODE=1
abi-compliance-checker -l Outcome -old abi_dumps/Outcome/$1-gcc9-cxx17/binary_only.dump -new abi_dumps/Outcome/test-gcc9-cxx17/binary_only.dump || RETCODE=1
exit $RETCODE
|
0 | repos/outcome | repos/outcome/abi-compliance/Readme.md | # Notes on the API and ABI stability checking
Outcome is a header only library with a very simple data type layout designed
for strong ABI. Therefore, your shared library with functions which consume
and return Outcomes ought to be perfectly binary stable in the pure sense of
that Outcome's core `result<T, E>` and `outcome<T, E, P>` object layout will
not change, no matter what changes occur in Outcome in the future.
That is, however, in the pure sense, and it only applies to shared libraries
which do not export any Outcome implementation (i.e. `-fvisibility=hidden` etc
on ELF). Where implementation is exported e.g. in a static library, one may
also wish to ensure that the API as well as ABI is compatible. Another example
of use case are precompiled C++ Modules which tend to leak a lot of implementation
detail.
This directory contains dumps of both Outcome's API and ABI for the v2.2 library
for selected compilers and configuration, which can be useful for verifying
stability. These are what are checked per CI commit:
<dl>
<dt>2.2-gcc7-cxx14</dt>
<dd>This is when compiled under the C++ 14 standard by GCC 7.5.</dd>
<dt>2.2-gcc9-cxx17</dt>
<dd>This is when compiled under the C++ 17 standard by GCC 9.3.</dd>
</dl>
## Prerequisites for using this directory:
1. GCC 7.5 with libstdc++.
2. GCC 9.3 with libstdc++.
3. Ubuntu 20.04 LTS.
### Prerequisites if you want to check only ABI (abi-dumper):
1. `abi-dumper`
2. `abi-compliance-checker`
Run `./check-abi.sh 2.2` to check that
the current Outcome's ABI is compatible with the stored ABI. A HTML report
will be generated by the `abi-compliance-checker` tool useful for displaying
in CI servers and/or emailing to team members.
If you see breakage in this tool, please do report such ABI breakages
to https://github.com/ned14/outcome/issues.
### Prerequisites if you want to check only ABI (libabigail):
1. `abigail-tools`
Run `./check-abigail.sh 2.2` to check that
the current Outcome's ABI is compatible with the stored ABI.
If you see breakage in this tool, please do report such ABI breakages
to https://github.com/ned14/outcome/issues.
### Prerequisites if you want to check ABI and API:
1. `abi-dumper`
2. `abi-compliance-checker`
Run `./check-api-abi.sh 2.2` to check that the current Outcome's ABI and API
is compatible with the stored ABI. A HTML report
will be generated by the `abi-compliance-checker` tool useful for displaying
in CI servers and/or emailing to team members.
As users familiar with this tool will know, this form of the tool is
somewhat prone to false positives. Every failure needs to be carefully
studied to determine if it is actually a problem or not.
|
0 | repos/outcome | repos/outcome/abi-compliance/check-abigail.sh | #!/bin/bash
rm -rf abi_dumps/Outcome/test-gcc7-cxx14/abigail.xml
rm -rf abi_dumps/Outcome/test-gcc9-cxx17/abigail.xml
sh ./dump-abigail.sh test || exit 1
cd abi_dumps/Outcome
tar xf $1.tar.bz2
cd ../..
RETCODE=0
abidiff --stats --deleted-fns --changed-fns --deleted-vars --changed-vars abi_dumps/Outcome/$1-gcc7-cxx14/abigail.xml abi_dumps/Outcome/test-gcc7-cxx14/abigail.xml
(( RETCODE=$RETCODE || ($? & 11) ))
echo Check returns $RETCODE
abidiff --stats --deleted-fns --changed-fns --deleted-vars --changed-vars abi_dumps/Outcome/$1-gcc9-cxx17/abigail.xml abi_dumps/Outcome/test-gcc9-cxx17/abigail.xml
(( RETCODE=$RETCODE || ($? & 11) ))
echo Check returns $RETCODE
exit $RETCODE
|
0 | repos/outcome | repos/outcome/abi-compliance/dump-abigail.sh | #!/bin/sh -e
mkdir -p build-gcc7-cxx14
cd build-gcc7-cxx14
CXX=g++-7 cmake .. -DCMAKE_BUILD_TYPE=Debug -DCMAKE_CXX_STANDARD=14 -DLABEL=gcc7-cxx14
cmake --build .
cd ..
mkdir -p build-gcc9-cxx17
cd build-gcc9-cxx17
CXX=g++-9 cmake .. -DCMAKE_BUILD_TYPE=Debug -DCMAKE_CXX_STANDARD=17 -DLABEL=gcc9-cxx17
cmake --build .
cd ..
if [ $# -eq 0 ]; then
DUMPFILE=2.2
else
DUMPFILE=$1
fi
RETCODE=0
abidw --stats --no-show-locs --out-file abi_dumps/Outcome/$DUMPFILE-gcc7-cxx14/abigail.xml --headers-dir ../single-header/abi.hpp build-gcc7-cxx14/liboutcome-abi-lib-gcc7-cxx14.so || RETCODE=1
abidw --stats --no-show-locs --out-file abi_dumps/Outcome/$DUMPFILE-gcc9-cxx17/abigail.xml --headers-dir ../single-header/abi.hpp build-gcc9-cxx17/liboutcome-abi-lib-gcc9-cxx17.so || RETCODE=1
if [ $RETCODE -eq 0 ]; then
cd abi_dumps/Outcome
tar jcf $DUMPFILE.tar.bz2 $DUMPFILE-gcc7-cxx14 $DUMPFILE-gcc9-cxx17 || true
cd ../..
fi
exit $RETCODE
|
0 | repos/outcome | repos/outcome/abi-compliance/dump-api-abi.sh | #!/bin/sh -e
mkdir -p build-gcc7-cxx14
cd build-gcc7-cxx14
CXX=g++-7 cmake .. -DCMAKE_BUILD_TYPE=Debug -DCMAKE_CXX_STANDARD=14 -DLABEL=gcc7-cxx14
cmake --build .
cd ..
mkdir -p build-gcc9-cxx17
cd build-gcc9-cxx17
CXX=g++-9 cmake .. -DCMAKE_BUILD_TYPE=Debug -DCMAKE_CXX_STANDARD=17 -DLABEL=gcc9-cxx17
cmake --build .
cd ..
if [ $# -eq 0 ]; then
DUMPFILE=2.2
else
DUMPFILE=$1
fi
rm -f $DUMPFILE.xml
echo "<version>$DUMPFILE-gcc7-cxx14</version><headers>../single-header/outcome.hpp</headers><libs>build-gcc7-cxx14/liboutcome-abi-lib-gcc7-cxx14.so</libs>" > $DUMPFILE.xml
RETCODE=0
abi-compliance-checker -l Outcome -dump $DUMPFILE.xml -gcc-path g++-7 || RETCODE=1
echo "<version>$DUMPFILE-gcc9-cxx17</version><headers>../single-header/outcome.hpp</headers><libs>build-gcc9-cxx17/liboutcome-abi-lib-gcc9-cxx17.so</libs>" > $DUMPFILE.xml
abi-compliance-checker -l Outcome -dump $DUMPFILE.xml -gcc-path g++-9 || RETCODE=1
if [ $RETCODE -eq 0 ]; then
cd abi_dumps/Outcome
tar jcf $DUMPFILE.tar.bz2 $DUMPFILE-gcc7-cxx14 $DUMPFILE-gcc9-cxx17 || true
cd ../..
fi
exit $RETCODE
|
0 | repos/outcome | repos/outcome/abi-compliance/dump-abi.sh | #!/bin/sh -e
mkdir -p build-gcc7-cxx14
cd build-gcc7-cxx14
CXX=g++-7 cmake .. -DCMAKE_BUILD_TYPE=Debug -DCMAKE_CXX_STANDARD=14 -DLABEL=gcc7-cxx14
cmake --build .
cd ..
mkdir -p build-gcc9-cxx17
cd build-gcc9-cxx17
CXX=g++-9 cmake .. -DCMAKE_BUILD_TYPE=Debug -DCMAKE_CXX_STANDARD=17 -DLABEL=gcc9-cxx17
cmake --build .
cd ..
if [ $# -eq 0 ]; then
DUMPFILE=2.2
else
DUMPFILE=$1
fi
RETCODE=0
abi-dumper -o abi_dumps/Outcome/$DUMPFILE-gcc7-cxx14/binary_only.dump -vnum $DUMPFILE-gcc7-cxx14 build-gcc7-cxx14/liboutcome-abi-lib-gcc7-cxx14.so || RETCODE=1
abi-dumper -o abi_dumps/Outcome/$DUMPFILE-gcc9-cxx17/binary_only.dump -vnum $DUMPFILE-gcc9-cxx17 build-gcc9-cxx17/liboutcome-abi-lib-gcc9-cxx17.so || RETCODE=1
if [ $RETCODE -eq 0 ]; then
cd abi_dumps/Outcome
tar jcf $DUMPFILE.tar.bz2 $DUMPFILE-gcc7-cxx14 $DUMPFILE-gcc9-cxx17 || true
cd ../..
fi
exit $RETCODE
|
0 | repos/outcome | repos/outcome/abi-compliance/CMakeLists.txt | cmake_minimum_required(VERSION 3.1 FATAL_ERROR)
if(NOT DEFINED LABEL)
set(LABEL default)
endif()
project(outcome-abi-test VERSION 1.0 LANGUAGES CXX)
set(OUTCOME_FORCE_ENABLE_PP_TARGETS TRUE)
add_subdirectory(.. outcome EXCLUDE_FROM_ALL)
add_library(outcome-abi-lib-${LABEL} SHARED "src/main.cpp")
target_link_libraries(outcome-abi-lib-${LABEL} PUBLIC outcome::hl)
add_dependencies(outcome-abi-lib-${LABEL} outcome_hl-pp-std)
target_compile_definitions(outcome-abi-lib-${LABEL} PUBLIC OUTCOME_DISABLE_ABI_PERMUTATION=1)
if(NOT MSVC)
target_compile_options(outcome-abi-lib-${LABEL} PUBLIC -Og)
endif()
|
0 | repos/outcome | repos/outcome/abi-compliance/check-api-abi.sh | #!/bin/sh
sh ./dump-api-abi.sh test || exit 1
cd abi_dumps/Outcome
tar xf $1.tar.bz2
cd ../..
RETCODE=0
#abi-compliance-checker -l Outcome -old abi_dumps/Outcome/$1-gcc7-cxx14/ABI.dump -new abi_dumps/Outcome/X/ABI.dump || RETCODE=1
abi-compliance-checker -l Outcome -old abi_dumps/Outcome/$1-gcc9-cxx17/ABI.dump -new abi_dumps/Outcome/X/ABI.dump || RETCODE=1
exit $RETCODE
|
0 | repos/outcome/abi-compliance | repos/outcome/abi-compliance/src/main.cpp | /* A shared library which uses Outcome in order to guarantee its ABI
(C) 2018-2021 Niall Douglas <http://www.nedproductions.biz/> (3 commits)
File Created: Mar 2018
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License in the accompanying file
Licence.txt or at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Distributed under the Boost Software License, Version 1.0.
(See accompanying file Licence.txt or copy at
http://www.boost.org/LICENSE_1_0.txt)
*/
#include "../../single-header/outcome.hpp"
struct NonTrivialType
{
void *foo{nullptr};
NonTrivialType()
: foo(nullptr)
{
}
NonTrivialType(const NonTrivialType &)
: foo(nullptr)
{
}
NonTrivialType(NonTrivialType &&) noexcept
: foo(nullptr)
{
}
NonTrivialType &operator=(const NonTrivialType &) { return *this; }
NonTrivialType &operator=(NonTrivialType &&) noexcept { return *this; }
~NonTrivialType() { foo = nullptr; }
};
// Lock ABI for the internal status bits
extern QUICKCPPLIB_SYMBOL_EXPORT OUTCOME_V2_NAMESPACE::detail::status_bitfield_type status_bits()
{
using status = OUTCOME_V2_NAMESPACE::detail::status;
return (status)((uint16_t) status::have_value | (uint16_t) status::have_error | (uint16_t) status::have_exception | (uint16_t) status::have_error_is_errno |
(uint16_t) status::have_lost_consistency | (uint16_t) status::have_moved_from);
}
// Lock ABI for the internal value storage for trivial types
extern QUICKCPPLIB_SYMBOL_EXPORT OUTCOME_V2_NAMESPACE::detail::value_storage_trivial<int, long>
value_storage_int(OUTCOME_V2_NAMESPACE::detail::value_storage_trivial<int, long> &v)
{
return v;
}
// Lock ABI for the internal value storage for non-trivial types
extern QUICKCPPLIB_SYMBOL_EXPORT OUTCOME_V2_NAMESPACE::detail::value_storage_nontrivial<NonTrivialType, int>
value_storage_NonTrivialType(OUTCOME_V2_NAMESPACE::detail::value_storage_nontrivial<NonTrivialType, int> &v)
{
return v;
}
template <class T, class EC, class EP, class NoValuePolicy, class... NoValuePolicies>
struct QUICKCPPLIB_SYMBOL_EXPORT abi_stamper : public abi_stamper<T, EC, EP, NoValuePolicies...>
{
using result = OUTCOME_V2_NAMESPACE::basic_result<T, EC, NoValuePolicy>;
using outcome = OUTCOME_V2_NAMESPACE::basic_outcome<T, EC, EP, NoValuePolicy>;
using bad_result_access = OUTCOME_V2_NAMESPACE::bad_result_access_with<EC>;
virtual ~abi_stamper() {}
virtual result get(result &v) { return v; }
virtual outcome get(outcome &v) { return v; }
virtual bad_result_access get(bad_result_access &v) { return v; }
#ifdef OUTCOME_FOUND_COROUTINE_HEADER
template <class X> using eager = OUTCOME_V2_NAMESPACE::awaitables::eager<X>;
template <class X> using lazy = OUTCOME_V2_NAMESPACE::awaitables::lazy<X>;
template <class X> using atomic_eager = OUTCOME_V2_NAMESPACE::awaitables::atomic_eager<X>;
template <class X> using atomic_lazy = OUTCOME_V2_NAMESPACE::awaitables::atomic_lazy<X>;
virtual eager<int> get(eager<int> &v) { return v; }
virtual eager<result> get(eager<result> &v) { return v; }
virtual eager<outcome> get(eager<outcome> &v) { return v; }
virtual lazy<int> get(lazy<int> &v) { return v; }
virtual lazy<result> get(lazy<result> &v) { return v; }
virtual lazy<outcome> get(lazy<outcome> &v) { return v; }
virtual atomic_eager<int> get(atomic_eager<int> &v) { return v; }
virtual atomic_eager<result> get(atomic_eager<result> &v) { return v; }
virtual atomic_eager<outcome> get(atomic_eager<outcome> &v) { return v; }
virtual atomic_lazy<int> get(atomic_lazy<int> &v) { return v; }
virtual atomic_lazy<result> get(atomic_lazy<result> &v) { return v; }
virtual atomic_lazy<outcome> get(atomic_lazy<outcome> &v) { return v; }
#endif
};
template <class T, class EC, class EP> struct QUICKCPPLIB_SYMBOL_EXPORT abi_stamper<T, EC, EP, void>
{
};
template <class T, class EC, class EP>
using abi_policies_stamper =
abi_stamper<T, EC, EP, OUTCOME_V2_NAMESPACE::policy::all_narrow, OUTCOME_V2_NAMESPACE::policy::terminate,
OUTCOME_V2_NAMESPACE::policy::error_code_throw_as_system_error<T, EC, EP>, OUTCOME_V2_NAMESPACE::policy::exception_ptr_rethrow<T, EC, EP>,
OUTCOME_V2_NAMESPACE::policy::throw_bad_result_access<EC, EP>, void>;
// Lock ABI for trivial types
extern QUICKCPPLIB_SYMBOL_EXPORT auto abi_stamp(abi_policies_stamper<int, std::error_code, double> &v)
{
return v;
}
// Lock ABI for non-trivial types
extern QUICKCPPLIB_SYMBOL_EXPORT auto abi_stamp(abi_policies_stamper<NonTrivialType, std::error_code, std::exception_ptr> &v)
{
return v;
}
|
0 | repos/outcome | repos/outcome/test/single-header-test.cpp | /* Single header test
(C) 2017-2019 Niall Douglas <http://www.nedproductions.biz/> (5 commits)
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License in the accompanying file
Licence.txt or at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Distributed under the Boost Software License, Version 1.0.
(See accompanying file Licence.txt or copy at
http://www.boost.org/LICENSE_1_0.txt)
*/
#include "../single-header/outcome.hpp"
int main()
{
using namespace OUTCOME_V2_NAMESPACE;
result<int> f(5);
outcome<void> m(in_place_type<void>);
(void) f;
(void) m;
return 0;
}
|
0 | repos/outcome | repos/outcome/test/expected-pass.cpp | //! \file test_expected.cpp
// Copyright Pierre Talbot 2013.
// Copyright Vicente J. Botet Escriba 2013,2014.
// Use, modification and distribution are subject to 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)
// Notes by ned:
// Original is at https://github.com/viboes/std-make/blob/master/test/expected/expected_pass.cpp
// This edition modified to use result with throw_bad_result_access policy
// Quite a lot of the test suite I had to disable, not because our Expected implementation is
// incorrect, but because the reference test suite is testing an Expected quite far away from
// the latest WG21 proposal paper, and we're implementing that latest edition.
#include <utility>
#include "../include/outcome/iostream_support.hpp"
#include "../include/outcome/std_result.hpp"
#if defined(__clang__) || __GNUC__ >= 7 || !defined(BOOST_MSVC) || (BOOST_MSVC > 0 && _HAS_CXX17)
#define QUICKCPPLIB_BOOST_UNIT_TEST_CUSTOM_MAIN_DEFINED
#include "quickcpplib/boost/test/unit_test.hpp"
#define JASEL_NORETURN
#ifndef BOOST_TEST
#define BOOST_TEST(expr) BOOST_CHECK(expr)
#endif
#ifndef BOOST_TEST_EQ
#define BOOST_TEST_EQ(a, b) BOOST_CHECK_EQUAL((a), (b))
#endif
#ifndef BOOST_TEST_THROWS
#define BOOST_TEST_THROWS(expr, ex) BOOST_CHECK_THROW((expr), ex)
#endif
#ifndef BOOST_CONSTEXPR
#define BOOST_CONSTEXPR constexpr
#endif
#ifdef _MSC_VER
#pragma warning(disable : 4127) // conditional expression is constant
#pragma warning(disable : 4244) // conversion from int to short
#endif
namespace stde
{
#if __cplusplus >= 201700 || _HAS_CXX17
using in_place_t = std::in_place_t;
using std::in_place;
#else
struct in_place_t
{
explicit in_place_t() = default;
};
constexpr in_place_t in_place{};
#endif
//! [expected_implementation]
/* Here is a fairly conforming implementation of P0323R3 `expected<T, E>` using `checked<T, E>`.
It passes the reference test suite for P0323R3 at
https://github.com/viboes/std-make/blob/master/test/expected/expected_pass.cpp with modifications
only to move the test much closer to the P0323R3 Expected, as the reference test suite is for a
much older proposed Expected.
Known differences from P0323R3 in this implementation:
- `T` and `E` cannot be the same type.
- No variant storage is implemented.
*/
namespace detail
{
template <class T, class E> using expected_result = OUTCOME_V2_NAMESPACE::checked<T, E>;
template <class T, class E> struct enable_default_constructor : public expected_result<T, E>
{
using base = expected_result<T, E>;
using base::base;
constexpr enable_default_constructor()
: base{OUTCOME_V2_NAMESPACE::in_place_type<T>}
{
}
};
template <class T, class E> using select_expected_base = std::conditional_t<std::is_default_constructible<T>::value, enable_default_constructor<T, E>, expected_result<T, E>>;
} // namespace detail
template <class T, class E> class expected : public detail::select_expected_base<T, E>
{
static_assert(!std::is_same<T, E>::value, "T and E cannot be the same in this expected implementation");
using base = detail::select_expected_base<T, E>;
public:
// Inherit base's constructors
using base::base;
expected() = default;
// Expected takes in_place not in_place_type
template <class... Args>
constexpr explicit expected(in_place_t /*unused*/, Args &&... args)
: base{OUTCOME_V2_NAMESPACE::in_place_type<T>, std::forward<Args>(args)...}
{
}
// Expected always accepts a T even if ambiguous
OUTCOME_TEMPLATE(class U)
OUTCOME_TREQUIRES(OUTCOME_TPRED(std::is_constructible<T, U>::value))
constexpr expected(U &&v) // NOLINT
: base{OUTCOME_V2_NAMESPACE::in_place_type<T>, std::forward<U>(v)}
{
}
// Expected has an emplace() modifier
template <class... Args> void emplace(Args &&... args) { *static_cast<base *>(this) = base{OUTCOME_V2_NAMESPACE::in_place_type<T>, std::forward<Args>(args)...}; }
// Expected has a narrow operator* and operator->
constexpr const T &operator*() const & { return base::assume_value(); }
constexpr T &operator*() & { return base::assume_value(); }
constexpr const T &&operator*() const && { return base::assume_value(); }
constexpr T &&operator*() && { return base::assume_value(); }
constexpr const T *operator->() const { return &base::assume_value(); }
constexpr T *operator->() { return &base::assume_value(); }
// Expected has a narrow error() observer
constexpr const E &error() const & { return base::assume_error(); }
constexpr E &error() & { return base::assume_error(); }
constexpr const E &&error() const && { return base::assume_error(); }
constexpr E &error() && { return base::assume_error(); }
};
template <class E> class expected<void, E> : public OUTCOME_V2_NAMESPACE::result<void, E, OUTCOME_V2_NAMESPACE::policy::throw_bad_result_access<E, void>>
{
using base = OUTCOME_V2_NAMESPACE::result<void, E, OUTCOME_V2_NAMESPACE::policy::throw_bad_result_access<E, void>>;
public:
// Inherit base constructors
using base::base;
// Expected has a narrow operator* and operator->
constexpr void operator*() const { base::assume_value(); }
constexpr void operator->() const { base::assume_value(); }
};
template <class E> using unexpected = OUTCOME_V2_NAMESPACE::failure_type<E>;
template <class E> unexpected<E> make_unexpected(E &&arg) { return OUTCOME_V2_NAMESPACE::failure<E>(std::forward<E>(arg)); }
template <class E, class... Args> unexpected<E> make_unexpected(Args &&... args) { return OUTCOME_V2_NAMESPACE::failure<E>(std::forward<Args>(args)...); }
template <class E> using bad_expected_access = OUTCOME_V2_NAMESPACE::bad_result_access_with<E>;
//! [expected_implementation]
// Not actually part of the Expected proposal, but needed to pass the test
template <typename T> using exception_or = expected<T, std::exception_ptr>;
} // namespace stde
template <class T> using expected_sc = stde::expected<T, std::error_code>;
struct NoDefaultConstructible
{
NoDefaultConstructible() = delete;
NoDefaultConstructible(int /*unused*/) {} // NOLINT
};
struct NoCopyConstructible
{
NoCopyConstructible() = default;
NoCopyConstructible(NoCopyConstructible const &) = delete;
NoCopyConstructible(NoCopyConstructible &&) noexcept = default;
};
struct NoMoveConstructible
{
NoMoveConstructible() = default;
NoMoveConstructible(NoMoveConstructible const &) noexcept = default;
NoMoveConstructible(NoMoveConstructible &&) = delete;
NoMoveConstructible &operator=(NoMoveConstructible const &) noexcept = default;
NoMoveConstructible &operator=(NoMoveConstructible &&) = delete;
};
enum State
{
sDefaultConstructed,
sValueCopyConstructed,
sValueMoveConstructed,
sCopyConstructed,
sMoveConstructed,
sMoveAssigned,
sCopyAssigned,
sValueCopyAssigned,
sValueMoveAssigned,
sMovedFrom,
sValueConstructed
};
struct OracleVal
{
State s{sValueConstructed};
int i;
constexpr OracleVal(int i_ = 0) // NOLINT
: i(i_)
{
}
};
struct Oracle
{
State s{sDefaultConstructed};
OracleVal val;
Oracle() = default;
Oracle(const OracleVal &v) // NOLINT
: s(sValueCopyConstructed),
val(v)
{
}
Oracle(OracleVal &&v) noexcept : s(sValueMoveConstructed), val(v) { v.s = sMovedFrom; } // NOLINT
Oracle(const Oracle &o)
: s(sCopyConstructed)
, val(o.val)
{
}
Oracle(Oracle &&o) noexcept : s(sMoveConstructed), val(std::move(o.val)) { o.s = sMovedFrom; } // NOLINT
Oracle &operator=(const OracleVal &v)
{
s = sValueCopyConstructed;
val = v;
return *this;
}
Oracle &operator=(OracleVal &&v) noexcept
{
s = sValueMoveConstructed;
val = std::move(v); // NOLINT
v.s = sMovedFrom;
return *this;
}
Oracle &operator=(const Oracle &o)
{
s = sCopyConstructed;
val = o.val;
return *this;
}
Oracle &operator=(Oracle &&o) noexcept
{
s = sMoveConstructed;
val = std::move(o.val); // NOLINT
o.s = sMovedFrom;
return *this;
}
};
struct Guard
{
std::string val;
Guard() = default;
explicit Guard(std::string s, int /*unused*/ = 0)
: val(std::move(s))
{
}
Guard(const Guard &) = delete;
Guard(Guard &&) = delete;
void operator=(const Guard &) = delete;
void operator=(Guard &&) = delete;
};
struct ExplicitStr
{
std::string s;
explicit ExplicitStr(const char *chp)
: s(chp)
{
}
};
struct Date
{
int i;
Date() = delete;
Date(int i_) noexcept : i{i_} {} // NOLINT
Date(Date &&d) noexcept : i(d.i) { d.i = 0; }
Date(const Date &) = delete;
Date &operator=(const Date &) = delete;
Date &operator=(Date &&d) noexcept
{
i = d.i;
d.i = 0;
return *this;
}
};
struct TExcept
{
int i;
TExcept() = delete;
TExcept(int i_) // NOLINT
: i{i_}
{
}
TExcept(TExcept &&d)
: i(d.i)
{
d.i = 0;
}
TExcept(const TExcept &) = delete;
TExcept &operator=(const TExcept &) = delete;
TExcept &operator=(TExcept &&d)
{
i = d.i;
d.i = 0;
return *this;
}
};
template <class T> struct MoveAware
{
T val;
bool moved;
MoveAware(T val_) // NOLINT
: val(val_),
moved(false)
{
}
MoveAware(MoveAware const &) = delete;
MoveAware(MoveAware &&rhs)
: val(rhs.val)
, moved(rhs.moved)
{
rhs.moved = true;
}
MoveAware &operator=(MoveAware const &) = delete;
MoveAware &operator=(MoveAware &&rhs)
{
val = (rhs.val);
moved = (rhs.moved);
rhs.moved = true;
return *this;
}
};
struct OverloadedAddressOf
{
OverloadedAddressOf() = default;
OverloadedAddressOf *operator&() const { return nullptr; }
};
// using namespace boost;
// using namespace boost::functional;
class test_exception : public std::exception
{
};
int throwing_fun()
{
throw test_exception();
}
int nothrowing_fun()
{
return 4;
}
JASEL_NORETURN void void_throwing_fun()
{
throw test_exception();
}
void do_nothing_fun()
{
}
void except_default_constructor()
{
// From value constructor.
expected_sc<int> e{};
try
{
int i = e.value();
(void) i;
BOOST_TEST(true);
}
catch(...)
{
BOOST_TEST(false);
};
BOOST_TEST(e.has_value());
BOOST_TEST(e);
BOOST_TEST(static_cast<bool>(e));
}
void except_default_constructor_error_code()
{
// From value constructor.
stde::expected<int, std::error_code> e;
BOOST_TEST(e.has_value());
BOOST_TEST(e);
BOOST_TEST(static_cast<bool>(e));
}
void except_default_constructor_constexpr()
{
// From value constructor.
BOOST_CONSTEXPR stde::expected<int, long> e;
BOOST_TEST(e.has_value());
}
void expected_from_value()
{
// using T = int;
using E = std::error_code;
// static_assert(noexcept(stde::adl::swap_impl(std::declval<T &>(), std::declval<T &>())), "");
static_assert(std::is_nothrow_copy_constructible<E>::value, "");
// static_assert(noexcept(stde::adl::swap_impl(std::declval<E &>(), std::declval<E &>())), "");
static_assert(std::is_nothrow_copy_constructible<expected_sc<int>>::value, "");
static_assert(std::is_nothrow_copy_assignable<expected_sc<int>>::value, "");
static_assert(std::is_nothrow_move_constructible<expected_sc<int>>::value, "");
static_assert(std::is_nothrow_move_assignable<expected_sc<int>>::value, "");
// From value constructor.
expected_sc<int> e(5);
// BOOST_REQUIRE_NO_THROW(e.value());
BOOST_TEST_EQ(e.value(), 5);
BOOST_TEST_EQ(*e, 5);
BOOST_TEST(e.has_value());
BOOST_TEST(static_cast<bool>(e));
}
void expected_from_value2()
{
// From value constructor.
expected_sc<int> e(5);
e = {};
BOOST_TEST(e.has_value());
BOOST_TEST_EQ(e.value(), 0);
}
void expected_from_cnv_value()
{
OracleVal v;
expected_sc<Oracle> e(v);
// BOOST_REQUIRE_NO_THROW(e.value());
BOOST_TEST(!!e);
BOOST_TEST(e.has_value());
BOOST_TEST(bool(e));
BOOST_TEST_EQ(e.value().s, sValueCopyConstructed);
BOOST_TEST_EQ(v.s, sValueConstructed);
expected_sc<Oracle> e2(std::move(v)); // NOLINT
// BOOST_REQUIRE_NO_THROW(e2.value());
BOOST_TEST(!!e2);
BOOST_TEST(e2.has_value());
BOOST_TEST(bool(e2));
BOOST_TEST_EQ(e2.value().s, sValueMoveConstructed);
BOOST_TEST_EQ(v.s, sMovedFrom);
}
struct NDCE // no default constructor
{ // (no default date exists)
explicit NDCE(int /*unused*/) {}
};
void except_constructor_NDCE()
{
expected_sc<NDCE> e{NDCE{1}};
BOOST_TEST(e.has_value());
}
struct NDC // no default constructor
{ // (no default date exists)
NDC(int /*unused*/) {} // NOLINT
};
void except_constructor_NDC()
{
static_assert(std::is_nothrow_copy_constructible<expected_sc<NDC>>::value, "");
static_assert(std::is_nothrow_copy_assignable<expected_sc<NDC>>::value, "");
static_assert(std::is_nothrow_move_constructible<expected_sc<NDC>>::value, "");
static_assert(std::is_nothrow_move_assignable<expected_sc<NDC>>::value, "");
expected_sc<NDC> e{1};
BOOST_TEST(e.has_value());
}
void except_constructor_Date()
{
static_assert(std::is_nothrow_move_constructible<expected_sc<Date>>::value, "");
static_assert(std::is_nothrow_move_assignable<expected_sc<Date>>::value, "");
expected_sc<Date> e{Date{1}};
BOOST_TEST(e.has_value());
}
void except_constructor_TExcept()
{
static_assert(!std::is_nothrow_move_constructible<expected_sc<TExcept>>::value, "");
static_assert(!std::is_nothrow_move_assignable<expected_sc<TExcept>>::value, "");
expected_sc<TExcept> e{TExcept{1}};
BOOST_TEST(e.has_value());
}
void expected_from_in_place_value()
{
OracleVal v;
expected_sc<Oracle> e{stde::in_place, v};
// BOOST_REQUIRE_NO_THROW(e.value());
BOOST_TEST(!!e);
BOOST_TEST(e.has_value());
BOOST_TEST(bool(e));
BOOST_TEST_EQ(e.value().s, sValueCopyConstructed);
BOOST_TEST_EQ(v.s, sValueConstructed);
expected_sc<Oracle> e2{stde::in_place, std::move(v)}; // NOLINT
// BOOST_REQUIRE_NO_THROW(e2.value());
BOOST_TEST(!!e2);
BOOST_TEST(e2.has_value());
BOOST_TEST(bool(e2));
BOOST_TEST_EQ(e2.value().s, sValueMoveConstructed);
BOOST_TEST_EQ(v.s, sMovedFrom);
}
#if 0
void expected_from_exception()
{
// From stde::unexpected constructor.
stde::exception_or<int> e(stde::make_unexpected(test_exception()));
BOOST_TEST_THROWS(e.value(), test_exception);
BOOST_TEST_EQ(e.has_value(), false);
BOOST_TEST_EQ(static_cast<bool>(e), false);
}
#endif
void expected_from_copy_value()
{
// From copy constructor.
expected_sc<int> ef(5);
expected_sc<int> e(ef);
// BOOST_REQUIRE_NO_THROW(e.value());
BOOST_TEST_EQ(e.value(), 5);
BOOST_TEST_EQ(*e, 5);
BOOST_TEST(e.has_value());
BOOST_TEST(static_cast<bool>(e));
}
#if 0
void expected_from_copy_exception()
{
// From stde::unexpected constructor.
stde::exception_or<int> ef(stde::make_unexpected(test_exception()));
stde::exception_or<int> e(ef);
BOOST_TEST_THROWS(e.value(), test_exception);
BOOST_TEST_EQ(e.has_value(), false);
BOOST_TEST_EQ(static_cast<bool>(e), false);
}
#endif
void expected_from_in_place()
{
// From stde::in_place constructor.
expected_sc<std::string> e(stde::in_place, "stde::in_place");
// BOOST_REQUIRE_NO_THROW(e.value());
BOOST_TEST_EQ(e.value(), "stde::in_place");
BOOST_TEST_EQ(*e, "stde::in_place");
BOOST_TEST(e.has_value());
BOOST_TEST(static_cast<bool>(e));
}
#if 0
void expected_from_exception_ptr()
{
// From exception_ptr constructor.
stde::exception_or<int> e(stde::make_unexpected(std::make_exception_ptr(test_exception())));
BOOST_TEST_THROWS(e.value(), test_exception);
BOOST_TEST_EQ(e.has_value(), false);
BOOST_TEST_EQ(static_cast<bool>(e), false);
}
#endif
void expected_from_moved_value()
{
// From move value constructor.
std::string value = "my value";
expected_sc<std::string> e = std::move(value);
// BOOST_REQUIRE_NO_THROW(e.value());
BOOST_TEST_EQ(e.value(), "my value");
BOOST_TEST_EQ(*e, "my value");
BOOST_TEST(e.has_value());
BOOST_TEST(static_cast<bool>(e));
}
void expected_from_catch_block()
{
// From catch block
try
{
throw test_exception();
}
catch(...)
{
stde::exception_or<int> e(stde::make_unexpected(std::current_exception()));
BOOST_TEST_THROWS(e.value(), std::exception);
BOOST_TEST_EQ(e.has_value(), false);
BOOST_TEST_EQ(static_cast<bool>(e), false);
}
}
void make_expected_E_from_value()
{
// auto e = stde::make_expected<std::string>( 5 );
// BOOST_TEST_EQ(e.has_value(), false);
}
void make_expected_const_from_value()
{
#if defined __clang__ && __clang_major__ >= 4 && __cplusplus > 201402L
const int i = 0;
auto e = expected_sc<const int>(i);
(void) e;
// static_assert(std::is_same<decltype(e), stde::success<const int>>::value, "");
#endif
}
void make_expected_from_U_value()
{
expected_sc<int> e = expected_sc<int>(short(5));
static_assert(std::is_same<decltype(e), expected_sc<int>>{}, "");
BOOST_TEST_EQ(e.has_value(), true);
}
void make_expected_from_U_value2()
{
expected_sc<std::string> e = expected_sc<std::string>("aa");
static_assert(std::is_same<decltype(e), expected_sc<std::string>>{}, "");
BOOST_TEST_EQ(e.has_value(), true);
}
void expected_from_value_error_condition()
{
// From value constructor.
stde::expected<int, std::error_condition> e(5);
// BOOST_REQUIRE_NO_THROW(e.value());
BOOST_TEST_EQ(e.value(), 5);
BOOST_TEST_EQ(*e, 5);
BOOST_TEST(e.has_value());
BOOST_TEST(static_cast<bool>(e));
}
void expected_from_error_error_condition()
{
// From stde::unexpected constructor.
stde::expected<int, std::error_condition> e(stde::make_unexpected<std::error_condition>(std::make_error_condition(std::errc::invalid_argument)));
auto error_from_except_check = [](const stde::bad_expected_access<std::error_condition> &except) { return std::errc(except.error().value()) == std::errc::invalid_argument; };
try
{
(void) e.value();
}
catch(stde::bad_expected_access<std::error_condition> &ex)
{
BOOST_TEST(error_from_except_check(ex));
}
BOOST_TEST_EQ(e.has_value(), false);
BOOST_TEST_EQ(static_cast<bool>(e), false);
}
void expected_from_error_convertible()
{
{
stde::expected<int, short> e1 = stde::make_unexpected<short>(1);
stde::expected<int, long> e2(e1);
BOOST_TEST_EQ(e2.has_value(), false);
BOOST_TEST_EQ(static_cast<bool>(e2), false);
BOOST_TEST_EQ(e2.error(), 1);
}
{
stde::expected<void, short> e1 = stde::make_unexpected<short>(1);
stde::expected<void, int> e2(e1);
BOOST_TEST_EQ(e2.has_value(), false);
BOOST_TEST_EQ(static_cast<bool>(e2), false);
BOOST_TEST_EQ(e2.error(), 1);
}
}
void except_valid_constexpr_int()
{
// From value constructor.
BOOST_CONSTEXPR stde::expected<int, long> e;
BOOST_CONSTEXPR bool b = e.has_value();
BOOST_TEST(b);
}
void except_value_constexpr_int()
{
// From value constructor.
BOOST_CONSTEXPR stde::expected<int, long> e(1);
BOOST_CONSTEXPR int x = e.value();
BOOST_TEST_EQ(x, 1);
}
void expected_from_value3()
{
expected_sc<int> e(5);
BOOST_TEST_EQ(e.value(), 5);
// From value assignment.
e = 8;
// BOOST_REQUIRE_NO_THROW(e.value());
BOOST_TEST_EQ(e.value(), 8);
BOOST_TEST_EQ(*e, 8);
BOOST_TEST(e.has_value());
BOOST_TEST(static_cast<bool>(e));
}
void expected_from_copy_expected()
{
expected_sc<int> e(5);
expected_sc<int> e2(8);
// From value assignment.
e = e2;
// BOOST_REQUIRE_NO_THROW(e.value());
BOOST_TEST_EQ(e.value(), 8);
BOOST_TEST_EQ(*e, 8);
BOOST_TEST(e.has_value());
BOOST_TEST(static_cast<bool>(e));
}
void expected_from_moved_expected()
{
expected_sc<std::string> e("e");
expected_sc<std::string> e2("e2");
// From value assignment.
e = std::move(e2);
// BOOST_REQUIRE_NO_THROW(e.value());
BOOST_TEST_EQ(e.value(), "e2");
BOOST_TEST_EQ(*e, "e2");
BOOST_TEST(e.has_value());
BOOST_TEST(static_cast<bool>(e));
// BOOST_REQUIRE_NO_THROW(e2.value());
#ifndef __GLIBCXX__
BOOST_TEST_EQ(e2.value(), "");
BOOST_TEST_EQ(*e2, "");
#endif
BOOST_TEST(e2.has_value());
BOOST_TEST(static_cast<bool>(e2));
}
void expected_from_in_place2()
{
// From stde::in_place constructor.
expected_sc<std::string> e(stde::in_place, "stde::in_place");
BOOST_TEST_EQ(e.value(), "stde::in_place");
// From emplace method.
e.emplace("emplace method");
// BOOST_REQUIRE_NO_THROW(e.value());
BOOST_TEST_EQ(e.value(), "emplace method");
BOOST_TEST_EQ(*e, "emplace method");
BOOST_TEST(e.has_value());
BOOST_TEST(static_cast<bool>(e));
}
void expected_from_move_value()
{
expected_sc<std::string> e("v");
std::string value = "my value";
// From assignment operator.
e = std::move(value);
// BOOST_REQUIRE_NO_THROW(e.value());
BOOST_TEST_EQ(e.value(), "my value");
BOOST_TEST_EQ(*e, "my value");
BOOST_TEST(e.has_value());
BOOST_TEST(static_cast<bool>(e));
}
void expected_from_in_place3()
{
// From stde::in_place factory.
// auto e = stde::make_expected<std::string>("stde::in_place");
auto e = expected_sc<std::string>("stde::in_place");
// BOOST_REQUIRE_NO_THROW(e.value());
BOOST_TEST_EQ(e.value(), "stde::in_place");
BOOST_TEST_EQ(*e, "stde::in_place");
BOOST_TEST(e.has_value());
BOOST_TEST(static_cast<bool>(e));
}
void expected_from_in_place_error()
{
// From stde::in_place factory.
auto e = stde::expected<std::string, std::error_condition>("stde::in_place");
// BOOST_REQUIRE_NO_THROW(e.value());
BOOST_TEST_EQ(e.value(), "stde::in_place");
BOOST_TEST_EQ(*e, "stde::in_place");
BOOST_TEST(e.has_value());
BOOST_TEST(static_cast<bool>(e));
}
void expected_from_exception_catch()
{
// From catch block
try
{
throw test_exception();
}
catch(...)
{
stde::exception_or<int> e = stde::make_unexpected(std::current_exception());
BOOST_TEST_THROWS(e.value(), std::exception);
BOOST_TEST_EQ(e.has_value(), false);
BOOST_TEST_EQ(static_cast<bool>(e), false);
}
}
#if 0
void expected_from_error()
{
// From stde::unexpected constructor.
auto e = stde::make_expected_from_error<int>(std::make_error_condition(std::errc::invalid_argument));
auto error_from_except_check = [](const stde::bad_expected_access<std::error_condition> &except) { return std::errc(except.error().value()) == std::errc::invalid_argument; };
try
{
(void) e.value();
}
catch(stde::bad_expected_access<std::error_condition> &ex)
{
BOOST_TEST(error_from_except_check(ex));
}
BOOST_TEST_EQ(e.has_value(), false);
BOOST_TEST_EQ(static_cast<bool>(e), false);
}
void expected_from_error_U()
{
// From stde::unexpected constructor.
auto e = stde::make_expected_from_error<int, short>(42);
static_assert(std::is_same<decltype(e), stde::expected<int, short>>{}, "");
BOOST_TEST_EQ(e.has_value(), false);
BOOST_TEST_EQ(static_cast<bool>(e), false);
}
void expected_from_exception2()
{
// From stde::unexpected constructor.
auto e = stde::make_expected_from_exception<int>(test_exception());
// auto e = expected_sc<int>(stde::unexpected<>(test_exception()));
BOOST_TEST_THROWS(e.value(), test_exception );
BOOST_TEST_EQ(e.has_value(), false);
BOOST_TEST_EQ(static_cast<bool>(e), false);
}
void expected_from_exception_ptr2()
{
// From exception_ptr constructor.
auto e = stde::exception_or<int>(stde::make_unexpected(test_exception()));
BOOST_TEST_THROWS(e.value(), test_exception );
BOOST_TEST_EQ(e.has_value(), false);
BOOST_TEST_EQ(static_cast<bool>(e), false);
}
void make_expected_from_call_fun()
{
try
{
stde::make_expected_from_call(throwing_fun);
BOOST_TEST(true);
}
catch(...)
{
BOOST_TEST(false);
}
stde::exception_or<int> e = stde::make_expected_from_call(throwing_fun);
BOOST_TEST_THROWS(e.value(), std::exception );
BOOST_TEST_EQ(e.has_value(), false);
BOOST_TEST_EQ(static_cast<bool>(e), false);
e = stde::make_expected_from_call(nothrowing_fun);
try
{
(void) e.value();
BOOST_TEST(true);
}
catch(...)
{
BOOST_TEST(false);
}
BOOST_TEST_EQ(e.value(), 4);
BOOST_TEST_EQ(*e, 4);
BOOST_TEST_EQ(e.has_value(), true);
BOOST_TEST_EQ(static_cast<bool>(e), true);
#if 0
BOOST_TEST_THROWS(stde::make_expected_from_call<std::error_condition>(throwing_fun), test_exception);
BOOST_TEST_NO_THROW(stde::make_expected_from_call<std::error_condition>(nothrowing_fun));
stde::expected<int, std::error_condition> e2 = stde::make_expected_from_call<std::error_condition>(nothrowing_fun);
BOOST_TEST_NO_THROW(e2.value());
BOOST_TEST_EQ(e2.value(), 4);
BOOST_TEST_EQ(*e2, 4);
BOOST_TEST_EQ(e2.has_value(), true);
BOOST_TEST_EQ(static_cast<bool>(e2), true);
#endif
}
void make_expected_from_call_void_fun()
{
#if 0
BOOST_TEST_NO_THROW(stde::make_expected_from_call(void_throwing_fun));
expected_sc<void> e = stde::make_expected_from_call(void_throwing_fun);
BOOST_TEST_THROWS(e.value(), std::exception);
BOOST_TEST_EQ(e.has_value(), false);
BOOST_TEST_EQ(static_cast<bool>(e), false);
e = stde::make_expected_from_call(do_nothing_fun);
BOOST_TEST_NO_THROW(e.value());
BOOST_TEST_EQ(e.has_value(), true);
BOOST_TEST_EQ(static_cast<bool>(e), true);
BOOST_TEST_THROWS(stde::make_expected_from_call<std::error_condition>(void_throwing_fun), test_exception);
try {
stde::make_expected_from_call<std::error_condition>(do_nothing_fun);
BOOST_TEST(true);
}
catch (...)
{
BOOST_TEST(false);
}
stde::expected<void, std::error_condition> e2 = stde::make_expected_from_call<std::error_condition>(do_nothing_fun);
try {
(void)e2.value();
BOOST_TEST(true);
}
catch (...)
{
BOOST_TEST(false);
}
//BOOST_TEST_NO_THROW(e2.value());
BOOST_TEST_EQ(e2.has_value(), true);
BOOST_TEST_EQ(static_cast<bool>(e2), true);
#endif
}
#endif
void expected_swap_value()
{
// From value constructor.
expected_sc<int> e(5);
expected_sc<int> e2(8);
e.swap(e2);
BOOST_TEST_EQ(e.value(), 8);
BOOST_TEST_EQ(e2.value(), 5);
e2.swap(e);
BOOST_TEST_EQ(e.value(), 5);
BOOST_TEST_EQ(e2.value(), 8);
}
#if 0
void expected_swap_exception()
{
// From value constructor.
stde::exception_or<int> e = stde::make_unexpected(std::invalid_argument("e"));
stde::exception_or<int> e2 = stde::make_unexpected(std::invalid_argument("e2"));
e.swap(e2);
auto equal_to_e = [](const std::invalid_argument &except) { return std::string(except.what()) == "e"; };
auto equal_to_e2 = [](const std::invalid_argument &except) { return std::string(except.what()) == "e2"; };
try
{
(void) e.value();
BOOST_TEST(true);
}
catch(std::invalid_argument &ex)
{
BOOST_TEST(equal_to_e2(ex));
}
try
{
(void) e2.value();
BOOST_TEST(true);
}
catch(std::invalid_argument &ex)
{
BOOST_TEST(equal_to_e(ex));
}
e2.swap(e);
try
{
(void) e.value();
BOOST_TEST(true);
}
catch(std::invalid_argument &ex)
{
BOOST_TEST(equal_to_e(ex));
}
try
{
(void) e2.value();
BOOST_TEST(true);
}
catch(std::invalid_argument &ex)
{
BOOST_TEST(equal_to_e2(ex));
}
}
#endif
void expected_swap_function_value()
{
// From value constructor.
expected_sc<int> e(5);
expected_sc<int> e2(8);
swap(e, e2);
BOOST_TEST_EQ(e.value(), 8);
BOOST_TEST_EQ(e2.value(), 5);
swap(e, e2);
BOOST_TEST_EQ(e.value(), 5);
BOOST_TEST_EQ(e2.value(), 8);
}
#ifdef QUICKCPPLIB_BOOST_UNIT_TEST_HPP
int main()
#else
BOOST_AUTO_TEST_CASE(expected_pass)
#endif
{
static_assert(!std::is_default_constructible<NoDefaultConstructible>::value, "");
static_assert(!std::is_default_constructible<expected_sc<NoDefaultConstructible>>::value, "");
static_assert(!std::is_copy_constructible<NoCopyConstructible>::value, "");
static_assert(!std::is_constructible<expected_sc<NoCopyConstructible>, NoCopyConstructible const &>::value, "");
static_assert(!std::is_constructible<stde::exception_or<NoCopyConstructible>, stde::exception_or<NoCopyConstructible> const &>::value, "");
static_assert(!std::is_copy_constructible<stde::exception_or<NoCopyConstructible>>::value, "");
#if 0
// fixme
{
NoMoveConstructible nmc;
// NoMoveConstructible nmc2 = std::move(nmc); // FAILS as expected
expected_sc<NoMoveConstructible> x{std::move(nmc)}; // DOESN'T FAIL as copy is selected instead
(void) x;
}
// fixme
#if defined __clang__ && __clang_major__ >= 4 && __cplusplus > 201402L
{
NoMoveConstructible nmc;
// NoMoveConstructible nmc2 = std::move(nmc); // FAILS as expected
expected_sc<NoMoveConstructible> x = std::move(nmc); // DOESN'T FAIL as copy is selected instead
(void) x;
}
#endif
#endif
static_assert(!std::is_move_constructible<NoMoveConstructible>::value, "");
static_assert(!std::is_constructible<expected_sc<NoMoveConstructible>, NoMoveConstructible &&>::value, "");
static_assert(std::is_move_constructible<expected_sc<NoMoveConstructible>>::value, "");
except_default_constructor();
except_default_constructor_error_code();
except_default_constructor_constexpr();
expected_from_value();
expected_from_value2();
expected_from_cnv_value();
except_constructor_NDCE();
except_constructor_NDC();
except_constructor_Date();
expected_from_in_place_value();
// expected_from_exception();
expected_from_copy_value();
// expected_from_copy_exception();
expected_from_in_place();
// expected_from_exception_ptr();
expected_from_moved_value();
expected_from_catch_block();
make_expected_E_from_value();
make_expected_const_from_value();
make_expected_from_U_value2();
expected_from_value_error_condition();
expected_from_error_error_condition();
expected_from_error_convertible();
except_valid_constexpr_int();
except_value_constexpr_int();
expected_from_value3();
expected_from_copy_expected();
expected_from_moved_expected();
expected_from_in_place2();
expected_from_move_value();
expected_from_in_place3();
expected_from_in_place_error();
expected_from_exception_catch();
// expected_from_error();
// expected_from_error_U();
// expected_from_exception2();
// expected_from_exception_ptr2();
// make_expected_from_call_fun();
// make_expected_from_call_void_fun();
expected_swap_value();
// expected_swap_exception();
expected_swap_function_value();
#ifdef QUICKCPPLIB_BOOST_UNIT_TEST_HPP
return QUICKCPPLIB_NAMESPACE::unit_test::current_test_case()->fails != 0;
#endif
}
#if 0
///////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////
//void expected_from_error_catch_exception)
//{
// // From catch block
// try
// {
// throw test_exception();
// }
// catch(...)
// {
// auto throw_lambda = [](){ return stde::make_expected_from_error<int,std::error_condition>();};
//
// //BOOST_TEST_THROWS(throw_lambda(), test_exception);
// }
//}
////////////////////////////////////
BOOST_AUTO_TEST_SUITE(expected_map)
void expected_map()
{
auto fun = [](bool b) -> expected_sc<int>
{
if (b)
return stde::make_expected(5);
else
return stde::make_unexpected(test_exception());
};
auto add_five = [](int sum) -> int
{
return sum + 5;
};
auto launch_except = [](int sum) -> int
{
throw test_exception();
};
expected_sc<int> e = fun(true).map(add_five);
BOOST_TEST_NO_THROW(e.value());
BOOST_TEST_EQ(*e, 10);
e = fun(true).map(add_five).map(add_five);
BOOST_TEST_NO_THROW(e.value());
BOOST_TEST_EQ(*e, 15);
e = fun(false).map(add_five).map(add_five);
BOOST_TEST_THROWS(e.value(), test_exception);
BOOST_TEST_THROWS(fun(true).map(launch_except), test_exception);
}
void expected_void_map()
{
auto fun = [](bool b)
{
if (b)
return stde::make_expected();
else
return expected_sc<void>(stde::make_unexpected(test_exception()));
};
auto launch_except = []() -> void
{
throw test_exception();
};
auto do_nothing = []() {};
expected_sc<void> e = fun(true).map(do_nothing);
BOOST_TEST_NO_THROW(e.value());
e = fun(false).map(do_nothing);
BOOST_TEST_THROWS(e.value(), test_exception);
BOOST_TEST_THROWS(fun(true).map(launch_except), test_exception);
}
BOOST_AUTO_TEST_SUITE_END()
////////////////////////////////////
BOOST_AUTO_TEST_SUITE(expected_bind)
void expected_bind()
{
auto fun = [](bool b) -> expected_sc<int>
{
if (b)
return stde::make_expected(5);
else
return stde::make_unexpected(test_exception());
};
auto add_five = [](int sum) -> expected_sc<int>
{
return stde::make_expected(sum + 5);
};
auto launch_except = [](int sum) -> expected_sc<int>
{
throw test_exception();
};
expected_sc<int> e = fun(true).bind(add_five);
BOOST_TEST_NO_THROW(e.value());
BOOST_TEST_EQ(*e, 10);
e = fun(true).bind(add_five).bind(add_five);
BOOST_TEST_NO_THROW(e.value());
BOOST_TEST_EQ(*e, 15);
e = fun(false).bind(add_five).bind(add_five);
BOOST_TEST_THROWS(e.value(), test_exception);
BOOST_TEST_THROWS(fun(true).bind(launch_except), test_exception);
}
void expected_void_bind()
{
auto fun = [](bool b)
{
if (b)
return stde::make_expected();
else
return expected_sc<void>(stde::make_unexpected(test_exception()));
};
auto launch_except = []() -> expected_sc<void>
{
throw test_exception();
};
auto do_nothing = []() {
return stde::make_expected();
};
expected_sc<void> e = fun(true).bind(do_nothing);
BOOST_TEST_NO_THROW(e.value());
e = fun(false).bind(do_nothing);
BOOST_TEST_THROWS(e.value(), test_exception);
BOOST_TEST_THROWS(fun(true).bind(launch_except), test_exception);
}
BOOST_AUTO_TEST_SUITE_END()
////////////////////////////////////
BOOST_AUTO_TEST_SUITE(expected_then)
void expected_non_void_then()
{
auto fun = [](bool b) -> expected_sc<int>
{
if (b)
return stde::make_expected(5);
else
return stde::make_unexpected(test_exception());
};
auto add_five = [](int sum) -> int
{
return sum + 5;
};
auto six = []() -> int
{
return 6;
};
auto pair = [](int a) -> bool
{
return (a % 2) == 0;
};
auto launch_except = [](int sum) -> int
{
throw test_exception();
};
auto then_launch_except = [](expected<int>) -> int
{
throw test_exception();
};
expected_sc<int> e = fun(true).then(if_valued(add_five));
BOOST_TEST_NO_THROW(e.value());
BOOST_TEST_EQ(*e, 10);
e = fun(true).then(if_valued(ident(six)));
BOOST_TEST_NO_THROW(e.value());
BOOST_TEST_EQ(*e, 6);
e = fun(false).then(if_unexpected(ident(six)));
BOOST_TEST_NO_THROW(e.value());
BOOST_TEST_EQ(*e, 6);
expected_sc<bool> e1 = fun(true).then(if_valued(pair));
BOOST_TEST_NO_THROW(e1.value());
BOOST_TEST_EQ(*e1, false);
e = fun(true).then(if_valued(add_five)).then(if_valued(add_five));
BOOST_TEST_NO_THROW(e.value());
BOOST_TEST_EQ(*e, 15);
e = fun(false).then(if_valued(add_five)).then(if_valued(add_five));
BOOST_TEST_THROWS(e.value(), test_exception);
BOOST_TEST_THROWS(fun(true).then(if_valued(launch_except)), test_exception);
e = fun(false).then(catch_all(then_launch_except));
BOOST_TEST_THROWS(e.value(), test_exception);
}
void expected_void_then()
{
auto fun = [](bool b) -> expected_sc<void>
{
if (b)
return stde::make_expected();
else
return stde::make_unexpected(test_exception());
};
auto launch_except = []()
{
throw test_exception();
};
auto do_nothing = []() {};
BOOST_TEST(true);
expected_sc<void> e = fun(true).then(if_valued(do_nothing));
BOOST_TEST_NO_THROW(e.value());
e = fun(false).then(if_valued(do_nothing));
BOOST_TEST_THROWS(e.value(), test_exception);
BOOST_TEST_THROWS(fun(true).then(if_valued(launch_except)), test_exception);
}
BOOST_AUTO_TEST_SUITE_END()
BOOST_AUTO_TEST_SUITE(expected_recover)
void expected_recover()
{
auto fun = [](bool b)
{
if (b)
return expected_sc<int>(5);
else
return expected_sc<int>(stde::make_unexpected(test_exception()));
};
auto add_five = [](int sum) -> expected_sc<int>
{
return stde::make_expected(sum + 5);
};
auto recover_error = [](std::exception_ptr p)
{
return stde::make_expected(0);
};
auto recover_error_silent_failure = [](std::exception_ptr p)
{
return expected_sc<int>(stde::make_unexpected(p));
};
auto recover_error_failure = [](std::exception_ptr p) -> expected_sc<int>
{
return expected_sc<int>(stde::make_unexpected(test_exception()));
};
auto recover_error_throws = [](std::exception_ptr p) -> expected_sc<int>
{
throw test_exception();
};
BOOST_TEST_EQ(fun(false).catch_error(recover_error).has_value(), true);
BOOST_TEST_EQ(fun(false).catch_error(recover_error).value(), 0);
BOOST_TEST_EQ(fun(true).catch_error(recover_error).value(), 5);
BOOST_TEST_EQ(fun(false).catch_error(recover_error_silent_failure).has_value(), false);
BOOST_TEST_EQ(fun(false).catch_error(recover_error_failure).has_value(), false);
BOOST_TEST_EQ(fun(true).bind(add_five).value(), 10);
BOOST_TEST_EQ(fun(true).bind(add_five).catch_error(recover_error).value(), 10);
BOOST_TEST_EQ(fun(true).bind(add_five).catch_error(recover_error_silent_failure).value(), 10);
BOOST_TEST_EQ(fun(true).bind(add_five).catch_error(recover_error_failure).value(), 10);
BOOST_TEST_EQ(fun(false).catch_error(recover_error).bind(add_five).value(), 5);
BOOST_TEST_EQ(fun(false).catch_error(recover_error).bind(add_five).bind(add_five).value(), 10);
BOOST_TEST_EQ(fun(false).catch_error(recover_error_failure).bind(add_five).has_value(), false);
BOOST_TEST_EQ(fun(false).bind(add_five).catch_error(recover_error_failure).bind(add_five).has_value(), false);
BOOST_TEST_EQ(fun(false).bind(add_five).catch_error(recover_error_silent_failure).bind(add_five).has_value(), false);
BOOST_TEST_THROWS(fun(false).catch_error(recover_error_throws), test_exception);
}
void expected_void_recover()
{
auto fun = [](bool b)
{
if (b)
return stde::make_expected();
else
return expected_sc<void>(boost::stde::make_unexpected(test_exception()));
};
auto do_nothing = []() {
return stde::make_expected();
};
auto recover_error = [](std::exception_ptr p)
{
return stde::make_expected();
};
auto recover_error_silent_failure = [](std::exception_ptr p)
{
return expected_sc<void>(boost::stde::make_unexpected(p));
};
auto recover_error_failure = [](std::exception_ptr p) -> expected_sc<void>
{
throw test_exception();
};
// The catch_error doesn't alter the stde::expected if it's valid.
BOOST_TEST_EQ(fun(true).catch_error(recover_error_failure).has_value(), true);
// Simple catch_error tests.
BOOST_TEST_EQ(fun(false).catch_error(recover_error).has_value(), true);
BOOST_TEST_THROWS(fun(false).catch_error(recover_error_failure), test_exception);
BOOST_TEST_EQ(fun(false).catch_error(recover_error_silent_failure).has_value(), false);
// With a bind between.
BOOST_TEST_THROWS(fun(false).bind(do_nothing).catch_error(recover_error_failure), test_exception);
}
BOOST_AUTO_TEST_SUITE_END()
BOOST_AUTO_TEST_SUITE(proposal)
void proposal_concept()
{
using namespace std;
{
stde::expected<int, string> ei = 0;
stde::expected<int, string> ej = 1;
stde::expected<int, string> ek = stde::make_unexpected(string());
ei = 1;
ej = stde::make_unexpected(string());;
ek = 0;
ei = stde::make_unexpected(string());;
ej = 0;
ek = 1;
}
}
void proposal_init()
{
using namespace std;
{
string s{ "STR" };
stde::expected<string, int> ep{ stde::make_unexpected(-1) }; // unexpected value, requires Movable<E>
stde::expected<string, int> eq = { stde::make_unexpected(-1) }; // unexpected value, requires Movable<E>
expected_sc<string> es{ s }; // requires Copyable<T>
expected_sc<string> et = s; // requires Copyable<T>
expected_sc<string> ev = string{ "STR" }; // requires Movable<T>
expected_sc<string> ew; // unexpected value
expected_sc<string> ex{}; // unexpected value
expected_sc<string> ey = {}; // unexpected value
expected_sc<string> ez = expected_sc<string>{}; // unexpected value
}
{
stde::expected<Guard, int> eg; // unexpected value
stde::expected<Guard, int> eh{}; // unexpected value
stde::expected<Guard, int> ei{ stde::in_place }; // calls Guard{} in place
stde::expected<Guard, int> ej{ stde::in_place, "arg" }; // calls Guard{"arg"} in place
}
{
stde::expected<int, string> ei{ unexpect }; // unexpected value, calls string{} in place
stde::expected<int, string> ej{ unexpect, "arg" }; // unexpected value, calls string{"arg"} in place
}
}
void proposal_make_unexpected_fact()
{
using namespace std;
{
stde::expected<string, int> opt1 = stde::make_unexpected(1);
stde::expected<string, int> opt2 = { unexpect, 1 };
opt1 = stde::make_unexpected(1);
opt2 = { unexpect, 1 };
}
}
void proposal_error_exception_ts()
{
using namespace std;
{
stde::expected<int, error_exception<std::error_code, std::system_error> > e =
stde::make_unexpected(make_error_code(errc::invalid_argument));
#if !defined BOOST_MSVC || BOOST_MSVC >= 1900
BOOST_TEST(e.error() == make_error_code(errc::invalid_argument));
#else
// VS2013 doesn't match operator==(boost::error_exception<std::error_code,std::system_error>, std::error_code)
BOOST_TEST(e.error() == (error_exception<std::error_code, std::system_error>(make_error_code(errc::invalid_argument))));
#endif
try {
e.value();
BOOST_TEST(false);
}
catch (std::system_error const& ex) {
}
catch (...) {
BOOST_TEST(false);
}
stde::expected<int, error_exception<std::error_code, std::system_error> > e2 = stde::make_unexpected(e.error());
#if !defined BOOST_MSVC || BOOST_MSVC >= 1900
BOOST_TEST(e2.error() == make_error_code(errc::invalid_argument));
#else
// VS2013 doesn't match operator==(boost::error_exception<std::error_code,std::system_error>, std::error_code)
BOOST_TEST(e2.error() == (error_exception<std::error_code, std::system_error>(make_error_code(errc::invalid_argument))));
#endif
try {
e2.value();
BOOST_TEST(false);
}
catch (std::system_error const& ex) {
}
catch (...) {
BOOST_TEST(false);
}
}
}
void proposal_ensured_read_ts()
{
using namespace std;
{
ensured_read<int> e = make_ensured_read(1);
BOOST_TEST(e == 1);
}
{
ensured_read<int> e = make_ensured_read(1);
stde::unexpected<ensured_read<int>> ue1 = stde::make_unexpected(std::move(e));
BOOST_TEST(ue1.value() == 1);
}
// {
// stde::make_unexpected(make_ensured_read(1));
// // calls to terminate.
// }
// {
// stde::expected<int, ensured_read<int> > e = stde::make_unexpected(make_ensured_read(1));
// // calls to terminate.
// }
{
stde::expected<int, ensured_read<int> > e{ 1 };
BOOST_TEST(e.value() == 1);
}
{
stde::expected<int, ensured_read<int> > e = stde::make_unexpected(make_ensured_read(1));
BOOST_TEST(e.error() == 1);
}
{
stde::expected<int, ensured_read<int> > e{ unexpect, 1 };
BOOST_TEST(e.error() == 1);
}
{
ensured_read<std::exception_ptr> e = make_ensured_read(std::make_exception_ptr(1));
BOOST_TEST_THROWS(std::rethrow_exception(e.value()), int);
}
{
stde::expected<int, ensured_read<std::exception_ptr> > e = stde::make_unexpected(make_ensured_read(std::make_exception_ptr(1)));
BOOST_TEST_THROWS(std::rethrow_exception(e.error().value()), int);
}
}
void proposal_relational_operators()
{
using namespace std;
{
stde::expected<unsigned, int> e0{ 0 };
stde::expected<unsigned, int> e1{ 1 };
stde::expected<unsigned, int> eN{ unexpect, -1 };
BOOST_TEST(eN < e0);
BOOST_TEST(e0 < e1);
BOOST_TEST(!(e0 < eN));
BOOST_TEST(eN <= e0);
BOOST_TEST(e0 <= e1);
BOOST_TEST(e0 > eN);
BOOST_TEST(e1 > e0);
BOOST_TEST(e0 >= eN);
BOOST_TEST(e1 >= e0);
BOOST_TEST(!(eN < eN));
BOOST_TEST(!(e1 < e1));
BOOST_TEST(eN <= eN);
BOOST_TEST(e1 <= e1);
BOOST_TEST(eN != e0);
BOOST_TEST(e0 != e1);
BOOST_TEST(eN == eN);
BOOST_TEST(e0 == e0);
//////
BOOST_TEST(eN == stde::make_unexpected(-1));
BOOST_TEST(e0 != stde::make_unexpected(1));
BOOST_TEST(eN != 1u);
BOOST_TEST(e1 == 1u);
BOOST_TEST(eN < 1u);
BOOST_TEST(eN <= 1u);
BOOST_TEST(1u > eN);
BOOST_TEST(!(1u < eN));
BOOST_TEST(1u >= eN);
BOOST_TEST(stde::make_unexpected(1) < e0);
BOOST_TEST(stde::make_unexpected(1) <= e0);
BOOST_TEST(!(stde::make_unexpected(1) > e0));
BOOST_TEST(!(stde::make_unexpected(1) >= e0));
BOOST_TEST(!(e0 < stde::make_unexpected(1)));
BOOST_TEST(!(e0 <= stde::make_unexpected(1)));
BOOST_TEST(e0 > stde::make_unexpected(1));
BOOST_TEST(e0 >= stde::make_unexpected(1));
}
{
stde::expected<void, int> e0{ boost::expect };
stde::expected<void, int> eN{ unexpect, -1 };
BOOST_TEST(!(e0 < e0));
BOOST_TEST(eN < e0);
BOOST_TEST(!(e0 < eN));
BOOST_TEST(!(eN < eN));
BOOST_TEST(e0 <= e0);
BOOST_TEST(eN <= e0);
BOOST_TEST(!(e0 <= eN));
BOOST_TEST(eN <= eN);
BOOST_TEST(!(e0 > e0));
BOOST_TEST(e0 > eN);
BOOST_TEST(!(eN > e0));
BOOST_TEST(!(eN > eN));
BOOST_TEST(e0 >= e0);
BOOST_TEST(e0 >= eN);
BOOST_TEST(!(eN >= e0));
BOOST_TEST(eN >= eN);
BOOST_TEST(!(e0 != e0));
BOOST_TEST(eN != e0);
BOOST_TEST(e0 != eN);
BOOST_TEST(!(eN != eN));
BOOST_TEST(e0 == e0);
BOOST_TEST(!(eN == e0));
BOOST_TEST(!(e0 == eN));
BOOST_TEST(eN == eN);
//////
BOOST_TEST(eN == stde::make_unexpected(-1));
BOOST_TEST(e0 != stde::make_unexpected(1));
BOOST_TEST(stde::make_unexpected(1) < e0);
BOOST_TEST(stde::make_unexpected(1) <= e0);
BOOST_TEST(!(stde::make_unexpected(1) > e0));
BOOST_TEST(!(stde::make_unexpected(1) >= e0));
BOOST_TEST(!(stde::make_unexpected(1) < eN));
BOOST_TEST(!(stde::make_unexpected(1) <= eN));
BOOST_TEST(stde::make_unexpected(1) > eN);
BOOST_TEST(stde::make_unexpected(1) >= eN);
BOOST_TEST(!(eN < stde::make_unexpected(-1)));
BOOST_TEST(eN <= stde::make_unexpected(-1));
BOOST_TEST(!(eN > stde::make_unexpected(-1)));
BOOST_TEST(eN >= stde::make_unexpected(-1));
}
}
void proposal_dereference_operators()
{
using namespace std;
{
const string s{ "STR" };
expected_sc<string> e0{ s };
const expected_sc<string> e1{ s };
BOOST_TEST(*e0.operator->() == s);
BOOST_TEST(*e1.operator->() == s);
// Test with class which has operator&() overloaded
const OverloadedAddressOf o{};
BOOST_TEST(&o == nullptr);
expected_sc<OverloadedAddressOf> e2{ o };
const expected_sc<OverloadedAddressOf> e3{ o };
BOOST_TEST(e2.operator->() != nullptr);
BOOST_TEST(e3.operator->() != nullptr);
}
}
BOOST_AUTO_TEST_SUITE_END()
BOOST_AUTO_TEST_SUITE(movesem)
//////////////////////////////
void movesem_moved_from_state()
{
// first, test mock:
MoveAware<int> i{ 1 }, j{ 2 };
BOOST_TEST(i.val == 1);
BOOST_TEST(!i.moved);
BOOST_TEST(j.val == 2);
BOOST_TEST(!j.moved);
MoveAware<int> k = std::move(i);
BOOST_TEST(k.val == 1);
BOOST_TEST(!k.moved);
BOOST_TEST(i.val == 1);
BOOST_TEST(i.moved);
k = std::move(j);
BOOST_TEST(k.val == 2);
BOOST_TEST(!k.moved);
BOOST_TEST(j.val == 2);
BOOST_TEST(j.moved);
// now, test stde::expected
expected_sc<MoveAware<int>> oi{ 1 }, oj{ 2 };
BOOST_TEST(oi);
BOOST_TEST(!oi->moved);
BOOST_TEST(oj);
BOOST_TEST(!oj->moved);
expected_sc<MoveAware<int>> ok{ std::move(oi) };
BOOST_TEST(ok);
BOOST_TEST(!ok->moved);
BOOST_TEST(oi);
BOOST_TEST(oi->moved);
ok = std::move(oj);
BOOST_TEST(ok);
BOOST_TEST(!ok->moved);
BOOST_TEST(oj);
BOOST_TEST(oj->moved);
}
void movesem_move_only_value()
{
const auto make_int = []() {
std::unique_ptr<int> value{ new int };
*value = 100;
return value;
};
const auto return_void = [](std::unique_ptr<int> value) {
BOOST_TEST(value != nullptr);
BOOST_TEST(*value == 100);
};
const auto return_expected = [](std::unique_ptr<int> value) {
BOOST_TEST(value != nullptr);
BOOST_TEST(*value == 100);
return expected_sc<void>{boost::expect};
};
const auto return_int = [](std::unique_ptr<int> value) {
BOOST_TEST(value != nullptr);
BOOST_TEST(*value == 100);
return 200;
};
BOOST_TEST(expected<std::unique_ptr<int>>{make_int()}.map(return_void));
BOOST_TEST(expected<std::unique_ptr<int>>{make_int()}.map(return_expected));
BOOST_TEST(expected<std::unique_ptr<int>>{make_int()}.map(return_int));
}
void movesem_move_only_value2()
{
const auto make_int = []() {
std::unique_ptr<int> value{ new int };
*value = 100;
return value;
};
const auto return_expected_void = [](std::unique_ptr<int> value) {
BOOST_TEST(value != nullptr);
BOOST_TEST(*value == 100);
return stde::make_expected();
};
const auto return_expected = [](std::unique_ptr<int> value) {
BOOST_TEST(value != nullptr);
BOOST_TEST(*value == 100);
return expected_sc<void>{boost::expect};
};
BOOST_TEST(expected<std::unique_ptr<int>>{make_int()}.bind(return_expected_void));
BOOST_TEST(expected<std::unique_ptr<int>>{make_int()}.bind(return_expected));
}
void movesem_copy_move_ctor_optional_int()
{
expected_sc<int> oi;
expected_sc<int> oj = oi;
BOOST_TEST(oj);
BOOST_TEST(oj == oi);
BOOST_TEST(bool(oj));
oi = 1;
expected_sc<int> ok = oi;
BOOST_TEST(!!ok);
BOOST_TEST(bool(ok));
BOOST_TEST(ok == oi);
BOOST_TEST(ok != oj);
BOOST_TEST(*ok == 1);
expected_sc<int> ol = std::move(oi);
BOOST_TEST(!!ol);
BOOST_TEST(bool(ol));
BOOST_TEST(ol == oi);
BOOST_TEST(ol != oj);
BOOST_TEST(*ol == 1);
}
void movesem_expected_expected()
{
expected_sc<stde::expected<int, int>> oi1 = stde::make_unexpected(-1);
BOOST_TEST(!oi1);
{
expected_sc<expected_sc<int>> oi2{ stde::expect };
BOOST_TEST(bool(oi2));
BOOST_TEST((*oi2));
//std::cout << typeid(**oi2).name() << std::endl;
}
{
expected_sc<stde::expected<int, int>> oi2{ stde::expect, stde::make_unexpected(-1) };
BOOST_TEST(bool(oi2));
BOOST_TEST(!*oi2);
}
{
stde::expected<stde::expected<int>> oi2{ stde::expected<int>{} };
BOOST_TEST(bool(oi2));
BOOST_TEST(*oi2);
}
stde::expected<int> oi;
auto ooi = stde::make_expected(oi);
static_assert(std::is_same<expected<expected<int>>, decltype(ooi)>::value, "");
}
BOOST_AUTO_TEST_SUITE_END()
void process() {}
void process(int) {}
void processNil() {}
BOOST_AUTO_TEST_SUITE(Examples)
//////////////////////////////
void example1()
{
stde::expected<int> oi; // create disengaged object
stde::expected<int> oj = { unexpect }; // alternative syntax
oi = oj; // assign disengaged object
stde::expected<int> ok = oj; // ok is disengaged
if (oi) BOOST_TEST(false); // 'if oi is engaged...'
if (!oi) BOOST_TEST(true); // 'if oi is disengaged...'
BOOST_TEST(oi == ok); // two disengaged optionals compare equal
///////////////////////////////////////////////////////////////////////////
stde::expected<int> ol{ 1 }; // ol is engaged; its contained value is 1
ok = 2; // ok becomes engaged; its contained value is 2
oj = ol; // oj becomes engaged; its contained value is 1
BOOST_TEST(oi != ol); // disengaged != engaged
BOOST_TEST(ok != ol); // different contained values
BOOST_TEST(oj == ol); // same contained value
//BOOST_TEST(oi < ol); // disengaged < engaged
//BOOST_TEST(ol < ok); // less by contained value
/////////////////////////////////////////////////////////////////////////////
stde::expected<int> om{ 1 }; // om is engaged; its contained value is 1
stde::expected<int> on = om; // on is engaged; its contained value is 1
om = 2; // om is engaged; its contained value is 2
BOOST_TEST(on != om); // on still contains 3. They are not pointers
/////////////////////////////////////////////////////////////////////////////
int i = *ol; // i obtains the value contained in ol
BOOST_TEST(i == 1);
*ol = 9; // the object contained in ol becomes 9
BOOST_TEST(*ol == 9);
BOOST_TEST(ol == stde::make_expected(9));
///////////////////////////////////
int p = 1;
stde::expected<int> op = p;
BOOST_TEST(*op == 1);
p = 2;
BOOST_TEST(*op == 1); // value contained in op is separated from p
////////////////////////////////
if (ol)
process(*ol); // use contained value if present
else
process(); // proceed without contained value
if (!om)
processNil();
else
process(*om);
/////////////////////////////////////////
process(ol.value_or(0)); // use 0 if ol is disengaged
////////////////////////////////////////////
ok = { unexpect }; // if ok was engaged calls T's dtor
oj = {}; // assigns a temporary disengaged stde::expected
}
//////////////////////////////////////////////////
void ValueOr()
{
stde::expected<int> oi = 1;
int i = oi.value_or(0);
BOOST_TEST(i == 1);
oi = { unexpect };
BOOST_TEST(oi.value_or(3) == 3);
stde::expected<std::string> os{ "AAA" };
BOOST_TEST(os.value_or("BBB") == "AAA");
os = {};
BOOST_TEST(os);
BOOST_TEST(os.value() == "");
BOOST_TEST(os.value_or(std::string("BBB")) == "");
{
constexpr stde::expected<int> e = 1;
static_assert(e.has_value(), "");
static_assert(*e == 1, "");
static_assert(e.value() == 1, "");
}
{
constexpr std::error_code ec = std::make_error_code(std::errc(1));
constexpr stde::expected<int> e = stde::make_unexpected(ec);
static_assert(!e.has_value(), "");
static_assert(e.error() == ec, "");
}
{
constexpr stde::expected<OracleVal> e = 1;
static_assert(e.has_value(), "");
static_assert(*e == 1, "");
static_assert(e.value() == 1, "");
}
{
constexpr std::error_code ec = std::make_error_code(std::errc(1));
constexpr stde::expected<OracleVal> e = stde::make_unexpected(ec);
static_assert(!e.has_value(), "");
static_assert(e.error() == ec, "");
}
}
//////////////////////////////////////////////////
BOOST_AUTO_TEST_SUITE_END()
#endif
#else
int main(void)
{
return 0;
}
#endif
|
0 | repos/outcome/test | repos/outcome/test/tests/fileopen.cpp | /* Unit testing for outcomes
(C) 2013-2019 Niall Douglas <http://www.nedproductions.biz/> (7 commits)
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License in the accompanying file
Licence.txt or at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Distributed under the Boost Software License, Version 1.0.
(See accompanying file Licence.txt or copy at
http://www.boost.org/LICENSE_1_0.txt)
*/
#define _CRT_SECURE_NO_WARNINGS
#include "../../include/outcome.hpp"
#include "quickcpplib/boost/test/unit_test.hpp"
#ifdef __cpp_exceptions
#ifdef _MSC_VER
#define OUTCOME_POSIX_OPEN ::_open
#include <io.h>
#else
#define OUTCOME_POSIX_OPEN ::open
#include <fcntl.h>
#endif
BOOST_OUTCOME_AUTO_TEST_CASE(works / outcome / fileopen, "Tests that the outcome semantically represents opening a file")
{
using namespace OUTCOME_V2_NAMESPACE;
//! [file_open_example]
auto openfile = [](std::string path) noexcept->outcome<int>
{
int fd;
do
{
fd = OUTCOME_POSIX_OPEN(path.c_str(), 0); // NOLINT
} while(-1 == fd && EINTR == errno);
try
{
if(-1 == fd)
{
int code = errno;
// If a temporary failure, this is an expected unexpected outcome
if(EBUSY == code || EISDIR == code || ELOOP == code || ENOENT == code || ENOTDIR == code || EPERM == code || EACCES == code)
{
return std::error_code(code, std::generic_category());
}
// If a non-temporary failure, this is an unexpected outcome
return std::make_exception_ptr(std::system_error(code, std::generic_category(), strerror(code)));
}
return fd;
}
catch(...)
{
// Any exception thrown is truly unexpected
return std::current_exception();
}
};
auto a = openfile("shouldneverexistnotever");
BOOST_CHECK(!a);
BOOST_CHECK(!a.has_value());
BOOST_CHECK(!a.has_exception());
BOOST_CHECK(a.has_error());
BOOST_CHECK(a.error() == std::error_code(ENOENT, std::generic_category()));
//! [file_open_example]
}
#endif
|
0 | repos/outcome/test | repos/outcome/test/tests/issue0247.cpp | /* Unit testing for outcomes
(C) 2013-2021 Niall Douglas <http://www.nedproductions.biz/> (1 commit)
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License in the accompanying file
Licence.txt or at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Distributed under the Boost Software License, Version 1.0.
(See accompanying file Licence.txt or copy at
http://www.boost.org/LICENSE_1_0.txt)
*/
#include "../../include/outcome/outcome.hpp"
#include "../../include/outcome/try.hpp"
#include "quickcpplib/boost/test/unit_test.hpp"
namespace issues247
{
namespace outcome = OUTCOME_V2_NAMESPACE;
outcome::result<int> foo1()
{
outcome::result<int> ret(std::errc::invalid_argument);
outcome::hooks::set_spare_storage(&ret, 43);
return ret;
}
outcome::result<int> test1()
{
OUTCOME_TRY(foo1());
return 7;
}
outcome::result<int> foo2() { return outcome::success(5, 43); }
outcome::result<int> test2() { return foo2(); }
outcome::outcome<int> foo3()
{
outcome::outcome<int> ret(std::make_exception_ptr(std::runtime_error("foo")));
outcome::hooks::set_spare_storage(&ret, 43);
return ret;
}
outcome::outcome<int> test3()
{
OUTCOME_TRY(foo3());
return 7;
}
} // namespace issues247
BOOST_OUTCOME_AUTO_TEST_CASE(issues / 0247 / test, "TRY strips spare storage value")
{
auto r1 = issues247::test1();
BOOST_CHECK(issues247::outcome::hooks::spare_storage(&r1) == 43);
auto r2 = issues247::test2();
BOOST_CHECK(issues247::outcome::hooks::spare_storage(&r2) == 43);
auto r3 = issues247::test3();
BOOST_CHECK(issues247::outcome::hooks::spare_storage(&r3) == 43);
}
|
0 | repos/outcome/test | repos/outcome/test/tests/default-construction.cpp | /* Unit testing for outcomes
(C) 2013-2019 Niall Douglas <http://www.nedproductions.biz/> (4 commits)
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License in the accompanying file
Licence.txt or at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Distributed under the Boost Software License, Version 1.0.
(See accompanying file Licence.txt or copy at
http://www.boost.org/LICENSE_1_0.txt)
*/
#include "../../include/outcome.hpp"
#include "quickcpplib/boost/test/unit_test.hpp"
BOOST_OUTCOME_AUTO_TEST_CASE(works / outcome / default_construction, "Tests that outcome default constructs when it ought to")
{
using namespace OUTCOME_V2_NAMESPACE;
struct udt
{
int _v{78};
udt() = default;
constexpr explicit udt(int v) noexcept : _v(v) {}
udt(udt &&o) = delete;
udt(const udt &) = delete;
udt &operator=(udt &&o) = delete;
udt &operator=(const udt &) = delete;
~udt() = default;
constexpr int operator*() const noexcept { return _v; }
};
// One path is via success_type<void>
outcome<udt> a(success());
BOOST_CHECK(*a.value() == 78);
// Other path is via empty initialiser list
outcome<udt> d({});
BOOST_CHECK(*d.value() == 78);
}
|
0 | repos/outcome/test | repos/outcome/test/tests/udts.cpp | /* Unit testing for outcomes
(C) 2013-2019 Niall Douglas <http://www.nedproductions.biz/> (7 commits)
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License in the accompanying file
Licence.txt or at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Distributed under the Boost Software License, Version 1.0.
(See accompanying file Licence.txt or copy at
http://www.boost.org/LICENSE_1_0.txt)
*/
#ifdef _MSC_VER
#pragma warning(disable : 4702) // unreachable code
#endif
#include "../../include/outcome.hpp"
#include "quickcpplib/boost/test/unit_test.hpp"
BOOST_OUTCOME_AUTO_TEST_CASE(works / outcome / udts, "Tests that the outcome works as intended with user-defined types")
{
using namespace OUTCOME_V2_NAMESPACE;
// No default constructor, no copy/move, no assignment
{
struct udt
{
int a;
explicit udt(int _a)
: a(_a)
{
}
udt() = delete;
udt(const udt &) = delete;
udt(udt &&) = delete;
udt &operator=(const udt &) = delete;
udt &operator=(udt &&) = delete;
~udt() = default;
};
outcome<udt> foo(in_place_type<udt>, 5);
BOOST_CHECK(5 == foo.value().a);
}
#ifdef __cpp_exceptions
// Emplace construct, throws during move and copy
{
struct udt
{
std::string a;
explicit udt(std::string _a)
: a(std::move(_a))
{
}
udt() = delete;
udt(const udt & /*unused*/) { throw std::logic_error("copy"); }
udt(udt && /*unused*/) noexcept(false) { throw std::logic_error("move"); } // NOLINT
udt &operator=(const udt & /*unused*/) { throw std::logic_error("copy"); }
udt &operator=(udt && /*unused*/) noexcept(false) { throw std::logic_error("move"); } // NOLINT
~udt() { a.clear(); }
};
static_assert(!std::is_default_constructible<udt>::value, "udt is default constructible");
static_assert(std::is_copy_constructible<udt>::value, "udt is not copy constructible");
static_assert(std::is_move_constructible<udt>::value, "udt is not move constructible");
static_assert(!std::is_default_constructible<outcome<udt>>::value, "outcome<udt> is default constructible");
static_assert(std::is_copy_constructible<outcome<udt>>::value, "outcome<udt> is not copy constructible");
static_assert(std::is_move_constructible<outcome<udt>>::value, "outcome<udt> is not move constructible");
// Emplace constructs
outcome<udt> foo(in_place_type<udt>, "niall");
BOOST_CHECK("niall" == foo.value().a);
try
{
auto foo2(foo); // NOLINT
BOOST_CHECK(false);
}
catch(const std::logic_error &e)
{
BOOST_CHECK(!strcmp(e.what(), "copy"));
}
catch(...)
{
BOOST_CHECK(false);
}
BOOST_CHECK("niall" == foo.value().a);
try
{
auto foo2(std::move(foo));
BOOST_CHECK(false);
}
catch(const std::logic_error &e)
{
BOOST_CHECK(!strcmp(e.what(), "move"));
}
catch(...)
{
BOOST_CHECK(false);
}
BOOST_CHECK("niall" == foo.value().a); // NOLINT
// Does throwing during copy assignment work?
{
outcome<udt> foo2(in_place_type<udt>, "douglas");
try
{
foo2 = foo;
BOOST_CHECK(false);
}
catch(const std::logic_error &e)
{
BOOST_CHECK(!strcmp(e.what(), "copy"));
BOOST_CHECK(foo2.value().a == "douglas");
}
catch(...)
{
BOOST_CHECK(false);
}
BOOST_CHECK("niall" == foo.value().a);
}
// Does throwing during move assignment work?
{
outcome<udt> foo2(in_place_type<udt>, "douglas");
try
{
foo2 = std::move(foo);
BOOST_CHECK(false);
}
catch(const std::logic_error &e)
{
BOOST_CHECK(!strcmp(e.what(), "move"));
BOOST_CHECK(foo2.value().a == "douglas");
}
catch(...)
{
BOOST_CHECK(false);
}
BOOST_CHECK("niall" == foo.value().a); // NOLINT
}
}
#endif
}
|
0 | repos/outcome/test | repos/outcome/test/tests/core-result.cpp | /* Unit testing for outcomes
(C) 2013-2019 Niall Douglas <http://www.nedproductions.biz/> (30 commits)
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License in the accompanying file
Licence.txt or at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Distributed under the Boost Software License, Version 1.0.
(See accompanying file Licence.txt or copy at
http://www.boost.org/LICENSE_1_0.txt)
*/
#define OUTCOME_USE_STD_ADDRESSOF 1
#ifdef TESTING_WG21_EXPERIMENTAL_RESULT
#include "../../include/outcome/experimental/result.hpp"
#define BOOST_OUTCOME_AUTO_TEST_CASE(...) BOOST_AUTO_TEST_CASE(__VA_ARGS__)
#else
#include "../../include/outcome/result.hpp"
#endif
#include "quickcpplib/boost/test/unit_test.hpp"
#include <iostream>
#ifdef __cpp_exceptions
// Custom error type with payload
struct payload
{
std::error_code ec;
const char *str{nullptr};
payload() = default;
payload(std::errc _ec, const char *_str)
: ec(make_error_code(_ec))
, str(_str)
{
}
};
struct payload_exception : std::runtime_error
{
explicit payload_exception(const char *what)
: std::runtime_error(what)
{
}
};
inline const std::error_code &make_error_code(const payload &p)
{
return p.ec;
}
inline void outcome_throw_as_system_error_with_payload(const payload &p)
{
throw payload_exception(p.str);
}
#endif
BOOST_OUTCOME_AUTO_TEST_CASE(works / result, "Tests that the result works as intended")
{
#ifdef TESTING_WG21_EXPERIMENTAL_RESULT
using namespace std::experimental;
using std::in_place_type;
#else
using namespace OUTCOME_V2_NAMESPACE;
#endif
static_assert(std::is_constructible<result<long>, int>::value, "Sanity check that monad can be constructed from a value_type");
static_assert(!std::is_constructible<result<result<long>>, int>::value, "Sanity check that outer monad can be constructed from an inner monad's value_type");
#if defined(__clang__) || !defined(__GNUC__) || __GNUC__ >= 9 // GCCs before 9 barf on this
static_assert(!std::is_constructible<result<result<result<long>>>, int>::value, "Sanity check that outer monad can be constructed from an inner inner monad's value_type");
static_assert(!std::is_constructible<result<result<result<result<long>>>>, int>::value, "Sanity check that outer monad can be constructed from an inner inner monad's value_type");
#endif
static_assert(std::is_constructible<result<int>, result<long>>::value, "Sanity check that compatible monads can be constructed from one another");
static_assert(std::is_constructible<result<result<int>>, result<long>>::value, "Sanity check that outer monad can be constructed from a compatible monad");
#if defined(__clang__) || !defined(__GNUC__) || __GNUC__ >= 9 // GCCs before 9 barf on this
static_assert(!std::is_constructible<result<result<result<int>>>, result<long>>::value, "Sanity check that outer monad can be constructed from a compatible monad up to two nestings deep");
static_assert(!std::is_constructible<result<result<result<result<int>>>>, result<long>>::value, "Sanity check that outer monad can be constructed from a compatible monad three or more nestings deep");
#endif
static_assert(!std::is_constructible<result<std::string>, result<int>>::value, "Sanity check that incompatible monads cannot be constructed from one another");
#ifndef TESTING_WG21_EXPERIMENTAL_RESULT
static_assert(std::is_constructible<result<int>, result<void>>::value, "Sanity check that all monads can be constructed from a void monad");
static_assert(std::is_constructible<result<result<int>>, result<void>>::value, "Sanity check that outer monad can be constructed from a compatible monad");
#if defined(__clang__) || !defined(__GNUC__) || __GNUC__ >= 9 // GCCs before 9 barf on this
static_assert(std::is_constructible<result<result<result<int>>>, result<void>>::value, "Sanity check that outer monad can be constructed from a compatible monad up to two nestings deep");
#endif
static_assert(!std::is_constructible<result<void>, result<int>>::value, "Sanity check that incompatible monads cannot be constructed from one another");
#endif
static_assert(std::is_void<result<void>::value_type>::value, "Sanity check that result<void> has a void value_type");
#ifndef TESTING_WG21_EXPERIMENTAL_RESULT
static_assert(std::is_void<result<void, void>::error_type>::value, "Sanity check that result<void, void> has a void error_type");
#endif
static_assert(std::is_same<result<int>::value_type, int>::value, "Sanity check that result<int> has a int value_type");
static_assert(std::is_same<result<int>::error_type, std::error_code>::value, "Sanity check that result<int> has a error_code error_type");
{ // errored int
result<int> m(std::errc::bad_address);
BOOST_CHECK(!m);
BOOST_CHECK(!m.has_value());
BOOST_CHECK(m.has_error());
// BOOST_CHECK(!m.has_exception());
BOOST_CHECK_THROW(m.value(), std::system_error);
BOOST_CHECK_NO_THROW(m.error());
}
{ // errored void
result<void> m(std::errc::bad_address);
BOOST_CHECK(!m);
BOOST_CHECK(!m.has_value());
BOOST_CHECK(m.has_error());
// BOOST_CHECK(!m.has_exception());
#ifndef TESTING_WG21_EXPERIMENTAL_RESULT
BOOST_CHECK_THROW(([&m]() -> void { return m.value(); }()), std::system_error);
#endif
BOOST_CHECK_NO_THROW(m.error());
}
{ // valued int
result<int> m(5);
BOOST_CHECK(m);
BOOST_CHECK(m.has_value());
BOOST_CHECK(!m.has_error());
// BOOST_CHECK(!m.has_exception());
BOOST_CHECK(m.value() == 5);
m.value() = 6;
BOOST_CHECK(m.value() == 6);
BOOST_CHECK_THROW(m.error(), bad_result_access);
}
{ // valued bool
result<bool> m(false);
BOOST_CHECK(m);
BOOST_CHECK(m.has_value());
BOOST_CHECK(!m.has_error());
// BOOST_CHECK(!m.has_exception());
BOOST_CHECK(m.value() == false);
m.value() = true;
BOOST_CHECK(m.value() == true);
BOOST_CHECK_THROW(m.error(), bad_result_access);
}
{ // moves do not clear state
result<std::string> m("niall");
BOOST_CHECK(m);
BOOST_CHECK(m.has_value());
BOOST_CHECK(!m.has_error());
// BOOST_CHECK(!m.has_exception());
BOOST_CHECK(m.value() == "niall");
m.value() = "NIALL";
BOOST_CHECK(m.value() == "NIALL");
auto temp(std::move(m).value());
BOOST_CHECK(temp == "NIALL");
BOOST_CHECK(m.value().empty()); // NOLINT
}
{ // valued void
result<void> m(in_place_type<void>);
BOOST_CHECK(m);
BOOST_CHECK(m.has_value());
BOOST_CHECK(!m.has_error());
// BOOST_CHECK(!m.has_exception());
BOOST_CHECK_NO_THROW(m.value()); // works, but type returned is unusable
BOOST_CHECK_THROW(m.error(), bad_result_access);
}
{ // errored
std::error_code ec(5, std::system_category());
result<int> m(ec);
BOOST_CHECK(!m);
BOOST_CHECK(!m.has_value());
BOOST_CHECK(m.has_error());
// BOOST_CHECK(!m.has_exception());
BOOST_CHECK_THROW(m.value(), std::system_error);
BOOST_CHECK(m.error() == ec);
}
#if !defined(__APPLE__) || defined(__cpp_exceptions)
{ // errored, custom
std::error_code ec(5, std::system_category());
auto e = std::make_exception_ptr(std::system_error(ec)); // NOLINT
result<int, std::exception_ptr> m(e);
BOOST_CHECK(!m);
BOOST_CHECK(!m.has_value());
BOOST_CHECK(m.has_error());
// BOOST_CHECK(!m.has_exception());
BOOST_CHECK_THROW(m.value(), std::system_error);
BOOST_CHECK(m.error() == e);
}
#endif
#ifndef TESTING_WG21_EXPERIMENTAL_RESULT
{ // custom error type
struct Foo
{
};
result<int, Foo> m(in_place_type<Foo>);
BOOST_CHECK(!m);
BOOST_CHECK(!m.has_value());
BOOST_CHECK(m.has_error());
// BOOST_CHECK(!m.has_exception());
// BOOST_CHECK_NO_THROW(m.value());
// BOOST_CHECK_NO_THROW(m.error());
}
if(false) // NOLINT
{ // void, void is permitted, but is not constructible
result<void, void> *m = nullptr;
m->value();
m->error();
}
#endif
{
// Deliberately define non-trivial operations
struct udt
{
int _v{0};
udt() = default;
udt(udt &&o) noexcept : _v(o._v) {}
udt(const udt &o) // NOLINT
: _v(o._v)
{
}
udt &operator=(udt &&o) noexcept
{
_v = o._v;
return *this;
}
udt &operator=(const udt &o) // NOLINT
{
_v = o._v;
return *this;
}
~udt() { _v = 0; }
};
// No default construction, no copy nor move
struct udt2
{
udt2() = delete;
udt2(udt2 &&) = delete;
udt2(const udt2 &) = delete;
udt2 &operator=(udt2 &&) = delete;
udt2 &operator=(const udt2 &) = delete;
explicit udt2(int /*unused*/) {}
~udt2() = default;
};
// Can only be constructed via multiple args
struct udt3
{
udt3() = delete;
udt3(udt3 &&) = delete;
udt3(const udt3 &) = delete;
udt3 &operator=(udt3 &&) = delete;
udt3 &operator=(const udt3 &) = delete;
explicit udt3(int /*unused*/, const char * /*unused*/, std::nullptr_t /*unused*/) {}
~udt3() = default;
};
// Trivial with custom operator&
struct udt4
{
int _v{0};
udt4() = default;
udt4(udt4 &&) = default;
udt4(const udt4 &) = default;
udt4 &operator=(udt4 &&) = default;
udt4 &operator=(const udt4 &) = default;
void operator&() {}
~udt4() = default;
};
// Non-trivial with custom operator&
struct udt5
{
int _v{0};
udt5() = default;
udt5(int v) : _v(v) {}
udt5(udt5 &&o) noexcept : _v(o._v) {}
udt5(const udt5 &o) // NOLINT
: _v(o._v)
{
}
udt5 &operator=(udt5 &&o) noexcept
{
_v = o._v;
return *this;
}
udt5 &operator=(const udt5 &o) // NOLINT
{
_v = o._v;
return *this;
}
void operator&() {}
~udt5() { _v = 0; }
};
result<int> a(5);
result<int> b(std::make_error_code(std::errc::invalid_argument));
std::cout << sizeof(a) << std::endl; // 32 bytes
if(false) // NOLINT
{
b.assume_value();
a.assume_error();
}
#ifdef __cpp_exceptions
try
{
b.value();
std::cerr << "fail" << std::endl;
std::terminate();
}
catch(const std::system_error & /*unused*/)
{
}
#endif
static_assert(!std::is_default_constructible<decltype(a)>::value, "");
static_assert(!std::is_nothrow_default_constructible<decltype(a)>::value, "");
static_assert(std::is_copy_constructible<decltype(a)>::value, "");
// Quality of implementation of std::optional is poor :(
#ifndef TESTING_WG21_EXPERIMENTAL_RESULT
static_assert(std::is_trivially_copy_constructible<decltype(a)>::value, "");
static_assert(std::is_nothrow_copy_constructible<decltype(a)>::value, "");
static_assert(std::is_copy_assignable<decltype(a)>::value, "");
static_assert(std::is_trivially_copy_assignable<decltype(a)>::value, "");
static_assert(std::is_nothrow_copy_assignable<decltype(a)>::value, "");
#endif
static_assert(std::is_trivially_destructible<decltype(a)>::value, "");
static_assert(std::is_nothrow_destructible<decltype(a)>::value, "");
// Test void compiles
result<void> c(in_place_type<void>);
result<void> c2(c);
(void) c2;
// Test a standard udt compiles
result<udt> d(in_place_type<udt>);
result<udt> d2(d);
static_assert(!std::is_default_constructible<decltype(d)>::value, "");
static_assert(!std::is_nothrow_default_constructible<decltype(d)>::value, "");
static_assert(std::is_copy_constructible<decltype(d)>::value, "");
static_assert(!std::is_trivially_copy_constructible<decltype(d)>::value, "");
static_assert(!std::is_nothrow_copy_constructible<decltype(d)>::value, "");
static_assert(std::is_copy_assignable<decltype(d)>::value, "");
static_assert(!std::is_trivially_copy_assignable<decltype(d)>::value, "");
static_assert(!std::is_nothrow_copy_assignable<decltype(d)>::value, "");
static_assert(std::is_move_assignable<decltype(d)>::value, "");
static_assert(!std::is_trivially_move_assignable<decltype(d)>::value, "");
static_assert(std::is_nothrow_move_assignable<decltype(d)>::value, "");
static_assert(!std::is_trivially_destructible<decltype(d)>::value, "");
static_assert(std::is_nothrow_destructible<decltype(d)>::value, "");
// Test a highly pathological udt compiles
result<udt2> e(in_place_type<udt2>, 5);
// result<udt2> e2(e);
static_assert(!std::is_default_constructible<decltype(e)>::value, "");
static_assert(!std::is_nothrow_default_constructible<decltype(e)>::value, "");
static_assert(!std::is_copy_constructible<decltype(e)>::value, "");
static_assert(!std::is_trivially_copy_constructible<decltype(e)>::value, "");
static_assert(!std::is_nothrow_copy_constructible<decltype(e)>::value, "");
static_assert(!std::is_copy_assignable<decltype(e)>::value, "");
static_assert(!std::is_trivially_copy_assignable<decltype(e)>::value, "");
static_assert(!std::is_nothrow_copy_assignable<decltype(e)>::value, "");
static_assert(!std::is_move_assignable<decltype(e)>::value, "");
static_assert(!std::is_trivially_move_assignable<decltype(e)>::value, "");
static_assert(!std::is_nothrow_move_assignable<decltype(e)>::value, "");
// Test a udt which can only be constructed in place compiles
result<udt3> g(in_place_type<udt3>, 5, static_cast<const char *>("niall"), nullptr);
// Does converting inplace construction also work?
result<udt3> h(5, static_cast<const char *>("niall"), nullptr);
result<udt3> i(ENOMEM, std::generic_category());
BOOST_CHECK(h.has_value());
BOOST_CHECK(i.has_error());
// Test udt with custom operator&
udt4 j0;
result<udt4> j1(in_place_type<udt4>);
result<udt4> j2(j0);
result<udt4> j3(j1);
result<udt4> j4(std::move(j0));
result<udt4> j5(std::move(j1));
(void) j3;
(void) j5;
j2 = j0;
j2 = j1;
j2 = std::move(j0);
j2 = std::move(j1);
j1.swap(j2);
udt5 k0;
result<udt5> k1(in_place_type<udt5>);
result<udt5> k2(k0);
result<udt5> k3(k1);
result<udt5> k4(std::move(k0));
result<udt5> k5(std::move(k1));
(void) k3;
(void) k5;
k2 = k0;
k2 = k1;
k2 = std::move(k0);
k2 = std::move(k1);
k1.swap(k2);
result<void> k6(in_place_type<void>);
result<udt5> k7(k6);
result<udt5> k8(std::move(k6));
result<int, void> k9(in_place_type<int>);
result<udt5, int> k10(k9);
result<udt5, int> k11(std::move(k9));
}
// Test direct use of error code enum works
{
constexpr result<int, std::errc> a(5), b(std::errc::invalid_argument);
static_assert(a.value() == 5, "a is not 5");
static_assert(b.error() == std::errc::invalid_argument, "b is not errored");
BOOST_CHECK_THROW(b.value(), std::system_error);
}
#ifndef TESTING_WG21_EXPERIMENTAL_RESULT
#ifdef __cpp_exceptions
// Test payload facility
{
const char *niall = "niall";
result<int, payload> b{std::errc::invalid_argument, niall};
try
{
b.value();
BOOST_CHECK(false);
}
catch(const payload_exception &e)
{
BOOST_CHECK(!strcmp(e.what(), niall));
}
catch(...)
{
BOOST_CHECK(false);
}
}
#endif
#endif
}
|
0 | repos/outcome/test | repos/outcome/test/tests/propagate.cpp | /* Unit testing for outcomes
(C) 2013-2019 Niall Douglas <http://www.nedproductions.biz/> (7 commits)
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License in the accompanying file
Licence.txt or at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Distributed under the Boost Software License, Version 1.0.
(See accompanying file Licence.txt or copy at
http://www.boost.org/LICENSE_1_0.txt)
*/
#include "../../include/outcome.hpp"
#include "../../include/outcome/try.hpp"
#include "quickcpplib/boost/test/unit_test.hpp"
BOOST_OUTCOME_AUTO_TEST_CASE(works / outcome / propagate, "Tests that the outcome propagates errors between different editions of itself")
{
using namespace OUTCOME_V2_NAMESPACE;
{
auto t0 = [&](int a) { return result<long>(std::error_code(a, std::generic_category())); };
auto t1 = [&](int a) {
result<double> f(t0(a)); // double is constructible from long
BOOST_CHECK(!f.has_value());
BOOST_CHECK(f.has_error());
return f;
};
auto t2 = [&](int a) {
result<void> f(t1(a).error());
BOOST_CHECK(!f.has_value());
BOOST_CHECK(f.has_error());
return f;
};
auto t3 = [&](int a) {
outcome<std::string> f(t2(a));
BOOST_CHECK(!f.has_value());
BOOST_CHECK(f.has_error());
return f;
};
BOOST_CHECK(t3(5).error().value() == 5);
result<int> a2{result<void>(in_place_type<void>)};
result<int> a3{result<void>(std::error_code(5, std::generic_category()))};
BOOST_CHECK(a2.has_value());
BOOST_CHECK(!a2.has_error());
BOOST_CHECK(!a3.has_value());
BOOST_CHECK(a3.has_error());
}
{
auto t0 = [&](int a) { return result<long>(a); };
auto t1 = [&](int a) -> result<std::string> {
OUTCOME_TRY(auto &&f, (t0(a)));
return std::to_string(f);
};
BOOST_CHECK(t1(5).value() == "5");
}
{
auto t0 = [&](int a) { return result<long>(a); };
auto t1 = [&](int a) -> outcome<std::string> {
OUTCOME_TRY(auto &&f, (t0(a)));
return std::to_string(f);
};
BOOST_CHECK(t1(5).value() == "5");
}
{
auto t0 = [&](int a) -> result<long> { return result<long>(a); };
auto t1 = [&](int a) -> outcome<void> {
OUTCOME_TRY((t0(a)));
return outcome<void>(in_place_type<void>);
};
(void) t1(5);
}
}
|
0 | repos/outcome/test | repos/outcome/test/tests/issue0071.cpp | /* Unit testing for outcomes
(C) 2013-2019 Niall Douglas <http://www.nedproductions.biz/> (4 commits)
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License in the accompanying file
Licence.txt or at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Distributed under the Boost Software License, Version 1.0.
(See accompanying file Licence.txt or copy at
http://www.boost.org/LICENSE_1_0.txt)
*/
#include "../../include/outcome/result.hpp"
#include "quickcpplib/boost/test/unit_test.hpp"
BOOST_OUTCOME_AUTO_TEST_CASE(issues / 0071 / outcome, "Implicit construction is over eager")
{
using namespace OUTCOME_V2_NAMESPACE;
struct udt
{
int v;
explicit udt(int a)
: v(a){};
};
result<udt> m = udt{5};
BOOST_CHECK(m.value().v == 5);
}
|
0 | repos/outcome/test | repos/outcome/test/tests/issue0065.cpp | /* Unit testing for outcomes
(C) 2013-2019 Niall Douglas <http://www.nedproductions.biz/> (3 commits)
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License in the accompanying file
Licence.txt or at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Distributed under the Boost Software License, Version 1.0.
(See accompanying file Licence.txt or copy at
http://www.boost.org/LICENSE_1_0.txt)
*/
#include "../../include/outcome.hpp"
#include "../../include/outcome/try.hpp"
#include "quickcpplib/boost/test/unit_test.hpp"
BOOST_OUTCOME_AUTO_TEST_CASE(issues / 0065 / outcome, "OUTCOME_TRY does not preserve the exception_ptr")
{
#ifdef __cpp_exceptions
using namespace OUTCOME_V2_NAMESPACE;
auto g = []() -> outcome<int> {
auto f = []() -> outcome<int> {
try
{
throw std::runtime_error{"XXX"};
}
catch(...)
{
return std::current_exception();
}
};
OUTCOME_TRY(auto &&ans, (f()));
return ans;
};
outcome<int> o = g();
BOOST_CHECK(!o);
BOOST_CHECK(o.has_exception());
try
{
o.value();
BOOST_CHECK(false);
}
catch(const std::runtime_error &e)
{
BOOST_CHECK(!strcmp(e.what(), "XXX"));
}
#endif
}
|
0 | repos/outcome/test | repos/outcome/test/tests/experimental-c-result.cpp | /* Unit testing for outcomes
(C) 2013-2024 Niall Douglas <http://www.nedproductions.biz/> (8 commits)
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License in the accompanying file
Licence.txt or at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Distributed under the Boost Software License, Version 1.0.
(See accompanying file Licence.txt or copy at
http://www.boost.org/LICENSE_1_0.txt)
*/
#ifndef SYSTEM_ERROR2_NOT_POSIX
#include "../../include/outcome/experimental/result.h"
struct custom_value_type
{
int v[16];
bool operator==(const custom_value_type &o) const noexcept { return 0 == memcmp(v, o.v, sizeof(v)); }
};
enum c_enum
{
c_enum_success,
c_enum_failure
};
#ifdef __GNUC__
#pragma GCC diagnostic ignored "-Wunused-function"
#endif
CXX_DECLARE_RESULT_SYSTEM(test, custom_value_type);
using result_custom = CXX_RESULT_SYSTEM(test);
CXX_DECLARE_RESULT_SYSTEM_FROM_ENUM(test, c_enum, "{74ceb994-7622-3a21-07f0-b016aa705585}", {c_enum::c_enum_success, "success", {errc::success}},
{c_enum::c_enum_failure, "failure", {errc::invalid_argument}});
template <class T> using result = OUTCOME_V2_NAMESPACE::experimental::status_result<T>;
#include "quickcpplib/boost/test/unit_test.hpp"
BOOST_OUTCOME_AUTO_TEST_CASE(works / status_code / c_result, "Tests that the C result with status_code works as intended")
{
using namespace SYSTEM_ERROR2_NAMESPACE;
const custom_value_type shouldbe{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15};
{ // errored with posix code
result_custom l(outcome_make_result_system_test_failure_posix((int) errc::bad_address));
result<custom_value_type> m(to_result(l));
BOOST_CHECK(!m);
BOOST_CHECK(!m.has_value());
BOOST_CHECK(m.has_error());
// BOOST_CHECK(!m.has_exception());
BOOST_CHECK_THROW(m.value(), posix_error);
BOOST_CHECK_NO_THROW(m.error());
result_custom l2(outcome_make_result_system_test_failure_posix((int) errc::bad_address));
BOOST_CHECK(outcome_status_code_equal(&l.error, &l2.error));
BOOST_CHECK(outcome_status_code_equal_generic(&l.error, EFAULT));
std::cout << outcome_status_code_message(&l.error) << std::endl;
BOOST_CHECK(0 == strcmp(outcome_status_code_message(&l.error), "Bad address"));
}
{ // valued
result_custom l(outcome_make_result_system_test_success(shouldbe));
result<custom_value_type> m(to_result(l));
BOOST_CHECK(m);
BOOST_CHECK(m.has_value());
BOOST_CHECK(!m.has_error());
// BOOST_CHECK(!m.has_exception());
BOOST_CHECK(m.value() == shouldbe);
}
if(false) // correctly contract asserts
{ // errored from custom C enum 1
result_custom l(CXX_MAKE_RESULT_SYSTEM_FROM_ENUM(test, c_enum, c_enum::c_enum_success));
result<custom_value_type> m(to_result(l));
BOOST_CHECK(!m);
BOOST_CHECK(!m.has_value());
BOOST_CHECK(m.has_error());
// BOOST_CHECK(!m.has_exception());
BOOST_CHECK_THROW(m.value(), status_error<_quick_status_code_from_enum_domain<c_enum>>);
BOOST_CHECK_NO_THROW(m.error());
result_custom l2(outcome_make_result_system_test_failure_posix((int) errc::invalid_argument));
BOOST_CHECK(!outcome_status_code_equal(&l.error, &l2.error));
}
{ // errored from custom C enum 2
result_custom l(CXX_MAKE_RESULT_SYSTEM_FROM_ENUM(test, c_enum, c_enum::c_enum_failure));
result<custom_value_type> m(to_result(l));
BOOST_CHECK(!m);
BOOST_CHECK(!m.has_value());
BOOST_CHECK(m.has_error());
// BOOST_CHECK(!m.has_exception());
BOOST_CHECK_THROW(m.value(), status_error<_quick_status_code_from_enum_domain<c_enum>>);
BOOST_CHECK_NO_THROW(m.error());
result_custom l2(outcome_make_result_system_test_failure_posix((int) errc::invalid_argument));
BOOST_CHECK(outcome_status_code_equal(&l.error, &l2.error));
BOOST_CHECK(outcome_status_code_equal_generic(&l.error, EINVAL));
std::cout << outcome_status_code_message(&l.error) << std::endl;
BOOST_CHECK(0 == strcmp(outcome_status_code_message(&l.error), "failure"));
}
auto d(outcome_make_result_system_test_failure_posix((int) errc::bad_address));
static_assert(std::is_default_constructible<decltype(d)>::value, "");
static_assert(std::is_nothrow_default_constructible<decltype(d)>::value, "");
static_assert(std::is_copy_constructible<decltype(d)>::value, "");
static_assert(std::is_trivially_copy_constructible<decltype(d)>::value, "");
static_assert(std::is_nothrow_copy_constructible<decltype(d)>::value, "");
static_assert(std::is_copy_assignable<decltype(d)>::value, "");
static_assert(std::is_trivially_copy_assignable<decltype(d)>::value, "");
static_assert(std::is_nothrow_copy_assignable<decltype(d)>::value, "");
static_assert(std::is_move_assignable<decltype(d)>::value, "");
static_assert(std::is_trivially_move_assignable<decltype(d)>::value, "");
static_assert(std::is_nothrow_move_assignable<decltype(d)>::value, "");
static_assert(std::is_trivially_destructible<decltype(d)>::value, "");
static_assert(std::is_nothrow_destructible<decltype(d)>::value, "");
// Single parameter C try
{
auto will_succeed = [&]() -> result_custom { return outcome_make_result_system_test_success(shouldbe); };
auto will_fail = [&]() -> result_custom { return outcome_make_result_system_test_failure_posix((int) errc::bad_address); };
auto test = [&](result_custom r) -> result_custom
{
CXX_RESULT_SYSTEM_TRY(r);
return will_succeed();
};
auto r1 = test(will_succeed());
BOOST_CHECK(CXX_RESULT_HAS_VALUE(r1));
BOOST_CHECK(0 == memcmp(r1.value.v, shouldbe.v, sizeof(shouldbe.v)));
auto r2 = test(will_fail());
BOOST_CHECK(CXX_RESULT_HAS_ERROR(r2));
BOOST_CHECK(outcome_status_code_equal_generic(&r2.error, EFAULT));
}
// C try with cleanup on failure
{
auto will_succeed = [&]() -> result_custom { return outcome_make_result_system_test_success(shouldbe); };
auto will_fail = [&]() -> result_custom { return outcome_make_result_system_test_failure_posix((int) errc::bad_address); };
auto test = [&](result_custom r) -> result_custom
{
CXX_RESULT_SYSTEM_TRY(printf("failed!\n"), r);
return will_succeed();
};
auto r1 = test(will_succeed());
BOOST_CHECK(CXX_RESULT_HAS_VALUE(r1));
BOOST_CHECK(0 == memcmp(r1.value.v, shouldbe.v, sizeof(shouldbe.v)));
auto r2 = test(will_fail());
BOOST_CHECK(CXX_RESULT_HAS_ERROR(r2));
BOOST_CHECK(outcome_status_code_equal_generic(&r2.error, EFAULT));
}
// C try with cleanup and success output
{
auto will_succeed = [&]() -> result_custom { return outcome_make_result_system_test_success(shouldbe); };
auto will_fail = [&]() -> result_custom { return outcome_make_result_system_test_failure_posix((int) errc::bad_address); };
auto test = [&](result_custom r) -> result_custom
{
CXX_RESULT_SYSTEM_TRY(custom_value_type v, printf("failed!\n"), r);
return outcome_make_result_system_test_success(v);
};
auto r1 = test(will_succeed());
BOOST_CHECK(CXX_RESULT_HAS_VALUE(r1));
BOOST_CHECK(0 == memcmp(r1.value.v, shouldbe.v, sizeof(shouldbe.v)));
auto r2 = test(will_fail());
BOOST_CHECK(CXX_RESULT_HAS_ERROR(r2));
BOOST_CHECK(outcome_status_code_equal_generic(&r2.error, EFAULT));
}
// C try with cleanup and success output and different return type
{
auto will_succeed = [&]() -> result_custom { return outcome_make_result_system_test_success(shouldbe); };
auto will_fail = [&]() -> result_custom { return outcome_make_result_system_test_failure_posix((int) errc::bad_address); };
auto test = [&](result_custom r) -> result_custom
{
CXX_RESULT_SYSTEM_TRY(custom_value_type v, test, printf("failed!\n"), r);
return outcome_make_result_system_test_success(v);
};
auto r1 = test(will_succeed());
BOOST_CHECK(CXX_RESULT_HAS_VALUE(r1));
BOOST_CHECK(0 == memcmp(r1.value.v, shouldbe.v, sizeof(shouldbe.v)));
auto r2 = test(will_fail());
BOOST_CHECK(CXX_RESULT_HAS_ERROR(r2));
BOOST_CHECK(outcome_status_code_equal_generic(&r2.error, EFAULT));
}
}
#else
int main(void)
{
return 0;
}
#endif
|
0 | repos/outcome/test | repos/outcome/test/tests/experimental-p0709a.cpp | /* Unit testing for outcomes
(C) 2017-2019 Niall Douglas <http://www.nedproductions.biz/> (7 commits)
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License in the accompanying file
Licence.txt or at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Distributed under the Boost Software License, Version 1.0.
(See accompanying file Licence.txt or copy at
http://www.boost.org/LICENSE_1_0.txt)
*/
#include "../../include/outcome/experimental/status_result.hpp"
#include <climits> // for INT_MAX
#include <cstdio>
// status_code<erased<intptr_t>>
using error = SYSTEM_ERROR2_NAMESPACE::error;
// Outcome's result must be told when it is dealing with an erased status code
template <class T, class E> using result = OUTCOME_V2_NAMESPACE::experimental::status_result<T, E, OUTCOME_V2_NAMESPACE::policy::all_narrow>;
enum class arithmetic_errc
{
success,
divide_by_zero,
integer_divide_overflows,
not_integer_division
};
class _arithmetic_errc_domain;
using arithmetic_errc_error = SYSTEM_ERROR2_NAMESPACE::status_code<_arithmetic_errc_domain>;
class _arithmetic_errc_domain : public SYSTEM_ERROR2_NAMESPACE::status_code_domain
{
using _base = SYSTEM_ERROR2_NAMESPACE::status_code_domain;
public:
using value_type = arithmetic_errc;
constexpr explicit _arithmetic_errc_domain(typename _base::unique_id_type id = 0x290f170194f0c6c7) noexcept : _base(id) {}
static inline constexpr const _arithmetic_errc_domain &get();
virtual _base::string_ref name() const noexcept override final // NOLINT
{
static string_ref v("arithmetic error domain");
return v; // NOLINT
}
virtual payload_info_t payload_info() const noexcept override
{
return {sizeof(value_type), sizeof(status_code_domain *) + sizeof(value_type),
(alignof(value_type) > alignof(status_code_domain *)) ? alignof(value_type) : alignof(status_code_domain *)};
}
protected:
virtual bool _do_failure(const SYSTEM_ERROR2_NAMESPACE::status_code<void> &code) const noexcept override final // NOLINT
{
assert(code.domain() == *this); // NOLINT
const auto &c1 = static_cast<const arithmetic_errc_error &>(code); // NOLINT
return c1.value() != arithmetic_errc::success;
}
virtual bool _do_equivalent(const SYSTEM_ERROR2_NAMESPACE::status_code<void> &, const SYSTEM_ERROR2_NAMESPACE::status_code<void> &) const noexcept override final { return false; } // NOLINT
virtual SYSTEM_ERROR2_NAMESPACE::generic_code _generic_code(const SYSTEM_ERROR2_NAMESPACE::status_code<void> &) const noexcept override final { return {}; } // NOLINT
virtual _base::string_ref _do_message(const SYSTEM_ERROR2_NAMESPACE::status_code<void> &code) const noexcept override final // NOLINT
{
assert(code.domain() == *this); // NOLINT
const auto &c1 = static_cast<const arithmetic_errc_error &>(code); // NOLINT
switch(c1.value())
{
case arithmetic_errc::success:
return _base::string_ref("success");
case arithmetic_errc::divide_by_zero:
return _base::string_ref("divide by zero");
case arithmetic_errc::integer_divide_overflows:
return _base::string_ref("integer divide overflows");
case arithmetic_errc::not_integer_division:
return _base::string_ref("not integer division");
}
return _base::string_ref("unknown");
}
SYSTEM_ERROR2_NORETURN virtual void _do_throw_exception(const SYSTEM_ERROR2_NAMESPACE::status_code<void> &) const override final { abort(); } // NOLINT
};
constexpr _arithmetic_errc_domain arithmetic_errc_domain;
inline constexpr const _arithmetic_errc_domain &_arithmetic_errc_domain::get()
{
return arithmetic_errc_domain;
}
// Tell status code about the available implicit conversion
inline arithmetic_errc_error make_status_code(arithmetic_errc e)
{
return arithmetic_errc_error(SYSTEM_ERROR2_NAMESPACE::in_place, e);
}
OUTCOME_V2_NAMESPACE_BEGIN
namespace trait
{
// Tell Outcome that arithmetic_errc is convertible into std::error
template <> struct is_error_type_enum<error, arithmetic_errc>
{
static constexpr bool value = true;
};
}
OUTCOME_V2_NAMESPACE_END
// And tell Outcome how to perform the implicit conversion
inline error make_error_code(arithmetic_errc e)
{
return arithmetic_errc_error(SYSTEM_ERROR2_NAMESPACE::in_place, e);
}
result<int, error> safe_divide(int i, int j)
{
if(j == 0)
{
return arithmetic_errc::divide_by_zero;
}
if(i == INT_MIN && j == -1)
{
return arithmetic_errc::integer_divide_overflows;
}
if(i % j != 0)
{
return arithmetic_errc::not_integer_division;
}
return i / j;
}
int caller2(int i, int j)
{
auto r = safe_divide(i, j);
if(r)
{
return r.value();
}
if(r.error() == arithmetic_errc::divide_by_zero)
{
return 0;
}
if(r.error() == arithmetic_errc::not_integer_division)
{
return i / j; // ignore
}
if(r.error() == arithmetic_errc::integer_divide_overflows)
{
return INT_MIN;
}
return 0;
}
int main()
{
printf("%d\n", caller2(5, 6)); // NOLINT
return 0;
}
|
0 | repos/outcome/test | repos/outcome/test/tests/issue0012.cpp | /* Unit testing for outcomes
(C) 2013-2019 Niall Douglas <http://www.nedproductions.biz/> (5 commits)
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License in the accompanying file
Licence.txt or at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Distributed under the Boost Software License, Version 1.0.
(See accompanying file Licence.txt or copy at
http://www.boost.org/LICENSE_1_0.txt)
*/
#include "../../include/outcome.hpp"
#include "quickcpplib/boost/test/unit_test.hpp"
BOOST_OUTCOME_AUTO_TEST_CASE(issues / 0012 / test, "outcome's copy assignment gets instantiated even when type T cannot be copied")
{
using namespace OUTCOME_V2_NAMESPACE;
const char *s = "hi";
struct udt // NOLINT
{
const char *_v{nullptr};
udt() = default;
constexpr explicit udt(const char *v) noexcept : _v(v) {}
constexpr udt(udt &&o) noexcept : _v(o._v) { o._v = nullptr; }
udt(const udt &) = delete;
constexpr udt &operator=(udt &&o) noexcept
{
_v = o._v;
o._v = nullptr;
return *this;
}
udt &operator=(const udt &) = delete;
constexpr const char *operator*() const noexcept { return _v; }
};
static_assert(std::is_move_constructible<outcome<udt>>::value, "expected<udt> is not move constructible!");
static_assert(!std::is_copy_constructible<outcome<udt>>::value, "expected<udt> is copy constructible!");
outcome<udt> p(udt{s}), n(std::error_code(ENOMEM, std::generic_category()));
n = std::error_code(EINVAL, std::generic_category());
BOOST_CHECK(n.error().value() == EINVAL);
}
|
0 | repos/outcome/test | repos/outcome/test/tests/hooks.cpp | /* Unit testing for outcomes
(C) 2013-2020 Niall Douglas <http://www.nedproductions.biz/> (14 commits)
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License in the accompanying file
Licence.txt or at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Distributed under the Boost Software License, Version 1.0.
(See accompanying file Licence.txt or copy at
http://www.boost.org/LICENSE_1_0.txt)
*/
#define _CRT_SECURE_NO_WARNINGS
#define OUTCOME_ENABLE_LEGACY_SUPPORT_FOR 210 // legacy ADL hooks support
#include "../../include/outcome.hpp"
#include "quickcpplib/boost/test/unit_test.hpp"
#include <iostream>
namespace hook_test
{
using OUTCOME_V2_NAMESPACE::in_place_type;
// Use static storage to convey extended error info from result construction to outcome conversion
static char extended_error_info[256];
// Use the error_code type as the ADL bridge for the hooks by creating a type here
struct error_code : public std::error_code
{
error_code() = default;
error_code(std::error_code ec) // NOLINT
: std::error_code(ec)
{
}
};
// Localise result to using the local error_code so this namespace gets looked up for the hooks
template <class R> using result = OUTCOME_V2_NAMESPACE::result<R, error_code>;
// Specialise the result construction hook for our localised result
template <class U> constexpr inline void hook_result_construction(result<int> *res, U && /*unused*/) noexcept
{
// Write the value in the result into the static storage
snprintf(extended_error_info, sizeof(extended_error_info), "%d", res->assume_value()); // NOLINT
}
template <class U> constexpr inline void hook_result_construction(result<std::string> *res, U && /*unused*/) noexcept
{
// Write the value in the result into the static storage
snprintf(extended_error_info, sizeof(extended_error_info), "%s", res->assume_value().c_str()); // NOLINT
}
} // namespace hook_test
BOOST_OUTCOME_AUTO_TEST_CASE(works / result / hooks, "Tests that you can hook result's construction")
{
using namespace hook_test;
result<int> a(5);
BOOST_CHECK(!strcmp(extended_error_info, "5")); // NOLINT
result<std::string> b("niall");
BOOST_CHECK(!strcmp(extended_error_info, "niall")); // NOLINT
}
//! [extended_error_coding2]
namespace hook_test
{
// Localise outcome to using the local error_code so this namespace gets looked up for the hooks
template <class R> using outcome = OUTCOME_V2_NAMESPACE::outcome<R, error_code, std::string>;
// Specialise the outcome copy and move conversion hook for our localised result
template <class T, class U> constexpr inline void hook_outcome_copy_construction(outcome<T> *res, const result<U> & /*unused*/) noexcept
{
// when copy constructing from a result<T>, place extended_error_coding::extended_error_info into the payload
std::cout << "hook_outcome_copy_construction fires" << std::endl;
OUTCOME_V2_NAMESPACE::hooks::override_outcome_exception(res, extended_error_info);
}
template <class T, class U> constexpr inline void hook_outcome_move_construction(outcome<T> *res, result<U> && /*unused*/) noexcept
{
// when move constructing from a result<T>, place extended_error_coding::extended_error_info into the payload
std::cout << "hook_outcome_move_construction fires" << std::endl;
OUTCOME_V2_NAMESPACE::hooks::override_outcome_exception(res, extended_error_info);
}
} // namespace hook_test
BOOST_OUTCOME_AUTO_TEST_CASE(works / outcome / hooks, "Tests that you can hook outcome's conversion from a result")
{
using namespace hook_test;
outcome<int> a(result<int>(5));
BOOST_REQUIRE(a.has_exception()); // NOLINT
BOOST_CHECK(a.exception() == "5");
outcome<std::string> b(result<std::string>("niall"));
BOOST_CHECK(b.exception() == "niall");
// Make sure hook does not fire for any other kind of outcome copy or move, only when converting from our custom result only
outcome<int> c(5);
outcome<long> d(c); // can't be the same type as source, else copy elision takes place and no ADL hook calling
BOOST_CHECK(!d.has_exception());
outcome<int> e(OUTCOME_V2_NAMESPACE::result<int>(5));
BOOST_CHECK(!e.has_exception());
}
|
0 | repos/outcome/test | repos/outcome/test/tests/issue0210.cpp | /* Unit testing for outcomes
(C) 2013-2019 Niall Douglas <http://www.nedproductions.biz/> (1 commit)
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License in the accompanying file
Licence.txt or at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Distributed under the Boost Software License, Version 1.0.
(See accompanying file Licence.txt or copy at
http://www.boost.org/LICENSE_1_0.txt)
*/
#include "../../include/outcome.hpp"
#include "../../include/outcome/try.hpp"
#include "quickcpplib/boost/test/unit_test.hpp"
namespace issues210
{
namespace outcome = OUTCOME_V2_NAMESPACE;
struct error
{
std::error_code code;
};
// say that my custom error code type is error code compatible
inline std::error_code make_error_code(error error) noexcept { return error.code; }
template <typename T> using custom_result = outcome::basic_result<T, error, outcome::policy::default_policy<T, error, void>>;
// source of custom result type with error code compatible error type
inline custom_result<int> funcA(int x) { return x; }
// Is the custom result type explicitly constructible to an ordinary result type?
inline outcome::result<int> funcB(int x) { return outcome::result<int>(funcA(x)); }
// Does the custom result type TRY-convert to an ordinary result type?
inline outcome::result<int> func1(int x)
{
OUTCOME_TRY(auto &&y, funcA(x));
return funcB(y);
}
// Is the custom result type explicitly constructible to an ordinary outcome type?
inline outcome::outcome<int> funcC(int x) { return outcome::outcome<int>(funcA(x)); }
// Does the custom result type TRY-convert to an ordinary outcome type?
inline outcome::outcome<int> func2(int x)
{
OUTCOME_TRY(auto &&y, funcA(x));
return funcC(y);
}
} // namespace issues210
BOOST_OUTCOME_AUTO_TEST_CASE(issues / 0210 / test, "result<int, E> with error code compatible custom E does not TRY into a result<int, std::error_code> function")
{
BOOST_CHECK(issues210::func1(5).value() == 5);
BOOST_CHECK(issues210::func2(5).value() == 5);
}
|
0 | repos/outcome/test | repos/outcome/test/tests/value-or-error.cpp | /* Unit testing for outcomes
(C) 2013-2019 Niall Douglas <http://www.nedproductions.biz/> (3 commits)
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License in the accompanying file
Licence.txt or at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Distributed under the Boost Software License, Version 1.0.
(See accompanying file Licence.txt or copy at
http://www.boost.org/LICENSE_1_0.txt)
*/
#include "../../include/outcome.hpp"
#include "quickcpplib/boost/test/unit_test.hpp"
BOOST_OUTCOME_AUTO_TEST_CASE(works / outcome / valueorerror, "Tests that outcome constructs from value_or_error and value_or_none concept inputs")
{
using namespace OUTCOME_V2_NAMESPACE;
{
struct value_or_error
{
using value_type = int;
using error_type = void;
bool has_value() const { return true; }
int value() const { return 78; }
void error() const {}
} a;
static_assert(concepts::value_or_none<value_or_error>, "");
static_assert(concepts::value_or_error<value_or_error>, "");
static_assert(!concepts::basic_result<value_or_error>, "");
static_assert(!concepts::basic_outcome<value_or_error>, "");
BOOST_CHECK((convert::value_or_error<result<long>, value_or_error>{}(a).value() == 78));
result<long> b(a);
BOOST_CHECK(b.has_value());
BOOST_CHECK(b.value() == 78);
struct local_basic_result1 : result<int>
{
};
static_assert(concepts::value_or_none<local_basic_result1>, "");
static_assert(concepts::value_or_error<local_basic_result1>, "");
static_assert(concepts::basic_result<result<int>>, "");
static_assert(concepts::basic_result<local_basic_result1>, "");
static_assert(!concepts::basic_outcome<result<int>>, "");
static_assert(!concepts::basic_outcome<local_basic_result1>, "");
struct local_basic_result2 : protected result<int>
{
using _base = result<int>;
using value_type = _base::value_type;
using error_type = _base::error_type;
using _base::has_value;
using _base::value;
using _base::error;
};
static_assert(concepts::value_or_none<local_basic_result2>, "");
static_assert(concepts::value_or_error<local_basic_result2>, "");
static_assert(!concepts::basic_result<local_basic_result2>, "");
static_assert(!concepts::basic_outcome<local_basic_result2>, "");
struct local_basic_outcome1 : outcome<int>
{
};
static_assert(!std::is_convertible<outcome<int>, result<int>>::value, "");
static_assert(!std::is_convertible<local_basic_outcome1, result<int>>::value, "");
static_assert(concepts::value_or_none<local_basic_outcome1>, "");
static_assert(concepts::value_or_error<local_basic_outcome1>, "");
static_assert(!concepts::basic_result<outcome<int>>, "");
static_assert(!concepts::basic_result<local_basic_outcome1>, "");
static_assert(concepts::basic_outcome<local_basic_outcome1>, "");
struct local_basic_outcome2 : protected outcome<int>
{
using _base = outcome<int>;
using value_type = _base::value_type;
using error_type = _base::error_type;
using exception_type = _base::exception_type;
using _base::error;
using _base::has_value;
using _base::value;
};
static_assert(concepts::value_or_none<local_basic_outcome2>, "");
static_assert(concepts::value_or_error<local_basic_outcome2>, "");
static_assert(!concepts::basic_result<local_basic_outcome2>, "");
static_assert(!concepts::basic_outcome<local_basic_outcome2>, "");
}
}
|
0 | repos/outcome/test | repos/outcome/test/tests/issue0064.cpp | /* Unit testing for outcomes
(C) 2013-2019 Niall Douglas <http://www.nedproductions.biz/> (4 commits)
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License in the accompanying file
Licence.txt or at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Distributed under the Boost Software License, Version 1.0.
(See accompanying file Licence.txt or copy at
http://www.boost.org/LICENSE_1_0.txt)
*/
#include "../../include/outcome/iostream_support.hpp"
#include "../../include/outcome.hpp"
#include "../../include/outcome/try.hpp"
#include "quickcpplib/boost/test/unit_test.hpp"
BOOST_OUTCOME_AUTO_TEST_CASE(issues / 0064 / outcome, "OUTCOME_TRY on excepted outcome is propagating a null error rather than just an exception")
{
#ifdef __cpp_exceptions
using namespace OUTCOME_V2_NAMESPACE;
auto f = []() -> outcome<int> {
auto h = []() -> outcome<int> { return std::make_exception_ptr(std::runtime_error("hello")); };
OUTCOME_TRY((h()));
return 0;
}();
std::cout << print(f) << std::endl;
BOOST_CHECK(!f.has_value());
BOOST_CHECK(!f.has_error());
BOOST_CHECK(f.has_exception());
#endif
}
|
0 | repos/outcome/test | repos/outcome/test/tests/issue0095.cpp | /* Unit testing for outcomes
(C) 2013-2019 Niall Douglas <http://www.nedproductions.biz/> (6 commits)
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License in the accompanying file
Licence.txt or at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Distributed under the Boost Software License, Version 1.0.
(See accompanying file Licence.txt or copy at
http://www.boost.org/LICENSE_1_0.txt)
*/
#include "../../include/outcome/result.hpp"
#include "../../include/outcome/try.hpp"
#include "quickcpplib/boost/test/unit_test.hpp"
namespace issue0095
{
namespace out = OUTCOME_V2_NAMESPACE;
struct E
{
};
// struct F : E {};
struct F
{
operator E() const { return E{}; } // NOLINT
};
out::result<int, F> f() { return F{}; }
out::result<int, E> e()
{
OUTCOME_TRY(auto &&i, (f()));
return i;
}
} // namespace issue0095
BOOST_OUTCOME_AUTO_TEST_CASE(issues / 0095 / outcome, "operator conversions on E type cause TRY to fail")
{
BOOST_CHECK(issue0095::e().has_error());
}
|
0 | repos/outcome/test | repos/outcome/test/tests/success-failure.cpp | /* Unit testing for outcomes
(C) 2017-2019 Niall Douglas <http://www.nedproductions.biz/> (10 commits)
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License in the accompanying file
Licence.txt or at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Distributed under the Boost Software License, Version 1.0.
(See accompanying file Licence.txt or copy at
http://www.boost.org/LICENSE_1_0.txt)
*/
#include "../../include/outcome/result.hpp"
#include "quickcpplib/boost/test/unit_test.hpp"
#include <iostream>
BOOST_OUTCOME_AUTO_TEST_CASE(works / success - failure, "Tests that the success and failure type sugars work as intended")
{
using namespace OUTCOME_V2_NAMESPACE;
#ifdef __cpp_deduction_guides
std::cout << "__cpp_deduction_guides = 1" << std::endl;
#endif
{
auto a = success(5);
auto b = success();
auto c = success("hello");
static_assert(std::is_same<decltype(a), success_type<int>>::value, "");
static_assert(std::is_same<decltype(b), success_type<void>>::value, "");
static_assert(std::is_same<decltype(c), success_type<const char *>>::value, "");
static_assert(std::is_same<decltype(a)::value_type, int>::value, "");
// static_assert(std::is_same<decltype(b.value), int>::value, "");
static_assert(std::is_same<decltype(c)::value_type, const char *>::value, "");
}
#if !defined(__APPLE__) || defined(__cpp_exceptions)
{
auto e = std::make_exception_ptr(std::exception());
auto a = failure(5);
auto b = failure(5, e);
auto c = failure(5, 5);
static_assert(std::is_same<decltype(a), failure_type<int, void>>::value, "");
static_assert(std::is_same<decltype(b), failure_type<int, std::exception_ptr>>::value, "");
static_assert(std::is_same<decltype(c), failure_type<int, int>>::value, "");
static_assert(std::is_same<decltype(a)::error_type, int>::value, "");
static_assert(std::is_same<decltype(b)::error_type, int>::value, "");
static_assert(std::is_same<decltype(b)::exception_type, std::exception_ptr>::value, "");
static_assert(std::is_same<decltype(c)::error_type, int>::value, "");
static_assert(std::is_same<decltype(c)::exception_type, int>::value, "");
}
#endif
}
|
0 | repos/outcome/test | repos/outcome/test/tests/constexpr.cpp | /* Unit testing for outcomes
(C) 2013-2019 Niall Douglas <http://www.nedproductions.biz/> (9 commits)
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License in the accompanying file
Licence.txt or at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Distributed under the Boost Software License, Version 1.0.
(See accompanying file Licence.txt or copy at
http://www.boost.org/LICENSE_1_0.txt)
*/
#include "../../include/outcome.hpp"
#include "quickcpplib/boost/test/unit_test.hpp"
#if __cplusplus >= 201700 || _HAS_CXX17
// Match LiteralType, even on C++ 17 and later
template <class T> struct is_literal_type
{
static constexpr bool value = //
std::is_void<T>::value //
|| std::is_scalar<T>::value //
|| std::is_reference<T>::value //
// leave out is_array for simplicity
|| (std::is_class<T>::value && std::is_trivially_destructible<T>::value
// how does one detect if a type has at least one constexpr constructor without Reflection???
) // leave out union for simplicity
;
};
#else
template <class T> using is_literal_type = std::is_literal_type<T>;
#endif
BOOST_OUTCOME_AUTO_TEST_CASE(works / outcome / constexpr, "Tests that outcome works as intended in a constexpr evaluation context")
{
using namespace OUTCOME_V2_NAMESPACE;
static_assert(is_literal_type<result<int, void, void>>::value, "result<int, void, void> is not a literal type!");
static_assert(is_literal_type<outcome<int, void, void>>::value, "outcome<int, void, void> is not a literal type!");
// Unfortunately result<T> can never be a literal type as error_code can never be literal
//
// It can however be trivially destructible as error_code is trivially destructible. That
// makes possible lots of compiler optimisations
static_assert(std::is_trivially_destructible<result<int>>::value, "result<int> is not trivially destructible!");
static_assert(std::is_trivially_destructible<result<void>>::value, "result<void> is not trivially destructible!");
// outcome<T> default has no trivial operations, but if configured it can become so
static_assert(std::is_trivially_destructible<outcome<int, std::error_code, void>>::value,
"outcome<int, std::error_code, void> is not trivially destructible!");
{
// Test compatible results can be constructed from one another
constexpr result<int, long> g(in_place_type<int>, 5);
constexpr result<long, int> g2(g);
static_assert(g.has_value(), "");
static_assert(!g.has_error(), "");
static_assert(g.assume_value() == 5, ""); // value() with UDT E won't compile
static_assert(g2.has_value(), "");
static_assert(!g2.has_error(), "");
static_assert(g2.assume_value() == 5, ""); // value() with UDT E won't compile
constexpr result<void, int> g3(in_place_type<void>);
constexpr result<long, int> g4(g3);
constexpr result<int, void> g5(in_place_type<void>);
constexpr result<long, int> g6(g5);
(void) g4;
(void) g6;
// Test void
constexpr result<void, int> h(in_place_type<void>);
static_assert(h.has_value(), "");
constexpr result<int, void> h2(in_place_type<void>);
static_assert(!h2.has_value(), "");
static_assert(h2.has_error(), "");
// Test const
constexpr result<const int, void> i(5);
constexpr result<const int, void> i2(i);
(void) i2;
}
{
// Test compatible outcomes can be constructed from one another
constexpr outcome<int, long, char *> g(in_place_type<int>, 5);
constexpr outcome<long, int, const char *> g2(g);
static_assert(g.has_value(), "");
static_assert(!g.has_error(), "");
static_assert(!g.has_exception(), "");
static_assert(g.assume_value() == 5, ""); // value() with UDT E won't compile
static_assert(g2.has_value(), "");
static_assert(!g2.has_error(), "");
static_assert(!g2.has_exception(), "");
static_assert(g2.assume_value() == 5, ""); // value() with UDT E won't compile
constexpr outcome<void, int, char *> g3(in_place_type<void>);
constexpr outcome<long, int, const char *> g4(g3);
constexpr outcome<int, void, char *> g5(in_place_type<void>);
constexpr outcome<long, int, const char *> g6(g5);
(void) g4;
(void) g6;
}
}
|
0 | repos/outcome/test | repos/outcome/test/tests/issue0059.cpp | /* Unit testing for outcomes
(C) 2013-2019 Niall Douglas <http://www.nedproductions.biz/> (8 commits)
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License in the accompanying file
Licence.txt or at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Distributed under the Boost Software License, Version 1.0.
(See accompanying file Licence.txt or copy at
http://www.boost.org/LICENSE_1_0.txt)
*/
#include "../../include/outcome/result.hpp"
#include "../../include/outcome/try.hpp"
#include "quickcpplib/boost/test/unit_test.hpp"
BOOST_OUTCOME_AUTO_TEST_CASE(issues / 0059 / test, "result<NonMovable> supported?")
{
#if (defined(_MSC_VER) && !defined(__clang__)) || __cplusplus >= 201700
using namespace OUTCOME_V2_NAMESPACE;
struct udt
{
const char *_v{nullptr};
udt() = delete;
constexpr udt(const char *v) noexcept : _v(v) {} // NOLINT
udt(udt &&o) = delete;
udt(const udt &) = delete;
udt &operator=(udt &&o) = delete;
udt &operator=(const udt &) = delete;
~udt() = default;
constexpr const char *operator*() const noexcept { return _v; }
};
const char *niall = "niall";
auto f = [niall]() -> result<void> {
auto g = [niall]() -> result<udt> { return {niall}; };
OUTCOME_TRY((auto &&, v), g()); // this must never copy nor move
BOOST_CHECK(*v == niall);
return success();
};
(void) f();
#endif
}
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.