View source code
Display the source code in std/experimental/allocator/package.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.

Function std.experimental.allocator.expandArray

Grows array by appending delta more elements. The needed memory is allocated using alloc. The extra elements added are either default- initialized, filled with copies of init, or initialized with values fetched from range.

bool expandArray(T, Allocator) (
  auto ref Allocator alloc,
  ref T[] array,
  size_t delta

bool expandArray(T, Allocator) (
  auto ref Allocator alloc,
  ref T[] array,
  size_t delta,
  auto ref T init

bool expandArray(T, Allocator, R) (
  auto ref Allocator alloc,
  ref T[] array,
  R range
if (isInputRange!R);


T element type of the array being created
alloc the allocator used for getting memory
array a reference to the array being grown
delta number of elements to add (upon success the new length of array is array.length + delta)
init element used for filling the array
range range used for initializing the array elements


true upon success, false if memory could not be allocated. In the latter case array is left unaffected.


The first two overloads throw only if alloc's primitives do. The overloads that involve copy initialization deallocate memory and propagate the exception if the copy operation throws.


auto arr = theAllocator.makeArray!int([1, 2, 3]);
assert(theAllocator.expandArray(arr, 2));
writeln(arr); // [1, 2, 3, 0, 0]
import std.range : only;
assert(theAllocator.expandArray(arr, only(4, 5)));
writeln(arr); // [1, 2, 3, 0, 0, 4, 5]


Andrei Alexandrescu


Boost License 1.0.