Skip to content

Commit 3be3318

Browse files
committed
Fix SFINAE bug in container base type
This commit fixes a bug in the use of SFINAE in the container base type. In particuler, this issue has three layers: 1. The existing code uses the `typename = std::enable_if` anti-pattern which is discouraged in the C++ standard. 2. The code used `std::enable_if` without getting `::type` from it, meaning that a specialization failure cannot ever occur, rendering the SFINAE useless. 3. The check used about type equality is incorrect, it should rather check constructability. This commit fixes the issues by converting the code to a C++20 requires clause and by modifying the conditions.
1 parent eb002e8 commit 3be3318

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

core/include/traccc/edm/details/container_base.hpp

+5-7
Original file line numberDiff line numberDiff line change
@@ -137,13 +137,11 @@ class container_base {
137137
/**
138138
* @brief Constructor from a pair of "view type" objects
139139
*/
140-
template <typename header_vector_tp, typename item_vector_tp,
141-
typename = std::enable_if<
142-
std::is_same<header_vector_tp, header_vector>::value>,
143-
typename = std::enable_if<
144-
std::is_same<item_vector_tp, item_vector>::value>>
145-
TRACCC_HOST_DEVICE container_base(const header_vector_tp& hv,
146-
const item_vector_tp& iv)
140+
template <typename header_vector_tp, typename item_vector_tp>
141+
requires(std::constructible_from<header_vector, const header_vector_tp&>&&
142+
std::constructible_from<item_vector, const item_vector_tp&>)
143+
TRACCC_HOST_DEVICE
144+
container_base(const header_vector_tp& hv, const item_vector_tp& iv)
147145
: m_headers(hv), m_items(iv) {
148146

149147
assert(m_headers.size() == m_items.size());

0 commit comments

Comments
 (0)