The Concepts SemiRegular and Regular

Apply theoretical knowledge to define advanced concepts: 'SemiRegular' and 'Regular'.

When you want to define a concrete type that works well in the C++ ecosystem, you should define a type that “behaves like an int”. Formally, your concrete type should be a regular type. In this section, I define the concepts SemiRegular and Regular.

SemiRegular and Regular are essential ideas in C++. Sorry, I should say concepts. For example, here is rule T.46 from the C++ Core Guidelines: T.46: Require template arguments to be at least Regular or SemiRegular. Now, only one important question is left to answer: What are Regular or SemiRegular types? Before I dive into the details, this is the informal answer:

  • A regular type “behaves like an int.” It can be copied and the result of the copy operation is independent of the original one and has the same value.

Okay, let me be more formal. A regular type is also a semiregular type, so let’s begin.

Get hands-on with 1200+ tech skills courses.