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_resource
wraps 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_resource
models thecuda::std::regular
concept.See also
See also
See also
See also
- Template Parameters:
_Kind – Either
_ResourceKind::_Synchronous
forany_synchronous_resource
, or_ResourceKind::_Asynchronous
forany_resource
._Properties – A pack of property types that a memory resource must provide in order to be storable in instances of this
basic_any_resource
type.
Public Functions
-
basic_any_resource() noexcept#
Constructs a
basic_any_resource
with no value.- Post:
has_value()
isfalse
-
basic_any_resource(basic_any_resource &&__other) noexcept#
Move constructs a
basic_any_resource
.- Post:
has_value()
istrue
if__other
had a value prior to the move, andfalse
otherwise.__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_resource
from a type that satisfies theresource
concept.and that supports all of the specified properties.
- Parameters:
__res – The resource to be wrapped by the
basic_any_resource
.- Pre:
_Resource
is not a specialization ofbasic_any_resource
orbasic_resource_ref
, or a type derived from such.- Pre:
synchronous_resource_with<_Resource, _Properties...>
istrue
.- Pre:
If
_Kind
is_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:
_OtherKind
is equal to either_Kind
or_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
__res
refers is copied into*this
.- Parameters:
__res – The reference to copy from.
- Pre:
_OtherKind
is equal to either_Kind
or_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()
istrue
if__other
had a value prior to the move, andfalse
otherwise.- 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
resource
concept and that supports all of the specified properties.- Parameters:
__res – The resource to be wrapped within the
basic_any_resource
- Pre:
_Resource
is not a specialization ofbasic_any_resource
orbasic_resource_ref
, or a type derived from such.- Pre:
synchronous_resource_with<_Resource, _Properties...>
istrue
.- Pre:
If
_Kind
is_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:
_OtherKind
is equal to either_Kind
or_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:
_OtherKind
is equal to either_Kind
or_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:
_OtherKind
is equal to either_Kind
or_ResourceKind::_Asynchronous
.- Pre:
The set
_Properties...
is equal to the set_OtherProperties...
.- Returns:
true
if both resources hold objects of the same type and those objects compare equal, andfalse
otherwise.
-
template<_ResourceKind _OtherKind, class ..._OtherProperties>
bool operator==( - const basic_resource_ref<_OtherKind, _OtherProperties...> &__rhs,
Equality comparison between
*this
and a type-erased resource reference.- Parameters:
__rhs – The type-erased resource reference to compare with
*this
.- Pre:
_OtherKind
is equal to either_Kind
or_ResourceKind::_Asynchronous
.- Pre:
The set
_Properties...
is equal to the set_OtherProperties...
.- Returns:
true
if__rhs
refers to an object of the same type as that wrapped by*this
and those objects compare equal;false
otherwise.
- void *allocate_sync(
- size_t __size,
- size_t __align = alignof(cuda::std::max_align_t),
Calls
allocate_sync
on the wrapped object with the specified arguments.- Pre:
has_value()
istrue
.- Returns:
obj.allocate_sync(__size, __align)
, whereobj
is the wrapped object.
- void deallocate_sync(
- void *__pv,
- size_t __size,
- size_t __align = alignof(cuda::std::max_align_t),
Calls
deallocate_sync
on the wrapped object with the specified arguments.- Pre:
has_value()
istrue
.- Pre:
__pv
must be a pointer that was previously returned by a call toallocate
on the object wrapped by*this
.- Returns:
obj.deallocate_sync(__pv, __size, __align)
, whereobj
is the wrapped object.
- void *allocate(
- cuda::stream_ref __stream,
- size_t __size,
- size_t __align,
Calls
allocate
on the wrapped object with the specified arguments.Warning
The returned pointer is not valid until
__stream
has been synchronized.- Pre:
_Kind
is_ResourceKind::_Asynchronous
.- Pre:
has_value()
istrue
.- Returns:
obj.allocate(__stream, __size, __align)
, whereobj
is 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
deallocate
on the wrapped object with the specified arguments.- Pre:
_Kind
is_ResourceKind::_Asynchronous
.- Pre:
has_value()
istrue
.- Pre:
__pv
must be a pointer that was previously returned by a call toallocate
on the object wrapped by*this
.- Returns:
obj.deallocate(__stream, __pv, __size, __align)
, whereobj
is 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
*this
holds a value.- Returns:
true
if*this
holds a value;false
otherwise.
-
void reset() noexcept#
Resets
*this
to the empty state.- Post:
has_value() == false
-
const cuda::std::type_info &type() const noexcept#
- Returns:
A reference to the
type_info
object 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_resource
object__prop – The property to query
- Pre:
The type
_Property
is one of the types in the pack_Properties...
.- Returns:
The result of calling
get_property(__obj, __prop)
, where__obj
is 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_resource
object__prop – The property to query
- Pre:
has_value()
istrue
.- Returns:
Let:
obj
be the wrapped object.ValueType
be the associated value type of__prop
.ReturnType
bebool
ifValueType
isvoid
. Otherwise,ReturnType
iscuda::std::optional<ValueType>
._OtherProperties
be the pack of type parameters of thebasic_any_resource
object that first type-erasedobj
. [Note:_OtherProperties
is different than_Properties
when*this
is the result of a conversion from a different__basic_any
type. — end note]
try_get_property(__res, __prop)
has typeReturnType
. If_Property
is not in the pack_OtherProperties
, returnsReturnType()
. Otherwise:Returns
true
ifValueType
isvoid
.Returns
ReturnType(get_property(obj, __prop))
otherwise.