Skip to content

Commit f28c570

Browse files
hugtalbotalxbilger
andauthored
[Helper] Fix warning in SelectableItem (#5163)
* [Helper] Fix warning in SelectableItem * simpler code * simplify trait using concept * remove unused include --------- Co-authored-by: Alex Bilger <alexbilger0@gmail.com>
1 parent bf730d2 commit f28c570

File tree

1 file changed

+10
-17
lines changed

1 file changed

+10
-17
lines changed

Sofa/framework/Helper/src/sofa/helper/SelectableItem.h

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -240,27 +240,20 @@ class SelectableItem : public BaseSelectableItem
240240

241241
static constexpr id_type findId(const std::string_view key)
242242
{
243-
return findId_impl(key, std::make_index_sequence<numberOfItems()>{});
244-
}
245-
246-
template<id_type... Is>
247-
static constexpr id_type findId_impl(const std::string_view key, std::index_sequence<Is...>)
248-
{
249-
id_type result = static_cast<id_type>(-1);
250-
((Derived::s_items[Is].key == key ? (result = Is, true) : false) || ...);
251-
return result;
243+
//use std::ranges::enumerate in C++23
244+
for (id_type i = 0; i < numberOfItems(); ++i)
245+
{
246+
if (key == Derived::s_items[i].key)
247+
{
248+
return i;
249+
}
250+
}
251+
return static_cast<id_type>(-1);
252252
}
253253

254-
template <typename, typename = std::void_t<>>
255-
struct has_deprecation_map : std::false_type {};
256-
257-
// Specialization when T has a static member s_foo
258-
template <typename T>
259-
struct has_deprecation_map<T, std::void_t<decltype(T::s_deprecationMap)>> : std::true_type {};
260-
261254
void keyError(const std::string_view key)
262255
{
263-
if constexpr (has_deprecation_map<Derived>::value)
256+
if constexpr (requires {Derived::s_deprecationMap;})
264257
{
265258
static_assert(std::is_same_v<std::remove_cv_t<decltype(Derived::s_deprecationMap)>, std::map<std::string_view, DeprecatedItem>>);
266259
const auto it = Derived::s_deprecationMap.find(key);

0 commit comments

Comments
 (0)