Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix issue #446 byy adding workround for visual studio 2017 #449

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 8 additions & 0 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,14 @@ list(APPEND TF_EXAMPLES
cancel_async
)

if (MSVC)
if(MSVC_VERSION VERSION_LESS 1920)
message("visual studio 2017 can not compile example: parallel_data_pipeline, skip it")
endif()
else()
list(append TF_EXAMPLES parallel_data_pipeline)
endif()

foreach(example IN LISTS TF_EXAMPLES)
add_executable(${example} ${example}.cpp)
target_link_libraries(
Expand Down
30 changes: 27 additions & 3 deletions taskflow/core/executor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -752,6 +752,9 @@ class Executor {
template <typename P>
void _loop_until(Worker&, P&&);

template <typename F, bool IsVoidRet, typename... ArgsT>
auto _named_async_T(const std::string& name, F&& f, ArgsT&&... args);

template <typename C, std::enable_if_t<is_cudaflow_task_v<C>, void>* = nullptr>
void _invoke_cudaflow_task_entry(Node*, C&&);

Expand Down Expand Up @@ -818,9 +821,16 @@ inline Worker* Executor::_this_worker() {
return itr == _wids.end() ? nullptr : &_workers[itr->second];
}

// Function: named_async
template <typename F, typename... ArgsT>
auto Executor::named_async(const std::string& name, F&& f, ArgsT&&... args) {
// workaround for visual studio 2017, see details in issues#446
return _named_async_T<F, std::is_same_v<std::invoke_result_t<F, ArgsT...>, void>, ArgsT...>
(name, std::forward<F>(f), std::forward<ArgsT>(args)...);
}

// Function: named_async
template <typename F, bool IsVoidRet, typename... ArgsT>
auto Executor::_named_async_T(const std::string& name, F&& f, ArgsT&&... args) {

_increment_topology();

Expand All @@ -837,7 +847,7 @@ auto Executor::named_async(const std::string& name, F&& f, ArgsT&&... args) {
std::in_place_type_t<Node::Async>{},
[p=make_moc(std::move(p)), f=std::forward<F>(f), args...]
(bool cancel) mutable {
if constexpr(std::is_same_v<R, void>) {
if constexpr(IsVoidRet) {
if(!cancel) {
f(args...);
}
Expand Down Expand Up @@ -2010,6 +2020,20 @@ auto Subflow::named_async(const std::string& name, F&& f, ArgsT&&... args) {
// Function: _named_async
template <typename F, typename... ArgsT>
auto Subflow::_named_async(
Worker& w,
const std::string& name,
F&& f,
ArgsT&&... args
) {
// workaround for visual studio 2017, see details in discussion in issues#446
// by adding an extra function call wrapper, because type_trait not working in lambda
return _named_async_T<F, std::is_same_v<std::invoke_result_t<F, ArgsT...>, void>, ArgsT...>
(w, name, std::forward<F>(f), std::forward<ArgsT>(args)...);
}

// workaround
template <typename F, bool IsVoidRet, typename... ArgsT>
auto Subflow::_named_async_T(
Worker& w,
const std::string& name,
F&& f,
Expand All @@ -2031,7 +2055,7 @@ auto Subflow::_named_async(
std::in_place_type_t<Node::Async>{},
[p=make_moc(std::move(p)), f=std::forward<F>(f), args...]
(bool cancel) mutable {
if constexpr(std::is_same_v<R, void>) {
if constexpr(IsVoidRet) {
if(!cancel) {
f(args...);
}
Expand Down
3 changes: 3 additions & 0 deletions taskflow/core/flow_builder.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1096,6 +1096,9 @@ class Subflow : public FlowBuilder {
template <typename F, typename... ArgsT>
auto _named_async(Worker& w, const std::string& name, F&& f, ArgsT&&... args);

template <typename F, bool IsVoidRet, typename... ArgsT>
auto _named_async_T(Worker& w, const std::string& name, F&& f, ArgsT&&... args);

template <typename F, typename... ArgsT>
void _named_silent_async(Worker& w, const std::string& name, F&& f, ArgsT&&... args);
};
Expand Down
9 changes: 8 additions & 1 deletion unittests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,17 @@ list(APPEND TF_UNITTESTS
scalable_pipelines
deferred_pipelines
runtimes
data_pipelines
workers
)

if (MSVC)
if(MSVC_VERSION VERSION_LESS 1920)
message("visual studio 2017 can not compile unittest: data_pipelines, skip it")
endif()
else()
list(append TF_UNITTESTS data_pipelines)
endif()

foreach(unittest IN LISTS TF_UNITTESTS)
add_executable(${unittest} ${unittest}.cpp)
target_link_libraries(${unittest} ${PROJECT_NAME} tf::default_settings)
Expand Down