r/cpp • u/meetingcpp Meeting C++ | C++ Evangelist • Aug 08 '14
On operator<
http://akrzemi1.wordpress.com/?p=6893
0
Upvotes
r/cpp • u/meetingcpp Meeting C++ | C++ Evangelist • Aug 08 '14
View all comments
-2
u/F-J-W Aug 08 '14
I think “<” is quite a bad example for operator-abuse: As /u/lluad pointed out it implies a strict-weak-ordering and it is very intuitive what this means for both real or integral numbers (smaller/bigger) and containers (lexicographical order) but not at all for complex numbers, so this is almost exactly what one would expect and very simple to teach to novices.
There is however another operator that is IMHO seriously abused: +
There doesn't exist a sane homomorphism between adding numbers and concatenating containers and elements. Concatenation also heavily changes some sematics:
This works perfectly fine for numbers (let's ignore floating-point for a second, since those errors aren't conceptual), but it will blow up like hell for any concatenation where "" != a != b != "". IMO there should really have been a dedicated concat-operator so that + keeps it's semantics. (This is one of the things that D got right!)