C++ 20 Concepts

Time to use them.

C++ 20 Concepts part 1 and part 2

by Gajendra Gulgulia

From the article:

Concepts is one of the 4 major additions in C++20 standard. The idea of concepts has existed as long as C++ templates themselves but it has only been until few years that the foundation of C++ concepts have been laid out in the manner it had earlier been desired desired, i.e., in coherence with C++ templates design principles:

  • a generalized code
  • better code than hand written code with zero overhead
  • well specified interfaces on the template method/class usage.

C++ templates fell short on the last requirements but the first two requirements were good enough and templates few off with a huge success. In simpler terms the last requirement on concepts is about imposing constraints on the template parameters themselves, that a function or a class can accept.
In this article, I’ll give an introductory example of how concepts could be useful in terms of specifying the interface of a generic code, which amongh many advantages helps get rid of the verbose error message and achieve faster compilation, and consequently help make generic programming more expressive and fun. In the later long running series about concepts with gradually increasing complexity, I’ll present details as and when necessary. Lastly before beginning, I encourage all users to try out the code examples with a compiler that supports C++20 . So lets start with concepts of concepts wink

Add a Comment

Comments are closed.

Comments (0)

There are currently no comments on this entry.