Skip to content

Instantly share code, notes, and snippets.

@picanumber
Last active September 9, 2021 19:53
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save picanumber/7703b3c70b1c3d4045300ffcc30be9ff to your computer and use it in GitHub Desktop.
Save picanumber/7703b3c70b1c3d4045300ffcc30be9ff to your computer and use it in GitHub Desktop.
template <class T, class Tuple, std::size_t I = 0>
consteval std::size_t TypeIndex() {
if constexpr (I >= std::tuple_size<Tuple>::value) {
return 0;
} else if constexpr (std::is_same_v<T, std::tuple_element_t<I, Tuple>>) {
return I + 1;
} else {
return TypeIndex<T, Tuple, I + 1>();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment