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

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

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

        C++0x lambda 按值捕获总是常量?

        时间:2023-06-30
        <tfoot id='DTyXO'></tfoot>
        • <legend id='DTyXO'><style id='DTyXO'><dir id='DTyXO'><q id='DTyXO'></q></dir></style></legend>
          <i id='DTyXO'><tr id='DTyXO'><dt id='DTyXO'><q id='DTyXO'><span id='DTyXO'><b id='DTyXO'><form id='DTyXO'><ins id='DTyXO'></ins><ul id='DTyXO'></ul><sub id='DTyXO'></sub></form><legend id='DTyXO'></legend><bdo id='DTyXO'><pre id='DTyXO'><center id='DTyXO'></center></pre></bdo></b><th id='DTyXO'></th></span></q></dt></tr></i><div id='DTyXO'><tfoot id='DTyXO'></tfoot><dl id='DTyXO'><fieldset id='DTyXO'></fieldset></dl></div>

                <tbody id='DTyXO'></tbody>
                <bdo id='DTyXO'></bdo><ul id='DTyXO'></ul>

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

                  本文介绍了C++0x lambda 按值捕获总是常量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  有没有办法按值捕获,并使捕获的值非常量?我有一个库仿函数,我想捕获 &调用一个非常量但应该是的方法.

                  Is there any way to capture by value, and make the captured value non-const? I have a library functor that I would like to capture & call a method that is non-const but should be.

                  以下内容不能编译,但使 foo::operator() const 修复它.

                  The following doesn't compile but making foo::operator() const fixes it.

                  struct foo
                  {
                    bool operator () ( const bool & a )
                    {
                      return a;
                    }
                  };
                  
                  
                  int _tmain(int argc, _TCHAR* argv[])
                  {
                    foo afoo;
                  
                    auto bar = [=] () -> bool
                      {
                        afoo(true);
                      };
                  
                    return 0;
                  }
                  

                  推荐答案

                  使用可变的.

                  
                  auto bar = [=] () mutable -> bool ....
                  

                  如果没有 mutable,您将声明 lambda 对象的运算符 () const.

                  Without mutable you are declaring the operator () of the lambda object const.

                  这篇关于C++0x lambda 按值捕获总是常量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:绑定与 Lambda? 下一篇:lambda 函数/表达式是否支持 constexpr?

                  相关文章

                • <legend id='8a8CP'><style id='8a8CP'><dir id='8a8CP'><q id='8a8CP'></q></dir></style></legend>
                    <bdo id='8a8CP'></bdo><ul id='8a8CP'></ul>

                      <small id='8a8CP'></small><noframes id='8a8CP'>

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