Skip to content

Instantly share code, notes, and snippets.

@cqfd
Last active August 22, 2018 23:52
Show Gist options
  • Save cqfd/aae7a1d0721279e5e1e04ad8a7205d62 to your computer and use it in GitHub Desktop.
Save cqfd/aae7a1d0721279e5e1e04ad8a7205d62 to your computer and use it in GitHub Desktop.
Type predicates.
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