• <legend id='2Fm7B'><style id='2Fm7B'><dir id='2Fm7B'><q id='2Fm7B'></q></dir></style></legend>
    • <bdo id='2Fm7B'></bdo><ul id='2Fm7B'></ul>

        <i id='2Fm7B'><tr id='2Fm7B'><dt id='2Fm7B'><q id='2Fm7B'><span id='2Fm7B'><b id='2Fm7B'><form id='2Fm7B'><ins id='2Fm7B'></ins><ul id='2Fm7B'></ul><sub id='2Fm7B'></sub></form><legend id='2Fm7B'></legend><bdo id='2Fm7B'><pre id='2Fm7B'><center id='2Fm7B'></center></pre></bdo></b><th id='2Fm7B'></th></span></q></dt></tr></i><div id='2Fm7B'><tfoot id='2Fm7B'></tfoot><dl id='2Fm7B'><fieldset id='2Fm7B'></fieldset></dl></div>
      1. <small id='2Fm7B'></small><noframes id='2Fm7B'>

        <tfoot id='2Fm7B'></tfoot>

      2. 泛型 lambda 的数量

        Arity of a generic lambda(泛型 lambda 的数量)
      3. <tfoot id='DRHDK'></tfoot>

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

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

                1. 本文介绍了泛型 lambda 的数量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  可以通过访问它的 operator() 来推断非泛型 lambda 的 arity.

                  It is possible to deduce arity of a non-generic lambda by accessing its operator().

                  template <typename F>
                  struct fInfo : fInfo<decltype(&F::operator())> { };
                  
                  template <typename F, typename Ret, typename... Args>
                  struct fInfo<Ret(F::*)(Args...)const> { static const int arity = sizeof...(Args); };
                  

                  这对于 [](int x){ return x;} 因为 operator() 不是模板化的.

                  This is nice and dandy for something like [](int x){ return x; } as the operator() is not templated.

                  但是,泛型 lambda 对 operator() 进行模板化,并且只能访问模板的具体实例 - 这有点问题,因为我无法手动为 operator() 提供模板参数code>operator() 因为我不知道它的 arity 是什么.

                  However, generic lambdas do template the operator() and it is only possible to access a concrete instantiation of the template - which is slightly problematic because I can't manually provide template arguments for the operator() as I don't know what its arity is.

                  所以,当然,像

                  auto lambda = [](auto x){ return x; };
                  auto arity = fInfo<decltype(lambda)>::arity;
                  

                  不起作用.

                  我不知道要转换为什么,也不知道要提供哪些模板参数(或提供多少)(operator()).
                  任何想法如何做到这一点?

                  I don't know what to cast to nor do I know what template arguments to provide (or how many) (operator()<??>).
                  Any ideas how to do this?

                  推荐答案

                  这是不可能的,因为函数调用运算符可以是可变参数模板.一般来说,对于函数对象永远不可能这样做,特殊情况下的 lambdas 因为它们碰巧不是同样强大,所以总是一个坏主意.现在是时候让这个坏主意回家了.

                  It's impossible, as the function call operator can be a variadic template. It's been impossible to do this forever for function objects in general, and special-casing lambdas because they happened to not be equally powerful was always going to be a bad idea. Now it's just time for that bad idea to come home to roost.

                  这篇关于泛型 lambda 的数量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  How to print vector#39;s data(如何打印矢量的数据)
                  Visual C++ appends 0xCC (int3) bytes at the end of functions(Visual C++ 在函数末尾附加 0xCC (int3) 字节)
                  How to use a variable inside a _T wrapper?(如何在 _T 包装器中使用变量?)
                  MSVC++ warning flags(MSVC++ 警告标志)
                  How to read file which contains uxxxx in vc++(如何在vc++中读取包含uxxxx的文件)
                  stack overflow error in C++ program(C++程序中的堆栈溢出错误)
                      <tbody id='KHnmu'></tbody>

                      <bdo id='KHnmu'></bdo><ul id='KHnmu'></ul>

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

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