[any.class.general]

# 22 General utilities library [[utilities]](./#utilities)

## 22.7 Storage for any type [[any]](any#class.general)

### 22.7.4 Class any [[any.class]](any.class#general)

#### 22.7.4.1 General [any.class.general]

namespace std {class any {public:// [[any.cons]](any.cons "22.7.4.2 Construction and destruction"), construction and destructionconstexpr any() noexcept;

 any(const any& other);
 any(any&& other) noexcept; template<class T> any(T&& value); template<class T, class... Args>explicit any(in_place_type_t<T>, Args&&...); template<class T, class U, class... Args>explicit any(in_place_type_t<T>, initializer_list<U>, Args&&...); ~any(); // [[any.assign]](any.assign "22.7.4.3 Assignment"), assignments any& operator=(const any& rhs);
 any& operator=(any&& rhs) noexcept; template<class T> any& operator=(T&& rhs); // [[any.modifiers]](any.modifiers "22.7.4.4 Modifiers"), modifierstemplate<class T, class... Args> decay_t<T>& emplace(Args&&...); template<class T, class U, class... Args> decay_t<T>& emplace(initializer_list<U>, Args&&...); void reset() noexcept; void swap(any& rhs) noexcept; // [[any.observers]](any.observers "22.7.4.5 Observers"), observersbool has_value() const noexcept; const type_info& type() const noexcept; };}

[1](#1)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L7138)

An object of class any stores an instance of any type that meets the constructor requirements or it has no value,
and this is referred to as the [*state*](#def:state "22.7.4.1 General [any.class.general]") of the class any object[.](#1.sentence-1)

The stored instance is called the [*contained value*](#def:contained_value,any "22.7.4.1 General [any.class.general]")[.](#1.sentence-2)

Two states are equivalent if either they both have no value, or they both have a value and the contained values are equivalent[.](#1.sentence-3)

[2](#2)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L7144)

The non-member any_cast functions provide type-safe access to the contained value[.](#2.sentence-1)

[3](#3)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L7147)

Implementations should avoid the use of dynamically allocated memory for a small contained value[.](#3.sentence-1)

However, any such small-object optimization shall only be applied to types T for whichis_nothrow_move_constructible_v<T> is true[.](#3.sentence-2)

[*Example [1](#example-1)*:

A contained value of type int could be stored in an internal buffer,
not in separately-allocated memory[.](#3.sentence-3)

â *end example*]
