| Technical Specification | ||||
| Filesystem library(filesystem TS) | ||||
| Library fundamentals(library fundamentals TS) | ||||
| Library fundamentals 2(library fundamentals TS v2) | ||||
| Library fundamentals 3(library fundamentals TS v3) | ||||
| Extensions for parallelism(parallelism TS) | ||||
| Extensions for parallelism 2(parallelism TS v2) | ||||
| Extensions for concurrency(concurrency TS) | ||||
| Extensions for concurrency 2(concurrency TS v2) | ||||
| Concepts(concepts TS) | ||||
| Ranges(ranges TS) | ||||
| Reflection(reflection TS) | ||||
| Mathematical special functions(special functions TR) | ||||
| Experimental Non-TS | ||||
| Pattern Matching | ||||
| Linear Algebra | ||||
| std::execution | ||||
| Contracts | ||||
| 2D Graphics |
experimental::unique_resource |
| Member functions | ||||
| Modifiers | ||||
| Observers | ||||
| Non-member functions | ||||
| Deduction guides |
Defined in header <experimental/scope> | ||
template<class R,class D> class unique_resource; | (library fundamentals TS v3) | |
unique_resource is universal RAII wrapper for resource handles that owns and manages a resource through a handle and disposes of that resource when theunique_resource is destroyed.
The resource is disposed of using the deleter of typeD when either of the following happens:
unique_resource object is destroyed,unique_resource object is assigned from another resource viaoperator= orreset().Let typeRS beR ifR is an object type, orstd::reference_wrapper<std::remove_reference_t<R>> otherwise:
unique_resource effectively holds a subobject of typeRS which is or wraps the resource handle, a deleter of typeD and abool flag indicating whether the wrapper is owning the resource.RS is calledstored resource handle, and the stored (ifR is an object type) or wrapped (ifR is a reference type)R is calledunderlying resource handle. These two terms are not used by the LFTS.Contents |
| R | - | resource handle type |
| D | - | deleter type |
| Type requirements | ||
-R shall be an object type or an lvalue reference to an object type. LetUnrefR bestd::remove_reference_t<R>,UnrefR shall beMoveConstructible, and ifUnrefR is notCopyConstructible,std::is_nothrow_move_constructible_v<UnrefR> shall betrue. | ||
-D shall be aDestructible andMoveConstructibleFunctionObject type, and ifD is notCopyConstructible,std::is_nothrow_move_constructible_v<D> shall betrue. Given an lvalued of typeD and an lvaluer of typeUnrefR, the expressiond(r) shall be well-formed. | ||
constructs a newunique_resource(public member function)[edit] | |
| disposes the managed resource if such is present (public member function)[edit] | |
assigns aunique_resource(public member function)[edit] | |
Modifiers | |
| releases the ownership (public member function)[edit] | |
| disposes or replaces the managed resource (public member function)[edit] | |
Observers | |
| accesses the underlying resource handle (public member function)[edit] | |
| accesses the deleter used for disposing of the managed resource (public member function)[edit] | |
| accesses the pointee if the resource handle is a pointer (public member function)[edit] | |
creates aunique_resource, checking invalid value(function template)[edit] |
Resource handle types satisfyingNullablePointer can also be managed bystd::unique_ptr. Unlikeunique_ptr,unique_resource does not requireNullablePointer.
| This section is incomplete Reason: no example |
(C++11) | smart pointer with unique object ownership semantics (class template)[edit] |