element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet & Tria Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • About Us
    About the element14 Community
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Japan
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      •  Vietnam
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Code Exchange
  • Technologies
  • More
Code Exchange
Blog Sorting in the C++20 release
  • Blog
  • Forum
  • Documents
  • Events
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Code Exchange to participate - click to join for free!
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: Jan Cumps
  • Date Created: 13 Oct 2020 8:14 PM Date Created
  • Views 4478 views
  • Likes 6 likes
  • Comments 20 comments
  • cpp
  • c++
  • c++20
Related
Recommended

Sorting in the C++20 release

Jan Cumps
Jan Cumps
13 Oct 2020

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

  • Sign in to reply

Top Comments

  • shabaz
    shabaz over 5 years ago in reply to neuromodulator +3
    I too agree on the productivity despite the ugliness of some Python features : ) And the perpetual messy changing ways for concurrent programming with Python. I've only used C++ in a large real-time app…
  • Jan Cumps
    Jan Cumps over 5 years ago in reply to Andrew J +3
    Andrew J wrote: You're right, a specific toolchain isn't applicable to the source code, I digressed into the wider C/C++ ecosystem which wasn't the point of your original post. I do need to get a much…
  • neuromodulator
    neuromodulator over 5 years ago +2
    C++ has turned into such a complex language and gets more complex at every release. Today not even Stroustrup knows every feature of the language. The other aspect that I don't like much about C++, is…
  • shabaz
    shabaz over 5 years ago in reply to neuromodulator

    I too agree on the productivity despite the ugliness of some Python features : ) And the perpetual messy changing ways for concurrent programming with Python.

    I've only used C++ in a large real-time app where many hardware limits were being hit, until computers progressed! For many other tasks though, there are far more productive languages like Python as you say.

    Currently I want to learn C# and TypeScript, I think they will benefit me the most for now, but that changes often.

    For embedded real-time use, I think C++ with STL is exciting, because embedded processors have enough resources for it now it seems. And there is middleware out there intended for real-time systems which relies on STL. I'm trying it anyway, as a first attempt for me, to see how it turns out.

    • Cancel
    • Vote Up +3 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • Jan Cumps
    Jan Cumps over 5 years ago in reply to neuromodulator

    Yes. I do think though that this release simplified the additions of the past more than adding complexity.

    There are new features that add new things to learn. But the majority reflects on the language, and streamline the proposed use.

     

    If the language is static, there is no discussion. Then it dies.

    In this language, there is a lively community that will challenge any existing or proposed feature.

    It resulted in discarding/embracing proposals, reverting/defending to previously made promises, improvements and instability. Without drama.

    Like my marriage (did not last as long as C++, but ended without drama).

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • neuromodulator
    neuromodulator over 5 years ago in reply to Jan Cumps

    I guess it depends on how you define simpler. Sure you can stick to a very small subset of features. But the language specification is increasing not decreasing in size. So unless all the code you work with is yours, you will have to work with code that could use any feature of the language.

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • Jan Cumps
    Jan Cumps over 5 years ago in reply to neuromodulator

    C++ is getting simpler mostly, not more complex.

    Let's hang on to Python for the same lifespan (I think they can and will be able to do that, because it's a good language). They are going through similar motions.

    • Cancel
    • Vote Up +2 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • neuromodulator
    neuromodulator over 5 years ago

    C++ has turned into such a complex language and gets more complex at every release. Today not even Stroustrup knows every feature of the language.

    The other aspect that I don't like much about C++, is that the STL is very limited, and installing external libs can get quite complex. There is no reason for Python to require less coding time than C++, except because Python's libraries are more readily available and easier to install and use.

     

    These days I mostly use Python, but I still find it a pretty "ugly" language, I don't like their duck typing, the spacing being part of its syntax, and its OOP with lack of encapsulation (justified by their: "we are all adults"). The only reason I use Python is because of how easy it is to prototype an idea.

    • Cancel
    • Vote Up +2 Vote Down
    • Sign in to reply
    • More
    • Cancel
<
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2026 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube