【问题标题】:C++ expand parameter pack to tuple of arraysC++ 将参数包扩展为数组元组
【发布时间】:2023-03-09 21:08:01
【问题描述】:

我想实例化一个类喜欢

template<typename ...Args>
class X {
private:
    std::tuple<std::array<Arg0, 255>, std::array<Arg1, 255>, ...> m_tuples; // For Arg in Args
}

我知道这不是正确的C++,但是如何实现将类的参数包模板扩展为元组中保存的数组的效果?

【问题讨论】:

    标签: c++ variadic-templates


    【解决方案1】:
    template<typename ...Args>
    class X {
    private:
        std::tuple<std::array<Args, 255>...> m_tuples; // For Arg in Args
    };
    

    ...你没想到会如此接近,是吗:)

    【讨论】:

    • 我没有!你能解释一下这个扩展是如何工作的吗?我一直在思考这个问题,因为我会递归函数调用,弹出参数包的第一个元素。
    • @shane 规则对我来说有点模糊,但简而言之,包扩展通过复制(句法)模式并替换此模式中的参数包来工作。这里的模式是整个 std::array&lt;Args, 255&gt;,通过替换 Args 可以扩展为您所追求的。
    猜你喜欢
    • 2010-12-31
    • 2021-07-04
    • 2012-11-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多