4 ms·
One problem in C++ is if you define a struct then you have to define a bunch of operators yourself (operator<, etc.) which gets annoying after you've realized y
by throwaway613834 9y ago
One problem in C++ is if you define a struct then you have to define a bunch of operators yourself (operator<, etc.) which gets annoying after you've realized you've needed them a bunch of times.
- marcosdumay 9y agoDoes C++ Pair<> define operator< and operator>? That's surprising, and for me looks completely uncalled for. EDIT: Just looked into Haskell (because it's easier), and tuples do derive Ord there. Is there some universal convention I'm missing?
- throwaway613834 9y ago> Is there some universal convention I'm missing? Tuples are always compared lexicographically, is the universal convention. Not sure if that's what you might be missing?
- khedoros1 9y ago> Does C++ Pair<> define operator< and operator>? It does. std::sort(pairarray.begin(),pairarray.end()) works about how you'd expect, as long as operator< is defined for the constituent types of the pair.