我正在创建一组函数,这些函数的实际作用都相同:
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的第二个模板参数中应该填什么?