STD::_OPTIONAL_BASE(3)
okay so bestie π welcome to the std::_Opti...ol, bool >(3) page β itβs from the Library Functions Manual, and itβs all about a very specific little base class. Buckle up, weβre going in. π
π NAME π
std::_Optional_base< _Tp, bool, bool >β Class template that provides copy/move constructors of optional. Thatβs the whole name-and-purpose situation, periodt. π
β¨ SYNOPSIS β¨
okay so first, the inheritance tea β:
- Inherits
std::_Optional_base_impl< _Tp, _Dp >.
and itβs inherited by this whole squad:
std::optional< _Inner_iter >[private]std::experimental::fundamentals_v1::optional< _Tp >[private]std::optional< _Tp >[private]std::ranges::__detail::__non_propagating_cache< _Tp >[protected]
πΈ Public Member Functions πΈ
constexpr _Optional_base (_Optional_base &&__other) noexcept(is_nothrow_move_constructible_v< _Tp >)constexpr _Optional_base (const _Optional_base &__other)template<typename... _Args, enable_if_t< is_constructible_v< _Tp, _Args... >, bool > = false> constexpr _Optional_base (in_place_t, _Args &&... __args)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)_Optional_base & operator= (_Optional_base &&)=default_Optional_base & operator= (const _Optional_base &)=default
π§ Public Attributes π§
_Optional_payload< _Tp > _M_payloadβ the one public attribute, living its best life. π«Ά
π¦ Protected Types π¦
using _Stored_type = remove_const_t< _Tp >
π Protected Member Functions π
template<typename... _Args> constexpr void _M_construct (_Args &&... __args) noexcept(is_nothrow_constructible_v< _Stored_type, _Args... >)constexpr void _M_destruct () noexceptconstexpr const _Tp & _M_get () const noexceptconstexpr _Tp & _M_get () noexceptconstexpr bool _M_is_engaged () const noexceptconstexpr void _M_reset () noexcept
π Detailed Description π
the template signature is giving:
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.
and the reason is literally this: Such a separate base class template is necessary in order to conditionally make copy/move constructors trivial. Thatβs the whole assignment. π
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. Otherwise, they will invoke _Optional_payload(bool, const _Optional_payload&) or _Optional_payload(bool, _Optional_payload&&) to initialize the contained value, if copying/moving an engaged optional.
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. No human author to hype up, just Doxygen doing its little automated thing. π€π
later bestie π
β this page is from libstdc++, dated Fri Feb 14 2025, and the title is std::_Opti...ol, bool >(3). mwah π
π¦ where this page comes from
- centos-stream 9: gcc-toolset-13-libstdc++-docs 13.3.1-2.3.el9 Β· GPLv3+ and GPLv3+ with exceptions and GPLv2+ with exceptions and LGPLv2+ and BSD
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms