View source code
Display the source code in object.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 object.assumeSafeAppend
Assume that it is safe to append to this array. Appends made to this array after calling this function may append in place, even if the array was a slice of a larger array to begin with.
auto ref inout(T[]) assumeSafeAppend(T)
(
auto ref inout(T[]) arr
) nothrow;
Use this only when it is certain there are no elements in use beyond the array in the memory block. If there are, those elements will be overwritten by appending to this array.
Warning
Calling this function, and then using references to data located after the given array results in undefined behavior.
Returns
The input is returned.
Example
int[] a = [1, 2, 3, 4];
// Without assumeSafeAppend. Appending relocates.
int[] b = a [0 .. 3];
b ~= 5;
assert(a .ptr != b .ptr);
debug(SENTINEL) {} else
{
// With assumeSafeAppend. Appending overwrites.
int[] c = a [0 .. 3];
c .assumeSafeAppend() ~= 5;
writeln(a .ptr); // c.ptr
}
Authors
Walter Bright, Sean Kelly
License
Copyright © 1999-2022 by the D Language Foundation | Page generated by ddox.