---
name: "std::any"
section: "3cxx"
platform: "linux"
package: "libstdc++-12-doc"
version: "12.4.0-5"
release: "Debian 13 (Trixie)"
platforms: ["linux"]
url: "https://new.carta.tech/std::any"
---

# std::any(3cxx)

A type-safe container of any type.

## NAME

std::any - A type-safe container of any type.

## SYNOPSIS

`#include <any>`

### Public Member Functions

constexpr **any** () noexcept\
 Default constructor, creates an empty object.  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 `__value` as the contained object.  **any** (**any** &&\_\_other) noexcept\
 Move constructor, transfer the state from `__other`.  **any** (const **any** &\_\_other)\
 Copy constructor, copies the state of `__other`.  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 `__args` as the contained object.  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 `__il` and `__args` as the contained object.  **~any** ()\
 Destructor, calls `reset()`  template\<**typename** \_Tp , typename... \_Args\> \_\_emplace\_t\< **decay\_t**\< \_Tp \>, \_Args... \> **emplace** (**\_Args** &&... **\_\_args**)\
 Emplace with an object created from `__args` as the contained object.  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 `__il` and `__args` as the contained object.  bool **has\_value** () const noexcept\
 Reports whether there is a contained object 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 `__rhs` as the contained object.  **any** & **operator=** (**any** &&**\_\_rhs**) noexcept\
 Move assignment operator.  **any** & **operator=** (const **any** &**\_\_rhs**)\
 Copy the state of another object.  **void** **reset** () noexcept\
 If not empty, destroy the contained object.  **void** **swap** (**any** &**\_\_rhs**) noexcept\
 Exchange state with another object.  const **type\_info** & **type** () const noexcept\
 The `typeid` of the contained object, or `typeid(void)` if empty.

## 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

## Constructor & Destructor Documentation

### constexpr std::any::any ()` [inline]`, ` [constexpr]`, ` [noexcept]`

Default constructor, creates an empty object.

### 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)

### 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.

### 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.

### 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.

### 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.

### 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.

### bool std::any::has\_value () const` [inline]`, ` [noexcept]`

Reports whether there is a contained object or not.

### 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.

### any & std::any::operator= (any && \_\_rhs)` [inline]`, ` [noexcept]`

Move assignment operator.

**Postcondition**

`!__rhs`.has\_value() (not guaranteed for other implementations)

### any & std::any::operator= (const any & \_\_rhs)` [inline]`

Copy the state of another object.

### void std::any::reset ()` [inline]`, ` [noexcept]`

If not empty, destroy the contained object.

### 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.

## Author

Generated automatically by Doxygen for libstdc++ from the source code.
