public member function
<memory>

std::unique_ptr::~unique_ptr

~unique_ptr();
Destroy unique_ptr
If the object is an empty unique_ptr (i.e., get()==nullptr), the destructor has no effect.

Otherwise, it deletes its owned object as if by calling get_deleter()(get())

Example

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
// unique_ptr destructor example #include <iostream> #include <memory> int main () { auto deleter = [](int*p){ delete p; std::cout << "[deleter called]\n"; }; std::unique_ptr<int,decltype(deleter)> foo (new int,deleter); std::cout << "foo " << (foo?"is not":"is") << " empty\n"; return 0; // [deleter called] }

Output:
foo is not empty [deleter called] 


See also