cuda::experimental::basic_any_resource#
-
template<_ResourceKind _Kind, class ..._Properties>
class basic_any_resource# Type erased wrapper around a resource or a synchronous_resource#
basic_any_resourcewraps any given resource that satisfies the required properties. It owns the contained resource, taking care of construction / destruction. This makes it especially suited for use in e.g. container types that need to ensure that the lifetime of the container exceeds the lifetime of the memory resource used to allocate the storagebasic_any_resourcemodels thecuda::std::regularconcept.See also
See also
See also
See also
- Template Parameters:
_Kind – Either
_ResourceKind::_Synchronousforany_synchronous_resource, or_ResourceKind::_Asynchronousforany_resource._Properties – A pack of property types that a memory resource must provide in order to be storable in instances of this
basic_any_resourcetype.
Public Functions
-
basic_any_resource() noexcept#
Constructs a
basic_any_resourcewith no value.- Post:
has_value()isfalse
-
basic_any_resource(basic_any_resource &&__other) noexcept#
Move constructs a
basic_any_resource.- Post:
has_value()istrueif__otherhad a value prior to the move, andfalseotherwise.__other.has_value()isfalse.
-
basic_any_resource(const basic_any_resource &__other)#
Copy constructs a
basic_any_resource.- Post:
has_value()is the same as__other.has_value().
-
template<class _Resource>
basic_any_resource(_Resource __res)# Constructs a
basic_any_resourcefrom a type that satisfies theresourceconcept.and that supports all of the specified properties.
- Parameters:
__res – The resource to be wrapped by the
basic_any_resource.- Pre:
_Resourceis not a specialization ofbasic_any_resourceorbasic_resource_ref, or a type derived from such.- Pre:
synchronous_resource_with<_Resource, _Properties...>istrue.- Pre:
If
_Kindis_ResourceKind::_Asynchronous,resource_with<_Resource, _Properties...>istrue.- Post:
has_value()istrue
-
template<_ResourceKind _OtherKind, class ..._OtherProperties>
basic_any_resource( - basic_any_resource<_OtherKind, _OtherProperties...> __res,
Conversion from a type-erased resource with a superset of the required properties.
- Parameters:
__res – The object to copy from.
- Pre:
_OtherKindis equal to either_Kindor_ResourceKind::_Asynchronous.- Pre:
The set
_OtherProperties...is a superset of_Properties....- Post:
has_value()is equal to__res.has_value()
-
template<_ResourceKind _OtherKind, class ..._OtherProperties>
basic_any_resource( - basic_resource_ref<_OtherKind, _OtherProperties...> __res,
Deep copy from a type-erased resource reference with a superset of the required properties.
The object to which
__resrefers is copied into*this.- Parameters:
__res – The reference to copy from.
- Pre:
_OtherKindis equal to either_Kindor_ResourceKind::_Asynchronous.- Pre:
The set
_OtherProperties...is a superset of_Properties....
-
basic_any_resource &operator=(basic_any_resource &&__other) noexcept#
Move assigns a
basic_any_resource.- Post:
has_value()istrueif__otherhad a value prior to the move, andfalseotherwise.- Post:
__other.has_value()isfalse.
-
basic_any_resource &operator=(const basic_any_resource &__other)#
Copy assigns a
basic_any_resource.- Post:
has_value()is the same as__other.has_value().
-
template<class _Resource>
basic_any_resource &operator=( - _Resource __res,
Assigns from a type that satisfies the
resourceconcept and that supports all of the specified properties.- Parameters:
__res – The resource to be wrapped within the
basic_any_resource- Pre:
_Resourceis not a specialization ofbasic_any_resourceorbasic_resource_ref, or a type derived from such.- Pre:
synchronous_resource_with<_Resource, _Properties...>istrue.- Pre:
If
_Kindis_ResourceKind::_Asynchronous,resource_with<_Resource, _Properties...>istrue.- Post:
has_value()istrue
-
template<_ResourceKind _OtherKind, class ..._OtherProperties>
basic_any_resource &operator=( - basic_any_resource<_OtherKind, _OtherProperties...> __res,
Assignment from a type-erased resource with a superset of the required properties.
- Parameters:
__res – The object to copy from.
- Pre:
_OtherKindis equal to either_Kindor_ResourceKind::_Asynchronous.- Pre:
The set
_OtherProperties...is a superset of_Properties....- Post:
has_value()is equal to__res.has_value().
-
template<_ResourceKind _OtherKind, class ..._OtherProperties>
basic_any_resource &operator=( - basic_resource_ref<_OtherKind, _OtherProperties...> __res,
Deep copy from a type-erased resource reference with a superset of the required properties.
- Parameters:
__res – The type-erased resource reference to copy from.
- Pre:
_OtherKindis equal to either_Kindor_ResourceKind::_Asynchronous.- Pre:
The set
_OtherProperties...is a superset of_Properties....- Post:
has_value()istrue.
-
template<_ResourceKind _OtherKind, class ..._OtherProperties>
bool operator==( - const basic_any_resource<_OtherKind, _OtherProperties...> &__rhs,
Equality comparison between two type-erased memory resource.
- Parameters:
__rhs – The type-erased resource to compare with
*this.- Pre:
_OtherKindis equal to either_Kindor_ResourceKind::_Asynchronous.- Pre:
The set
_Properties...is equal to the set_OtherProperties....- Returns:
trueif both resources hold objects of the same type and those objects compare equal, andfalseotherwise.
-
template<_ResourceKind _OtherKind, class ..._OtherProperties>
bool operator==( - const basic_resource_ref<_OtherKind, _OtherProperties...> &__rhs,
Equality comparison between
*thisand a type-erased resource reference.- Parameters:
__rhs – The type-erased resource reference to compare with
*this.- Pre:
_OtherKindis equal to either_Kindor_ResourceKind::_Asynchronous.- Pre:
The set
_Properties...is equal to the set_OtherProperties....- Returns:
trueif__rhsrefers to an object of the same type as that wrapped by*thisand those objects compare equal;falseotherwise.
- void *allocate_sync(
- size_t __size,
- size_t __align = alignof(cuda::std::max_align_t),
Calls
allocate_syncon the wrapped object with the specified arguments.- Pre:
has_value()istrue.- Returns:
obj.allocate_sync(__size, __align), whereobjis the wrapped object.
- void deallocate_sync(
- void *__pv,
- size_t __size,
- size_t __align = alignof(cuda::std::max_align_t),
Calls
deallocate_syncon the wrapped object with the specified arguments.- Pre:
has_value()istrue.- Pre:
__pvmust be a pointer that was previously returned by a call toallocateon the object wrapped by*this.- Returns:
obj.deallocate_sync(__pv, __size, __align), whereobjis the wrapped object.
- void *allocate(
- cuda::stream_ref __stream,
- size_t __size,
- size_t __align,
Calls
allocateon the wrapped object with the specified arguments.Warning
The returned pointer is not valid until
__streamhas been synchronized.- Pre:
_Kindis_ResourceKind::_Asynchronous.- Pre:
has_value()istrue.- Returns:
obj.allocate(__stream, __size, __align), whereobjis the wrapped object.
-
void *allocate(cuda::stream_ref __stream, size_t __size)#
Equivalent to
.allocate(__stream, __size,
alignof(::cuda::std::max_align_t))
- void deallocate(
- cuda::stream_ref __stream,
- void *__pv,
- size_t __size,
- size_t __align,
Calls
deallocateon the wrapped object with the specified arguments.- Pre:
_Kindis_ResourceKind::_Asynchronous.- Pre:
has_value()istrue.- Pre:
__pvmust be a pointer that was previously returned by a call toallocateon the object wrapped by*this.- Returns:
obj.deallocate(__stream, __pv, __size, __align), whereobjis the wrapped object.
-
void deallocate(cuda::stream_ref __stream, void *__pv, size_t __size)#
Equivalent to
.deallocate(__stream, __pv, __size,
alignof(::cuda::std::max_align_t), __stream)
-
bool has_value() const noexcept#
Checks if
*thisholds a value.- Returns:
trueif*thisholds a value;falseotherwise.
-
void reset() noexcept#
Resets
*thisto the empty state.- Post:
has_value() == false
-
const cuda::std::type_info &type() const noexcept#
- Returns:
A reference to the
type_infoobject for the wrapped resource, ortypeid(void)ifhas_value()isfalse.
Friends
-
template<class _Property>
friend decltype(auto) get_property( - const basic_any_resource &__res,
- _Property __prop,
Forwards a property query to the type-erased object.
- Parameters:
__res – The
basic_any_resourceobject__prop – The property to query
- Pre:
The type
_Propertyis one of the types in the pack_Properties....- Returns:
The result of calling
get_property(__obj, __prop), where__objis the type-erased object stored in__res.
-
template<class _Property>
friend auto try_get_property( - const basic_any_resource &__res,
- _Property __prop,
Attempts to forward a property query to the type-erased object and returns a _
boolean-testable_ object that contains the result, if any.- Template Parameters:
_Property –
- Parameters:
__res – The
basic_any_resourceobject__prop – The property to query
- Pre:
has_value()istrue.- Returns:
Let:
objbe the wrapped object.ValueTypebe the associated value type of__prop.ReturnTypebeboolifValueTypeisvoid. Otherwise,ReturnTypeiscuda::std::optional<ValueType>._OtherPropertiesbe the pack of type parameters of thebasic_any_resourceobject that first type-erasedobj. [Note:_OtherPropertiesis different than_Propertieswhen*thisis the result of a conversion from a different__basic_anytype. — end note]
try_get_property(__res, __prop)has typeReturnType. If_Propertyis not in the pack_OtherProperties, returnsReturnType(). Otherwise:Returns
trueifValueTypeisvoid.Returns
ReturnType(get_property(obj, __prop))otherwise.