cuda::experimental::basic_resource_ref#
-
template<_ResourceKind _Kind, class ..._Properties>
class basic_resource_ref# Type erased wrapper around a reference to an object that satisfies the
resource
concept and that provides the requested_Properties
.basic_resource_ref
models thecuda::std::copyable
andcuda::std::equality_comparable
concepts.- Template Parameters:
_Properties – The properties that any resource wrapped within the
basic_resource_ref
needs to provide.
Public Functions
-
basic_resource_ref(const basic_resource_ref &__other)#
Copy constructs a
basic_resource_ref
.- Post:
*this
and__other
both refer to the same resource object.
-
template<class _Resource>
basic_resource_ref(_Resource &__res)# Constructs a
basic_resource_ref
from a reference to a type that satisfies theresource
concept and that supports all of the specified properties.- Parameters:
__res – The resource reference to be wrapped.
- Pre:
synchronous_resource_with<_Resource, _Properties...>
istrue
.- Pre:
If
_Kind
is_ResourceKind::_Asynchronous
,resource_with<_Resource, _Properties...>
istrue
.- Pre:
If
__res
refers to a specialization ofbasic_any_resource
or a type derived from such,__res.has_value()
istrue
.
-
template<_ResourceKind _OtherKind, class ..._OtherProperties>
basic_resource_ref( - basic_resource_ref<_OtherKind, _OtherProperties...> __res,
Conversion from type-erased resource reference with a superset of the required properties.
- Parameters:
__res – The other 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:
*this
and__res
both refer to the same resource object.
-
basic_resource_ref &operator=(const basic_resource_ref &__other)#
Rebinds
*this
to refer to the object to which__other
refers.- Post:
*this
and__other
both refer to the same resource object.
-
template<class _Resource>
basic_resource_ref &operator=( - _Resource &__res,
Rebinds the wrapped reference to an object whose type satisfies the
resource
concept and that supports all of the specified properties.- Parameters:
__res – The reference to the resource to be wrapped by the
basic_resource_ref
.- Pre:
synchronous_resource_with<_Resource, _Properties...>
istrue
.- Pre:
If
_Kind
is_ResourceKind::_Asynchronous
,synchronous_resource_with<_Resource, _Properties...>
istrue
.- Pre:
If
__res
refers to a specialization ofbasic_any_resource
or a type derived from such,__res.has_value()
istrue
.
-
template<_ResourceKind _OtherKind, class ..._OtherProperties>
basic_resource_ref &operator=( - basic_resource_ref<_OtherKind, _OtherProperties...> __res,
Rebinds
*this
to refer to the object to which__other
refers.- Parameters:
__res – The other 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:
*this
and__res
both refer to the same resource object.
-
template<_ResourceKind _OtherKind, class ..._OtherProperties>
bool operator==( - const basic_resource_ref<_OtherKind, _OtherProperties...> &__rhs,
Equality comparison between two type-erased resource references.
- Parameters:
__rhs – The other type-erased resource reference.
- 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 refer to objects of the same type and those objects compare equal. Otherwise, returnsfalse
.
- void *allocate_sync(
- size_t __size,
- size_t __align = alignof(cuda::std::max_align_t),
Calls
allocate_sync
on the wrapped reference with the specified arguments.- Returns:
obj.allocate_sync(__size, __align)
, whereobj
is the wrapped reference.
- void deallocate_sync(
- void *__pv,
- size_t __size,
- size_t __align = alignof(cuda::std::max_align_t),
Calls
deallocate_sync
on the wrapped reference with the specified arguments.- Pre:
__pv
must be a pointer that was previously returned by a call toallocate
on the object referenced by*this
.- Returns:
obj.deallocate_sync(__pv, __size, __align)
, whereobj
is the wrapped reference.
- void *allocate(
- cuda::stream_ref __stream,
- size_t __size,
- size_t __align,
Calls
allocate
on the wrapped reference with the specified arguments.Warning
The returned pointer is not valid until
__stream
has been synchronized.- Pre:
_Kind
is_ResourceKind::_Asynchronous
.- Returns:
obj.allocate(__stream, __size, __align)
, whereobj
is the wrapped reference.
-
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 reference with the specified arguments.- Pre:
_Kind
is_ResourceKind::_Asynchronous
.- Pre:
__pv
must be a pointer that was previously returned by a call toallocate
on the object referenced by*this
.- Returns:
obj.deallocate(__stream, __pv, __size, __align)
, whereobj
is the wrapped reference.
-
void deallocate(cuda::stream_ref __stream, void *__pv, size_t __size)#
Equivalent to
.deallocate(__stream, __pv, __size,
alignof(::cuda::std::max_align_t), __stream)
-
const cuda::std::type_info &type() const noexcept#
- Returns:
A reference to the
type_info
object for the type of the object to which*this
refers.
Friends
-
template<class _Property>
friend decltype(auto) get_property( - const basic_resource_ref &__res,
- _Property __prop,
Forwards a property query to the type-erased reference.
- Template Parameters:
_Property –
- Parameters:
__res – The
basic_resource_ref
object__prop – The property to query
- Pre:
_Property
is a type in_Properties...
.- Returns:
The result of calling
get_property(__obj, __prop)
, where__obj
is the type-erased reference stored in__res
.
-
template<class _Property>
friend auto try_get_property( - const basic_resource_ref &__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
any_synchronous_resource
object__prop – The property to query
- Pre:
has_value()
istrue
.- Returns:
Let:
obj
be the wrapped reference.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 the wrapper type that first type-erasedobj
. [Note:_OtherProperties
is different than_Properties
when*this
is the result of an interface-narrowing conversion. — 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.