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'sis_convertibleand the bool defaults totrue:
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_optionalbeing 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 β thetruetwin, 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_optionalis 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 aninitializer_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, markednoexceptlike 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_optionalAND__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β thenullopt_tassignment,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) &&β thevalue_orfallback, rvalue flavour.template<typename _Up> constexpr _Tp value_or (_Up &&__u) const &β thevalue_orfallback, const lvalue flavour, this one'sconstexpr.
π 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