Skip to content

Commit

Permalink
Fix ODR violation where end() might be defined by multiple mixin oper…
Browse files Browse the repository at this point in the history
…ators (#440)

This PR fixes an ODR violation that occurs when mixing multiple
operators that define `end()` in their body, e.g., `find()` and
`insert_and_find().`

Solution: Move definition of `end()` to the `_ref` class instead of
defining it in the operators.
  • Loading branch information
sleeepyjack authored Feb 12, 2024
1 parent dae5d68 commit 4fdc73b
Show file tree
Hide file tree
Showing 4 changed files with 101 additions and 104 deletions.
91 changes: 39 additions & 52 deletions include/cuco/detail/static_map/static_map_ref.inl
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,45 @@ static_map_ref<Key, T, Scope, KeyEqual, ProbingScheme, StorageRef, Operators...>
return this->impl_.key_eq();
}

template <typename Key,
typename T,
cuda::thread_scope Scope,
typename KeyEqual,
typename ProbingScheme,
typename StorageRef,
typename... Operators>
__host__ __device__ constexpr static_map_ref<Key,
T,
Scope,
KeyEqual,
ProbingScheme,
StorageRef,
Operators...>::const_iterator
static_map_ref<Key, T, Scope, KeyEqual, ProbingScheme, StorageRef, Operators...>::end()
const noexcept
{
return this->impl_.end();
}

template <typename Key,
typename T,
cuda::thread_scope Scope,
typename KeyEqual,
typename ProbingScheme,
typename StorageRef,
typename... Operators>
__host__ __device__ constexpr static_map_ref<Key,
T,
Scope,
KeyEqual,
ProbingScheme,
StorageRef,
Operators...>::iterator
static_map_ref<Key, T, Scope, KeyEqual, ProbingScheme, StorageRef, Operators...>::end() noexcept
{
return this->impl_.end();
}

template <typename Key,
typename T,
cuda::thread_scope Scope,
Expand Down Expand Up @@ -517,32 +556,6 @@ class operator_impl<
static constexpr auto window_size = base_type::window_size;

public:
/**
* @brief Returns a const_iterator to one past the last slot.
*
* @note This API is available only when `find_tag` or `insert_and_find_tag` is present.
*
* @return A const_iterator to one past the last slot
*/
[[nodiscard]] __host__ __device__ constexpr const_iterator end() const noexcept
{
auto const& ref_ = static_cast<ref_type const&>(*this);
return ref_.impl_.end();
}

/**
* @brief Returns an iterator to one past the last slot.
*
* @note This API is available only when `find_tag` or `insert_and_find_tag` is present.
*
* @return An iterator to one past the last slot
*/
[[nodiscard]] __host__ __device__ constexpr iterator end() noexcept
{
auto const& ref_ = static_cast<ref_type const&>(*this);
return ref_.impl_.end();
}

/**
* @brief Inserts the given element into the map.
*
Expand Down Expand Up @@ -724,32 +737,6 @@ class operator_impl<
static constexpr auto window_size = base_type::window_size;

public:
/**
* @brief Returns a const_iterator to one past the last slot.
*
* @note This API is available only when `find_tag` or `insert_and_find_tag` is present.
*
* @return A const_iterator to one past the last slot
*/
[[nodiscard]] __host__ __device__ constexpr const_iterator end() const noexcept
{
auto const& ref_ = static_cast<ref_type const&>(*this);
return ref_.impl_.end();
}

/**
* @brief Returns an iterator to one past the last slot.
*
* @note This API is available only when `find_tag` or `insert_and_find_tag` is present.
*
* @return An iterator to one past the last slot
*/
[[nodiscard]] __host__ __device__ constexpr iterator end() noexcept
{
auto const& ref_ = static_cast<ref_type const&>(*this);
return ref_.impl_.end();
}

