A std::map must satisfy the requirements of the associative container specified in clause 23.1.2 / 2:
Each associative container is parameterized by key and ordering. A relation that causes strict weak ordering (25.3) on the Key elements. In addition, the map and multimap map an arbitrary type T with a key. An object of type Compare is called a container comparison object. This comparison object may be a pointer to a function or object of a type with the corresponding function call operator.
But then in paragraph 23.3.1 / 2, the std::map template is specified as:
template <class Key, class T, class Compare = less<Key>, class Allocator = allocator<pair<const Key, T> > > class map;
which explicitly prohibits the use of the function pointer like Compare . Is this a contradiction or am I misunderstanding the standard?
EDIT: Yes, the problem I really ran into is why the code, for example, GMan:
struct foo { int x; }; bool compare_foo(const foo& x, const foo& y) { return xx < yx; } std::map<foo, bool, compare_foo> fooMap;
will not compile (yes, I stupidly mixed the type and value of the Compare parameter).
source share