Skip to content

Commit

Permalink
arrays.dd: clarify intended meaning of reserve function and append op…
Browse files Browse the repository at this point in the history
…erator with example
  • Loading branch information
jamadagni committed Oct 25, 2015
1 parent 5019e76 commit 63cbc91
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions arrays.dd
Expand Up @@ -549,7 +549,7 @@ a[15] = 'z'; // does not affect c, because either a or c has reallocated.


$(P To guarantee copying behavior, use the .dup property to ensure
a unique array that can be resized. Also, one may use the phobos
a unique array that can be resized. Also, one may use the
$(D .capacity) property to determine how many elements can be appended
to the array without reallocating.
)
Expand Down Expand Up @@ -600,9 +600,17 @@ array.length = i;
input from the console - it's unlikely to be longer than 80.
)

$(P Also, you may wish to utilize the phobos $(D reserve)
$(P Also, you may wish to utilize the $(D reserve)
function to pre-allocate array data to use with the append operator.)

---------
int[] array;
size_t cap = array.reserve(10); // request
array ~= [1, 2, 3, 4, 5];
assert(cap >= 10); // allocated may be more than request
assert(cap == array.capacity);
---------

$(H3 $(LNAME2 func-as-property, Functions as Array Properties))

$(P If the first parameter to a function is an array, the
Expand Down

0 comments on commit 63cbc91

Please sign in to comment.