---
name: "std::experimental::any"
section: "3"
platform: "linux"
package: "gcc"
version: "16.2.1+r23+gd564253eb6c8-1"
release: "Arch Linux 2026-11-01"
platforms: ["linux"]
url: "https://new.carta.tech/std::experimental::any"
---

# std::experimental::any(3)

A type-safe container of any type.

## NAME

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

## SYNOPSIS

\#include \<any\>

### Public Member Functions

**any** () noexcept\
 Default constructor, creates an empty object.  template\<typename \_ValueType, typename \_Tp = \_Decay\<\_ValueType\>, typename \_Mgr = \_Manager\<\_Tp\>, typename **enable\_if**\<!**is\_constructible**\< \_Tp, \_ValueType && \>::value, bool \>**::type** = false\> **any** (\_ValueType &&\_\_value)\
 Construct with a copy of \_\_value as the contained object.  template\<typename \_ValueType, typename \_Tp = \_Decay\<\_ValueType\>, typename \_Mgr = \_Manager\<\_Tp\>, typename **enable\_if**\< **is\_constructible**\< \_Tp, \_ValueType && \>::value, bool \>**::type** = true\> **any** (\_ValueType &&\_\_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.  **~any** ()\
 Destructor, calls clear().  void **clear** () noexcept\
 If not empty, destroy the contained object.  bool **empty** () const noexcept\
 Reports whether there is a contained object or not.  template\<typename \_ValueType\> **enable\_if\_t**\<!is\_same\< **any**, **decay\_t**\< \_ValueType \> \>::value, **any** & \> **operator=** (\_ValueType &&\_\_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 **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.

### Static Public Member Functions

template\<typename \_Tp\> static constexpr bool **\_\_is\_valid\_cast** ()\

### Friends

template\<typename \_Tp\> **enable\_if\_t**\< **is\_object**\< \_Tp \>::value, void \* \> **\_\_any\_caster** (const **any** \*\_\_any)\

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

## Constructor & Destructor Documentation

### std::experimental::any::any () \[inline\], \[noexcept\]

Default constructor, creates an empty object.

Referenced by **any()**, **any()**, **operator=()**, **operator=()**, **operator=()**, and **swap()**.

### std::experimental::any::any (const any & \_\_other) \[inline\]

Copy constructor, copies the state of \_\_other.

References **any()**, and **empty()**.

### std::experimental::any::any (any && \_\_other) \[inline\], \[noexcept\]

Move constructor, transfer the state from \_\_other.

**Postcondition**

\_\_other.empty() (this postcondition is a GNU extension)

References **any()**.

### template\<typename \_ValueType, typename \_Tp = \_Decay\<\_ValueType\>, typename \_Mgr = \_Manager\<\_Tp\>, typename enable\_if\< is\_constructible\< \_Tp, \_ValueType && \>::value, bool \>::type = true\> std::experimental::any::any (\_ValueType && \_\_value) \[inline\]

Construct with a copy of \_\_value as the contained object.

References **std::forward()**.

### template\<typename \_ValueType, typename \_Tp = \_Decay\<\_ValueType\>, typename \_Mgr = \_Manager\<\_Tp\>, typename enable\_if\<!is\_constructible\< \_Tp, \_ValueType && \>::value, bool \>::type = false\> std::experimental::any::any (\_ValueType && \_\_value) \[inline\]

Construct with a copy of \_\_value as the contained object.

### std::experimental::any::~any () \[inline\]

Destructor, calls clear().

References **clear()**.

## Member Function Documentation

### void std::experimental::any::clear () \[inline\], \[noexcept\]

If not empty, destroy the contained object.

References **empty()**.

Referenced by **~any()**, and **operator=()**.

### bool std::experimental::any::empty () const \[inline\], \[nodiscard\], \[noexcept\]

Reports whether there is a contained object or not.

Referenced by **any()**, **clear()**, **swap()**, and **type()**.

### template\<typename \_ValueType\> enable\_if\_t\<!is\_same\< any, decay\_t\< \_ValueType \> \>::value, any & \> std::experimental::any::operator= (\_ValueType && \_\_rhs) \[inline\]

Store a copy of \_\_rhs as the contained object.

References **any()**, and **std::forward()**.

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

Move assignment operator.

**Postcondition**

\_\_rhs.empty() (not guaranteed for other implementations)

References **any()**, and **clear()**.

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

Copy the state of another object.

References **any()**.

### void std::experimental::any::swap (any & \_\_rhs) \[inline\], \[noexcept\]

Exchange state with another object.

References **any()**, and **empty()**.

### const type\_info & std::experimental::any::type () const \[inline\], \[noexcept\]

The typeid of the contained object, or typeid(void) if empty.

References **empty()**.

## Author

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