Array.this - multiple declarations

Function Array.this

Creates a new Array with the elements from a static array.

this(size_t R) (
  T[R] init,
  shared Allocator allocator = defaultAllocator
);

Parameters

NameDescription
R Static array size.
init Values to initialize the array with.
allocator Allocator.

Function Array.this

Creates a new Array with the elements from an input range.

this(R) (
  scope R init,
  shared Allocator allocator = defaultAllocator
)
if (!isInfinite!R && isInputRange!R && isImplicitlyConvertible!(ElementType!R, T));

Parameters

NameDescription
R Type of the initial range.
init Values to initialize the array with.
allocator Allocator.

Function Array.this

Initializes this array from another one.

this(R) (
  ref R init,
  shared Allocator allocator = defaultAllocator
)
if (is(Unqual!R == Array));

this(R) (
  R init,
  shared Allocator allocator = defaultAllocator
) @trusted
if (is(R == Array));

If init is passed by value, it won't be copied, but moved. If the allocator of ($D_PARAM init) matches allocator, this will just take the ownership over init's storage, otherwise, the storage will be allocated with allocator and all elements will be moved; init will be destroyed at the end.

If init is passed by reference, it will be copied.

Parameters

NameDescription
R Source array type.
init Source array.
allocator Allocator.

Example

auto v1 = Array!int([1, 2, 3]);
auto v2 = Array!int(v1);
assert(v1 == v2);

auto v3 = Array!int(Array!int([1, 2, 3]));
assert(v1 == v3);
assert(v3.length == 3);
assert(v3.capacity == 3);

Function Array.this

Creates a new Array.

this (
  size_t len,
  auto ref T init,
  shared Allocator allocator = defaultAllocator
);

this (
  size_t len,
  shared Allocator allocator = defaultAllocator
);

this (
  shared Allocator allocator
);

Parameters

NameDescription
len Initial length of the array.
init Initial value to fill the array with.
allocator Allocator.

Example

auto v = Array!int([3, 8, 2]);

assert(v.capacity == 3);
assert(v.length == 3);
assert(v[0] == 3 && v[1] == 8 && v[2] == 2);

Example

auto v = Array!int(3, 5);

assert(v.capacity == 3);
assert(v.length == 3);
assert(v[0] == 5 && v[1] == 5 && v[2] == 5);