std::refere...ence_wrapper(3)

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

πŸ’… std::reference_wrapper::reference_wrapper

okay so bestie, welcome to the std::reference_wrapper constructor page β€” that's std::refere...ence_wrapper(3) from the C++ Standard Libary if you're being formal about it. yes the title's truncated, she's shy, it's giving "name too long for the terminal." anyway. this is the constructor. let's get into it 🫢


✨ Synopsis

template< class U >                                      (1) (since C++11)
reference_wrapper( U&& x ) noexcept(/*see below*/) ;
(constexpr since C++20)
reference_wrapper( const reference_wrapper& other )      (2) (since C++11)
noexcept;
(constexpr since C++20)

Constructs a new reference wrapper. that's the whole vibe πŸ’«

  1. Converts x to T& as if by T& t = std::forward<U>(x);, then stores a reference to t. This overload participates in overload resolution only if typename std::decay<U>::type is not the same type as reference_wrapper and the expression FUN(std::declval<U>()) is well-formed, where FUN names the set of imaginary functions:
void FUN(T&) noexcept;
void FUN(T&&) = delete;

like, yes, "imaginary functions," she said what she said 🧚 not me inventing overload resolution rules and calling them imaginary πŸ’€

  1. Copy constructor. Stores a reference to other.get().

🌸 Parameters

  • x β€” an object to wrap 🎁
  • other β€” another reference wrapper πŸŽ€

πŸ”₯ Exceptions

  1. noexcept specification:
noexcept(noexcept(FUN(std::declval<U>())))

where FUN is the set of imaginary functions described in the description above. it's giving noexcept inception, iykyk 😭


πŸ¦‹ Example

This section is incomplete

Reason: no example

not me being obsessed with a page that literally has no example πŸ™ˆ it's fine, we're fine, everything's fine

πŸ‘‘ Defect reports

The following behavior-changing defect reports were applied retroactively to previously published C++ standards. retroactive glow-ups, we love to see it ✨

  • DR LWG 2993, applied to C++11 β€” behavior as published: deleted reference_wrapper(T&&) constructor interferes with overload resolution in some cases. Correct behavior: replaced with a constructor template. she ate and left no crumbs πŸ’…

⭐ Categories

  • conditionally noexcept
  • Todo no example

okay that's the whole page bestie, every flag, every overload, every imaginary function accounted for πŸ”₯ no cap. this little cutie dropped 2024.06.10 courtesy of http://cppreference.com β€” go drink some water and go read a book (a C++ book, obviously) πŸ’œπŸŒˆ bye bye 🫢

πŸ“¦ where this page comes from