TaskFlow.for_each_index() compilation error
WalterDehnen opened this issue · comments
Describe the bug
template <typename B, typename E, typename S, typename C, typename P = DefaultPartitioner>
Task FlowBuilder::for_each_index(B first, E last, S step, C callable, P part = P());
defined in flow_builder.hpp allows for different types for first, last, and step. However, the actual implementation in algorithm/for_each.hpp fails should these not decay to identical types, since it calls
distance(T beg, T end, T step)
of utility/iterator.hpp.
To Reproduce
tf::Taskflow flow;
flow.for_each_index(0u, 10u, 1, [] (unsigned i) { printf("i=%d",i); });
tf::Executor exec;
exec.run(flow).wait();
To avoid, simply only allow first, last, and end to be of identical integer type, i.e.
template <typename T, typename C, typename P = DefaultPartitioner>
std::enable_if_t<std::is_integral<std::decay_t<T>>::value, Task>
FlowBuilder::for_each_index(T first, T last, T step, C callable, P part = P());
The same issue pertains to many similarly defined methods in taskflow.
Hi @WalterDehnen , the purpose of this design is to enable stateful parameter passing, as the range may be modified by other task before running the algorithm task. This is why we template the three different arguments. You may have a look at this page.