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

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

      1. <legend id='jVexp'><style id='jVexp'><dir id='jVexp'><q id='jVexp'></q></dir></style></legend>
      2. <tfoot id='jVexp'></tfoot>
        • <bdo id='jVexp'></bdo><ul id='jVexp'></ul>

        在 C++11 lambdas 中使用 Boost 适配器

        Using Boost adaptors with C++11 lambdas(在 C++11 lambdas 中使用 Boost 适配器)
              <bdo id='hD9JO'></bdo><ul id='hD9JO'></ul>

              1. <small id='hD9JO'></small><noframes id='hD9JO'>

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

                  <i id='hD9JO'><tr id='hD9JO'><dt id='hD9JO'><q id='hD9JO'><span id='hD9JO'><b id='hD9JO'><form id='hD9JO'><ins id='hD9JO'></ins><ul id='hD9JO'></ul><sub id='hD9JO'></sub></form><legend id='hD9JO'></legend><bdo id='hD9JO'><pre id='hD9JO'><center id='hD9JO'></center></pre></bdo></b><th id='hD9JO'></th></span></q></dt></tr></i><div id='hD9JO'><tfoot id='hD9JO'></tfoot><dl id='hD9JO'><fieldset id='hD9JO'></fieldset></dl></div>
                    <tbody id='hD9JO'></tbody>
                  本文介绍了在 C++11 lambdas 中使用 Boost 适配器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我试图编译这段代码:

                  #include <boost/range/adaptors.hpp>
                  #include <boost/range/algorithm.hpp>
                  #include <vector>
                  
                  int main() {
                      std::vector<int> v{
                          1,5,4,2,8,5,3,7,9
                      };
                      std::cout << *boost::min_element(v | boost::adaptors::transformed(
                              [](int i) { return -i; })) << std::endl;
                      return 0;
                  }
                  

                  编译失败并显示以下错误消息(经过很长的模板实例化小说):

                  The compilation failed with the following error message (after a long template instantiation novel):

                  /usr/local/include/boost/iterator/transform_iterator.hpp:84:26: error: use of deleted function ‘main()::<lambda(int)>::<lambda>()’
                  ../main.cpp:12:5: error: a lambda closure type has a deleted default constructor
                  

                  我用谷歌搜索了这个问题,发现 this 在 Boost Users 邮件列表存档中.它建议使用 #define BOOST_RESULT_OF_USE_DECLTYPE 可以解决问题.我把它放在代码的最开始,但它仍然无法编译.错误信息的长度似乎要短得多,但最后的错误信息是一样的.我目前使用的是 Boost 1.50.

                  I googled the problem, and found this in the Boost Users mailing list archive. It suggested that using #define BOOST_RESULT_OF_USE_DECLTYPE would solve the problem. I put it into the very beginning of my code, but it still doesn't compile. The length of the error message seems to be much shorter, but the error message at the end is the same. I'm currently using Boost 1.50.

                  这里有什么问题?有什么办法可以让这个工作吗?

                  What can be the problem here? Is there any way to make this work?

                  推荐答案

                  http://smellegantcode.wordpress.com/2011/10/31/linq-to-c-or-something-much-better/

                  但是你可以使用这个,效果很好.

                  But you can use this, that works well.

                  #include <boost/range/adaptors.hpp>
                  #include <boost/range/algorithm.hpp>
                  #include <vector>
                  #include <functional>
                  
                  int main() {
                      std::vector<int> v{
                          1,5,4,2,8,5,3,7,9
                      };
                      std::function<int(int)> func = [](int i) { return -i; };
                      std::cout << *boost::min_element(v | boost::adaptors::transformed(
                      func)) << std::endl;
                      return 0;
                  }
                  

                  http://liveworkspace.org/code/b78b3f7d05049515ac207e0c12054c70

                  #define BOOST_RESULT_OF_USE_DECLTYPE 例如在 VS2012 中工作正常.

                  #define BOOST_RESULT_OF_USE_DECLTYPE works fine in VS2012 for example.

                  这篇关于在 C++11 lambdas 中使用 Boost 适配器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  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++程序中的堆栈溢出错误)

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

                    • <bdo id='t5C8A'></bdo><ul id='t5C8A'></ul>
                        <tbody id='t5C8A'></tbody>
                    • <tfoot id='t5C8A'></tfoot>

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

                          <legend id='t5C8A'><style id='t5C8A'><dir id='t5C8A'><q id='t5C8A'></q></dir></style></legend>