Skip to content

Commit

Permalink
Fix coding style for d-array-article.dd
Browse files Browse the repository at this point in the history
  • Loading branch information
H. S. Teoh committed Aug 23, 2014
1 parent 901e6fd commit 0d22b01
Showing 1 changed file with 15 additions and 15 deletions.
30 changes: 15 additions & 15 deletions d-array-article.dd
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,9 @@ void shrinkTo2(int[] arr)

void main()
{
int[] arr = new int[5];
arr.shrinkTo2(); // note the ability to call shrinkTo2 as a method
writeln(arr.length); // outputs 5
int[] arr = new int[5];
arr.shrinkTo2(); // note the ability to call shrinkTo2 as a method
writeln(arr.length); // outputs 5
}
------

Expand Down Expand Up @@ -153,10 +153,10 @@ import std.stdio;

char[] fillAs(char[] buf, size_t num)
{
if(buf.length < num)
buf.length = num; // increase buffer length to be able to hold the A's
buf[0..num] = 'A'; // assign A to all the elements
return buf[0..num]; // return the result
if (buf.length < num)
buf.length = num; // increase buffer length to be able to hold the A's
buf[0..num] = 'A'; // assign A to all the elements
return buf[0..num]; // return the result
}
------

Expand All @@ -166,13 +166,13 @@ $(P What's wrong with the $(D fillAs) function? Nothing really, but what happen
// continued example...
void main()
{
char[] str = new char[10]; // Note, the block capacity allocated for this is
char[] str = new char[10]; // Note, the block capacity allocated for this is
// 15 elements
str[] = 'B';
fillAs(str, 20); // buffer must be reallocated (20 > 15)
writeln(str); // "BBBBBBBBBB"
fillAs(str, 12); // buffer can be extended in place (12 <= 15)!
writeln(str); // "AAAAAAAAAA";
str[] = 'B';
fillAs(str, 20); // buffer must be reallocated (20 > 15)
writeln(str); // "BBBBBBBBBB"
fillAs(str, 12); // buffer can be extended in place (12 <= 15)!
writeln(str); // "AAAAAAAAAA";
}
------

Expand Down Expand Up @@ -203,8 +203,8 @@ $(P $(OBJREF reserve, size_t reserve(size_t n)): Reserves n elements for appendi
------
int[] slice;
slice.reserve(50);
foreach(int i; 0..50)
slice ~= i; // does not reallocate
foreach (int i; 0..50)
slice ~= i; // does not reallocate
------

$(P $(OBJREF capacity, size_t capacity): A property which gives you the number of elements the slice can hold via appending. If the slice cannot be appended in place, this returns 0. Note that capacity (if non-zero) includes the current slice elements.)
Expand Down

0 comments on commit 0d22b01

Please sign in to comment.