/**
* @brief Finds an element in the map with key equivalent to the probe key.
*
Expand Down
86 changes: 34 additions & 52 deletions include/cuco/detail/static_set/static_set_ref.inl
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,40 @@ static_set_ref<Key, Scope, KeyEqual, ProbingScheme, StorageRef, Operators...>::k
return this->impl_.key_eq();
}

template <typename Key,
cuda::thread_scope Scope,
typename KeyEqual,
typename ProbingScheme,
typename StorageRef,
typename... Operators>
__host__ __device__ constexpr static_set_ref<Key,
Scope,
KeyEqual,
ProbingScheme,
StorageRef,
Operators...>::const_iterator
static_set_ref<Key, Scope, KeyEqual, ProbingScheme, StorageRef, Operators...>::end() const noexcept
{
return this->impl_.end();
}

template <typename Key,
cuda::thread_scope Scope,
typename KeyEqual,
typename ProbingScheme,
typename StorageRef,
typename... Operators>
__host__ __device__ constexpr static_set_ref<Key,
Scope,
KeyEqual,
ProbingScheme,
StorageRef,
Operators...>::iterator
static_set_ref<Key, Scope, KeyEqual, ProbingScheme, StorageRef, Operators...>::end() noexcept
{
return this->impl_.end();
}

template <typename Key,
cuda::thread_scope Scope,
typename KeyEqual,
Expand Down Expand Up @@ -286,32 +320,6 @@ class operator_impl<op::insert_and_find_tag,
static constexpr auto window_size = base_type::window_size;

public:
/**
* @brief Returns a const_iterator to one past the last slot.
*
* @note This API is available only when `find_tag` or `insert_and_find_tag` is present.
*
* @return A const_iterator to one past the last slot
*/
[[nodiscard]] __host__ __device__ constexpr const_iterator end() const noexcept
{
auto const& ref_ = static_cast<ref_type const&>(*this);
return ref_.impl_.end();
}

/**
* @brief Returns an iterator to one past the last slot.
*
* @note This API is available only when `find_tag` or `insert_and_find_tag` is present.
*
* @return An iterator to one past the last slot
*/
[[nodiscard]] __host__ __device__ constexpr iterator end() noexcept
{
auto const& ref_ = static_cast<ref_type const&>(*this);
return ref_.impl_.end();
}

/**
* @brief Inserts the given element into the set.
*
Expand Down Expand Up @@ -486,32 +494,6 @@ class operator_impl<op::find_tag,
static constexpr auto window_size = base_type::window_size;

public:
/**
* @brief Returns a const_iterator to one past the last slot.
*
* @note This API is available only when `find_tag` or `insert_and_find_tag` is present.
*
* @return A const_iterator to one past the last slot
*/
[[nodiscard]] __host__ __device__ constexpr const_iterator end() const noexcept
{
auto const& ref_ = static_cast<ref_type const&>(*this);
return ref_.impl_.end();
}

/**
* @brief Returns an iterator to one past the last slot.
*
* @note This API is available only when `find_tag` or `insert_and_find_tag` is present.
*
* @return An iterator to one past the last slot
*/
[[nodiscard]] __host__ __device__ constexpr iterator end() noexcept
{
auto const& ref_ = static_cast<ref_type const&>(*this);
return ref_.impl_.end();
}

/**
* @brief Finds an element in the set with key equivalent to the probe key.
*
Expand Down
14 changes: 14 additions & 0 deletions include/cuco/static_map_ref.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,20 @@ class static_map_ref
*/
[[nodiscard]] __host__ __device__ constexpr key_equal key_eq() const noexcept;

/**
* @brief Returns a const_iterator to one past the last slot.
*
* @return A const_iterator to one past the last slot
*/
[[nodiscard]] __host__ __device__ constexpr const_iterator end() const noexcept;

/**
* @brief Returns an iterator to one past the last slot.
*
* @return An iterator to one past the last slot
*/
[[nodiscard]] __host__ __device__ constexpr iterator end() noexcept;

/**
* @brief Creates a reference with new operators from the current object.
*
Expand Down
14 changes: 14 additions & 0 deletions include/cuco/static_set_ref.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,20 @@ class static_set_ref
*/
[[nodiscard]] __host__ __device__ constexpr key_equal key_eq() const noexcept;

/**
* @brief Returns a const_iterator to one past the last slot.
*
* @return A const_iterator to one past the last slot
*/
[[nodiscard]] __host__ __device__ constexpr const_iterator end() const noexcept;

/**
* @brief Returns an iterator to one past the last slot.
*
* @return An iterator to one past the last slot
*/
[[nodiscard]] __host__ __device__ constexpr iterator end() noexcept;

/**
* @brief Creates a reference with new operators from the current object.
*
Expand Down

0 comments on commit 4fdc73b

Please sign in to comment.