Ranges Without Actual Elements
Let’s discuss the power and flexibility of ranges.
We'll cover the following
Flexibility of not actually owning elements
The elements of the School
objects were actually stored in the students
member slices. So, School.front
returned a reference to an existing Student
object.
One of the powers of ranges is the flexibility of not actually owning elements. For example, front
does not need to return an actual element of an actual container. The returned element can be calculated each time when popFront()
is called, and it can be used as the value that is returned by front
.
You have already seen a range without actual elements. Since char
and wchar
cannot represent all Unicode characters, the Unicode characters that appear as range elements cannot be actual elements of any char
or wchar
array. In the case of strings, front
returns a dchar
that is constructed from the corresponding UTF code units of arrays:
Get hands-on with 1400+ tech skills courses.