STD::_OPTIONAL_BASE(3cxx)

✨ std::_Optional_base< _Tp, bool, bool > ✨

okay bestie, welcome to the 3cxx manual πŸ’– you're reading the page for std::_Optional_base< _Tp, bool, bool >, and yes the name is a whole mouthful, we love that for it 🫢


🌸 NAME 🌸

std::_Optional_base< _Tp, bool, bool > β€” the class template that hands optional its copy/move constructors. that's literally its whole job. main character behavior, honestly πŸ‘‘


πŸŽ€ SYNOPSIS πŸŽ€

#include <optional>

Inherited by std::experimental::fundamentals_v1::optional< _Tp > [private], and std::optional< _Tp > [private]. so like… two very iconic children, both keeping it private πŸ”’βœ¨

πŸ’… Public Member Functions

  • constexpr _Optional_base (_Optional_base &&__other) noexcept(is_nothrow_move_constructible_v< _Tp >) β€” move-constructs from another one. no cap, whether it's noexcept depends entirely on whether _Tp is nothrow move constructible.
  • constexpr _Optional_base (const _Optional_base &__other) β€” copies from another one. classic.
  • template<typename... _Args, enable_if_t< is_constructible_v< _Tp, _Args... >, bool > = false> constexpr _Optional_base (in_place_t, _Args &&... __args) β€” the in_place_t one, where you hand it args and it builds the value right there in place. only exists when _Tp is constructible from those _Args..., otherwise SFINAE just quietly deletes it from existence πŸ™ˆ
  • template<typename _Up, typename... _Args, enable_if_t< is_constructible_v< _Tp, initializer_list< _Up > &, _Args... >, bool > = false> constexpr _Optional_base (in_place_t, initializer_list< _Up > __il, _Args &&... __args) β€” same energy but with an initializer_list< _Up > __il in the mix. also gated on constructibility, bestie.
  • _Optional_base & operator= (_Optional_base &&)=default β€” move assignment, defaulted. periodt.
  • _Optional_base & operator= (const _Optional_base &)=default β€” copy assignment, defaulted. also periodt.

✨ Public Attributes

  • _Optional_payload< _Tp > _M_payload β€” the actual payload member. the whole vibe lives in here πŸ“

🧚 Protected Types

  • using _Stored_type β€” a protected type alias. mysterious. lowkey iconic.

🌈 Protected Member Functions

  • template<typename... _Args> constexpr void _M_construct (_Args &&... __args) noexcept(is_nothrow_constructible_v< _Stored_type, _Args... >) β€” constructs the stored thing-y from __args. its nothrow-ness is inherited from whether _Stored_type is nothrow constructible from those args.
  • constexpr void _M_destruct () noexcept β€” destroys it. no drama, marked noexcept.
  • constexpr const _Tp & _M_get () const noexcept β€” const getter, returns a const _Tp &.
  • constexpr _Tp & _M_get () noexcept β€” non-const getter, returns a _Tp &. yes there are two, we love overloading πŸ’•
  • constexpr bool _M_is_engaged () const noexcept β€” are we engaged or not?? (as in, does it hold a value. not, like, romantically. though πŸ‘€)
  • constexpr void _M_reset () noexcept β€” resets everything. goodbye value πŸ’€

🌟 Detailed Description 🌟

template<typename _Tp, bool = is_trivially_copy_constructible_v<_Tp>, bool = is_trivially_move_constructible_v<_Tp>>
struct std::_Optional_base< _Tp, bool, bool >

"Class template that provides copy/move constructors of optional." yes ma'am πŸ’–

okay so here's the tea β˜• a separate base class template like this is necessary so that the copy/move constructors can be conditionally trivial. it's giving "i have to be my own class to make my constructors behave."

when the contained value is trivially copy/move constructible, the copy/move constructors of _Optional_base will invoke the trivial copy/move constructor of _Optional_payload. and otherwise?? they will invoke _Optional_payload(bool, const _Optional_payload&) or _Optional_payload(bool, _Optional_payload&&) to initialize the contained value β€” but only if we're copying/moving an engaged optional 🫢

and whether the other special members are trivial is determined by the _Optional_payload<_Tp> specialization used for the _M_payload member. iykyk.

πŸ‘‘ See also

optional, _Enable_special_members


πŸ’œ Author πŸ’œ

Generated automatically by Doxygen for libstdc++ from the source code. not a human bestie, just the machines doing their little machine thing πŸ€–βœ¨


⚠️ heads up: this is auto-generated Doxygen output for libstdc++, on the 3cxx manual β€” that's the vibe, that's the source, no cap.

okay that's the whole page, you ate it πŸ’… go forth and understand your _Optional_base the way it deserves, bestie. libstdc++ out here, 3cxx manual, generated by Doxygen, mwah πŸŽ€