Fix find_if and find_if_not to support infinite ranges#715
Open
eckertliam wants to merge 1 commit intotaskflow:masterfrom
Open
Fix find_if and find_if_not to support infinite ranges#715eckertliam wants to merge 1 commit intotaskflow:masterfrom
eckertliam wants to merge 1 commit intotaskflow:masterfrom
Conversation
- 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.
doocman
reviewed
Sep 17, 2025
| part([=, &result]() mutable { | ||
| result = std::find_if(beg, end, predicate); | ||
| })(); | ||
| return; |
Contributor
There was a problem hiding this comment.
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.