table of contents
- Tumbleweed 2026.11.13-1.1
- Leap-16.0
- Leap-15.6
| std::experimental::unique_resource::unique_resource(3) | C++ Standard Libary | std::experimental::unique_resource::unique_resource(3) |
NAME¶
std::experimental::unique_resource::unique_resource - std::experimental::unique_resource::unique_resource
Synopsis¶
unique_resource(); (1) (library fundamentals TS v3) template< class RR, class DD > (2) (library fundamentals TS v3) unique_resource( RR&& r, DD&& d ) noexcept(/*see below*/) unique_resource( unique_resource&& other ); (3) (library fundamentals TS v3)
Follow items are used for explanatory purpose:
* RS is the type of stored resource handle.
* The expression res_ refers the underlying resource handle.
* del_ refers the deleter object. 1) Default constructor. Value-initializes
the stored resource handle and the deleter. The constructed unique_resource
does not own the resource. This overload participates in overload resolution
only if both std::is_default_constructible_v<R> and
std::is_default_constructible_v<D> are true. 2) The stored resource
handle is initialized with std::forward<RR>(r) if
std::is_nothrow_constructible_v<RS, RR> is true, otherwise r. If
initialization of the stored resource handle throws an exception, calls
d(r). Then, the deleter is initialized with std::forward<DD>(d) if
std::is_nothrow_constructible_v<D, DD> is true, otherwise d. If
initialization of deleter throws an exception, calls d(res_). The
constructed unique_resource owns the resource. This overload participates in
overload resolution only if all of std::is_constructible_v<RS, RR>,
std::is_constructible_v<D, DD>, std::is_nothrow_constructible_v<RS,
RR> || std::is_constructible_v<RS, RR&> and
std::is_nothrow_constructible_v<D, DD> ||
std::is_constructible_v<D, DD&> are true. The program is
ill-formed if any of the expressions d(r), d(res_) and del_(res_) is
ill-formed. The behavior is undefined if any of the expressions d(r),
d(res_) and del_(res_) results in undefined behavior or throws an exception.
3) Move constructor. The stored resource handle is initialized from the one
of other, using std::move if std::is_nothrow_move_constructible_v<RS>
is true. If initialization of the stored resource handle throws an
exception, other is not modified. Then, the deleter is initialized with the
one of other, using std::move if
std::is_nothrow_move_constructible_v<D> is true. If initialization of
the deleter throws an exception and
std::is_nothrow_move_constructible_v<RS> is true and other owns the
resource, calls the deleter of other with res_ to dispose the resource, then
calls other.release(). After construction, the constructed unique_resource
owns its resource if and only if other owned the resource before the
construction, and other is set to not own the resource.
Parameters¶
r - a resource handle d - a deleter to use to dispose the resource other - another unique_resource to acquire the ownership from
Exceptions¶
Any exception thrown during initialization of the stored resource handle or the deleter.
2) noexcept specification: noexcept((
std::is_nothrow_constructible_v<RS, RR> || std::is_nothrow_constructible_v<RS, RR&> ) && ( std::is_nothrow_constructible_v<D, DD> || std::is_nothrow_constructible_v<D, DD&>
)) 3) noexcept specification: noexcept(
std::is_nothrow_move_constructible_v<R1> && std::is_nothrow_move_constructible_v<D>
)
Notes¶
The mechanism of these constructors ensures no leaking of resources.
Example¶
This section is incomplete
Reason: no example
See also¶
constructor constructs a new unique_ptr
(public member function of std::unique_ptr<T,Deleter>)
| 2026.11.10 | http://cppreference.com |