Incorporating D

Szymon noemail at gmail.com
Fri Jan 25 14:32:19 PST 2013


Ah, perfectly clear now. Thanks guys. At one point I though maybe 
it was about move semantics but it indeed about something much 
more fundamental. And indeed surprising coming from C++.


On Friday, 25 January 2013 at 22:29:44 UTC, Adam D. Ruppe wrote:
> On Friday, 25 January 2013 at 22:22:44 UTC, Szymon wrote:
>> So structs in D are always passed by-value? That is 
>> unfortunate...
>
> It has both pointers and ref but they both only work with 
> lvalues, regardless of const:
>
> struct S {}
>
> void test(const ref S s) {}
> void test2(const S* s) {}
>
> S getS() { return S(); }
>
> void main() {
>         S s;
>         test(s); // ok
>         test2(&s); // ok
>         test(getS()); // not ok (line 12)
>         test2(&getS()); // not ok (line 13)
> }
>
> test.d(12): Error: function test.test (ref const(S) s) is not 
> callable using argument types (S)
> test.d(12): Error: getS() is not an lvalue
> test.d(13): Error: getS() is not an lvalue



More information about the Digitalmars-d mailing list