【发布时间】:2014-09-11 14:38:40
【问题描述】:
尝试使用 C++11 lambda 作为 boost::multi_index 的密钥访问器:
#include <boost/multi_index_container.hpp>
#include <boost/multi_index/hashed_index.hpp>
#include <boost/multi_index/global_fun.hpp>
struct Foobar {
int key;
};
void func()
{
namespace mii = boost::multi_index;
typedef boost::multi_index_container< Foobar,
mii::hashed_unique< mii::global_fun< const Foobar &, int,
[]( const Foobar &f ) { return f.key; } > > > Container;
}
但是从 g++ 4.8.2 和 boost 1.53 得到编译错误:
error: could not convert template argument '<lambda closure object>func()::__lambda0{}' to 'int (*)(const Foobar&)'
这个答案Using Boost adaptors with C++11 lambdas 建议转换成std::function 在这种情况下不起作用。有没有简单的方法来解决这个问题?
【问题讨论】: