【问题标题】:wrapping tuple members in other templated types [duplicate]将元组成员包装在其他模板类型中[重复]
【发布时间】:2017-06-11 17:53:47
【问题描述】:

我希望能够使用模板包声明一个类,这样该类本身将具有一个成员变量元组,该元组将每个模板包成员包装在某种容器类型中。基本目标如下所示:

template <typename Types...>
class VectorOfMembers 
{
public:
    // Member tuple where each element is expanded in a container
    std::tuple<std::vector<Type[1]>, std::vector<Type[2]>, std::vector<TypeN...>>
};

理想情况下,我也希望能够使用任何模板化对象作为包装类型来做到这一点。

【问题讨论】:

    标签: c++ templates variadic


    【解决方案1】:

    嗯,你几乎拥有它:

    template <typename... Types>
    class VectorOfMembers
    {
    public:
        // Member tuple where each element is expanded in a container
        std::tuple<std::vector<Types>...> tuple;
    };
    

    【讨论】:

      猜你喜欢
      • 2019-10-29
      • 1970-01-01
      • 2021-08-28
      • 1970-01-01
      • 1970-01-01
      • 2020-05-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多