使用Boost适配器与C ++ 11 lambda表达式 [英] Using Boost adaptors with C++11 lambdas

查看:232
本文介绍了使用Boost适配器与C ++ 11 lambda表达式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图编译这个code:

I tried to compile this code:

#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

我GOOGLE了这个问题,并发现<一个href=\"http://boost.2283326.n4.nabble.com/Compilation-errors-when-trying-to-use-range-adaptors-with-C-11-lambdas-td4631527.html\">this在升压用户邮件列表归档。它建议使用的#define BOOST_RESULT_OF_USE_DECLTYPE 将解决这个问题。我把它放到我的code的开始,但它仍然不能编译。该错误消息的长度似乎是要短得多,但在结束时的错误消息是相同的。我目前使用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?

推荐答案

<一个href=\"http://smellegant$c$c.word$p$pss.com/2011/10/31/linq-to-c-or-something-much-better/\">http://smellegant$c$c.word$p$pss.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;
}

<一个href=\"http://liveworkspace.org/$c$c/b78b3f7d05049515ac207e0c12054c70\">http://liveworkspace.org/$c$c/b78b3f7d05049515ac207e0c12054c70

的#define BOOST_RESULT_OF_USE_DECLTYPE 工作正常VS2012为例。

#define BOOST_RESULT_OF_USE_DECLTYPE works fine in VS2012 for example.

这篇关于使用Boost适配器与C ++ 11 lambda表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