I don't get over-excited about programming languages and their evolution easily.
But it happened this time. C++ is introducing a new dialect. The 2020 standard.
There are a number of things that are useful but I wouldn't consider them groundbreaking (watch cppcon videos for people that get excited but do not sound like they are excited).
Then there is the new sorting functionality.
In C++, you can overload the sort algorithm.
This is very handy. Developers can create sorting algorithms that can teach their objects to sort themselves.
In the past you had to generate equal, not equal, greater than, smaller than, greater or equal, smaller or equal.
Many times, you implemented two of those, and derived the other ones based on that.
There's a new comparator now: "<=>".
This one covers all situations. If it fits your scenario (I think it does in many cases), you get all the comparators implemented in one class member.
That means that it 'll be easer to write objects that plug in to the sorting algorithms of C++.
We all dream to write code that says if (thisObject < thatObject). Or use standard algorithms that can sort or compare our home-written objects.
I think that the <=> operator helps with this, by reducing the work for the class designer.
For the record: this does not cause any run-time or code-size cost. It's resolved at compilation.
I take the critique of developers that do not like abstraction: things are happening under the hood.
But no cost for memory, code size or performance. And a gain in understanding what you want to achieve in the code.
I'll post examples later.
If you want to start playing with the new options: Try out C++20 Preview: set up a development environment
Top Comments