mirror of
https://github.com/Naios/continuable.git
synced 2025-12-06 08:46:44 +08:00
Add support for stable coroutines (/await:strict and -fcoroutines)
* The definition CONTINUABLE_HAS_COROUTINE now indicates support for coroutines, while CONTINUABLE_HAS_EXPERIMENTAL_COROUTINE is added if the experimental version is used.
This commit is contained in:
parent
2fcc2bf281
commit
01f9dbd1f4
197
CMakeLists.txt
197
CMakeLists.txt
@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
# Copyright(c) 2015 - 2020 Denis Blank <denis.blank at outlook dot com>
|
# Copyright(c) 2015 - 2020 Denis Blank <denis.blank at outlook dot com>
|
||||||
#
|
#
|
||||||
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
@ -8,8 +7,8 @@
|
|||||||
# copies of the Software, and to permit persons to whom the Software is
|
# copies of the Software, and to permit persons to whom the Software is
|
||||||
# furnished to do so, subject to the following conditions :
|
# furnished to do so, subject to the following conditions :
|
||||||
#
|
#
|
||||||
# The above copyright notice and this permission notice shall be included in
|
# The above copyright notice and this permission notice shall be included in all
|
||||||
# all copies or substantial portions of the Software.
|
# copies or substantial portions of the Software.
|
||||||
#
|
#
|
||||||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
@ -21,56 +20,59 @@
|
|||||||
|
|
||||||
cmake_minimum_required(VERSION 3.11)
|
cmake_minimum_required(VERSION 3.11)
|
||||||
|
|
||||||
project(continuable VERSION 4.0.0 LANGUAGES C CXX)
|
project(
|
||||||
|
continuable
|
||||||
|
VERSION 4.0.0
|
||||||
|
LANGUAGES C CXX)
|
||||||
|
|
||||||
if (CTI_CONTINUABLE_IS_FIND_INCLUDED)
|
if(CTI_CONTINUABLE_IS_FIND_INCLUDED)
|
||||||
set(CTI_CONTINUABLE_IS_TOP_LEVEL_PROJECT OFF)
|
set(CTI_CONTINUABLE_IS_TOP_LEVEL_PROJECT OFF)
|
||||||
else()
|
else()
|
||||||
string(COMPARE EQUAL ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_SOURCE_DIR}
|
string(COMPARE EQUAL ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_SOURCE_DIR}
|
||||||
CTI_CONTINUABLE_IS_TOP_LEVEL_PROJECT)
|
CTI_CONTINUABLE_IS_TOP_LEVEL_PROJECT)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
option(CTI_CONTINUABLE_WITH_INSTALL
|
if(CTI_CONTINUABLE_IS_TOP_LEVEL_PROJECT)
|
||||||
"Add the continuable install targets"
|
message(
|
||||||
${CTI_CONTINUABLE_IS_TOP_LEVEL_PROJECT})
|
STATUS
|
||||||
|
"Building with ${CMAKE_CXX_COMPILER_ID} (${CMAKE_CXX_COMPILER_VERSION})")
|
||||||
|
endif()
|
||||||
|
|
||||||
option(CTI_CONTINUABLE_WITH_TESTS
|
option(CTI_CONTINUABLE_WITH_INSTALL "Add the continuable install targets"
|
||||||
"Build the continuable unit tests"
|
${CTI_CONTINUABLE_IS_TOP_LEVEL_PROJECT})
|
||||||
${CTI_CONTINUABLE_IS_TOP_LEVEL_PROJECT})
|
|
||||||
|
|
||||||
option(CTI_CONTINUABLE_WITH_EXAMPLES
|
option(CTI_CONTINUABLE_WITH_TESTS "Build the continuable unit tests"
|
||||||
"Build the continuable examples"
|
${CTI_CONTINUABLE_IS_TOP_LEVEL_PROJECT})
|
||||||
${CTI_CONTINUABLE_IS_TOP_LEVEL_PROJECT})
|
|
||||||
|
|
||||||
option(CTI_CONTINUABLE_WITH_BENCHMARKS
|
option(CTI_CONTINUABLE_WITH_EXAMPLES "Build the continuable examples"
|
||||||
"Build the continuable benchmarks"
|
${CTI_CONTINUABLE_IS_TOP_LEVEL_PROJECT})
|
||||||
OFF)
|
|
||||||
|
|
||||||
option(CTI_CONTINUABLE_WITH_NO_EXCEPTIONS
|
option(CTI_CONTINUABLE_WITH_BENCHMARKS "Build the continuable benchmarks" OFF)
|
||||||
"Disable exception support"
|
|
||||||
OFF)
|
option(CTI_CONTINUABLE_WITH_NO_EXCEPTIONS "Disable exception support" OFF)
|
||||||
|
|
||||||
option(CTI_CONTINUABLE_WITH_UNHANDLED_EXCEPTIONS
|
option(CTI_CONTINUABLE_WITH_UNHANDLED_EXCEPTIONS
|
||||||
"Enable unhandled asynchronous exceptions"
|
"Enable unhandled asynchronous exceptions" OFF)
|
||||||
OFF)
|
|
||||||
|
option(CTI_CONTINUABLE_WITH_COROUTINE "Enable C++20 coroutines" OFF)
|
||||||
|
|
||||||
option(CTI_CONTINUABLE_WITH_EXPERIMENTAL_COROUTINE
|
option(CTI_CONTINUABLE_WITH_EXPERIMENTAL_COROUTINE
|
||||||
"Enable co_await support"
|
"Enable experimental coroutines" OFF)
|
||||||
OFF)
|
|
||||||
|
|
||||||
option(CTI_CONTINUABLE_WITH_CPP_LATEST
|
option(CTI_CONTINUABLE_WITH_CPP_LATEST
|
||||||
"Enable the highest C++ standard available for testing polyfills"
|
"Enable the highest C++ standard available for testing polyfills" OFF)
|
||||||
OFF)
|
|
||||||
|
|
||||||
option(CTI_CONTINUABLE_WITH_LIGHT_TESTS
|
option(CTI_CONTINUABLE_WITH_LIGHT_TESTS
|
||||||
"Disable some template heavy unit tests (for CI usage)"
|
"Disable some template heavy unit tests (for CI usage)" OFF)
|
||||||
OFF)
|
|
||||||
|
|
||||||
# Top level project settings only
|
# Top level project settings only
|
||||||
if (CTI_CONTINUABLE_IS_TOP_LEVEL_PROJECT)
|
if(CTI_CONTINUABLE_IS_TOP_LEVEL_PROJECT)
|
||||||
set(CTI_CONTINUABLE_WITH_CONCURRENT_JOBS
|
set(CTI_CONTINUABLE_WITH_CONCURRENT_JOBS
|
||||||
"0" CACHE STRING
|
"0"
|
||||||
"Set the number of concurrent compilation jobs (0 = unlimited, for CI usage)")
|
CACHE
|
||||||
|
STRING
|
||||||
|
"Set the number of concurrent compilation jobs (0 = unlimited, for CI usage)"
|
||||||
|
)
|
||||||
else()
|
else()
|
||||||
set(CTI_CONTINUABLE_WITH_CONCURRENT_JOBS "0")
|
set(CTI_CONTINUABLE_WITH_CONCURRENT_JOBS "0")
|
||||||
endif()
|
endif()
|
||||||
@ -80,7 +82,7 @@ if(NOT TARGET Threads::Threads)
|
|||||||
find_package(Threads REQUIRED)
|
find_package(Threads REQUIRED)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if (CTI_CONTINUABLE_IS_TOP_LEVEL_PROJECT)
|
if(CTI_CONTINUABLE_IS_TOP_LEVEL_PROJECT)
|
||||||
include(cmake/CMakeLists.txt)
|
include(cmake/CMakeLists.txt)
|
||||||
add_subdirectory(dep)
|
add_subdirectory(dep)
|
||||||
else()
|
else()
|
||||||
@ -90,7 +92,7 @@ else()
|
|||||||
endif()
|
endif()
|
||||||
|
|
||||||
# continuable-base
|
# continuable-base
|
||||||
if (CTI_CONTINUABLE_IS_TOP_LEVEL_PROJECT)
|
if(CTI_CONTINUABLE_IS_TOP_LEVEL_PROJECT)
|
||||||
add_library(continuable-base INTERFACE)
|
add_library(continuable-base INTERFACE)
|
||||||
else()
|
else()
|
||||||
add_library(continuable-base INTERFACE IMPORTED GLOBAL)
|
add_library(continuable-base INTERFACE IMPORTED GLOBAL)
|
||||||
@ -98,55 +100,56 @@ endif()
|
|||||||
|
|
||||||
add_library(continuable::continuable-base ALIAS continuable-base)
|
add_library(continuable::continuable-base ALIAS continuable-base)
|
||||||
|
|
||||||
target_include_directories(continuable-base
|
target_include_directories(
|
||||||
INTERFACE
|
continuable-base
|
||||||
$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/include>
|
INTERFACE $<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/include>
|
||||||
$<INSTALL_INTERFACE:include>)
|
$<INSTALL_INTERFACE:include>)
|
||||||
|
|
||||||
target_link_libraries(continuable-base
|
target_link_libraries(continuable-base INTERFACE Threads::Threads)
|
||||||
INTERFACE
|
|
||||||
Threads::Threads)
|
|
||||||
|
|
||||||
target_compile_features(continuable-base
|
target_compile_features(
|
||||||
INTERFACE
|
continuable-base
|
||||||
cxx_alias_templates
|
INTERFACE cxx_alias_templates
|
||||||
cxx_auto_type
|
cxx_auto_type
|
||||||
cxx_constexpr
|
cxx_constexpr
|
||||||
cxx_decltype
|
cxx_decltype
|
||||||
cxx_decltype_auto
|
cxx_decltype_auto
|
||||||
cxx_final
|
cxx_final
|
||||||
cxx_lambdas
|
cxx_lambdas
|
||||||
cxx_generic_lambdas
|
cxx_generic_lambdas
|
||||||
cxx_variadic_templates
|
cxx_variadic_templates
|
||||||
cxx_defaulted_functions
|
cxx_defaulted_functions
|
||||||
cxx_nullptr
|
cxx_nullptr
|
||||||
cxx_trailing_return_types
|
cxx_trailing_return_types
|
||||||
cxx_return_type_deduction)
|
cxx_return_type_deduction)
|
||||||
|
|
||||||
if (CTI_CONTINUABLE_WITH_CPP_LATEST)
|
if(CTI_CONTINUABLE_WITH_CPP_LATEST)
|
||||||
target_compile_features(continuable-base
|
target_compile_features(continuable-base INTERFACE cxx_std_20)
|
||||||
INTERFACE
|
|
||||||
cxx_std_17)
|
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if (CTI_CONTINUABLE_WITH_EXPERIMENTAL_COROUTINE)
|
if(CTI_CONTINUABLE_WITH_COROUTINE)
|
||||||
target_compile_options(continuable-base
|
if(NOT CTI_CONTINUABLE_WITH_CPP_LATEST)
|
||||||
INTERFACE
|
message(FATAL_ERROR "CTI_CONTINUABLE_WITH_COROUTINE requires "
|
||||||
$<$<CXX_COMPILER_ID:MSVC>:/await>
|
"CTI_CONTINUABLE_WITH_CPP_LATEST!")
|
||||||
$<$<CXX_COMPILER_ID:Clang>:-fcoroutines-ts>)
|
endif()
|
||||||
|
|
||||||
|
target_compile_options(
|
||||||
|
continuable-base
|
||||||
|
INTERFACE $<$<CXX_COMPILER_ID:MSVC>:/await:strict>
|
||||||
|
$<$<CXX_COMPILER_ID:Clang>:-fcoroutines-ts>
|
||||||
|
$<$<CXX_COMPILER_ID:GNU>:-fcoroutines>)
|
||||||
|
elseif(CTI_CONTINUABLE_WITH_EXPERIMENTAL_COROUTINE)
|
||||||
|
target_compile_options(
|
||||||
|
continuable-base INTERFACE $<$<CXX_COMPILER_ID:MSVC>:/await>
|
||||||
|
$<$<CXX_COMPILER_ID:Clang>:-fcoroutines-ts>)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(CTI_CONTINUABLE_WITH_UNHANDLED_EXCEPTIONS)
|
||||||
target_compile_definitions(continuable-base
|
target_compile_definitions(continuable-base
|
||||||
INTERFACE
|
INTERFACE CONTINUABLE_WITH_UNHANDLED_EXCEPTIONS)
|
||||||
CONTINUABLE_WITH_EXPERIMENTAL_COROUTINE)
|
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if (CTI_CONTINUABLE_WITH_UNHANDLED_EXCEPTIONS)
|
if(CTI_CONTINUABLE_IS_TOP_LEVEL_PROJECT)
|
||||||
target_compile_definitions(continuable-base
|
|
||||||
INTERFACE
|
|
||||||
CONTINUABLE_WITH_UNHANDLED_EXCEPTIONS)
|
|
||||||
endif()
|
|
||||||
|
|
||||||
if (CTI_CONTINUABLE_IS_TOP_LEVEL_PROJECT)
|
|
||||||
add_library(continuable INTERFACE)
|
add_library(continuable INTERFACE)
|
||||||
else()
|
else()
|
||||||
add_library(continuable INTERFACE IMPORTED GLOBAL)
|
add_library(continuable INTERFACE IMPORTED GLOBAL)
|
||||||
@ -154,18 +157,15 @@ endif()
|
|||||||
|
|
||||||
add_library(continuable::continuable ALIAS continuable)
|
add_library(continuable::continuable ALIAS continuable)
|
||||||
|
|
||||||
target_link_libraries(continuable
|
target_link_libraries(continuable INTERFACE continuable::continuable-base
|
||||||
INTERFACE
|
function2::function2)
|
||||||
continuable::continuable-base
|
|
||||||
function2::function2)
|
|
||||||
|
|
||||||
if (CTI_CONTINUABLE_WITH_INSTALL)
|
if(CTI_CONTINUABLE_WITH_INSTALL)
|
||||||
include(ExternalProject)
|
include(ExternalProject)
|
||||||
include(GNUInstallDirs)
|
include(GNUInstallDirs)
|
||||||
include(CMakePackageConfigHelpers)
|
include(CMakePackageConfigHelpers)
|
||||||
|
|
||||||
# Create an install target:
|
# Create an install target: Headers and license files
|
||||||
# Headers and license files
|
|
||||||
install(DIRECTORY "${PROJECT_SOURCE_DIR}/include/continuable"
|
install(DIRECTORY "${PROJECT_SOURCE_DIR}/include/continuable"
|
||||||
DESTINATION "include")
|
DESTINATION "include")
|
||||||
install(FILES "LICENSE.txt" DESTINATION .)
|
install(FILES "LICENSE.txt" DESTINATION .)
|
||||||
@ -180,7 +180,8 @@ if (CTI_CONTINUABLE_WITH_INSTALL)
|
|||||||
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}")
|
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}")
|
||||||
|
|
||||||
# ConfigVersion.cmake
|
# ConfigVersion.cmake
|
||||||
configure_package_config_file("cmake/config.cmake.in"
|
configure_package_config_file(
|
||||||
|
"cmake/config.cmake.in"
|
||||||
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake"
|
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake"
|
||||||
INSTALL_DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}"
|
INSTALL_DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}"
|
||||||
# PATH_VARS INCLUDE_INSTALL_DIR SYSCONFIG_INSTALL_DIR
|
# PATH_VARS INCLUDE_INSTALL_DIR SYSCONFIG_INSTALL_DIR
|
||||||
@ -189,15 +190,19 @@ if (CTI_CONTINUABLE_WITH_INSTALL)
|
|||||||
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}")
|
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}")
|
||||||
|
|
||||||
# Targets.cmake
|
# Targets.cmake
|
||||||
export(TARGETS ${PROJECT_NAME} ${PROJECT_NAME}-base
|
export(
|
||||||
NAMESPACE ${PROJECT_NAME}::
|
TARGETS ${PROJECT_NAME} ${PROJECT_NAME}-base
|
||||||
FILE "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Targets.cmake")
|
NAMESPACE ${PROJECT_NAME}::
|
||||||
install(TARGETS ${PROJECT_NAME} ${PROJECT_NAME}-base
|
FILE "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Targets.cmake")
|
||||||
EXPORT "${PROJECT_NAME}Targets"
|
install(
|
||||||
INCLUDES DESTINATION "include")
|
TARGETS ${PROJECT_NAME} ${PROJECT_NAME}-base
|
||||||
install(EXPORT "${PROJECT_NAME}Targets"
|
EXPORT "${PROJECT_NAME}Targets"
|
||||||
NAMESPACE ${PROJECT_NAME}::
|
INCLUDES
|
||||||
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}")
|
DESTINATION "include")
|
||||||
|
install(
|
||||||
|
EXPORT "${PROJECT_NAME}Targets"
|
||||||
|
NAMESPACE ${PROJECT_NAME}::
|
||||||
|
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}")
|
||||||
|
|
||||||
# Setup CPack for bundling
|
# Setup CPack for bundling
|
||||||
set(CPACK_GENERATOR "ZIP")
|
set(CPACK_GENERATOR "ZIP")
|
||||||
@ -209,8 +214,8 @@ if (CTI_CONTINUABLE_WITH_INSTALL)
|
|||||||
endif()
|
endif()
|
||||||
|
|
||||||
# Testing and examples
|
# Testing and examples
|
||||||
if (CTI_CONTINUABLE_WITH_TESTS OR CTI_CONTINUABLE_WITH_EXAMPLES)
|
if(CTI_CONTINUABLE_WITH_TESTS OR CTI_CONTINUABLE_WITH_EXAMPLES)
|
||||||
if (MSVC)
|
if(MSVC)
|
||||||
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
|
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
|
||||||
string(REGEX REPLACE "/W[0-4]" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
|
string(REGEX REPLACE "/W[0-4]" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
|
||||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4")
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4")
|
||||||
@ -218,11 +223,11 @@ if (CTI_CONTINUABLE_WITH_TESTS OR CTI_CONTINUABLE_WITH_EXAMPLES)
|
|||||||
|
|
||||||
enable_testing()
|
enable_testing()
|
||||||
|
|
||||||
if (CTI_CONTINUABLE_WITH_TESTS)
|
if(CTI_CONTINUABLE_WITH_TESTS)
|
||||||
add_subdirectory(test)
|
add_subdirectory(test)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if (CTI_CONTINUABLE_WITH_EXAMPLES)
|
if(CTI_CONTINUABLE_WITH_EXAMPLES)
|
||||||
add_subdirectory(examples)
|
add_subdirectory(examples)
|
||||||
endif()
|
endif()
|
||||||
endif ()
|
endif()
|
||||||
|
|||||||
@ -47,10 +47,9 @@
|
|||||||
#include <continuable/detail/utility/traits.hpp>
|
#include <continuable/detail/utility/traits.hpp>
|
||||||
#include <continuable/detail/utility/util.hpp>
|
#include <continuable/detail/utility/util.hpp>
|
||||||
|
|
||||||
#ifdef CONTINUABLE_HAS_EXPERIMENTAL_COROUTINE
|
#if defined(CONTINUABLE_HAS_COROUTINE)
|
||||||
# include <experimental/coroutine>
|
|
||||||
# include <continuable/detail/other/coroutines.hpp>
|
# include <continuable/detail/other/coroutines.hpp>
|
||||||
#endif // CONTINUABLE_HAS_EXPERIMENTAL_COROUTINE
|
#endif // defined(CONTINUABLE_HAS_COROUTINE)
|
||||||
|
|
||||||
namespace cti {
|
namespace cti {
|
||||||
/// \defgroup Base Base
|
/// \defgroup Base Base
|
||||||
@ -715,7 +714,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// \cond false
|
/// \cond false
|
||||||
#ifdef CONTINUABLE_HAS_EXPERIMENTAL_COROUTINE
|
#if defined(CONTINUABLE_HAS_COROUTINE)
|
||||||
/// \endcond
|
/// \endcond
|
||||||
/// Implements the operator for awaiting on continuables using `co_await`.
|
/// Implements the operator for awaiting on continuables using `co_await`.
|
||||||
///
|
///
|
||||||
@ -781,7 +780,7 @@ public:
|
|||||||
return detail::awaiting::create_awaiter(std::move(*this).finish());
|
return detail::awaiting::create_awaiter(std::move(*this).finish());
|
||||||
}
|
}
|
||||||
/// \cond false
|
/// \cond false
|
||||||
#endif // CONTINUABLE_HAS_EXPERIMENTAL_COROUTINE
|
#endif // defined(CONTINUABLE_HAS_COROUTINE)
|
||||||
/// \endcond
|
/// \endcond
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|||||||
@ -39,11 +39,9 @@
|
|||||||
# include <exception>
|
# include <exception>
|
||||||
#endif // CONTINUABLE_HAS_EXCEPTIONS
|
#endif // CONTINUABLE_HAS_EXCEPTIONS
|
||||||
|
|
||||||
#ifdef CONTINUABLE_HAS_EXPERIMENTAL_COROUTINE
|
#if defined(CONTINUABLE_HAS_COROUTINE)
|
||||||
# include <continuable/detail/other/coroutines.hpp>
|
# include <continuable/detail/other/coroutines.hpp>
|
||||||
#endif // CONTINUABLE_HAS_EXPERIMENTAL_COROUTINE
|
|
||||||
|
|
||||||
#if defined(CONTINUABLE_HAS_EXPERIMENTAL_COROUTINE)
|
|
||||||
namespace cti {
|
namespace cti {
|
||||||
# if defined(CONTINUABLE_HAS_EXCEPTIONS)
|
# if defined(CONTINUABLE_HAS_EXCEPTIONS)
|
||||||
/// Is thrown from co_await expressions if the awaited continuable is canceled
|
/// Is thrown from co_await expressions if the awaited continuable is canceled
|
||||||
@ -78,7 +76,9 @@ using await_canceled_exception = detail::awaiting::await_canceled_exception;
|
|||||||
// As far as I know there is no other way to implement this specialization...
|
// As far as I know there is no other way to implement this specialization...
|
||||||
// NOLINTNEXTLINE(cert-dcl58-cpp)
|
// NOLINTNEXTLINE(cert-dcl58-cpp)
|
||||||
namespace std {
|
namespace std {
|
||||||
|
# if defined(CONTINUABLE_HAS_EXPERIMENTAL_COROUTINE)
|
||||||
namespace experimental {
|
namespace experimental {
|
||||||
|
# endif // defined(CONTINUABLE_HAS_EXPERIMENTAL_COROUTINE)
|
||||||
template <typename Data, typename... Args, typename... FunctionArgs>
|
template <typename Data, typename... Args, typename... FunctionArgs>
|
||||||
struct coroutine_traits<
|
struct coroutine_traits<
|
||||||
cti::continuable_base<Data, cti::detail::identity<Args...>>,
|
cti::continuable_base<Data, cti::detail::identity<Args...>>,
|
||||||
@ -87,9 +87,11 @@ struct coroutine_traits<
|
|||||||
using promise_type = cti::detail::awaiting::promise_type<
|
using promise_type = cti::detail::awaiting::promise_type<
|
||||||
cti::continuable<Args...>, cti::promise<Args...>, Args...>;
|
cti::continuable<Args...>, cti::promise<Args...>, Args...>;
|
||||||
};
|
};
|
||||||
|
# if defined(CONTINUABLE_HAS_EXPERIMENTAL_COROUTINE)
|
||||||
} // namespace experimental
|
} // namespace experimental
|
||||||
|
# endif // defined(CONTINUABLE_HAS_EXPERIMENTAL_COROUTINE)
|
||||||
} // namespace std
|
} // namespace std
|
||||||
/// \endcond
|
/// \endcond
|
||||||
#endif // CONTINUABLE_HAS_EXPERIMENTAL_COROUTINE
|
#endif // defined(CONTINUABLE_HAS_COROUTINE)
|
||||||
|
|
||||||
#endif // CONTINUABLE_COROUTINE_HPP_INCLUDED
|
#endif // CONTINUABLE_COROUTINE_HPP_INCLUDED
|
||||||
|
|||||||
@ -33,19 +33,19 @@
|
|||||||
|
|
||||||
// Defines CONTINUABLE_WITH_NO_EXCEPTIONS when exception support is disabled
|
// Defines CONTINUABLE_WITH_NO_EXCEPTIONS when exception support is disabled
|
||||||
#ifndef CONTINUABLE_WITH_NO_EXCEPTIONS
|
#ifndef CONTINUABLE_WITH_NO_EXCEPTIONS
|
||||||
#if defined(_MSC_VER)
|
# if defined(_MSC_VER)
|
||||||
#if !defined(_HAS_EXCEPTIONS) || (_HAS_EXCEPTIONS == 0)
|
# if !defined(_HAS_EXCEPTIONS) || (_HAS_EXCEPTIONS == 0)
|
||||||
#define CONTINUABLE_WITH_NO_EXCEPTIONS
|
# define CONTINUABLE_WITH_NO_EXCEPTIONS
|
||||||
#endif
|
# endif
|
||||||
#elif defined(__clang__)
|
# elif defined(__clang__)
|
||||||
#if !(__EXCEPTIONS && __has_feature(cxx_exceptions))
|
# if !(__EXCEPTIONS && __has_feature(cxx_exceptions))
|
||||||
#define CONTINUABLE_WITH_NO_EXCEPTIONS
|
# define CONTINUABLE_WITH_NO_EXCEPTIONS
|
||||||
#endif
|
# endif
|
||||||
#elif defined(__GNUC__)
|
# elif defined(__GNUC__)
|
||||||
#if !__EXCEPTIONS
|
# if !__EXCEPTIONS
|
||||||
#define CONTINUABLE_WITH_NO_EXCEPTIONS
|
# define CONTINUABLE_WITH_NO_EXCEPTIONS
|
||||||
#endif
|
# endif
|
||||||
#endif
|
# endif
|
||||||
#endif // CONTINUABLE_WITH_NO_EXCEPTIONS
|
#endif // CONTINUABLE_WITH_NO_EXCEPTIONS
|
||||||
|
|
||||||
// clang-format off
|
// clang-format off
|
||||||
@ -86,24 +86,40 @@
|
|||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/// Usually this is enabled by the CMake project
|
// Automatically detects support for coroutines.
|
||||||
#if !defined(CONTINUABLE_HAS_EXPERIMENTAL_COROUTINE)
|
// Parts of this detection mechanism were adapted from boost::asio,
|
||||||
|
// with support added for experimental coroutines.
|
||||||
|
#if !defined(CONTINUABLE_HAS_DISABLED_COROUTINE) \
|
||||||
|
&& !defined(CONTINUABLE_HAS_COROUTINE)
|
||||||
/// Define CONTINUABLE_HAS_EXPERIMENTAL_COROUTINE when
|
/// Define CONTINUABLE_HAS_EXPERIMENTAL_COROUTINE when
|
||||||
/// CONTINUABLE_WITH_EXPERIMENTAL_COROUTINE is defined.
|
/// CONTINUABLE_WITH_EXPERIMENTAL_COROUTINE is defined.
|
||||||
#if defined(CONTINUABLE_WITH_EXPERIMENTAL_COROUTINE)
|
#if defined(CONTINUABLE_WITH_EXPERIMENTAL_COROUTINE)
|
||||||
#define CONTINUABLE_HAS_EXPERIMENTAL_COROUTINE
|
#define CONTINUABLE_HAS_COROUTINE 1
|
||||||
#elif defined(_MSC_VER)
|
#elif defined(CONTINUABLE_WITH_COROUTINE)
|
||||||
#if _MSC_FULL_VER >= 190023506
|
#define CONTINUABLE_HAS_COROUTINE 1
|
||||||
|
#define CONTINUABLE_HAS_EXPERIMENTAL_COROUTINE 1
|
||||||
|
#elif defined(_MSC_VER) // Visual Studio
|
||||||
|
#if (_MSC_VER >= 1928) && (_MSVC_LANG >= 201705)
|
||||||
|
#define CONTINUABLE_HAS_COROUTINE 1
|
||||||
|
#elif _MSC_FULL_VER >= 190023506
|
||||||
#if defined(_RESUMABLE_FUNCTIONS_SUPPORTED)
|
#if defined(_RESUMABLE_FUNCTIONS_SUPPORTED)
|
||||||
#define CONTINUABLE_HAS_EXPERIMENTAL_COROUTINE
|
#define CONTINUABLE_HAS_COROUTINE 1
|
||||||
|
#define CONTINUABLE_HAS_EXPERIMENTAL_COROUTINE 1
|
||||||
#endif // defined(_RESUMABLE_FUNCTIONS_SUPPORTED)
|
#endif // defined(_RESUMABLE_FUNCTIONS_SUPPORTED)
|
||||||
#endif // _MSC_FULL_VER >= 190023506
|
#endif // _MSC_FULL_VER >= 190023506
|
||||||
#elif defined(__clang__)
|
#elif defined(__clang__) // Clang
|
||||||
#if defined(__cpp_coroutines) && (__cpp_coroutines >= 201707)
|
#if defined(__cpp_coroutines) && (__cpp_coroutines >= 201707)
|
||||||
#define CONTINUABLE_HAS_EXPERIMENTAL_COROUTINE
|
#define CONTINUABLE_HAS_COROUTINE 1
|
||||||
|
#define CONTINUABLE_HAS_EXPERIMENTAL_COROUTINE 1
|
||||||
#endif // defined(__cpp_coroutines) && (__cpp_coroutines >= 201707)
|
#endif // defined(__cpp_coroutines) && (__cpp_coroutines >= 201707)
|
||||||
#endif // defined(__clang__)
|
#elif defined(__GNUC__) // GCC
|
||||||
#endif // !defined(CONTINUABLE_HAS_EXPERIMENTAL_COROUTINE)
|
#if (__cplusplus >= 201709) && (__cpp_impl_coroutine >= 201902)
|
||||||
|
#if __has_include(<coroutine>)
|
||||||
|
#define CONTINUABLE_HAS_COROUTINE 1
|
||||||
|
#endif // __has_include(<coroutine>)
|
||||||
|
#endif // (__cplusplus >= 201709) && (__cpp_impl_coroutine >= 201902)
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
/// Define CONTINUABLE_HAS_EXCEPTIONS when exceptions are used
|
/// Define CONTINUABLE_HAS_EXCEPTIONS when exceptions are used
|
||||||
#if !defined(CONTINUABLE_WITH_CUSTOM_ERROR_TYPE) && \
|
#if !defined(CONTINUABLE_WITH_CUSTOM_ERROR_TYPE) && \
|
||||||
|
|||||||
@ -34,7 +34,6 @@
|
|||||||
|
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
#include <type_traits>
|
#include <type_traits>
|
||||||
#include <experimental/coroutine>
|
|
||||||
#include <continuable/continuable-primitives.hpp>
|
#include <continuable/continuable-primitives.hpp>
|
||||||
#include <continuable/continuable-result.hpp>
|
#include <continuable/continuable-result.hpp>
|
||||||
#include <continuable/detail/core/annotation.hpp>
|
#include <continuable/detail/core/annotation.hpp>
|
||||||
@ -48,13 +47,26 @@
|
|||||||
# include <exception>
|
# include <exception>
|
||||||
#endif // CONTINUABLE_HAS_EXCEPTIONS
|
#endif // CONTINUABLE_HAS_EXCEPTIONS
|
||||||
|
|
||||||
|
#if defined(CONTINUABLE_HAS_EXPERIMENTAL_COROUTINE)
|
||||||
|
# include <experimental/coroutine>
|
||||||
|
#elif defined(CONTINUABLE_HAS_COROUTINE)
|
||||||
|
# include <coroutine>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(CONTINUABLE_HAS_COROUTINE)
|
||||||
namespace cti {
|
namespace cti {
|
||||||
namespace detail {
|
namespace detail {
|
||||||
namespace awaiting {
|
namespace awaiting {
|
||||||
/// We import the coroutine handle in our namespace
|
/// We import the coroutine handle in our namespace
|
||||||
|
# if defined(CONTINUABLE_HAS_EXPERIMENTAL_COROUTINE)
|
||||||
using std::experimental::coroutine_handle;
|
using std::experimental::coroutine_handle;
|
||||||
|
using std::experimental::suspend_never;
|
||||||
|
# else
|
||||||
|
using std::coroutine_handle;
|
||||||
|
using std::suspend_never;
|
||||||
|
# endif
|
||||||
|
|
||||||
#if defined(CONTINUABLE_HAS_EXCEPTIONS)
|
# if defined(CONTINUABLE_HAS_EXCEPTIONS)
|
||||||
class await_canceled_exception : public std::exception {
|
class await_canceled_exception : public std::exception {
|
||||||
public:
|
public:
|
||||||
await_canceled_exception() noexcept = default;
|
await_canceled_exception() noexcept = default;
|
||||||
@ -63,7 +75,7 @@ public:
|
|||||||
return "co_await canceled due to cancellation of the continuation";
|
return "co_await canceled due to cancellation of the continuation";
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
#endif // CONTINUABLE_HAS_EXCEPTIONS
|
# endif // CONTINUABLE_HAS_EXCEPTIONS
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
struct result_from_identity;
|
struct result_from_identity;
|
||||||
@ -126,16 +138,16 @@ public:
|
|||||||
|
|
||||||
assert(result_.is_exception());
|
assert(result_.is_exception());
|
||||||
|
|
||||||
#if defined(CONTINUABLE_HAS_EXCEPTIONS)
|
# if defined(CONTINUABLE_HAS_EXCEPTIONS)
|
||||||
if (exception_t e = result_.get_exception()) {
|
if (exception_t e = result_.get_exception()) {
|
||||||
std::rethrow_exception(std::move(e));
|
std::rethrow_exception(std::move(e));
|
||||||
} else {
|
} else {
|
||||||
throw await_canceled_exception();
|
throw await_canceled_exception();
|
||||||
}
|
}
|
||||||
#else // CONTINUABLE_HAS_EXCEPTIONS
|
# else // CONTINUABLE_HAS_EXCEPTIONS
|
||||||
// Returning error types from co_await isn't supported!
|
// Returning error types from co_await isn't supported!
|
||||||
CTI_DETAIL_TRAP();
|
CTI_DETAIL_TRAP();
|
||||||
#endif // CONTINUABLE_HAS_EXCEPTIONS
|
# endif // CONTINUABLE_HAS_EXCEPTIONS
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -213,12 +225,12 @@ struct promise_type
|
|||||||
return {handle_};
|
return {handle_};
|
||||||
}
|
}
|
||||||
|
|
||||||
std::experimental::suspend_never final_suspend() {
|
suspend_never final_suspend() noexcept {
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
void unhandled_exception() noexcept {
|
void unhandled_exception() noexcept {
|
||||||
#if defined(CONTINUABLE_HAS_EXCEPTIONS)
|
# if defined(CONTINUABLE_HAS_EXCEPTIONS)
|
||||||
try {
|
try {
|
||||||
std::rethrow_exception(std::current_exception());
|
std::rethrow_exception(std::current_exception());
|
||||||
} catch (await_canceled_exception const&) {
|
} catch (await_canceled_exception const&) {
|
||||||
@ -226,14 +238,15 @@ struct promise_type
|
|||||||
} catch (...) {
|
} catch (...) {
|
||||||
promise_.set_exception(std::current_exception());
|
promise_.set_exception(std::current_exception());
|
||||||
}
|
}
|
||||||
#else // CONTINUABLE_HAS_EXCEPTIONS
|
# else // CONTINUABLE_HAS_EXCEPTIONS
|
||||||
// Returning exception types from a coroutine isn't supported
|
// Returning exception types from a coroutine isn't supported
|
||||||
CTI_DETAIL_TRAP();
|
CTI_DETAIL_TRAP();
|
||||||
#endif // CONTINUABLE_HAS_EXCEPTIONS
|
# endif // CONTINUABLE_HAS_EXCEPTIONS
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
} // namespace awaiting
|
} // namespace awaiting
|
||||||
} // namespace detail
|
} // namespace detail
|
||||||
} // namespace cti
|
} // namespace cti
|
||||||
|
#endif // defined(CONTINUABLE_HAS_COROUTINE)
|
||||||
|
|
||||||
#endif // CONTINUABLE_DETAIL_UTIL_HPP_INCLUDED
|
#endif // CONTINUABLE_DETAIL_UTIL_HPP_INCLUDED
|
||||||
|
|||||||
@ -24,7 +24,8 @@
|
|||||||
#include <test-continuable.hpp>
|
#include <test-continuable.hpp>
|
||||||
|
|
||||||
#include <continuable/detail/features.hpp>
|
#include <continuable/detail/features.hpp>
|
||||||
#ifdef CONTINUABLE_HAS_EXPERIMENTAL_COROUTINE
|
|
||||||
|
#ifdef CONTINUABLE_HAS_COROUTINE
|
||||||
|
|
||||||
# ifndef CONTINUABLE_WITH_NO_EXCEPTIONS
|
# ifndef CONTINUABLE_WITH_NO_EXCEPTIONS
|
||||||
# include <exception>
|
# include <exception>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user