9 Iterators library [iterators]

9.7 Iterator adaptors [iterators.predef]

9.7.7 Dangling wrapper [dangling.wrappers]

9.7.7.1 Class template dangling [dangling.wrap]

Class template dangling is a wrapper for an object that refers to another object whose lifetime may have ended. It is used by algorithms that accept rvalue ranges and return iterators.

namespace std { namespace experimental { namespace ranges { inline namespace v1 {
  template <CopyConstructible T>
  class dangling {
  public:
    constexpr dangling() requires DefaultConstructible<T>;
    constexpr dangling(T t);
    constexpr T get_unsafe() const;
  private:
    T value; // exposition only
  };

  template <Range R>
  using safe_iterator_t =
    conditional_t<is_lvalue_reference<R>::value,
      iterator_t<R>,
      dangling<iterator_t<R>>>;
}}}}

9.7.7.2 dangling operations [dangling.wrap.ops]

9.7.7.2.1 dangling constructors [dangling.wrap.op.const]

constexpr dangling() requires DefaultConstructible<T>;

Effects: Constructs a dangling, value-initializing value.

constexpr dangling(T t);

Effects: Constructs a dangling, initializing value with t.

9.7.7.2.2 dangling::get_unsafe [dangling.wrap.op.get]

constexpr T get_unsafe() const;

Returns: value.