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

Add MapType capability for TypePack

上级 4d8f2a2b
...@@ -101,6 +101,18 @@ struct TakeFirstN<1, TypePack<T, Ts...>> { ...@@ -101,6 +101,18 @@ struct TakeFirstN<1, TypePack<T, Ts...>> {
using type = TypePack<T>; using type = TypePack<T>;
}; };
template <template <typename> class M, typename... Ts>
struct MapType;
template <template <typename> class M, typename T>
struct MapType<M, TypePack<T>> {
using type = TypePack<M<T>>;
};
template <template <typename> class M, typename T, typename... Ts>
struct MapType<M, TypePack<T, Ts...>> {
using type = typename Prepend<M<T>, typename MapType<M, TypePack<Ts...>>::type>::type;
};
template <typename F, typename... Ts> template <typename F, typename... Ts>
void ForEachType(F func, TypePack<Ts...>); void ForEachType(F func, TypePack<Ts...>);
template <typename F, typename T, typename... Ts> template <typename F, typename T, typename... Ts>
......
...@@ -128,3 +128,24 @@ TEST(TypePack, HasType) { ...@@ -128,3 +128,24 @@ TEST(TypePack, HasType) {
EXPECT_FALSE((HasType<char, Pack>::value)); EXPECT_FALSE((HasType<char, Pack>::value));
EXPECT_FALSE((HasType<unsigned int, Pack>::value)); EXPECT_FALSE((HasType<unsigned int, Pack>::value));
} }
TEST(TypePack, TakeRemove) {
using Pack = TypePack<signed int, float, double>;
static_assert(std::is_same_v<TypePack<signed int>, typename TakeFirstN<1, Pack>::type>);
static_assert(std::is_same_v<TypePack<float>, typename TakeFirstN<1, typename RemoveFirstN<1, Pack>::type>::type>);
static_assert(std::is_same_v<TypePack<double>, typename TakeFirstN<1, typename RemoveFirstN<2, Pack>::type>::type>);
}
template <typename T> struct Set { };
TEST(TypePack, Map) {
using SetPack = typename MapType<Set, TypePack<signed int, float, double>>::type;
static_assert(std::is_same_v<TypePack<Set<signed int>>,
typename TakeFirstN<1, SetPack>::type>);
static_assert(std::is_same_v<TypePack<Set<float>>,
typename TakeFirstN<1, typename RemoveFirstN<1, SetPack>::type>::type>);
static_assert(std::is_same_v<TypePack<Set<double>>,
typename TakeFirstN<1, typename RemoveFirstN<2, SetPack>::type>::type>);
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册