16:37 I think the idiomatic way to silence this error is to specialize the `enabled_borrowed_range` template en.cppreference.com/w/cpp/ranges/borrowed_range
What about this solution for the dangling problem at 25:58? auto fun() { using namespace ranges::view; // a vector by value auto v = std::vector{1,2,3}; auto w = filter([](auto i){ return i%2;}); // return a lambda which captures the vector // and provides this and the filtered vector when called // to avoid a dangling reference return [=]{ return std::make_tuple(v, v | w);}; } Unfortunately the use of this as a whole is limited, as when using it you have to take care that the lambda stays alive so its captures stay alive. Here C++ gets nasty, i hope compilers will give more help/warnings/errors about various object lifetime troubles in the future.
16:37 I think the idiomatic way to silence this error is to specialize the `enabled_borrowed_range` template en.cppreference.com/w/cpp/ranges/borrowed_range
What about this solution for the dangling problem at 25:58?
auto fun()
{
using namespace ranges::view;
// a vector by value
auto v = std::vector{1,2,3};
auto w = filter([](auto i){ return i%2;});
// return a lambda which captures the vector
// and provides this and the filtered vector when called
// to avoid a dangling reference
return [=]{ return std::make_tuple(v, v | w);};
}
Unfortunately the use of this as a whole is limited, as when using it you have to take care that the lambda stays alive so its captures stay alive.
Here C++ gets nasty, i hope compilers will give more help/warnings/errors about various object lifetime troubles in the future.
This seems very similar to Rust's iterators, but in C++. Very cool.
Rust iterators look like other language iterators as well