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..b71d3e6c5 100644 --- a/include/cuco/sentinel.cuh +++ b/include/cuco/sentinel.cuh @@ -20,47 +20,17 @@ namespace cuco { /** - * @brief A strong type wrapper used to denote the empty key sentinel. - * - * @tparam T Type of the key values + * @brief A strong type wrapper `cuco::empty_key` used to denote the empty key sentinel. */ -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 + * @brief A strong type wrapper `cuco::empty_value` used to denote the empty value sentinel. */ -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 + * @brief A strong type wrapper `cuco::erased_key` used to denote the erased key sentinel. */ -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