From c855d33eb32c785cd358187c61f7008c2274bd29 Mon Sep 17 00:00:00 2001 From: Daniel Juenger <2955913+sleeepyjack@users.noreply.github.com> Date: Tue, 2 Apr 2024 13:21:12 +0000 Subject: [PATCH 1/2] Add convenience macro for defining strong type (correctly) --- include/cuco/detail/utility/strong_type.cuh | 23 ++++++++++++- include/cuco/sentinel.cuh | 36 ++------------------- 2 files changed, 25 insertions(+), 34 deletions(-) diff --git a/include/cuco/detail/utility/strong_type.cuh b/include/cuco/detail/utility/strong_type.cuh index 13040909a..d08ddc91a 100644 --- a/include/cuco/detail/utility/strong_type.cuh +++ b/include/cuco/detail/utility/strong_type.cuh @@ -21,8 +21,9 @@ namespace cuco::detail { * @brief A strong type wrapper * * @tparam T Type of the value + * */ -template +template struct strong_type { /** * @brief Constructs a strong type @@ -42,3 +43,23 @@ struct strong_type { }; } // namespace cuco::detail + +/** + * @brief Convenience wrapper for defining a strong type + */ +#define CUCO_DEFINE_STRONG_TYPE(Name, Type) \ + struct Name : public cuco::detail::strong_type { \ + __host__ __device__ explicit constexpr Name(Type value) \ + : cuco::detail::strong_type(value) \ + { \ + } \ + }; + +/** + * @brief Convenience wrapper for defining a templated strong type + */ +#define CUCO_DEFINE_TEMPLATE_STRONG_TYPE(Name) \ + template \ + struct Name : public cuco::detail::strong_type { \ + __host__ __device__ explicit constexpr Name(T value) : cuco::detail::strong_type(value) {} \ + }; diff --git a/include/cuco/sentinel.cuh b/include/cuco/sentinel.cuh index 550bffbf2..4a46f74c7 100644 --- a/include/cuco/sentinel.cuh +++ b/include/cuco/sentinel.cuh @@ -21,46 +21,16 @@ namespace cuco { /** * @brief A strong type wrapper used to denote the empty key sentinel. - * - * @tparam T Type of the key values */ -template -struct empty_key : public cuco::detail::strong_type { - /** - * @brief Constructs an empty key sentinel with the given `v`. - * - * @param v The empty key sentinel value - */ - __host__ __device__ explicit constexpr empty_key(T v) : cuco::detail::strong_type(v) {} -}; +CUCO_DEFINE_TEMPLATE_STRONG_TYPE(empty_key); /** * @brief A strong type wrapper used to denote the empty value sentinel. - * - * @tparam T Type of the mapped values */ -template -struct empty_value : public cuco::detail::strong_type { - /** - * @brief Constructs an empty value sentinel with the given `v`. - * - * @param v The empty value sentinel value - */ - __host__ __device__ explicit constexpr empty_value(T v) : cuco::detail::strong_type(v) {} -}; +CUCO_DEFINE_TEMPLATE_STRONG_TYPE(empty_value); /** * @brief A strong type wrapper used to denote the erased key sentinel. - * - * @tparam T Type of the key values */ -template -struct erased_key : public cuco::detail::strong_type { - /** - * @brief Constructs an erased key sentinel with the given `v`. - * - * @param v The erased key sentinel value - */ - __host__ __device__ explicit constexpr erased_key(T v) : cuco::detail::strong_type(v) {} -}; +CUCO_DEFINE_TEMPLATE_STRONG_TYPE(erased_key); } // namespace cuco From 7cd344ce9cfea57573b69db66eaf7c14e57216bf Mon Sep 17 00:00:00 2001 From: Daniel Juenger <2955913+sleeepyjack@users.noreply.github.com> Date: Tue, 2 Apr 2024 23:47:35 +0000 Subject: [PATCH 2/2] Update sentinel docs --- include/cuco/sentinel.cuh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/include/cuco/sentinel.cuh b/include/cuco/sentinel.cuh index 4a46f74c7..b71d3e6c5 100644 --- a/include/cuco/sentinel.cuh +++ b/include/cuco/sentinel.cuh @@ -20,17 +20,17 @@ namespace cuco { /** - * @brief A strong type wrapper used to denote the empty key sentinel. + * @brief A strong type wrapper `cuco::empty_key` used to denote the empty key sentinel. */ CUCO_DEFINE_TEMPLATE_STRONG_TYPE(empty_key); /** - * @brief A strong type wrapper used to denote the empty value sentinel. + * @brief A strong type wrapper `cuco::empty_value` used to denote the empty value sentinel. */ CUCO_DEFINE_TEMPLATE_STRONG_TYPE(empty_value); /** - * @brief A strong type wrapper used to denote the erased key sentinel. + * @brief A strong type wrapper `cuco::erased_key` used to denote the erased key sentinel. */ CUCO_DEFINE_TEMPLATE_STRONG_TYPE(erased_key); } // namespace cuco