www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Will D 2.x have refrences

reply BLS <nanali nospam-wanadoo.fr> writes:
I mean something comparable to :
//C++
int value = 100;
int & rIntRef = value;
if (rIntRef == 100)
   // be ashured my val is 100
rIntref = 101
if (&rIntref == &value)
   // Yes we have the same address

(not parameter passing)
Bjoern
Oct 10 2007
next sibling parent reply Jari-Matti =?ISO-8859-1?Q?M=E4kel=E4?= <jmjmak utu.fi.invalid> writes:
BLS wrote:

 I mean something comparable to :
 //C++
 int value = 100;
 int & rIntRef = value;
 if (rIntRef == 100)
    // be ashured my val is 100
 rIntref = 101
 if (&rIntref == &value)
    // Yes we have the same address
 
 (not parameter passing)
 Bjoern

void main() { int value = 100; alias value rIntRef; if (rIntRef == 100) rIntRef = 101; assert(value == 101); assert(&value == &rIntRef); } Alias parameters also work in functions wrapped inside templates.
Oct 11 2007
next sibling parent reply Bill Baxter <dnewsgroup billbaxter.com> writes:
Jari-Matti Mäkelä wrote:
 BLS wrote:
 
 I mean something comparable to :
 //C++
 int value = 100;
 int & rIntRef = value;
 if (rIntRef == 100)
    // be ashured my val is 100
 rIntref = 101
 if (&rIntref == &value)
    // Yes we have the same address

 (not parameter passing)
 Bjoern

void main() { int value = 100; alias value rIntRef; if (rIntRef == 100) rIntRef = 101; assert(value == 101); assert(&value == &rIntRef); } Alias parameters also work in functions wrapped inside templates.

But they don't work for things that require '.'s to get to. void main() { int& value = myClass.some.value_member; // C++, ok ... } void main() { alias myClass.some.value_member value; // D, ack! } --bb
Oct 11 2007
parent reply Jari-Matti =?ISO-8859-1?Q?M=E4kel=E4?= <jmjmak utu.fi.invalid> writes:
Bill Baxter wrote:

 But they don't work for things that require '.'s to get to.
 
 void main() {
     int& value = myClass.some.value_member; // C++, ok
     ...
 }
 
 void main() {
     alias myClass.some.value_member  value;  // D, ack!
 }
 

Hmm, interesting. Wouldn't it be possible to extend the functionality? Doesn't seem like alias fully handles those as symbols. For example this gives me two(?!) "Error: need 'this' for address of bar" errors on the last line: struct foo { struct b { int a; } b bar; } foo f; alias f.bar b; assert(b.a == 0);
Oct 11 2007
next sibling parent Bill Baxter <dnewsgroup billbaxter.com> writes:
Jari-Matti Mäkelä wrote:
 Bill Baxter wrote:
 
 But they don't work for things that require '.'s to get to.

 void main() {
     int& value = myClass.some.value_member; // C++, ok
     ...
 }

 void main() {
     alias myClass.some.value_member  value;  // D, ack!
 }

Hmm, interesting. Wouldn't it be possible to extend the functionality?

Seems like it should be possible to make it work. There was some talk previously about extending alias to work on (constant?) expressions too. So you could do something like alias Pi/2 half_pi;
 Doesn't seem like alias fully handles those as symbols. For example this
 gives me two(?!) "Error: need 'this' for address of bar" errors on the last
 line:
 
 struct foo {
   struct b { int a; }
   b bar;
 }
 
 foo f;
 alias f.bar b;
 assert(b.a == 0);

Yeh, the error messages don't make much sense. I think I've seen that one a lot.
Oct 11 2007
prev sibling parent BLS <nanali nospam-wanadoo.fr> writes:
Jari-Matti Mäkelä schrieb:
 Bill Baxter wrote:
 
 But they don't work for things that require '.'s to get to.

 void main() {
     int& value = myClass.some.value_member; // C++, ok
     ...
 }

 void main() {
     alias myClass.some.value_member  value;  // D, ack!
 }

Hmm, interesting. Wouldn't it be possible to extend the functionality? Doesn't seem like alias fully handles those as symbols. For example this gives me two(?!) "Error: need 'this' for address of bar" errors on the last line: struct foo { struct b { int a; } b bar; } foo f; alias f.bar b; assert(b.a == 0);

Yes, I also would like to see extended alias functionality too. ...having alias instead of & for refrences will make D more readable. I especially don't like the double and triple meanings of symbols. Is * used as pointer, as dereference, as mul operator ? Same is valid for & refrence or address of ? Sure, the context will show it, but I prefer "p IS POINTER TO" style languages D should be more reliable the C++, guess you know what I mean. Bjoern Bjoern
Oct 11 2007
prev sibling parent BLS <nanali nospam-wanadoo.fr> writes:
Jari-Matti Mäkelä schrieb:
 BLS wrote:
 
 I mean something comparable to :
 //C++
 int value = 100;
 int & rIntRef = value;
 if (rIntRef == 100)
    // be ashured my val is 100
 rIntref = 101
 if (&rIntref == &value)
    // Yes we have the same address

 (not parameter passing)
 Bjoern

void main() { int value = 100; alias value rIntRef; if (rIntRef == 100) rIntRef = 101; assert(value == 101); assert(&value == &rIntRef); } Alias parameters also work in functions wrapped inside templates.

Thanks Jari, I simply did not know about that feature. (ashamed) Bjoern
Oct 11 2007
prev sibling parent reply Bill Baxter <dnewsgroup billbaxter.com> writes:
BLS wrote:
 I mean something comparable to :
 //C++
 int value = 100;
 int & rIntRef = value;
 if (rIntRef == 100)
   // be ashured my val is 100
 rIntref = 101
 if (&rIntref == &value)
   // Yes we have the same address
 
 (not parameter passing)
 Bjoern

I posted a list of three things that D doesn't have that make life a lot easier in C++. One of them was returning references from functions. Walter's response was "D will get all of those". Now it may be a really long time before they come to pass, and Walter may change his mind, but at least at one point he said references would become returnable. --bb
Oct 11 2007
parent reply BLS <nanali nospam-wanadoo.fr> writes:
Bill Baxter schrieb:
 BLS wrote:
 I mean something comparable to :
 //C++
 int value = 100;
 int & rIntRef = value;
 if (rIntRef == 100)
   // be ashured my val is 100
 rIntref = 101
 if (&rIntref == &value)
   // Yes we have the same address

 (not parameter passing)
 Bjoern

I posted a list of three things that D doesn't have that make life a lot easier in C++. One of them was returning references from functions. Walter's response was "D will get all of those". Now it may be a really long time before they come to pass, and Walter may change his mind, but at least at one point he said references would become returnable. --bb

with surprising new featues all the time... which is nice but, frankly said, I would prefer a straight milestone roadmap. Bjoern
Oct 11 2007
parent Frits van Bommel <fvbommel REMwOVExCAPSs.nl> writes:
BLS wrote:
 Let's hope "we'll get all of those". Unfortunately Walter is comming up 
 with surprising new featues all the time... which is nice but, frankly 
 said, I would prefer a straight milestone roadmap.

Some "unsurprising" (i.e. oft-requested) new features would be nice too :P.
Oct 11 2007