简体   繁体   English

如何提取/扩展可变参数模板参数

[英]How to extract/expand variadic template parameters

template <typename T1, typename T2>
class Base
{
  T1 t1; 
  T2 t2;
};

template <typename...TN>
class Derived
    : public Base< std::tuple<QList<TN...>>,
                   std::tuple<QVector<TN...>> > //does not work
{
};

Derived<int, double> d;
  • t1 shall become std::tuple<QList<int>, QList<double>> t1将变为std::tuple<QList<int>, QList<double>>
  • t2 shall become std::tuple<QVector<int>, QVector<double>> t2将变为std::tuple<QVector<int>, QVector<double>>

I don't know if this is possible in general. 我不知道这是否可能。 Currently I use preprocessor magic for that. 目前,我为此使用预处理器魔术。 But I hoped that variadic template can do that too. 但是我希望可变参数模板也可以做到这一点。 So, can I do any recursive things or any similar to extract the template? 因此,我可以做任何递归操作或类似的操作来提取模板吗?

As @dyp says, you expanded the pack in the wrong place. 正如@dyp所说,您将扩展包放在错误的位置。 It should be like this: 应该是这样的:

: public Base< std::tuple<QList<TN>...>,
               std::tuple<QVector<TN>...> >

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM