我創建了一堆的功能,這都有效地做同樣的事情:存儲的boost ::綁定功能於一身的std ::地圖
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 ::綁定和boost ::功能,這樣做:
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>'
。
究竟應該映射的第二個模板參數是什麼?
你試圖包裹設置參數(綁定)中的boost :: ref或無論它叫什麼?引用是不可分配的。 – 2012-03-29 01:20:15
@ Cheersandhth.-Alf試圖用boost :: cref(currentSet)包裝它,但是它給出了完全相同的錯誤。如果我通過非const,相同,如果我通過非const值... – Yuushi 2012-03-29 01:36:45
哦,當。那麼請嘗試在最小程序中重現該問題,併發布(完整代碼)。 – 2012-03-29 01:38:14