Concept Regular vs. Concept Semiregular

Viewed 90

Are there programming models that clearly differentiate the use of the regular concept and semiregular concept?

According to the elements of programming, the regular concept has a clear mathematical definition. I gather that the semiregular concept (from the draft) is a regular concept without the == comparator overload .

The ranges library uses semiregular concepts for its implementation. However, I fail to understand why the distinction between the two is necessary if one could be derived from the other.

1 Answers

To constrain a template against a concept is to, essentially, make the claim that the template will freely use any of the expressions that the concept requires. If you are writing a template that, by the nature of the algorithm being implemented, has no need to do equality tests, then there is no point in excluding a type from that template solely on the basis of the viability of an expression that you don't want to use.

Not every type logically has the concept of equality testing. That's fine. But there are many places where the tools of regularity except for equality testing are useful. Hence there is a concept for types that are regular in every way other than testing for equality.

And regular is "derived from" (subsumes in C++-speak) semiregular. regular is explicitly defined as semiregular and equality_comparable.

Related