Re: Declare reference to variable ?

2013-07-29 Thread Namespace
Alternative: import std.stdio; struct S { uint longnamed; alias longnamed this; } void main() { S somestruct; alias v = somestruct; writeln(v); v++; writeln(v); }

Re: Declare reference to variable ?

2013-07-29 Thread yaz
Oh, it doesn't work when accessing member data. Sorry for the noise.

Re: Declare reference to variable ?

2013-07-29 Thread Dicebot
On Monday, 29 July 2013 at 21:25:21 UTC, Temtaime wrote: No, i cannot. struct S { uint longnamed; } void main() { S somestruct; alias v = somestruct.longnamed; writeln(v); } Error: need 'this' for 'longnamed' of type 'uint' Is it a bug ? I'd say this is some

Re: Declare reference to variable ?

2013-07-29 Thread yaz
You don't need to use dereference operator. Example: http://dpaste.dzfl.pl/d34c23e5 import std.stdio; struct Foo { void answer() { writeln("As you wish!"); } } void main() { Foo veryVeryLongNamedStruct; auto v = &veryVeryLongNamedStruct; v.answer(); }

Re: Declare reference to variable ?

2013-07-29 Thread Namespace
On Monday, 29 July 2013 at 21:25:21 UTC, Temtaime wrote: No, i cannot. struct S { uint longnamed; } void main() { S somestruct; alias v = somestruct.longnamed; writeln(v); } Error: need 'this' for 'longnamed' of type 'uint' Is it a bug ? Oh, that is annoying

Re: Declare reference to variable ?

2013-07-29 Thread Maxim Fomin
On Monday, 29 July 2013 at 21:37:30 UTC, bearophile wrote: Temtaime: Why i cannot declare reference in D ? I don't know the reasons. But maybe you can create a little struct with just a pointer inside and an alias this to a member function that returns a ref. Bye, bearophile It doesn't

Re: Declare reference to variable ?

2013-07-29 Thread bearophile
Temtaime: I have a long named variable in a struct. For example let's name that longnamedstruct.longnamedmember I need to use that variable in many places of the code and i cannot create the copy of it. You can shorten the outer name with an alias or "remove" it with a with() statement.

Re: Declare reference to variable ?

2013-07-29 Thread Temtaime
No, i cannot. struct S { uint longnamed; } void main() { S somestruct; alias v = somestruct.longnamed; writeln(v); } Error: need 'this' for 'longnamed' of type 'uint' Is it a bug ?

Re: Declare reference to variable ?

2013-07-29 Thread Namespace
On Monday, 29 July 2013 at 21:13:54 UTC, Temtaime wrote: I have a long named variable in a struct. For example let's name that longnamedstruct.longnamedmember I need to use that variable in many places of the code and i cannot create the copy of it. In c++ i can auto &v = longnamedstruct.lon

Declare reference to variable ?

2013-07-29 Thread Temtaime
I have a long named variable in a struct. For example let's name that longnamedstruct.longnamedmember I need to use that variable in many places of the code and i cannot create the copy of it. In c++ i can auto &v = longnamedstruct.longnamedmember; Now i can use v anywhere. Why i cannot decl