std.range.EvenChunks/evenChunks
- multiple declarations
Function evenChunks
This range splits a source
range into chunkCount
chunks of
approximately equal length. Source
must be a forward range with
known length.
EvenChunks!Source evenChunks(Source)
(
Source source,
size_t chunkCount
)
if (isForwardRange!Source && hasLength!Source);
Unlike chunks
, evenChunks
takes a chunk count (not size).
The returned range will contain zero or more source
elements followed by source
elements. If source
, some chunks will be empty.
chunkCount
must not be zero, unless source
is also empty.
Example
import std .algorithm .comparison : equal;
auto source = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
auto chunks = evenChunks(source, 3);
writeln(chunks[0]); // [1, 2, 3, 4]
writeln(chunks[1]); // [5, 6, 7]
writeln(chunks[2]); // [8, 9, 10]
Struct EvenChunks
This range splits a source
range into chunkCount
chunks of
approximately equal length. Source
must be a forward range with
known length.
struct EvenChunks(Source)
if (isForwardRange!Source && hasLength!Source);
Unlike chunks
, evenChunks
takes a chunk count (not size).
The returned range will contain zero or more source
elements followed by source
elements. If source
, some chunks will be empty.
chunkCount
must not be zero, unless source
is also empty.
Constructors
Name | Description |
---|---|
this
|
Standard constructor |
Properties
Name | Type | Description |
---|---|---|
back [get]
|
auto | Indexing, slicing and bidirectional operations and range primitives.
Provided only if hasSlicing!Source is true .
|
empty [get]
|
bool | Forward range primitives. Always present. |
front [get]
|
auto | Forward range primitives. Always present. |
length [get]
|
size_t | Length |
save [get]
|
typeof(this) | Forward range primitives. Always present. |
Methods
Name | Description |
---|---|
opIndex
|
Indexing, slicing and bidirectional operations and range primitives.
Provided only if hasSlicing!Source is true .
|
opSlice
|
Indexing, slicing and bidirectional operations and range primitives.
Provided only if hasSlicing!Source is true .
|
popBack
|
Indexing, slicing and bidirectional operations and range primitives.
Provided only if hasSlicing!Source is true .
|
popFront
|
Forward range primitives. Always present. |
Example
import std .algorithm .comparison : equal;
auto source = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
auto chunks = evenChunks(source, 3);
writeln(chunks[0]); // [1, 2, 3, 4]
writeln(chunks[1]); // [5, 6, 7]
writeln(chunks[2]); // [8, 9, 10]
Authors
Andrei Alexandrescu, David Simcha, Jonathan M Davis, and Jack Stouffer. Credit for some of the ideas in building this module goes to Leonardo Maffi.