description | title | ms.date | f1_keywords | helpviewer_keywords | no-loc | |||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Learn more about the std::any class from the C++ Standard Library. |
any class |
09/20/2021 |
|
|
|
An any
object either stores an instance of a type that satisfies the constructor requirements, or it has no value. Whether it has a stored instance, or no value, is called the state of the any
object.
The stored instance is called the contained value. Two any
objects have the same state if either they both have no value, or both have a contained value and those values are the same.
class any;
Name | Description |
---|---|
any |
Constructs an object of type any . |
Name | Description |
---|---|
emplace |
Sets an any value. |
has_value |
Returns true if any has a value. |
reset |
Resets an any . |
swap |
Exchanges two any objects. |
type |
Returns the any type. |
Name | Description |
---|---|
operator= |
Replaces the any with a copy of another any . |
Constructs an object of type any
. Also includes a destructor.
constexpr 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();
Sets an any
value.
template <class T, class... Args>
decay_t<T>& emplace(Args&& ...);
template <class T, class U, class... Args>
decay_t<T>& emplace(initializer_list<U>, Args&&...);
Returns true
if the any
object has a value.
bool has_value() const noexcept;
Replaces the any
content with a copy of another any
.
any& operator=(const any& right);
any& operator=(any&& right) noexcept;
template <class T>
any& operator=(T&& right);
right
The any
being copied into this any
.
Resets an any
.
void reset() noexcept;
Exchanges two any
objects.
void swap(any& rhs) noexcept;
Returns the any
type.
const type_info& type() const noexcept;
Header: <any>
Namespace: std
Standard: C++17 (Use at least /std:c++17
to compile.)