GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages
std::unique_ptr::release(3) C++ Standard Libary std::unique_ptr::release(3)

std::unique_ptr::release - std::unique_ptr::release


pointer release() noexcept; (since C++11)
(constexpr since C++23)


Releases the ownership of the managed object, if any.


get() returns nullptr after the call.


The caller is responsible for deleting the object.


(none)


Pointer to the managed object or nullptr if there was no managed object, i.e. the
value which would be returned by get() before the call.

// Run this code


#include <memory>
#include <iostream>
#include <cassert>


struct Foo {
Foo() { std::cout << "Foo\n"; }
~Foo() { std::cout << "~Foo\n"; }
};


int main()
{
std::cout << "Creating new Foo...\n";
std::unique_ptr<Foo> up(new Foo());


std::cout << "About to release Foo...\n";
Foo* fp = up.release();


assert (up.get() == nullptr);
assert (up == nullptr);


std::cout << "Foo is no longer owned by unique_ptr...\n";


delete fp;
}


Creating new Foo...
Foo
About to release Foo...
Foo is no longer owned by unique_ptr...
~Foo


get returns a pointer to the managed object
(public member function)
reset replaces the managed object
(public member function)

2022.07.31 http://cppreference.com

Search for    or go to Top of page |  Section 3 |  Main Index

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with ManDoc.