Created
March 11, 2019 09:11
-
-
Save hutorny/714f7e67431b8523f77983707437e47c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 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