Use of Slices as Ranges
You will learn about the use of slices as ranges using the std.array module in this lesson.
We'll cover the following
The std.array
module to use slices as ranges
Merely importing the std.array
module makes the most common container type conform to the most capable range type; slices can seamlessly be used as RandomAccessRange objects.
The std.array
module provides the functions empty
, front
, popFront()
and other range functions for slices. As a result, slices are ready to be used with any range function, for example with print()
:
import std.array;
// ...
print([ 1, 2, 3, 4 ]);
It is not necessary to import std.array
if the std.range
module has already been imported.
Since it is not possible to remove elements from fixed-length arrays, popFront()
, cannot be defined for them. For that reason, fixed-length arrays cannot be used as ranges themselves:
Get hands-on with 1400+ tech skills courses.