<i id='Z8nhJ'><tr id='Z8nhJ'><dt id='Z8nhJ'><q id='Z8nhJ'><span id='Z8nhJ'><b id='Z8nhJ'><form id='Z8nhJ'><ins id='Z8nhJ'></ins><ul id='Z8nhJ'></ul><sub id='Z8nhJ'></sub></form><legend id='Z8nhJ'></legend><bdo id='Z8nhJ'><pre id='Z8nhJ'><center id='Z8nhJ'></center></pre></bdo></b><th id='Z8nhJ'></th></span></q></dt></tr></i><div id='Z8nhJ'><tfoot id='Z8nhJ'></tfoot><dl id='Z8nhJ'><fieldset id='Z8nhJ'></fieldset></dl></div>
    1. <legend id='Z8nhJ'><style id='Z8nhJ'><dir id='Z8nhJ'><q id='Z8nhJ'></q></dir></style></legend>

        <tfoot id='Z8nhJ'></tfoot>
        • <bdo id='Z8nhJ'></bdo><ul id='Z8nhJ'></ul>

        <small id='Z8nhJ'></small><noframes id='Z8nhJ'>

        来自元组的构造函数参数

        时间:2023-05-24

        <small id='i2fdP'></small><noframes id='i2fdP'>

          <bdo id='i2fdP'></bdo><ul id='i2fdP'></ul>
          <legend id='i2fdP'><style id='i2fdP'><dir id='i2fdP'><q id='i2fdP'></q></dir></style></legend>
            <tfoot id='i2fdP'></tfoot>

              <tbody id='i2fdP'></tbody>
            • <i id='i2fdP'><tr id='i2fdP'><dt id='i2fdP'><q id='i2fdP'><span id='i2fdP'><b id='i2fdP'><form id='i2fdP'><ins id='i2fdP'></ins><ul id='i2fdP'></ul><sub id='i2fdP'></sub></form><legend id='i2fdP'></legend><bdo id='i2fdP'><pre id='i2fdP'><center id='i2fdP'></center></pre></bdo></b><th id='i2fdP'></th></span></q></dt></tr></i><div id='i2fdP'><tfoot id='i2fdP'></tfoot><dl id='i2fdP'><fieldset id='i2fdP'></fieldset></dl></div>

                • 本文介绍了来自元组的构造函数参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  限时送ChatGPT账号..

                  假设我有一个模板,它由一个类类型和许多参数类型参数化.匹配这些类型的一组参数存储在一个元组中.如何将这些传递给类类型的构造函数?

                  Suppose I have a template which is parametrized by a class type and a number of argument types. a set of arguments matching these types are stored in a tuple. How can one pass these to a constructor of the class type?

                  几乎在 C++11 代码中:

                  In almost C++11 code:

                  template<typename T, typename... Args>
                  struct foo {
                    tuple<Args...> args;
                    T gen() { return T(get<0>(args), get<1>(args), ...); }
                  };
                  

                  如何在不固定长度的情况下填充构造函数调用中的...?

                  How can the ... in the constructor call be filled without fixing the length?

                  我想我可以想出一些复杂的递归模板调用机制来做到这一点,但我不敢相信我是第一个想要这个的人,所以我想会有现成的解决方案这在那里,甚至可能在标准库中.

                  I guess I could come up with some complicated mechanism of recursive template calls which does this, but I can't believe that I'm the first to want this, so I guess there will be ready-to-use solutions to this out there, perhaps even in the standard libraries.

                  推荐答案

                  C++17 有 std::make_from_tuple 为此:

                  C++17 has std::make_from_tuple for this:

                  template <typename T, typename... Args>
                  struct foo
                  {
                    std::tuple<Args...> args;
                    T gen() { return std::make_from_tuple<T>(args); }
                  };
                  

                  这篇关于来自元组的构造函数参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:C++ 模板函数默认值 下一篇:为什么具有“相同签名"的模板和非模板函数

                  相关文章

                  最新文章

                • <legend id='1knY5'><style id='1knY5'><dir id='1knY5'><q id='1knY5'></q></dir></style></legend>
                • <i id='1knY5'><tr id='1knY5'><dt id='1knY5'><q id='1knY5'><span id='1knY5'><b id='1knY5'><form id='1knY5'><ins id='1knY5'></ins><ul id='1knY5'></ul><sub id='1knY5'></sub></form><legend id='1knY5'></legend><bdo id='1knY5'><pre id='1knY5'><center id='1knY5'></center></pre></bdo></b><th id='1knY5'></th></span></q></dt></tr></i><div id='1knY5'><tfoot id='1knY5'></tfoot><dl id='1knY5'><fieldset id='1knY5'></fieldset></dl></div>
                  <tfoot id='1knY5'></tfoot>

                    <small id='1knY5'></small><noframes id='1knY5'>

                      • <bdo id='1knY5'></bdo><ul id='1knY5'></ul>