Skip to content

Commit 6ab9d0c

Browse files
committed
Simplify implementation of index_of
1 parent 98bc9c4 commit 6ab9d0c

File tree

1 file changed

+5
-16
lines changed

1 file changed

+5
-16
lines changed

include/cpp-sort/detail/type_traits.h

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -241,28 +241,17 @@ namespace cppsort::detail
241241
// list
242242

243243
template<typename Needle, typename... Haystack>
244-
struct index_of_impl;
244+
inline constexpr int index_of;
245245

246246
template<typename Needle>
247-
struct index_of_impl<Needle>
248-
{
249-
static constexpr int value = -1;
250-
};
247+
inline constexpr int index_of<Needle> = -1;
251248

252249
template<typename Needle, typename... Tail>
253-
struct index_of_impl<Needle, Needle, Tail...>
254-
{
255-
static constexpr int value = 0;
256-
};
250+
inline constexpr int index_of<Needle, Needle, Tail...> = 0;
257251

258252
template<typename Needle, typename Head, typename... Tail>
259-
struct index_of_impl<Needle, Head, Tail...>
260-
{
261-
static constexpr int value = index_of_impl<Needle, Tail...>::value + 1;
262-
};
263-
264-
template<typename Needle, typename... Haystack>
265-
constexpr int index_of = index_of_impl<Needle, Haystack...>::value;
253+
inline constexpr int index_of<Needle, Head, Tail...>
254+
= index_of<Needle, Tail...> + 1;
266255
}
267256

268257
#endif // CPPSORT_DETAIL_TYPE_TRAITS_H_

0 commit comments

Comments
 (0)