On Friday, 27 April 2012 at 14:51:01 UTC, bearophile wrote:
John Carmack:
Returning everything by value is the natural functional programming style, but relying on compilers to always perform return value optimization can be hazardous to performance, so passing reference parameter for output of complex data structures is often justifiable, but it has the unfortunate effect of preventing you from declaring the returned value as const to enforce single assignment.<

Is this what he is talking about?

class Foo {
    int x;
}
const(Foo) bar() pure {
    auto f = new Foo;
    f.x = 1;
    return f;
}
void main() pure {}

No, he is referring to the call site of the function which returns something by ref, where you can't declare the »target« const:

---
/* const */ Foo foo;
initializeFoo(foo);
---

David

Reply via email to