...

/

RandomAccessRange: Finite

RandomAccessRange: Finite

Learn the use of the finite RandomAccessRange.

We'll cover the following...

The following are all of the requirements of a RandomAccessRange that is based on a finite BidirectionalRange:

  • empty,front and popFront() required by InputRange

  • save required by ForwardRange

  • back and popBack() required by BidirectionalRange

  • opIndex() required by RandomAccessRange

  • length which provides the length of the range

Example

As an example of a finite RandomAccessRange, let’s define a range that works similar to std.range.chain. The chain() function presents the elements of a number of separate ranges as if they are elements of a single larger range. Although chain() works with any type of element and any type of range, to keep the example short, let’s implement a range that works only with int slices.

Let’s name this range Together and ...