Skip to content

Commit 756893f

Browse files
authored
Merge pull request #47 from IanLilleyT/invoke_result
2 parents 7d44011 + b9d2646 commit 756893f

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

CMakeLists.txt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,19 @@ if (NOT USE_CXX_EXCEPTIONS)
114114
endif()
115115
endif()
116116

117+
# /Zc:__cplusplus is required to make __cplusplus accurate
118+
# /Zc:__cplusplus is available starting with Visual Studio 2017 version 15.7
119+
# (according to https://docs.microsoft.com/en-us/cpp/build/reference/zc-cplusplus)
120+
# That version is equivalent to _MSC_VER==1914
121+
# (according to https://docs.microsoft.com/en-us/cpp/preprocessor/predefined-macros?view=vs-2019)
122+
# CMake's ${MSVC_VERSION} is equivalent to _MSC_VER
123+
# (according to https://cmake.org/cmake/help/latest/variable/MSVC_VERSION.html#variable:MSVC_VERSION)
124+
# GREATER and EQUAL are used because GREATER_EQUAL is available starting with CMake 3.7
125+
# (according to https://cmake.org/cmake/help/v3.7/release/3.7.html#commands)
126+
if ((MSVC) AND ((MSVC_VERSION GREATER 1914) OR (MSVC_VERSION EQUAL 1914)))
127+
target_compile_options(Async++ PUBLIC /Zc:__cplusplus)
128+
endif()
129+
117130
include(CMakePackageConfigHelpers)
118131
configure_package_config_file("${CMAKE_CURRENT_LIST_DIR}/Async++Config.cmake.in"
119132
"${PROJECT_BINARY_DIR}/Async++Config.cmake"

include/async++/task.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -473,8 +473,14 @@ class local_task {
473473
};
474474

475475
// Spawn a function asynchronously
476+
#if (__cplusplus >= 201703L)
477+
// Use std::invoke_result instead of std::result_of for C++17 or greater because std::result_of was deprecated in C++17 and removed in C++20
478+
template<typename Sched, typename Func>
479+
task<typename detail::remove_task<std::invoke_result_t<std::decay_t<Func>>>::type> spawn(Sched& sched, Func&& f)
480+
#else
476481
template<typename Sched, typename Func>
477482
task<typename detail::remove_task<typename std::result_of<typename std::decay<Func>::type()>::type>::type> spawn(Sched& sched, Func&& f)
483+
#endif
478484
{
479485
// Using result_of in the function return type to work around bugs in the Intel
480486
// C++ compiler.

0 commit comments

Comments
 (0)