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

taskflow find_if doesn't work with infinite ranges because std::distance is used #534

Open
bradphelan opened this issue Dec 1, 2023 · 3 comments
Labels
help wanted Extra attention is needed

Comments

@bradphelan
Copy link
Contributor

bradphelan commented Dec 1, 2023

In taskflow::find_if doesn't work with infinite ranges.

However an infinite range is a reasonable input to find_if. For example

std::ranges::iota(0)

produces an infinite range starting from 0.

However taskflow::find_if calls std::distance on the two iterators which cannot work if the second iterator is a sentinel std::unreachable_sentinel

In this case taskflow::find_if should find a sensible alternative to chunking. In our case we explicitly pass StaticPartitioner(1) so we don't require chunking.

@tsung-wei-huang
Copy link
Member

We are following the C++ standard algorithm (and parallel algorithms as well) that does not check if the given iterators are valid/invalid. Invalid range iterators will result in undefined behavior.

@bradphelan
Copy link
Contributor Author

bradphelan commented Dec 17, 2023 via email

@bradphelan
Copy link
Contributor Author

Also standard library does support infinite ranges. For example here is how to uses std::ranges::find to implement strlen

https://godbolt.org/z/Efhsjndv6

#include <ranges>
#include <iostream>
   
template<class CharT>
constexpr std::size_t my_strlen(const CharT *s)
{
    return std::ranges::find(s, std::unreachable_sentinel, CharT{}) - s;
}


int main(){
    const char * foo = "hello world";
    std::cout << my_strlen(foo) << std::endl;
}

@tsung-wei-huang tsung-wei-huang added the help wanted Extra attention is needed label Feb 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants