STD::EXPERIMENTAL::OPTIONAL(3)

πŸ’– std::experimental::optional< _Tp > πŸ’–

okay bestie, welcome to the Library Functions Manual page for std::experimental::optional< _Tp > β€” yes that's the manual name, yes it's section 3, yes we're doing this together 🫢


✨ NAME ✨

std::experimental::optional< _Tp > β€” the class template for optional values. that's it. that's the whole name. iconic. πŸ’…


🌸 SYNOPSIS 🌸

#include <optional>

πŸŽ€ Public Types πŸŽ€

  • using value_type β€” yep, that's the one public type. short and sweet, she said what she said πŸ’–

πŸ¦‹ Public Member Functions πŸ¦‹

okay so here's the FULL roster, no skipping, no summarizing, every single overload is getting its moment. the enable_if_t< __and_< ... > > situations are giving very much "i contain multitudes" and we respect it 😭

  • construct from _Up &&__t, not convertible β€” the sneaky non-converting one:
template<typename _Up = _Tp, enable_if_t< __and_< __not_< is_same< optional< _Tp >, decay_t< _Up > > >, is_constructible< _Tp, _Up && >, __not_< is_convertible< _Up &&, _Tp > > >::value, bool > = false> constexpr optional (_Up &&__t)
  • construct from _Up &&__t, convertible β€” same energy but this time it's is_convertible and the bool defaults to true:
template<typename _Up = _Tp, enable_if_t< __and_< __not_< is_same< optional< _Tp >, decay_t< _Up > > >, is_constructible< _Tp, _Up && >, is_convertible< _Up &&, _Tp > >::value, bool > = true> constexpr optional (_Up &&__t)
  • construct from const optional< _Up > &__t, not convertible β€” copy-adjacent, gated on __converts_from_optional being not a thing:
template<typename _Up, enable_if_t< __and_< __not_< is_same< _Tp, _Up > >, is_constructible< _Tp, const _Up & >, __not_< is_convertible< const _Up &, _Tp > >, __not_< __converts_from_optional< _Tp, _Up > > >::value, bool > = false> constexpr optional (const optional< _Up > &__t)
  • construct from const optional< _Up > &__t, convertible β€” the true twin, still refusing __converts_from_optional:
template<typename _Up, enable_if_t< __and_< __not_< is_same< _Tp, _Up > >, is_constructible< _Tp, const _Up & >, is_convertible< const _Up &, _Tp >, __not_< __converts_from_optional< _Tp, _Up > > >::value, bool > = true> constexpr optional (const optional< _Up > &__t)
  • move-construct from optional< _Up > &&__t, not convertible β€” rvalue ref era, bool = false, still no __converts_from_optional:
template<typename _Up, enable_if_t< __and_< __not_< is_same< _Tp, _Up > >, is_constructible< _Tp, _Up && >, __not_< is_convertible< _Up &&, _Tp > >, __not_< __converts_from_optional< _Tp, _Up > > >::value, bool > = false> constexpr optional (optional< _Up > &&__t)
  • move-construct from optional< _Up > &&__t, convertible β€” bool = true, and yes, __converts_from_optional is still blocked:
template<typename _Up, enable_if_t< __and_< __not_< is_same< _Tp, _Up > >, is_constructible< _Tp, _Up && >, is_convertible< _Up &&, _Tp >, __not_< __converts_from_optional< _Tp, _Up > > >::value, bool > = true> constexpr optional (optional< _Up > &&__t)
  • emplace (variadic) β€” the "build it right here from a pile of args" one:
template<typename... _Args> enable_if_t< is_constructible< _Tp, _Args &&... >::value > emplace (_Args &&... __args)
  • emplace (initializer_list flavour) β€” same, but it takes an initializer_list< _Up > first:
template<typename _Up, typename... _Args> enable_if_t< is_constructible< _Tp, initializer_list< _Up > &, _Args &&... >::value > emplace (initializer_list< _Up > __il, _Args &&... __args)
  • constexpr operator bool () const noexcept β€” the boolean-conversion situation, marked noexcept like the confident queen she is.
  • constexpr _Tp & operator* () & β€” deref, lvalue ref flavour.
  • constexpr _Tp && operator* () && β€” deref, rvalue ref flavour.
  • constexpr const _Tp & operator* () const & β€” deref, const lvalue ref flavour.
  • constexpr const _Tp && operator* () const && β€” deref, const rvalue ref flavour. all four ref qualifiers, no crumbs. πŸ‘‘
  • _Tp * operator-> () β€” the arrow, non-const.
  • constexpr const _Tp * operator-> () const β€” the arrow, const.
  • assign from _Up &&__u β€” note the extra __not_< __and_< is_scalar< _Tp >, is_same< _Tp, decay_t< _Up > > > > gate, very specific, very demure:
template<typename _Up = _Tp> enable_if_t< __and_< __not_< is_same< optional< _Tp >, decay_t< _Up > > >, is_constructible< _Tp, _Up >, __not_< __and_< is_scalar< _Tp >, is_same< _Tp, decay_t< _Up > > > >, is_assignable< _Tp &, _Up > >::value, optional & > operator= (_Up &&__u)
  • assign from const optional< _Up > &__u β€” blocks both __converts_from_optional AND __assigns_from_optional, she has boundaries:
template<typename _Up> enable_if_t< __and_< __not_< is_same< _Tp, _Up > >, is_constructible< _Tp, const _Up & >, is_assignable< _Tp &, _Up >, __not_< __converts_from_optional< _Tp, _Up > >, __not_< __assigns_from_optional< _Tp, _Up > > >::value, optional & > operator= (const optional< _Up > &__u)
  • optional & operator= (nullopt_t) noexcept β€” the nullopt_t assignment, noexcept, no notes.
  • assign from optional< _Up > &&__u β€” rvalue version of that same gated assignment, same two __not_ guards:
template<typename _Up> enable_if_t< __and_< __not_< is_same< _Tp, _Up > >, is_constructible< _Tp, _Up >, is_assignable< _Tp &, _Up >, __not_< __converts_from_optional< _Tp, _Up > >, __not_< __assigns_from_optional< _Tp, _Up > > >::value, optional & > operator= (optional< _Up > &&__u)
  • swap β€” swaps with __other, and its noexcept-ness is exactly whatever this says it is, nothing more:
void swap (optional &__other) noexcept(is_nothrow_move_constructible< _Tp >() &&__is_nothrow_swappable< _Tp >::value)
  • constexpr _Tp & value () & β€” value getter, lvalue ref flavour.
  • constexpr _Tp && value () && β€” value getter, rvalue ref flavour.
  • constexpr const _Tp & value () const & β€” value getter, const lvalue ref flavour.
  • constexpr const _Tp && value () const && β€” value getter, const rvalue ref flavour. again, all four, because consistency is a love language. ✨
  • template<typename _Up> _Tp value_or (_Up &&__u) && β€” the value_or fallback, rvalue flavour.
  • template<typename _Up> constexpr _Tp value_or (_Up &&__u) const & β€” the value_or fallback, const lvalue flavour, this one's constexpr.

πŸ’œ Detailed Description πŸ’œ

template<typename _Tp>
class std::experimental::optional< _Tp >
"Class template for optional values."

that's the whole description bestie, short, sweet, and honestly kind of mysterious of her. the quote marks are load-bearing, i don't make the rules. 🌸


🌈 Author 🌈

Generated automatically by Doxygen for libstdc++ from the source code. not a human, not a committee, just Doxygen doing its little thing and we thank it for its service 🫢


okay that's the whole page, every overload accounted for, nobody left behind πŸ’– this one lives in the libstdc++ manual, section 3, and the whole thing was auto-generated from the source code β€” so when you cite it, cite libstdc++, std::experimental::optional< _Tp >, section 3. mwah. πŸ˜˜πŸ’…

πŸ“¦ where this page comes from
  • arch rolling: gcc 16.2.1+r23+gd564253eb6c8-1 Β· GPL-3.0-or-later WITH GCC-exception-3.1 AND GFDL-1.3-or-later
  • fedora 44: libstdc++-docs 16.0.1-0.10.fc44 Β· GPL-3.0-or-later AND LGPL-3.0-or-later AND (GPL-3.0-or-later WITH GCC-exception-3.1) AND (GPL-3.0-or-later WITH Texinfo-exception) AND (LGPL-2.1-or-later WITH GCC-exception-2.0) AND (GPL-2.0-or-later WITH GCC-exception-2.0) AND (GPL-2.0-or-later WITH GNU-compiler-exception) AND BSL-1.0 AND GFDL-1.3-or-later AND Linux-man-pages-copyleft-2-para AND SunPro AND BSD-1-Clause AND BSD-2-Clause AND BSD-2-Clause-Views AND BSD-3-Clause AND BSD-4-Clause AND BSD-Source-Code AND Zlib AND MIT AND Apache-2.0 AND (Apache-2.0 WITH LLVM-Exception) AND ZPL-2.1 AND ISC AND LicenseRef-Fedora-Public-Domain AND HP-1986 AND curl AND Martin-Birgmeier AND HPND-Markus-Kuhn AND dtoa AND SMLNJ AND AMD-newlib AND OAR AND HPND-merchantability-variant AND HPND-Intel
  • fedora 44: libstdc++-docs 16.2.1-2.fc44
  • fedora 44: libstdc++-docs 16.2.1-3.fc44 Β· GPL-3.0-or-later AND LGPL-3.0-or-later AND (GPL-3.0-or-later WITH GCC-exception-3.1) AND (GPL-3.0-or-later WITH Texinfo-exception) AND (LGPL-2.1-or-later WITH GCC-exception-2.0) AND (GPL-2.0-or-later WITH GCC-exception-2.0) AND (GPL-2.0-or-later WITH GNU-compiler-exception) AND BSL-1.0 AND GFDL-1.3-or-later AND Linux-man-pages-copyleft-2-para AND SunPro AND BSD-1-Clause AND BSD-2-Clause AND BSD-2-Clause-Views AND BSD-3-Clause AND BSD-4-Clause AND BSD-Source-Code AND Zlib AND MIT AND Apache-2.0 AND (Apache-2.0 WITH LLVM-Exception) AND ZPL-2.1 AND ISC AND LicenseRef-Fedora-Public-Domain AND HP-1986 AND curl AND Martin-Birgmeier AND HPND-Markus-Kuhn AND dtoa AND SMLNJ AND AMD-newlib AND OAR AND HPND-merchantability-variant AND HPND-Intel
  • πŸ’– girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms