Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 1 addition & 19 deletions libcudacxx/include/cuda/__utility/__basic_any/basic_any_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,24 +60,7 @@ _CCCL_CONCEPT __is_basic_any =
);
// clang-format on

#if _CCCL_HAS_CONCEPTS()
template <class _Interface, int = 0>
struct __basic_any_base : __interface_of<_Interface>
{
private:
template <class>
friend struct __basic_any;
friend struct __basic_any_access;

static constexpr size_t __size_ = __buffer_size(_Interface::size);
static constexpr size_t __align_ = __buffer_align(_Interface::align);

__tagged_ptr<__vptr_for<_Interface>> __vptr_{};
alignas(__align_)::cuda::std::byte __buffer_[__size_];
};
#else // ^^^ _CCCL_HAS_CONCEPTS() ^^^ / vvv !_CCCL_HAS_CONCEPTS() vvv
// Without concepts, we need a base class to correctly implement movability
// and copyability.
// We need a base class to correctly implement movability and copyability.
template <class _Interface, int = __extension_of<_Interface, __imovable<>> + __extension_of<_Interface, __icopyable<>>>
struct __basic_any_base;

Expand Down Expand Up @@ -139,7 +122,6 @@ struct __basic_any_base<_Interface, 0> : __basic_any_base<_Interface, 2> // immo
auto operator=(__basic_any_base&&) noexcept -> __basic_any_base& = delete;
auto operator=(__basic_any_base const&) -> __basic_any_base& = delete;
};
#endif // ^^^ !_CCCL_HAS_CONCEPTS() ^^^

_CCCL_END_NAMESPACE_CUDA

Expand Down
14 changes: 0 additions & 14 deletions libcudacxx/include/cuda/__utility/__basic_any/basic_any_ref.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ struct __ireference : ::cuda::std::remove_const_t<_Interface>
using interface _CCCL_NODEBUG_ALIAS = ::cuda::std::remove_const_t<_Interface>;
};

#if !_CCCL_HAS_CONCEPTS()
//!
//! A base class for __basic_any<__ireference<_Interface>> that provides a
//! conversion to __basic_any<__ireference<_Interface const>>. Only used
Expand All @@ -79,7 +78,6 @@ struct __basic_any_reference_conversion_base
template <class _Interface>
struct __basic_any_reference_conversion_base<_Interface const>
{};
#endif // ^^^ !_CCCL_HAS_CONCEPTS() ^^^

_CCCL_DIAG_PUSH
// "operator __basic_any<...> will not be called for implicit or explicit conversions"
Expand All @@ -100,9 +98,7 @@ _CCCL_BEGIN_NV_DIAG_SUPPRESS(554)
template <class _Interface>
struct _CCCL_DECLSPEC_EMPTY_BASES __basic_any<__ireference<_Interface>>
: __interface_of<__ireference<_Interface>>
#if !_CCCL_HAS_CONCEPTS()
, __basic_any_reference_conversion_base<_Interface>
#endif // ^^^ !_CCCL_HAS_CONCEPTS() ^^^
{
static_assert(::cuda::std::is_class_v<_Interface>, "expecting a class type");
using interface_type = ::cuda::std::remove_const_t<_Interface>;
Expand All @@ -114,16 +110,6 @@ struct _CCCL_DECLSPEC_EMPTY_BASES __basic_any<__ireference<_Interface>>
auto operator=(__basic_any&&) -> __basic_any& = delete;
auto operator=(__basic_any const&) -> __basic_any& = delete;

#if _CCCL_HAS_CONCEPTS()
//! \brief A non-const __basic_any reference can be implicitly converted to a
//! const __basic_any reference.
[[nodiscard]] _CCCL_API operator __basic_any<__ireference<_Interface const>>() const noexcept
requires(!__is_const_ref)
{
return __basic_any<__ireference<_Interface const>>(*this);
}
#endif // _CCCL_HAS_CONCEPTS()

//! \brief Returns a const reference to the type_info for the decayed type
//! of the type-erased object.
[[nodiscard]] _CCCL_API auto type() const noexcept -> ::cuda::std::__type_info_ref
Expand Down
52 changes: 4 additions & 48 deletions libcudacxx/include/cuda/__utility/__basic_any/basic_any_value.h
Original file line number Diff line number Diff line change
Expand Up @@ -134,32 +134,10 @@ struct _CCCL_TYPE_VISIBILITY_DEFAULT __basic_any : __basic_any_base<_Interface>
__emplace_from<_Up>(static_cast<_Fn&&>(__fn), static_cast<_Args&&>(__args)...);
}

#if _CCCL_HAS_CONCEPTS() || defined(_CCCL_DOXYGEN_INVOKED)
//! @brief Move constructs a `__basic_any` object.
//! @pre `_Interface` must extend `__imovable<>`.
//! @post `__other.has_value() == false` and `has_value()` is `true` if and
//! only if `__other.has_value()` was `true`.
_CCCL_API __basic_any(__basic_any&& __other) noexcept
requires(__movable)
{
__convert_from(::cuda::std::move(__other));
}

//! @brief Copy constructs a `__basic_any` object.
//! @pre `_Interface` must extend `__icopyable<>`.
//! @post `has_value() == __other.has_value()`. If `_Interface` extends
//! `__iequality_comparable<>`, then `*this == __other` is `true`.
_CCCL_API __basic_any(__basic_any const& __other)
requires(__copyable)
{
__convert_from(__other);
}
#else // ^^^ _CCCL_HAS_CONCEPTS() ^^^ / vvv !_CCCL_HAS_CONCEPTS() vvv
// Without real concepts, we use base classes to implement movability and
// copyability. All we need here is to accept the default implementations.
// We use base classes to implement movability and copyability. All we need here is to
// accept the default implementations.
__basic_any(__basic_any&& __other) = default;
__basic_any(__basic_any const& __other) = default;
#endif // ^^^ !_CCCL_HAS_CONCEPTS() ^^^

//! @brief Converting constructor that move constructs from a compatible
//! `__basic_any` object.
Expand Down Expand Up @@ -213,32 +191,10 @@ struct _CCCL_TYPE_VISIBILITY_DEFAULT __basic_any : __basic_any_base<_Interface>
reset();
}

#if _CCCL_HAS_CONCEPTS() || defined(_CCCL_DOXYGEN_INVOKED)
//! @brief Move assigns a `__basic_any` object.
//! @pre `_Interface` must extend `__imovable<>`.
//! @post `__other.has_value() == false` and `has_value()` is `true` if and
//! only if `__other.has_value()` was `true`.
_CCCL_API __basic_any& operator=(__basic_any&& __other) noexcept
requires(__extension_of<_Interface, __imovable<>>)
{
return __assign_from(::cuda::std::move(__other));
}

//! @brief Copy assigns a `__basic_any` object.
//! @pre `_Interface` must extend `__icopyable<>`.
//! @post `has_value() == __other.has_value()`. If `_Interface` extends
//! `__iequality_comparable<>`, then `*this == __other` is `true`.
_CCCL_API __basic_any& operator=(__basic_any const& __other)
requires(__extension_of<_Interface, __icopyable<>>)
{
return __assign_from(__other);
}
#else // ^^^ _CCCL_HAS_CONCEPTS() ^^^ / vvv !_CCCL_HAS_CONCEPTS() vvv
// Without real concepts, we use base classes to implement movability and
// copyability. All we need here is to accept the default implementations.
// We use base classes to implement movability and copyability. All we need here is to
// accept the default implementations.
auto operator=(__basic_any&& __other) -> __basic_any& = default;
auto operator=(__basic_any const& __other) -> __basic_any& = default;
#endif // ^^^ !_CCCL_HAS_CONCEPTS() ^^^

//! @brief Converting move assignment operator from a compatible `__basic_any`
//! object.
Expand Down
39 changes: 20 additions & 19 deletions libcudacxx/include/cuda/__utility/__basic_any/semiregular.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,18 +51,21 @@ _CCCL_BEGIN_NAMESPACE_CUDA
//! semi-regular overrides
//!

//! @note We use `::cuda::std::enable_if_t` here instead of requires-clauses
//! to avoid ABI differences between C++17 and C++20 modes.

_CCCL_EXEC_CHECK_DISABLE
_CCCL_TEMPLATE(class _Tp)
_CCCL_REQUIRES(::cuda::std::movable<_Tp>)
_CCCL_PUBLIC_API auto __move_fn(_Tp& __src, void* __dst) noexcept -> void
template <class _Tp>
_CCCL_PUBLIC_API auto __move_fn(_Tp& __src, void* __dst) noexcept
-> ::cuda::std::enable_if_t<::cuda::std::movable<_Tp>, void>
{
::new (__dst) _Tp(static_cast<_Tp&&>(__src));
}

