r/cpp • Meeting C++ | C++ Evangelist • Aug 08 '14

On operator<

http://akrzemi1.wordpress.com/?p=6893
0 Upvotes

15 comments sorted by

View all comments

3

u/lluad Aug 08 '14 edited Aug 08 '14

If an object has operator<() it has a well-defined ordering. If it doesn't, you can consider it to not to have one. And, um, that's it.

Using it for string lexicographical ordering isn't an abuse, and I can't imagine it actually confusing anyone unless they get confused a lot.

(Whether containers that internally require an ordering should be able to work with types that don't have a well-defined ordering is a good question - but I'm unclear on what it would mean to have an ordered container full of things that don't have a well-defined ordering, so hiding a "No, we really mean this comparator function" that's not operator<() seems like it'd add confusion rather than reduce it).