Now I can't find any compiler yet that has this support for the "one ranges proposal" so this is more of an academic question. I'm curious if the following will work like I expect
#include <iostream>
#include <vector>
#include <ranges>
auto Foo (){
std::vector<int> a = {1,2,3,4,5};
return std::move(a) | std::reverse;
}
int main(){
for(auto a : Foo()){
std::cout << a << std::endl;
}
}
with an expected output of
5
4
3
2
1
The question has to do with the ownership semantics of the range adaptors. I say I want to move a and then wrap it with a view. What is expected to happen?
- Not compile.
- Compile but maybe crash with a memory corruption
- Work as expected