std.range and std.algorithm Modules

You will learn about the std.range and std.algorithm modules in this lesson.

We'll cover the following

A great benefit of defining our types as ranges is being able to use them not only with our own functions, but with Phobos and other libraries as well.

std.range includes a large number of range functions, structs, and classes.

std.algorithm includes many algorithms that are commonly found also in the standard libraries of other languages.

Example

To see an example of how our types can be used with standard modules, let’s use School with the std.algorithm.swapFront algorithm. swapFront() swaps the front elements of two InputRange ranges.

This requires the front elements of the two ranges to be swappable. Arrays satisfy that condition.

Get hands-on with 1200+ tech skills courses.