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
23 changes: 22 additions & 1 deletion include/cuco/detail/utility/strong_type.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@ namespace cuco::detail {
* @brief A strong type wrapper
*
* @tparam T Type of the value
*
*/
template <typename T>
template <class T>
struct strong_type {
/**
* @brief Constructs a strong type
Expand All @@ -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<Type> { \
__host__ __device__ explicit constexpr Name(Type value) \
: cuco::detail::strong_type<Type>(value) \
{ \
} \
};

/**
* @brief Convenience wrapper for defining a templated strong type
*/
#define CUCO_DEFINE_TEMPLATE_STRONG_TYPE(Name) \
template <typename T> \
struct Name : public cuco::detail::strong_type<T> { \
__host__ __device__ explicit constexpr Name(T value) : cuco::detail::strong_type<T>(value) {} \
};
42 changes: 6 additions & 36 deletions include/cuco/sentinel.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -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<Key>` used to denote the empty key sentinel.
*/
template <typename T>
struct empty_key : public cuco::detail::strong_type<T> {
/**
* @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<T>(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<T>` used to denote the empty value sentinel.
*/
template <typename T>
struct empty_value : public cuco::detail::strong_type<T> {
/**
* @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<T>(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<Key>` used to denote the erased key sentinel.
*/
template <typename T>
struct erased_key : public cuco::detail::strong_type<T> {
/**
* @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<T>(v) {}
};
CUCO_DEFINE_TEMPLATE_STRONG_TYPE(erased_key);
} // namespace cuco