24 Ranges library [ranges]

24.5 Range utilities [range.utility]

24.5.4 Dangling iterator handling [range.dangling]

The tag type dangling is used together with the template aliases safe_­iterator_­t and safe_­subrange_­t to indicate that an algorithm that typically returns an iterator into or subrange of a Range argument does not return an iterator or subrange which could potentially reference a range whose lifetime has ended for a particular rvalue Range argument which does not model forwarding-range ([range.range]).
namespace std {
  struct dangling {
    constexpr dangling() noexcept = default;
    template<class... Args>
      constexpr dangling(Args&&...) noexcept { }
  };
}
[Example
:
vector<int> f();
auto result1 = ranges::find(f(), 42);                                   // #1
static_assert(Same<decltype(result1), dangling>);
auto vec = f();
auto result2 = ranges::find(vec, 42);                                   // #2
static_assert(Same<decltype(result2), vector<int>::iterator>);
auto result3 = ranges::find(subrange{vec}, 42);                         // #3
static_assert(Same<decltype(result3), vector<int>::iterator>);
The call to ranges::find at #1 returns dangling since f() is an rvalue vector; the vector could potentially 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 subrange model forwarding-range.
end example
]