Skip to content

Conversation

@eckertliam
Copy link

The fix uses SFINAE to detect when E_t (end iterator type) differs from B_t (begin iterator type), indicating a sentinel-based range that cannot use std::distance.

- Add compile-time detection for sentinel-based ranges
- Fall back to sequential execution for infinite ranges
- Maintain parallel execution for finite ranges
- Fixes issue taskflow#534: taskflow::find_if doesn't work with infinite ranges

The fix uses SFINAE to detect when E_t (end iterator type) differs from B_t
(begin iterator type), indicating a sentinel-based range that cannot use std::distance.
part([=, &result]() mutable {
result = std::find_if(beg, end, predicate);
})();
return;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The early return here will not help against the compiler trying to instantiate std::distance further down. You must either wrap the remainder of the function in an else {... for the constexpr branch, or figure out a different way to avoid the std::distance-call.. This feature should be relatively simple to add a test for, so my suggestion is to do just that and make sure that it works. Github action should then try to run that test for various other toolchains.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants