Range Kind Templates
Explore how range kind templates in D are used to formalize template constraints and detect range capabilities. This lesson helps you understand InputRange, ForwardRange, and other range types, using practical examples like negative range transformations and static if for conditional features.
We'll cover the following...
We'll cover the following...
We used mostly int ranges in the previous chapter. In practice, containers, algorithms, and ranges are almost always implemented as templates. The print() example was a template as well:
void print(T)(T range) {
// ...
}
What lacks from the implementation of print() is that even though it requires T to be a kind of InputRange, it does not formalize that requirement with a temp ...