提交 d9a88beb 编写于 作者: M Matt Pharr

Add FilterTypes to TypePack functionality

(Not currently used.)
上级 bc82b836
......@@ -88,6 +88,10 @@ template <typename T, typename... Ts>
struct Prepend<T, TypePack<Ts...>> {
using type = TypePack<T, Ts...>;
};
template <typename... Ts>
struct Prepend<void, TypePack<Ts...>> {
using type = TypePack<Ts...>;
};
template <int index, typename T, typename... Ts>
struct TakeFirstN;
......@@ -113,6 +117,38 @@ struct MapType<M, TypePack<T, Ts...>> {
using type = typename Prepend<M<T>, typename MapType<M, TypePack<Ts...>>::type>::type;
};
template <template <typename> class Pred, typename... Ts>
struct FilterTypes;
namespace internal {
template <typename T, bool>
struct FilterTypesHelper;
template <typename T>
struct FilterTypesHelper<T, true> {
using type = T;
};
template <typename T>
struct FilterTypesHelper<T, false> {
using type = void;
};
}; // namespace internal
template <template <typename> class Pred, typename T>
struct FilterTypes<Pred, TypePack<T>> {
using type = typename TypePack<
typename internal::FilterTypesHelper<T, Pred<T>::value>::type>::type;
};
template <template <typename> class Pred, typename T, typename... Ts>
struct FilterTypes<Pred, TypePack<T, Ts...>> {
using type =
typename Prepend<typename internal::FilterTypesHelper<T, Pred<T>::value>::type,
TypePack<Ts...>>::type;
};
template <typename F, typename... Ts>
void ForEachType(F func, TypePack<Ts...>);
template <typename F, typename T, typename... Ts>
......
......@@ -149,3 +149,12 @@ TEST(TypePack, Map) {
static_assert(std::is_same_v<TypePack<Set<double>>,
typename TakeFirstN<1, typename RemoveFirstN<2, SetPack>::type>::type>);
}
TEST(TypePack, Filter) {
using Pack = TypePack<signed int, float, double>;
using FilteredPack = typename FilterTypes<std::is_floating_point, Pack>::type;
static_assert(std::is_same_v<TypePack<float>, typename TakeFirstN<1, FilteredPack>::type>);
static_assert(std::is_same_v<TypePack<double>,
typename TakeFirstN<1, typename RemoveFirstN<1, FilteredPack>::type>::type>);
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册