# std::any::~any

> C++ Atlas: `cppatlas.com/w/cpp/utility/any/~any` | Source: https://en.cppreference.com/w/cpp/utility/any/~any | Domain: Utility | Standards: C++17

Destroys the contained object, if any, as if by a call to reset().

## Official Specification Summary (cppreference)

```cpp
~any(); // (since C++17)
```

Destroys the contained object, if any, as if by a call to `reset()`.

### Example

```cpp
#include <any>
#include <cstdio>

struct X
{
    X() { std::puts("X::X()"); }
    X(const X&) { std::puts("X::X(const X&)"); }
    ~X() { std::puts("X::~X()"); }
};

int main()
{
    std::any a{X{}};
    std::puts("Leaving main()...");
}
```

Output:

```text
X::X()
X::X(const X&)
X::~X()
Leaving main()...
X::~X()
```

### See also

- [`reset`](https://en.cppreference.com/w/cpp/utility/any/reset): destroys contained object (public member function)

---
Attribution: content from https://en.cppreference.com/w/cpp/utility/any/~any (cppreference.com), licensed under CC-BY-SA 3.0 and GFDL. Modified: converted to markdown, study notes added. Offline snapshot of 9 February 2025.