View source code Display the source code in std/array.d from which this page was generated on github. 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. Page wiki View or edit the community-maintained wiki page associated with this page.

Function std.array.replaceInPlace

Replaces elements from array with indices ranging from from (inclusive) to to (exclusive) with the range stuff. Expands or shrinks the array as needed.

Prototypes

void replaceInPlace(T, Range)(
  T[] array,
  size_t from,
  size_t to,
  Range stuff
)
if (isDynamicArray!Range && is(ElementEncodingType!Range : T) && !is(T == const(T)) && !is(T == immutable(T)));

void replaceInPlace(T, Range)(
  T[] array,
  size_t from,
  size_t to,
  Range stuff
)
if (isInputRange!Range && (!isDynamicArray!Range && is(ElementType!Range : T) || isDynamicArray!Range && is(ElementType!Range : T) && (is(T == const(T)) || is(T == immutable(T))) || isSomeString!(T[]) && is(ElementType!Range : dchar)));

Example

int[] a = [1, 4, 5];
replaceInPlace(a, 1u, 2u, [2, 3, 4]);
assert(a == [1, 2, 3, 4, 5]);
replaceInPlace(a, 1u, 2u, cast(int[])[]);
assert(a == [1, 3, 4, 5]);
replaceInPlace(a, 1u, 3u, a[2 .. 4]);
assert(a == [1, 4, 5, 5]);

Authors

Andrei Alexandrescu and Jonathan M Davis

License

Boost License 1.0.

Comments