std::experimental::unique_resource
From cppreference.com
< cpp | experimental
C++
Feature test macros (C++20)
Concepts library (C++20)
Metaprogramming library (C++11)
Ranges library (C++20)
Filesystem library (C++17)
Concurrency support library (C++11)
Execution control library (C++26)
Experimental
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)
Library fundamentals v3
experimental::unique_resource
std::experimental::unique_resource
Member functions
Modifiers
Observers
Non-member functions
Defined in header
<experimental/scope>
template< class R, class D >
class unique_resource;
(library fundamentals TS v3)
class unique_resource;
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_resource
object is destroyed, - the managing
unique_resource
object 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_resource
effectively holds a subobject of typeRS
which is or wraps the resource handle, a deleter of typeD
and a bool flag indicating whether the wrapper is owning the resource. - For explanatory purpose, the subobject of type
RS
is called stored resource handle, and the stored (ifR
is an object type) or wrapped (ifR
is a reference type)R
is called underlying resource handle. These two terms are not used by the LFTS.
Contents
[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
Modifiers
Observers
[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
This section is incomplete
Reason: no example
Reason: no example