[英]C++ Template Template Instantiation
我有以下用於可變參數包的封裝代碼。
template <typename... Args>
struct pack
{
};
template <template <typename... Args> class ENCAP, typename... Args>
struct encapsulate_arguments
{
typedef pack<ENCAP<Args>...> type;
};
template <template <typename... Args> class ENCAP, typename... Args>
struct encapsulate_arguments<ENCAP, pack<Args...>>
{
typedef pack<ENCAP<Args>...> type;
};
template <typename L>
struct Master
{
template <typename T>
struct Slave
{
typedef T type;
};
};
這適用於封裝可變參數包,例如:
typedef encapsulate_arguments<Master<float>::Slave, double, int>::type foo;
要么
typedef encapsulate_arguments<Master<float>::Slave, pack<double, int>>::type foo;
要么
typedef encapsulate_arguments<std::vector, pack<double, int>>::type foo;
它不依賴於另一個模板參數 - 導致定義以下內容:
pack<Master<float>::Slave<double>, Master<float>::Slave<int>>
要么
pack<std::vector<double>, std::vector<int>>
問題是,如果我想使封裝模板參數ENCAP類型依賴,我無法編譯它:
template <typename L>
struct Other
{
// ARGGH!!!
// typedef encapsulate_arguments<Master<L>::Slave, pack<double, int>>::type EmbeddedType;
};
這是否可能和/或我怎樣才能使這項工作?
您缺少typename
和template
:
typedef typename encapsulate_arguments<
// ^^^^^^^^
Master<L>::template Slave, pack<double, int>
// ^^^^^^^^
>::type EmbeddedType;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.