Skip to content

Commit

Permalink
⚡ Speed up tuple contains_type
Browse files Browse the repository at this point in the history
Compilation benchmark performance regressed in intel#323 - this fixes the regression.
  • Loading branch information
elbeno committed Aug 20, 2023
1 parent 99f4b3f commit 687b6a6
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions include/cib/tuple_algorithms.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,9 +147,13 @@ template <typename... Ts> constexpr auto none_of(Ts &&...ts) -> bool {
return not any_of(std::forward<Ts>(ts)...);
}

namespace detail {
template <typename T, typename... Us>
constexpr auto contains_type(cib::tuple<Us...> const &)
-> std::bool_constant<(std::is_same_v<T, Us> or ...)>;
} // namespace detail

template <typename Tuple, typename T>
constexpr auto contains_type =
[]<std::size_t... Is>(std::index_sequence<Is...>) {
return (... or std::is_same_v<T, cib::tuple_element_t<Is, Tuple>>);
}(std::make_index_sequence<cib::tuple_size_v<Tuple>>{});
decltype(detail::contains_type<T>(std::declval<Tuple>()))::value;
} // namespace cib

0 comments on commit 687b6a6

Please sign in to comment.