std::any(3cxx)
π std::any β the 3cxx manual page, bestie edition π
okay so you opened the manual for std::any from the libstdc++ girlies and you need it explained with β¨flavorβ¨. welcome. sit down. hydrate. this container is iconic and you're about to understand it fr fr.
πΈ NAME πΈ
std::any β a type-safe container of any type. yes bestie, any. she contains multitudes π
β¨ SYNOPSIS β¨
#include <any>
π Public Member Functions π
constexpr any () noexceptβ bestie's default constructor, she makes an empty object. no thoughts, head empty, valid state πtemplate<typename _Tp, typename _VTp = _Decay_if_not_any<_Tp>, typename _Mgr = _Manager<_VTp>, enable_if_t< is_copy_constructible_v< _VTp > &&!__is_in_place_type_v< _VTp >, bool > = true> any (_Tp &&__value)β construct with a copy of__valueas the contained object. yes she copied your whole personality, and honestly? slay.any (any &&__other) noexceptβ move constructor, she transfers the state from__other. not copying, transferring. main character energy.any (const any &__other)β copy constructor, copies the state of__other. twin behavior πΈtemplate<typename _Tp, typename... _Args, typename _VTp = decay_t<_Tp>, typename _Mgr = _Manager<_VTp>, __any_constructible_t< _VTp, _Args &&... > = false> any (in_place_type_t< _Tp >, _Args &&... __args)β construct with an object created from__argsas the contained object. build-a-bear but it's a type π₯template<typename _Tp, typename _Up, typename... _Args, typename _VTp = decay_t<_Tp>, typename _Mgr = _Manager<_VTp>, __any_constructible_t< _VTp, initializer_list< _Up > &, _Args &&... > = false> any (in_place_type_t< _Tp >, initializer_list< _Up > __il, _Args &&... __args)β construct with an object created from__iland__argsas the contained object. now with curly-brace sprinkle π~any ()β destructor, she callsreset(). it's giving graceful exit β¨template<typename _Tp, typename... _Args> __emplace_t< decay_t< _Tp >, _Args... > emplace (_Args &&... __args)β emplace with an object created from__argsas the contained object. in-place glow-up πtemplate<typename _Tp, typename _Up, typename... _Args> __emplace_t< decay_t< _Tp >, initializer_list< _Up > &, _Args &&... > emplace (initializer_list< _Up > __il, _Args &&... __args)β emplace with an object created from__iland__argsas the contained object. same glow-up, extrainitializer_listflavor πbool has_value () const noexceptβ reports whether there is a contained object or not. the vibe check. does she have something in her or not πtemplate<typename _Tp> enable_if_t< is_copy_constructible< _Decay_if_not_any< _Tp > >::value, any & > operator= (_Tp &&__rhs)β store a copy of__rhsas the contained object. glow-up via assignment πany & operator= (any &&__rhs) noexceptβ move assignment operator. she's taking what__rhshad, no cap.any & operator= (const any &__rhs)β copy the state of another object. matching outfits fr fr.void reset () noexceptβ if not empty, destroy the contained object. she's clearing her camera roll π§Ήvoid swap (any &__rhs)β ... correction bestie:void swap (any &__rhs) noexceptβ exchange state with another object. trading bracelets, but with state πconst type_info & type () const noexceptβ thetypeidof the contained object, ortypeid(void)if empty. showing her ID at the door π
π Detailed Description π
A type-safe container of any type.
An any object's state is either empty or it stores a contained object of CopyConstructible type.
Since
C++17. she's not new but she IS timeless π
π« Constructor & Destructor Documentation π«
std::any::any () inline, constexpr, noexcept
Default constructor, creates an empty object.
Referenced by any(), operator=(), operator=(), and operator=().
std::any::any (const any & __other) inline
Copy constructor, copies the state of __other.
std::any::any (any && __other) inline, noexcept
Move constructor, transfer the state from __other.
Postcondition
!__other.has_value() (this postcondition is a GNU extension)
References any(), and has_value().
template<typename _Tp, typename _VTp = _Decay_if_not_any<_Tp>, typename _Mgr = _Manager<_VTp>, enable_if_t< is_copy_constructible_v< _VTp > &&!__is_in_place_type_v< _VTp >, bool > = true> std::any::any (_Tp && __value) inline
Construct with a copy of __value as the contained object.
References std::forward().
template<typename _Tp, typename... _Args, typename _VTp = decay_t<_Tp>, typename _Mgr = _Manager<_VTp>, __any_constructible_t< _VTp, _Args &&... > = false> std::any::any (in_place_type_t< _Tp > , _Args &&... __args) inline, explicit
Construct with an object created from __args as the contained object.
References std::forward().
template<typename _Tp, typename _Up, typename... _Args, typename _VTp = decay_t<_Tp>, typename _Mgr = _Manager<_VTp>, __any_constructible_t< _VTp, initializer_list< _Up > &, _Args &&... > = false> std::any::any (in_place_type_t< _Tp > , initializer_list< _Up > __il, _Args &&... __args) inline, explicit
Construct with an object created from __il and __args as the contained object.
References std::forward().
std::any::~any () inline
Destructor, calls reset().
π₯ Member Function Documentation π₯
template<typename _Tp, typename... _Args> __emplace_t< decay_t< _Tp >, _Args... > std::any::emplace (_Args &&... __args) inline
Emplace with an object created from __args as the contained object.
References std::forward().
template<typename _Tp, typename _Up, typename... _Args> __emplace_t< decay_t< _Tp >, initializer_list< _Up > &, _Args &&... > std::any::emplace (initializer_list< _Up > __il, _Args &&... __args) inline
Emplace with an object created from __il and __args as the contained object.
References std::forward().
bool std::any::has_value () const inline, noexcept
Reports whether there is a contained object or not.
Referenced by any(), reset(), and type().
template<typename _Tp> enable_if_t< is_copy_constructible< _Decay_if_not_any< _Tp > >::value, any & > std::any::operator= (_Tp && __rhs) inline
Store a copy of __rhs as the contained object.
References any(), and std::forward().
any & std::any::operator= (any && __rhs) inline, noexcept
Move assignment operator.
Postcondition
!__rhs.has_value() (not guaranteed for other implementations)
β οΈ bestie read that parenthetical again β that postcondition is not guaranteed for other implementations. do not build your whole life plan on it π
References any(), and reset().
any & std::any::operator= (const any & __rhs) inline
Copy the state of another object.
References any().
void std::any::reset () inline, noexcept
If not empty, destroy the contained object.
References has_value().
Referenced by operator=().
void std::any::swap (any & __rhs) inline, noexcept
Exchange state with another object.
const type_info & std::any::type () const inline, noexcept
The typeid of the contained object, or typeid(void) if empty.
References has_value().
π Author π
Generated automatically by Doxygen for libstdc++ from the source code. not a human, just a robot doing her little documentation duties π«Ά
aaaand that's the whole page bestie!! this manual page is brought to you by libstdc++, page std::any(3cxx) β go forth and store any type safely, you absolute icon πβ¨π
π¦ where this page comes from
- ubuntu resolute: libstdc++-11-doc 11.5.0-11ubuntu2
- ubuntu resolute: libstdc++-12-doc 12.5.0-9ubuntu1
- ubuntu resolute: libstdc++-13-doc 13.4.0-10ubuntu1
- ubuntu stonking: libstdc++-11-doc 11.5.0-11ubuntu2
- ubuntu stonking: libstdc++-12-doc 12.5.0-9ubuntu1
- ubuntu stonking: libstdc++-13-doc 13.5.0-1ubuntu1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms