Templates: Array slices not recognized

anonymous via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Mon Apr 20 03:26:59 PDT 2015


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.


More information about the Digitalmars-d-learn mailing list