This code appears to me to be conforming to the C++ standard, but it's rejected by G++/libstdc++: #include <set> struct compare { bool operator()(int a, int b); }; void func() { const std::set<int, compare> s; s.find(0); } because compare::operator() is not const qualified. N3690 [associative.reqmts]p2 says "The object of type Compare is called the comparison object of the container", and p3 talks about the requirements on behavior of a comparison object comp. However, none of the requirements seem to impose requirements on objects of type const Compare.
If that code is conforming then it's a defect in the standard.
Both Clang/libc++ and MSVC/Dinkumware reject it for the same reason.
(In reply to Jonathan Wakely from comment #1) > If that code is conforming then it's a defect in the standard. I agree. I believe the wording for associative containers is not as clear as it should be. For unordered containers 23.2.5 p11 speaks of "possibly const value" for hasher and binary predicate, but in 23.2.4 p8 this additional "possibly const" requirement is missing. I'm submitting an LWG issue for this and provide the issue number once available.
(In reply to Jonathan Wakely from comment #2) > Both Clang/libc++ and MSVC/Dinkumware reject it for the same reason. I notice that the Dinkumware version associated with Visual Studio 2015 accepts the code.
(In reply to Daniel Krügler from comment #3) > [..] I believe the wording for associative containers is not as clear as > it should be. For unordered containers 23.2.5 p11 speaks of "possibly const > value" for hasher and binary predicate, but in 23.2.4 p8 this additional > "possibly const" requirement is missing. I'm submitting an LWG issue for > this and provide the issue number once available. Please refer to LWG issue http://cplusplus.github.io/LWG/lwg-active.html#2542
(In reply to Daniel Krügler from comment #4) > (In reply to Jonathan Wakely from comment #2) > > Both Clang/libc++ and MSVC/Dinkumware reject it for the same reason. > > I notice that the Dinkumware version associated with Visual Studio 2015 > accepts the code. ... assuming a proper definition of the operator() overload is provided, of-course.
The standard was clarified to confirm that what we do is correct.