The Concepts SemiRegular and Regular
Apply theoretical knowledge to define advanced concepts: 'SemiRegular' and 'Regular'.
We'll cover the following...
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.
...🔑
Regular
typesAlexander Stepanov, the designer of the Standard Template Library, defined the terms
regular
type andsemiregular
type. A type, according to him, isregular
if it supports these functions:
- Copy construction