<tfoot id='jOoiw'></tfoot>

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

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

        • <bdo id='jOoiw'></bdo><ul id='jOoiw'></ul>

        如何制作可变参数 is_same?

        时间:2023-05-24
          • <bdo id='ZzGak'></bdo><ul id='ZzGak'></ul>

              <legend id='ZzGak'><style id='ZzGak'><dir id='ZzGak'><q id='ZzGak'></q></dir></style></legend>
              <tfoot id='ZzGak'></tfoot>

            • <small id='ZzGak'></small><noframes id='ZzGak'>

                    <tbody id='ZzGak'></tbody>

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

                1. 本文介绍了如何制作可变参数 is_same?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  限时送ChatGPT账号..

                  我如何制作一个类模板来返回它的任何可变参数类型是否等于第一个类型.我希望能够做到这一点:

                  How can I make a class template that returns whether any of its variadic types are equal to the first type. I want to be able to do this:

                  is_same<T, A, B, C>::value; // true if T is one of A, B or C
                  

                  如果 T 等于这些类型中的任何一种,则其静态 value 成员将为 true,否则 false.我该怎么做?

                  And if T is equal to any one of those types, its static value member will be true, otherwise false. How can I do this?

                  推荐答案

                  使用模板递归:

                  template<typename T, typename... Rest>
                  struct is_any : std::false_type {};
                  
                  template<typename T, typename First>
                  struct is_any<T, First> : std::is_same<T, First> {};
                  
                  template<typename T, typename First, typename... Rest>
                  struct is_any<T, First, Rest...>
                      : std::integral_constant<bool, std::is_same<T, First>::value || is_any<T, Rest...>::value>
                  {};
                  
                  static_assert(is_any<int, char, double, int>::value, "error 1");   // OK
                  static_assert(is_any<int, char, double, short>::value, "error 2"); // error
                  

                  这篇关于如何制作可变参数 is_same?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                2. <small id='tMDGA'></small><noframes id='tMDGA'>

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

                    <tbody id='tMDGA'></tbody>

                    <tfoot id='tMDGA'></tfoot>
                    • <legend id='tMDGA'><style id='tMDGA'><dir id='tMDGA'><q id='tMDGA'></q></dir></style></legend>

                        • <bdo id='tMDGA'></bdo><ul id='tMDGA'></ul>