是否有一个原因,我无法通过比较仿函数的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/是不是这到底是什么? –