[range.dangling] (original) (raw)
[Example 1: vector<int> f();auto result1 = ranges::find(f(), 42); static_assert(same_as<decltype(result1), ranges::dangling>);auto vec = f();auto result2 = ranges::find(vec, 42); static_assert(same_as<decltype(result2), vector<int>::iterator>);auto result3 = ranges::find(ranges::subrange{vec}, 42); static_assert(same_as<decltype(result3), vector<int>::iterator>);
The call to ranges::find at #1 returns ranges::danglingsince f() is an rvalue vector; it is possible for the vector to be destroyed before a returned iterator is dereferenced.
However, the calls at #2 and #3 both return iterators since the lvalue vec and specializations of subrangemodel borrowed_range.
— _end example_]