我正在创建一堆函数,它们都有效地做同样的事情:
long Foo::check(long retValue, unsigned toCheck, const std::set<unsigned>& s)
{
auto it = s.find(toCheck);
return (it == s.end()) ? -retValue : retValue;
}
其中 Foo 是一个类。到目前为止,一切都相当简单。现在,我实际上想在此创建很多变体,但绑定到不同的集合。然后我想将这些存储在 std::map 中。因此,使用 boost::bind 和 boost::function,执行以下操作:
void Foo::addToMap(unsigned option, const std::set<unsigned>& currentSet)
{
someMap[option] = boost::bind(&Foo::check, this, _1, _2, currentSet);
}
我遇到的问题是试图定义地图的类型。我以为会是:
std::map<unsigned, boost::function<long (long, unsigned)> > someMap;
但是用 MSVC 9.0 编译它会给出:error C2582: 'operator =' function is unavailable in 'boost::function<Signature>'
.
map 的第二个模板参数到底应该是什么?