range-v3
range-v3 copied to clipboard
Can't use for_each with move-only range
https://godbolt.org/z/ZZWbk7:
#include <iterator>
#include <range/v3/algorithm/for_each.hpp>
void f()
{
int x;
ranges::for_each(
std::move_iterator{&x},
std::move_iterator{&x + 1},
[](int&&)
{
});
}
The invocable<F &, iter_value_t<I> &>
requirement overconstraints the simplest algorithm which is even a first class citizen. I suggest changing the indirectly_unary_invocable<F, projected<I, P>>
constraint to the minimal invocable<projected<I, P>, iter_reference_t<I>>
.
This is actually how the constraints of for_each
are currently specified in the C++20 draft. We'll need to do some hard thinking about whether we should loosen the constraints of the for_each
algorithm and make them inconsistent with the others. We already loosened the requirements of transform
this way. @CaseyCarter, thoughts?
This should be solved by:
WG21 Number | Title | Author |
---|---|---|
P2997R0 | Removing the common reference requirement from the indirectly invocable concepts | Barry Revzin, Tim Song |