Last active
August 22, 2018 23:52
-
-
Save cqfd/aae7a1d0721279e5e1e04ad8a7205d62 to your computer and use it in GitHub Desktop.
Type predicates.
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
template <typename T, typename U> | |
struct Or : std::bool_constant<T::value || U::value> {}; | |
template <template<typename> class Predicate, typename... Ts> | |
struct any : false_type {}; | |
template <template<typename> class Predicate, typename T, typename... Ts> | |
struct any<Predicate, T, Ts...> : Or<Predicate<T>, any<Predicate, Ts...>> {}; | |
template <typename T> struct is_std_vector : false_type {}; | |
template <typename T> struct is_std_vector<vector<T>> : true_type {}; | |
static_assert(!any<is_std_vector>::value); | |
static_assert(!any<is_std_vector, int, bool>::value); | |
static_assert(any<is_std_vector, int, bool, vector<double>>::value); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment