c++

Function and variable concepts

In general, there are two kinds of distinct concepts. Those are function concepts and variable concepts. They are similar to their non-concept siblings template functions and template variables. If you haven’t heard about template variables, you’re not alone. Those are new in C++14, and allows you to define a variable as a template. However, variable concepts are modeled around template variables, so they will be covered.

Getting started with arithmetic concepts

Not long ago, I implemented a Matrix class with template expressions. Sadly, I cannot release it to the public because it belongs to my employer. Such libraries dealing with arithmetic will benefit greatly from concepts. The compile errors from not implemented operators are horrendous.

Your own concepts

The easiest concept is probably the boolean concepts true and false.

C++ Concepts: New keywords

The concepts extension introduces 5 new keywords. Only concept and requires are implemented, though the GCC documentation states there are 5 new keywords, only 2 are real keywords at the moment.

Hello concepts

Some of the motivation behind concepts, is to be able to restrict template interfaces in an easy-to-use way. It is possible today using template meta programming and static_assert with C++03/C++11/C++14/C++17. However, the error messages are insanely detailed and it’s almost not possible to decipher them without a black belt in template programming. With any modern compiler, it’s usually 50-100 lines of errors for simple template mistakes.

C++ Concepts

Concepts will be a new feature in C++. At the time of writing, concepts did not make it into the upcoming C++17 standard. There is a slight chance concepts will be available in C++20. To begin with, concepts where supposed to be in the C++11 standard. But it did miss that train a long while ago.

C++ std::sort predicate with templates

There are a couple of sorting algorithms in C++ from std::sort to lamdbas, each tailored to different use cases. As a programmer, you may or may not want to delve into the depths of sort algorithms. That’s a domain left for experts. Luckily, it’s quite easy to get started with sorting data.