DIP23 draft: Fixing properties redux

kenji hara k.hara.pg at gmail.com
Sun Feb 3 07:56:50 PST 2013


2013/2/4 Steven Schveighoffer <schveiguy at yahoo.com>

> On Sun, 03 Feb 2013 08:00:32 -0500, kenji hara <k.hara.pg at gmail.com>
> wrote:
>
>> On the contrary with you, I was read that we no longer get an address of
>> ref returned value by address-op.
>>
>> @property ref int foo();
>> static assert(is(typeof(&foo) == ref int function()));  // typeof does not
>> return int*
>>
>> If I am correct, there is no need for special enhancement like __traits.
>>
>
> You are right, it does not specify this, I was somewhat mistaken.
>
> But the spirit of the proposal seems to suggest that for all intents and
> purposes, a property's type is the type of it's return value.
>
[snip]

It is already satisfied. Inside typeof, all use of property makes its
return type.
I think the case of getting address of ref value returned from a property
is much rare.

If you really want to do it, we can write short workaround.

A potential workaround could be a la Timon's suggestion:
>
> ref int foowrap() { return foo;}
> int *x = &foowrap();
>

One liner version:

int* x = ((ref x) => &x)(foo);

Let's go with the current proposal, and I will address the __traits
> mechanism separately.
>

It seems to me that is an overkill.

Kenji Hara
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20130204/bede01b2/attachment.html>


More information about the Digitalmars-d mailing list