On Saturday, 11 October 2014 at 18:01:41 UTC, Uranuz wrote:
When I want to pass generic String by const reference I get an error.
Strings are passed by reference automatically, so you wouldn't want to double reference them anyway.
As far as I understand const should accept both mutable and immutable data. And there I want to pass it by reference.
Yes, but since "foo" isn't an lvalue (variable), you can't pass it by ref in D, even if it is const. This differs from C++, but I don't recall the reason, I think there's just too many weird edge cases that D wanted to avoid.
But in the case of strings, arrays, classes, pointers, and user defined structs that wrap these, you don't need to pass it as ref at all, just use plain const.
