www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Address of return value.

reply "monarch_dodra" <monarchdodra gmail.com> writes:
I feel incredibly stupid asking this one, but how does one 
extract the address of return value of a member function that 
returns by ref?

Case in point:

//----
struct S
{
     int i;
     ref front()  property
     {
         return i;
     }
}

void foo(int*){}

void main()
{
     auto s = S();
     static assert (hasLvalueElements!S);
     auto p = &(s.front);
     writeln(typeof(p).stringof); //produces int delegate() 
 property ref
     foo(p);
}
//----
Error: function main.foo (int* _param_0) is not callable using 
argument types (int delegate()  property ref)
Error: cannot implicitly convert expression (p) of type int 
delegate()  property ref to int*
//----
I want: the address of the value returned by s.front.
I get: the address of the function S.front.

:/
Dec 11 2012
parent reply "monarch_dodra" <monarchdodra gmail.com> writes:
On Tuesday, 11 December 2012 at 14:57:27 UTC, monarch_dodra wrote:
 :/
I got it to work with a cast, which removes the ambiguity: auto p = &cast(int)s.front; But it feels hackish. Any other way?
Dec 11 2012
parent reply "cal" <callumenator gmail.com> writes:
On Tuesday, 11 December 2012 at 15:38:38 UTC, monarch_dodra wrote:
 On Tuesday, 11 December 2012 at 14:57:27 UTC, monarch_dodra 
 wrote:
 :/
I got it to work with a cast, which removes the ambiguity: auto p = &cast(int)s.front; But it feels hackish. Any other way?
auto p = &(s.front()); Not sure if this is intended though, maybe some property weirdness?
Dec 11 2012
parent reply "monarch_dodra" <monarchdodra gmail.com> writes:
On Tuesday, 11 December 2012 at 16:45:54 UTC, cal wrote:
 On Tuesday, 11 December 2012 at 15:38:38 UTC, monarch_dodra 
 wrote:
 On Tuesday, 11 December 2012 at 14:57:27 UTC, monarch_dodra 
 wrote:
 :/
I got it to work with a cast, which removes the ambiguity: auto p = &cast(int)s.front; But it feels hackish. Any other way?
auto p = &(s.front()); Not sure if this is intended though, maybe some property weirdness?
Strange, I was *sure* I had tried that. Oh, well. Thanks :)
Dec 11 2012
parent reply Timon Gehr <timon.gehr gmx.ch> writes:
On 12/11/2012 05:58 PM, monarch_dodra wrote:
 On Tuesday, 11 December 2012 at 16:45:54 UTC, cal wrote:
 On Tuesday, 11 December 2012 at 15:38:38 UTC, monarch_dodra wrote:
 On Tuesday, 11 December 2012 at 14:57:27 UTC, monarch_dodra wrote:
 :/
I got it to work with a cast, which removes the ambiguity: auto p = &cast(int)s.front;
This might be be an accepts-invalid. I think it is undocumented.
 But it feels hackish. Any other way?
auto p = &(s.front()); Not sure if this is intended though, maybe some property weirdness?
Strange, I was *sure* I had tried that. Oh, well. Thanks :)
This will break, you call an property function with (). But I don't think it is decided yet how what you want to achieve should be done. :o)
Dec 11 2012
parent reply "monarch_dodra" <monarchdodra gmail.com> writes:
On Tuesday, 11 December 2012 at 21:00:11 UTC, Timon Gehr wrote:
 On 12/11/2012 05:58 PM, monarch_dodra wrote:
 On Tuesday, 11 December 2012 at 16:45:54 UTC, cal wrote:
 On Tuesday, 11 December 2012 at 15:38:38 UTC, monarch_dodra 
 wrote:
 On Tuesday, 11 December 2012 at 14:57:27 UTC, monarch_dodra 
 wrote:
 :/
I got it to work with a cast, which removes the ambiguity: auto p = &cast(int)s.front;
This might be be an accepts-invalid. I think it is undocumented.
 But it feels hackish. Any other way?
auto p = &(s.front()); Not sure if this is intended though, maybe some property weirdness?
Strange, I was *sure* I had tried that. Oh, well. Thanks :)
This will break, you call an property function with (). But I don't think it is decided yet how what you want to achieve should be done. :o)
So... basically, I have two solutions which are both accepts-invalid !? :(
Dec 11 2012
parent Artur Skawina <art.08.09 gmail.com> writes:
On 12/11/12 22:05, monarch_dodra wrote:
 On Tuesday, 11 December 2012 at 21:00:11 UTC, Timon Gehr wrote:
 On 12/11/2012 05:58 PM, monarch_dodra wrote:
 On Tuesday, 11 December 2012 at 16:45:54 UTC, cal wrote:
 On Tuesday, 11 December 2012 at 15:38:38 UTC, monarch_dodra wrote:
 On Tuesday, 11 December 2012 at 14:57:27 UTC, monarch_dodra wrote:
 :/
I got it to work with a cast, which removes the ambiguity: auto p = &cast(int)s.front;
This might be be an accepts-invalid. I think it is undocumented.
 But it feels hackish. Any other way?
auto p = &(s.front()); Not sure if this is intended though, maybe some property weirdness?
Strange, I was *sure* I had tried that. Oh, well. Thanks :)
This will break, you call an property function with (). But I don't think it is decided yet how what you want to achieve should be done. :o)
So... basically, I have two solutions which are both accepts-invalid !?
auto addrOf(T)(ref T a) { return &a; } auto p = addrOf(s.front); artur
Dec 11 2012