Namespaces
Variants
Actions

std::any::~any

From cppreference.com
< cpp‎ | utility‎ | any
 
C++
 
Utilities library
General utilities
Relational operators (deprecated in C++20)
 
std::any
~any();
(since C++17)

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

[edit] Example

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

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

[edit] See also

destroys contained object
(public member function) [edit]

Follow Lee on X/Twitter - Father, Husband, Serial builder creating AI, crypto, games & web tools. We are friends :) AI Will Come To Life!

Check out: eBank.nz (Art Generator) | Netwrck.com (AI Tools) | Text-Generator.io (AI API) | BitBank.nz (Crypto AI) | ReadingTime (Kids Reading) | RewordGame | BigMultiplayerChess | WebFiddle | How.nz | Helix AI Assistant