View source code
Display the source code in std/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.
Function std.array.insertInPlace
Inserts stuff
(which must be an input range or any number of
implicitly convertible items) in array
at position pos
.
void insertInPlace(T, U...)
(
ref T[] array,
size_t pos,
U stuff
)
if (!isSomeString!(T[]) && allSatisfy!(isInputRangeOrConvertible!T, U) && (U .length > 0));
void insertInPlace(T, U...)
(
ref T[] array,
size_t pos,
U stuff
)
if (isSomeString!(T[]) && allSatisfy!(isCharOrStringOrDcharRange, U));
Parameters
Name | Description |
---|---|
array | The array that stuff will be inserted into. |
pos | The position in array to insert the stuff . |
stuff | An input range,
or any number of implicitly convertible items to insert into array . |
Example
int[] a = [ 1, 2, 3, 4 ];
a .insertInPlace(2, [ 1, 2 ]);
writeln(a); // [1, 2, 1, 2, 3, 4]
a .insertInPlace(3, 10u, 11);
writeln(a); // [1, 2, 1, 10, 11, 2, 3, 4]
union U
{
float a = 3.0;
int b;
}
U u1 = { b : 3 };
U u2 = { b : 4 };
U u3 = { b : 5 };
U[] unionArr = [u2, u3];
unionArr .insertInPlace(2, [u1]);
writeln(unionArr); // [u2, u3, u1]
unionArr .insertInPlace(0, [u3, u2]);
writeln(unionArr); // [u3, u2, u2, u3, u1]
static class C
{
int a;
float b;
this(int a, float b) { this .a = a; this .b = b; }
}
C c1 = new C(42, 1.0);
C c2 = new C(0, 0.0);
C c3 = new C(int .max, float .init);
C[] classArr = [c1, c2, c3];
insertInPlace(classArr, 3, [c2, c3]);
C[5] classArr1 = classArr;
writeln(classArr1); // [c1, c2, c3, c2, c3]
insertInPlace(classArr, 0, c3, c1);
C[7] classArr2 = classArr;
writeln(classArr2); // [c3, c1, c1, c2, c3, c2, c3]
Authors
License
Copyright © 1999-2024 by the D Language Foundation | Page generated by ddox.