_CCCL_EXEC_CHECK_DISABLE
_CCCL_TEMPLATE(class _Tp)
_CCCL_REQUIRES(::cuda::std::movable<_Tp>)
[[nodiscard]] _CCCL_PUBLIC_API auto __try_move_fn(_Tp& __src, void* __dst, size_t __size, size_t __align) -> bool
template <class _Tp>
[[nodiscard]] _CCCL_PUBLIC_API auto __try_move_fn(_Tp& __src, void* __dst, size_t __size, size_t __align)
-> ::cuda::std::enable_if_t<::cuda::std::movable<_Tp>, bool>
{
if (::cuda::__is_small<_Tp>(__size, __align))
{
Expand All @@ -77,9 +80,9 @@ _CCCL_REQUIRES(::cuda::std::movable<_Tp>)
}

_CCCL_EXEC_CHECK_DISABLE
_CCCL_TEMPLATE(class _Tp)
_CCCL_REQUIRES(::cuda::std::copyable<_Tp>)
[[nodiscard]] _CCCL_PUBLIC_API auto __copy_fn(_Tp const& __src, void* __dst, size_t __size, size_t __align) -> bool
template <class _Tp>
[[nodiscard]] _CCCL_PUBLIC_API auto __copy_fn(_Tp const& __src, void* __dst, size_t __size, size_t __align)
-> ::cuda::std::enable_if_t<::cuda::std::copyable<_Tp>, bool>
{
if (::cuda::__is_small<_Tp>(__size, __align))
{
Expand All @@ -94,10 +97,10 @@ _CCCL_REQUIRES(::cuda::std::copyable<_Tp>)
}

_CCCL_EXEC_CHECK_DISABLE
_CCCL_TEMPLATE(class _Tp)
_CCCL_REQUIRES(::cuda::std::equality_comparable<_Tp>)
template <class _Tp>
[[nodiscard]] _CCCL_PUBLIC_API auto
__equal_fn(_Tp const& __self, ::cuda::std::__type_info_ref __type, void const* __other) -> bool
__equal_fn(_Tp const& __self, ::cuda::std::__type_info_ref __type, void const* __other)
-> ::cuda::std::enable_if_t<::cuda::std::equality_comparable<_Tp>, bool>
{
if (_CCCL_TYPEID(_Tp) == __type)
{
Expand All @@ -107,9 +110,9 @@ __equal_fn(_Tp const& __self, ::cuda::std::__type_info_ref __type, void const* _
}

_CCCL_EXEC_CHECK_DISABLE
_CCCL_TEMPLATE(class _From, class _To)
_CCCL_REQUIRES(::cuda::std::convertible_to<_From, _To>)
[[nodiscard]] _CCCL_PUBLIC_API _To __conversion_fn(::cuda::std::type_identity_t<_From> __self)
template <class _From, class _To>
[[nodiscard]] _CCCL_PUBLIC_API auto __conversion_fn(::cuda::std::type_identity_t<_From> __self)
-> ::cuda::std::enable_if_t<::cuda::std::convertible_to<_From, _To>, _To>
{
return static_cast<_To>(static_cast<_From&&>(__self));
}
Expand All @@ -120,8 +123,7 @@ _CCCL_REQUIRES(::cuda::std::convertible_to<_From, _To>)
template <class...>
struct __imovable : __basic_interface<__imovable>
{
_CCCL_TEMPLATE(class _Tp)
_CCCL_REQUIRES(::cuda::std::movable<_Tp>)
template <class _Tp>
using overrides _CCCL_NODEBUG_ALIAS = __overrides_for<_Tp, &::cuda::__try_move_fn<_Tp>, &::cuda::__move_fn<_Tp>>;

_CCCL_API auto __move_to(void* __pv) noexcept -> void
Expand All @@ -138,8 +140,7 @@ struct __imovable : __basic_interface<__imovable>
template <class...>
struct __icopyable : __basic_interface<__icopyable, __extends<__imovable<>>>
{
_CCCL_TEMPLATE(class _Tp)
_CCCL_REQUIRES(::cuda::std::copyable<_Tp>)
template <class _Tp>
using overrides _CCCL_NODEBUG_ALIAS = __overrides_for<_Tp, &::cuda::__copy_fn<_Tp>>;

[[nodiscard]] _CCCL_API auto __copy_to(void* __pv, size_t __size, size_t __align) const -> bool
Expand Down