Summary
Let’s summarize ranges in D.
We'll cover the following
Chapter summary
-
Ranges abstract data structures from algorithms and allow them to be used with algorithms seamlessly.
-
Ranges are a D concept and are the basis for many features of Phobos.
-
Many Phobos algorithms return lazy range objects to accomplish their special tasks.
-
UFCS works well with range algorithms.
-
When used as InputRange objects, the elements of strings are Unicode characters.
-
InputRange requires
empty
,front
, andpopFront()
. -
ForwardRange additionally requires
save
. -
BidirectionalRange additionally requires
back
andpopBack()
. -
Infinite RandomAccessRange requires
opIndex()
over ForwardRange. -
Finite RandomAccessRange requires
opIndex()
andlength
over BidirectionalRange. -
std.array.appender
returns an OutputRange that appends to slices. -
Slices are ranges of finite RandomAccessRange
-
Fixed-length arrays are not ranges.
-
The
std.range
module contains many useful range templates. -
Some of those templates allow templates to be more capable depending on the capabilities of original ranges.
Get hands-on with 1400+ tech skills courses.