Skip to content

Instantly share code, notes, and snippets.

@hutorny hutorny/any_of.hpp
Created Mar 11, 2019

Embed
What would you like to do?
/* constexpr any_of against a list of constants */
/** type_of_list<...>::type - helper structure for determining type of the first item in the list */
template<auto ... List> struct type_of_list;
template<auto List> struct type_of_list<List> { using type = decltype(List); };
template<auto First, auto ... List > struct type_of_list<First, List...> : type_of_list<First> {};
/** type_of<...>::type - determines type of the first item in the list */
template<auto ... List>
using type_of = typename type_of_list<List...>::type;
/** any_of<...>(value) - compares value against all template parameters and returns true if any matches */
template<auto ... List>
inline constexpr bool any_of(type_of<List...> value) noexcept {
return ((value == List) || ...);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.