View source code
Display the source code in std/container/array.d from which this
page was generated on github.
Report a bug
If you spot a problem with this page, click here to create a
Bugzilla issue.
Improve this page
Quickly fork, edit online, and submit a pull request for this page.
Requires a signed-in GitHub account. This works well for small changes.
If you'd like to make larger changes you may want to consider using
local clone.
Module std.container.array
This module provides an Array
type with deterministic memory usage not
reliant on the GC, as an alternative to the built-in arrays.
This module is a submodule of std
.
Example
auto arr = Array!int(0, 2, 3);
writeln(arr[0]); // 0
writeln(arr .front); // 0
writeln(arr .back); // 3
// reserve space
arr .reserve(1000);
writeln(arr .length); // 3
assert(arr .capacity >= 1000);
// insertion
arr .insertBefore(arr[1..$], 1);
writeln(arr .front); // 0
writeln(arr .length); // 4
arr .insertBack(4);
writeln(arr .back); // 4
writeln(arr .length); // 5
// set elements
arr[1] *= 42;
writeln(arr[1]); // 42
Example
import std .algorithm .comparison : equal;
auto arr = Array!int(1, 2, 3);
// concat
auto b = Array!int(11, 12, 13);
arr ~= b;
writeln(arr .length); // 6
// slicing
assert(arr[1 .. 3] .equal([2, 3]));
// remove
arr .linearRemove(arr[1 .. 3]);
assert(arr[0 .. 2] .equal([1, 11]));
Example
Array!bool
packs together values efficiently by allocating one bit per element
Array!bool arr;
arr .insert([true, true, false, true, false]);
writeln(arr .length); // 5
Structs
Name | Description |
---|---|
Array
|
Array type with deterministic control of memory. The memory allocated
for the array is reclaimed as soon as possible; there is no reliance
on the garbage collector. Array uses malloc , realloc and free
for managing its own memory.
|
Array
|
Array specialized for bool . Packs together values efficiently by
allocating one bit per element.
|
Authors
License
Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at ).
Copyright © 1999-2022 by the D Language Foundation | Page generated by ddox.