<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 按值捕获总是常量?

        C++0x lambda capture by value always const?(C++0x lambda 按值捕获总是常量?)
        <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 按值捕获总是常量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  Unable to access non-const member functions of objects in C++ std::set(无法访问 C++ std::set 中对象的非常量成员函数)
                  Constructing std::function argument from lambda(从 lambda 构造 std::function 参数)
                  STL BigInt class implementation(STL BigInt 类实现)
                  Sync is unreliable using std::atomic and std::condition_variable(使用 std::atomic 和 std::condition_variable 同步不可靠)
                  Move list element to the end in STL(在 STL 中将列表元素移动到末尾)
                  Why is overloading operatoramp;() prohibited for classes stored in STL containers?(为什么禁止对存储在 STL 容器中的类重载 operatoramp;()?)
                    <tbody id='8a8CP'></tbody>
                • <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>
                        • <tfoot id='8a8CP'></tfoot>