digitalmars.D.learn - Address of return value.
- monarch_dodra (32/32) Dec 11 2012 I feel incredibly stupid asking this one, but how does one
- monarch_dodra (4/5) Dec 11 2012 I got it to work with a cast, which removes the ambiguity:
- cal (4/10) Dec 11 2012 auto p = &(s.front());
- monarch_dodra (3/17) Dec 11 2012 Strange, I was *sure* I had tried that.
- Timon Gehr (5/21) Dec 11 2012 This will break, you call an @property function with ().
- monarch_dodra (4/30) Dec 11 2012 So... basically, I have two solutions which are both
- Artur Skawina (4/33) Dec 11 2012 auto addrOf(T)(ref T a) { return &a; }
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
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
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:auto p = &(s.front()); Not sure if this is intended though, maybe some property weirdness?:/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
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:Strange, I was *sure* I had tried that. Oh, well. Thanks :)On Tuesday, 11 December 2012 at 14:57:27 UTC, monarch_dodra wrote:auto p = &(s.front()); Not sure if this is intended though, maybe some property weirdness?:/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
On 12/11/2012 05:58 PM, monarch_dodra wrote:On Tuesday, 11 December 2012 at 16:45:54 UTC, cal wrote:This might be be an accepts-invalid. I think it is undocumented.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 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)Strange, I was *sure* I had tried that. Oh, well. Thanks :)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
On Tuesday, 11 December 2012 at 21:00:11 UTC, Timon Gehr wrote:On 12/11/2012 05:58 PM, monarch_dodra wrote:So... basically, I have two solutions which are both accepts-invalid !? :(On Tuesday, 11 December 2012 at 16:45:54 UTC, cal wrote:This might be be an accepts-invalid. I think it is undocumented.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 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)Strange, I was *sure* I had tried that. Oh, well. Thanks :)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
On 12/11/12 22:05, monarch_dodra wrote:On Tuesday, 11 December 2012 at 21:00:11 UTC, Timon Gehr wrote:auto addrOf(T)(ref T a) { return &a; } auto p = addrOf(s.front); arturOn 12/11/2012 05:58 PM, monarch_dodra wrote:So... basically, I have two solutions which are both accepts-invalid !?On Tuesday, 11 December 2012 at 16:45:54 UTC, cal wrote:This might be be an accepts-invalid. I think it is undocumented.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 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)Strange, I was *sure* I had tried that. Oh, well. Thanks :)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