Is it intended that following example exhibit precondition violation?
#include <memory>
#include <iostream>
#include <vector>
#include <ranges>
int main() {
std::vector<int> x{1, 2, 3, 4};
auto r = x | std::views::transform([](int x){return std::make_unique<int>(x); });
auto r2 = r | std::views::transform([](std::unique_ptr<int> v){
return *v;
});
for(auto i : r2) {
std::cout << i << ' ';
}
}
std::ranges::transform_view
has constraint on F fun
that it should be regular_invocable<F&, range_reference_t<V>>
. As written in [concept.regularinvocable] regular_invocable
"shall not modify the function object or the arguments". So r2
function violates that semantic constraint as it modifies argument by moving from it.
Is this interpretation valid?