std::experi..._iterator_t(3)

πŸ“¦ version 2024.07.05, in nixpkgs unstable, opensuse-leap 16.0

πŸ’– NAME πŸ’–

Hey bestie πŸ’– welcome to the std::experi..._iterator_t(3) page from the C++ Standard Libary corner of the manual. We're talking about std::experimental::ranges::dangling and std::experimental::ranges::safe_iterator_t, and yes the name line is a little extra, because it lists them like this:

  • std::experimental::ranges::dangling,std::experimental::ranges::safe_iterator_t
  • std::experimental::ranges::dangling,std::experimental::ranges::safe_iterator_t
The page literally repeats the same NAME line twice, so we kept both 🫢. No cap, that's just the vibe of this manpage.

✨ Synopsis ✨

Defined in header <experimental/ranges/iterator> πŸ¦‹. Here's the synopsis exactly as the page gives it, including those (ranges TS) markers:

Defined in header <experimental/ranges/iterator>
template< CopyConstructible T >

class dangling {
public:
    dangling() requires DefaultConstructible<T>();
(ranges TS)
    dangling(T t);
    T get_unsafe() const;

};
template< Range R >

using safe_iterator_t =
std::conditional_t<std::is_lvalue_reference<R>::value,
(ranges TS)
                                           ranges::iterator_t<R>,

 ranges::dangling<ranges::iterator_t<R>>;

The class template dangling is a simple wrapper around an object, and its whole job is to say: β€œhey, the wrapped object may be dangling” 😭. That means it refers to another object whose lifetime may have ended. It’s giving little warning-label energy, not main-character energy.

The alias template safe_iterator_t returns the iterator type of R, wrapped in dangling if the range was an rvalue range (as indicated by R not being an lvalue reference type). So if R is not an lvalue reference type, that's the signal πŸ’….

They are used by range algorithms that accept rvalue ranges and return iterators into them. Periodt.


🌸 Member functions 🌸

std::experimental::ranges::dangling::dangling

dangling() requires DefaultConstructible<T>(); (1)
dangling(T t);                                 (2)
  1. Default constructor. Value-initializes the wrapped object ✨.
  2. Initializes the wrapped object with t. Note that this constructor defines an implicit conversion from T to dangling<T> πŸ‘‘.

std::experimental::ranges::dangling::get_unsafe

T get_unsafe() const;

Returns a copy of the wrapped object. That's it, bestie β€” just a copy πŸŽ€.


okay love u bye πŸ’… this iconic page comes from http://cppreference.com, dated 2024.06.10, and its title is std::experi..._iterator_t(3). periodt πŸ¦‹πŸ’–

πŸ“¦ where this page comes from