是否有一個原因,我無法通過比較仿函數的map
構造函數參數:地圖比較構造函數的參數
map<int, string, greater<int>> foo;
//map<int, string> foo(greater<int>()); Doesn't work
或者爲什麼我不能沒有提供我自己的比較式傳遞一個拉姆達:
map<int, string, function<bool(const int&, const int&)>> bar([](const int& lhs, const int& rhs){ return lhs > rhs; });
//map<int, string> bar([](const int& lhs, const int& rhs){ return lhs > rhs; }); Doesn't work
我想只能聲明map<int, string>
並用比較器構造它。爲什麼我不能?
因爲這會涉及一些類型擦除,這不是最佳的? –
可能的重複:[爲什麼不從構造函數推斷模板參數?](http://stackoverflow.com/questions/984394/why-not-infer-template-parameter-from-constructor) – NathanOliver
@PiotrSkotnicki你在說,對於函子的版本?但是'map'沒有提供比較構造函數? http://www.cplusplus.com/reference/map/map/map/是不是這到底是什麼? –