あなたはstd::tuple
にあなたのタイプレベルのリストからパラメータを再バインドするためのテンプレートを追加することができます:
template<class A, template<class...> class B>
struct rebind_;
template<template<class...> class A, class... T, template<class...> class B>
struct rebind_<A<T...>, B> {
using type = B<T...>;
};
template<class A, template<class...> class B>
using rebind = typename rebind_<A, B>::type;
template <class ... T>
struct ComponentList {
typedef std::tuple<T...> tuple_t;
};
template<class T>
class ComponentManager {
typename T::tuple_t components;
};
使い方はあなたが期待するものですそのように使用してください:
template<class... T>
struct ComponentList {};
template<class List>
struct ComponentManager {
rebind<List, std::tuple> components;
};
int main() {
using List = ComponentList<int, char, long>;
ComponentManager<List> manager;
std::cout << std::get<0>(manager.components) << '\n';
}
私はあなたが元の型がComponentList
であることを強制したい場合、あなたはenable_if
とis_instantiation_of
を使用することができますね。
template<class List,
typename = std::enable_if<is_instantiation_of<List, ComponentList>::value>::type>
struct ComponentManager {
rebind<List, std::tuple> components;
};
これは可能性があるが、私は提供されるクラスの施行タイプの両方のよりよい解決策を期待していました(タプルを作る代わりに、それぞれの型を型のベクトルにして、それをタプルの内側に貼り付けるなど)、型リストの中の型を操作することができるようにするために使用されます。 – user975989