Templates: Array slices not recognized
Chris via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Mon Apr 20 03:42:53 PDT 2015
On Monday, 20 April 2015 at 10:27:00 UTC, anonymous wrote:
> On Monday, 20 April 2015 at 10:14:27 UTC, Chris wrote:
>> string a = "bla";
>> string b = "blub";
>>
>> auto res = doSomething(a, b);
>>
>> If I didn't use "auto ref" or "ref", string would get copied,
>> wouldn't it?
>>
>> auto ref doSomething(R needle, R haystack);
>>
>> To avoid this, I would have to write a[0..$], b[0..$], which
>> is not nice. Right or wrong?
>
> Wrong. `a[0..$]` is the same as simply `a`. A `string` is just
> another slice: a pointer and a length.
Ah, I see. So strings don't get copied around and I can remove
ref, very good.
More information about the Digitalmars-d-learn
mailing list