std.base64 question

Adam D. Ruppe destructionator at gmail.com
Tue Nov 26 19:18:41 PST 2013


On Wednesday, 27 November 2013 at 03:14:38 UTC, Parke wrote:
> Are slices passed (and returned) by value or by reference?

By value, though they are a pointer into the data.

void foo(int[] data) {
   data[0] = 20;
   data ~= 100;
}

void main() {
   int[4] buffer;
   foo(buffer[]); // slice passed by value, but it still points 
into the buffer
   assert(buffer[0] == 20); // so the change to the data is 
reflected here
   assert(buffer.length == 4); // but the append is not visible 
here, since that affected the slice itself, passed by value, not 
the contents it pointed to.
}


More information about the Digitalmars-d-learn mailing list