A concept is a compile-time predicate that's used in conjunction with templates. The C++20 standard definitely boosted generic programming by providing more compile-time opportunity for the developer to communicate its intention. We can visualize concepts such as requirements (or constraints)Â the user of the template must adhere to. Why do we need concepts? Do you have do define concepts by yourself? This recipe will answer these and many more questions.Â
Understanding concepts
How to do it...
In this section, we will develop a concrete template example using concepts:
- We want to create our own version of the std::sort template function from the C++ standard library. Let's start by writing the...