Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

      std::experimental::unique_resource

      From cppreference.com
      <cpp‎ |experimental
       
       
       
       
       
      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:

      • the managingunique_resource object is destroyed,
      • the managingunique_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.
      • For explanatory purpose, the subobject of typeRS 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

      [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. 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.

      [edit]Member functions

      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]

      [edit]Non-member functions

      creates aunique_resource, checking invalid value
      (function template)[edit]

      [edit]Deduction guides

      [edit]Notes

      Resource handle types satisfyingNullablePointer can also be managed bystd::unique_ptr. Unlikeunique_ptr,unique_resource does not requireNullablePointer.

      [edit]Example

      This section is incomplete
      Reason: no example

      [edit]See also

      (C++11)
      smart pointer with unique object ownership semantics
      (class template)[edit]
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=cpp/experimental/unique_resource&oldid=156343"

      [8]ページ先頭

      ©2009-2025 Movatter.jp