Thread overview | |||||||||
---|---|---|---|---|---|---|---|---|---|
|
December 11, 2012 Address of return value. | ||||
---|---|---|---|---|
| ||||
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. :/ |
December 11, 2012 Re: Address of return value. | ||||
---|---|---|---|---|
| ||||
Posted in reply to monarch_dodra | 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?
|
December 11, 2012 Re: Address of return value. | ||||
---|---|---|---|---|
| ||||
Posted in reply to monarch_dodra | 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?
|
December 11, 2012 Re: Address of return value. | ||||
---|---|---|---|---|
| ||||
Posted in reply to cal | 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 :)
|
December 11, 2012 Re: Address of return value. | ||||
---|---|---|---|---|
| ||||
Posted in reply to monarch_dodra | 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) |
December 11, 2012 Re: Address of return value. | ||||
---|---|---|---|---|
| ||||
Posted in reply to Timon Gehr | 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 !?
:(
|
December 11, 2012 Re: Address of return value. | ||||
---|---|---|---|---|
| ||||
Posted in reply to monarch_dodra | 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
|
Copyright © 1999-2021 by the D Language Foundation