The C++20 standard says in [range.adaptors.general] that range adaptors
evaluate lazily as the resulting view is iterated.
On the other hand, there is a remark in [range.filter.view] for filter_view's begin function mentioning caching the result. To what degree are the adaptors lazy then?
When executing following code:
#include <iostream>
#include <ranges>
void print(std::ranges::range auto&& r)
{
for (const auto& item : r)
{
std::cout << item << ", ";
}
std::cout << " <end of range>\n";
}
int main()
{
using namespace std::ranges;
bool filter = false;
auto v = iota_view{4, 10} | views::filter([&filter](auto item){return filter;});
// multipass guarantee
static_assert(std::ranges::forward_range<decltype(v)>);
filter = true;
print(v);
filter = false;
print(v);
filter = true;
print(v);
}
Is there a guarantee that adaptor will respect the value of filter
variable? If not, what kind of behavior am I invoking and where is it stated?