std::experimental::unique_resource - cppreference.com (original) (raw)
std::experimental::unique_resource
| | | | | ----------------------------------------------------- | | ---------------------------- | | 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 the unique_resource is destroyed.
The resource is disposed of using the deleter of type D when either of the following happens:
- the managing
unique_resourceobject is destroyed, - the managing
unique_resourceobject is assigned from another resource via operator= or reset().
Let type RS be R if R is an object type, or std::reference_wrapper<std::remove_reference_t<R>> otherwise:
unique_resourceeffectively holds a subobject of typeRSwhich is or wraps the resource handle, a deleter of typeDand a bool flag indicating whether the wrapper is owning the resource.- For explanatory purpose, the subobject of type
RSis called stored resource handle, and the stored (ifRis an object type) or wrapped (ifRis a reference type)Ris called underlying resource handle. These two terms are not used by the LFTS.
Contents
- 1 Template parameters
- 2 Member functions
- 3 Non-member functions
- 4 Deduction guides
- 5 Notes
- 6 Example
- 7 See also
[edit] Template parameters
| R | - | resource handle type |
|---|---|---|
| D | - | deleter type |
| Type requirements | ||
| -R shall be an object type or an lvalue reference to an object type. Let UnrefR be std::remove_reference_t<R>, UnrefR shall be MoveConstructible, and if UnrefR is not CopyConstructible, std::is_nothrow_move_constructible_v<UnrefR> shall be true. | ||
| -D shall be a Destructible and MoveConstructible FunctionObject type, and if D is not CopyConstructible, std::is_nothrow_move_constructible_v<D> shall be true. Given an lvalue d of type D and an lvalue r of type UnrefR, the expression d(r) shall be well-formed. |
[edit] Member functions
| (constructor) | constructs a new unique_resource (public member function) [edit] |
|---|---|
| (destructor) | disposes the managed resource if such is present (public member function) [edit] |
| operator= | assigns a unique_resource (public member function) [edit] |
| Modifiers | |
| release | releases the ownership (public member function) [edit] |
| reset | disposes or replaces the managed resource (public member function) [edit] |
| Observers | |
| get | accesses the underlying resource handle (public member function) [edit] |
| get_deleter | accesses the deleter used for disposing of the managed resource (public member function) [edit] |
| operator*operator-> | accesses the pointee if the resource handle is a pointer (public member function) [edit] |
[edit] Non-member functions
[edit] Deduction guides
[edit] Notes
Resource handle types satisfying NullablePointer can also be managed by std::unique_ptr. Unlike unique_ptr, unique_resource does not require NullablePointer.
[edit] Example
[edit] See also
| | smart pointer with unique object ownership semantics (class template) [edit] | | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |