El 17/07/2013 16:58, Thorsten Ottosen escribió:
Reading up on the standard, it seems that all standard containers are implemented this way.
Consequence: when having e.g. set
, the comparison is not portable, since only std::less is guaranteed to be. So isn't this a defect? The other issue is perhaps more sensitive. What should users expect from
typedef setstd::string,CaseInsensitiveLess Set; Set s1{ "foo", "BAR" }; Set s2{ "FOO", "bar" }; assert( s1 < s2 ); // true? assert( s1 == s2 ); // true?
I was at least surprised by this behavior.
It's a bit surprising but that's also how vector::operator< is implemented (vector has no Compare function object so std::less<T> is used). The operator is just there to have a default order to be inserted in parent associative containers. The standard is quite clear: (taken from N3680) Table 98 — Optional container operations -> Expression: a < b -> Return type: convertible to bool -> Operational semantics lexicographical_compare (a.begin(), a.end(), b.begin(), b.end()) -> Assertion/note: pre: < is defined for values of T. < is a total ordering relationship. -> Complexity: linear I guess using Compare for associative containers' operator < could perfectly work it won't be the standard behaviour. Best, Ion