On the subject of properties, and possibility of having them in the library
Simen Kjaeraas
simen.kjaras at gmail.com
Sun Jan 27 02:54:31 PST 2013
On 2013-49-27 09:01, Timon Gehr <timon.gehr at gmx.ch> wrote:
> On 01/27/2013 12:23 AM, Simen Kjaeraas wrote:
>> On 2013-23-26 20:01, Timon Gehr <timon.gehr at gmx.ch> wrote:
>>
>>> On 01/26/2013 03:41 PM, Simen Kjaeraas wrote:
>>>> While the storm raged, I decided to try implementing properties as
>>>> library types. I encountered a few obstacles, which I will outline
>>>> here.
>>>>
>>>> First, my intended syntax:
>>>>
>>>> class A {
>>>> int _n;
>>> mixin Property!(
>>>> () => _n,
>>>> value => _n = value
>>>> ) n;
>>>> }
>>>> ...
>>>
>>>
>>> http://d.puremagic.com/issues/show_bug.cgi?id=7653
>>
>> And how might that work?
>>
>>
>
> It wouldn't work so well. I think there is no way to get what you want,
> because the type of a.n would need to be 'int', and so there is no way
> to hook in the setter.
There's an enhancement request[1] in bugzilla for operator overloading on
non-type template instances. This, with opDispatch and alias this (and
allowing for typeof to return the alias this'd type in this situation),
would allow for properties to be a simple template.
[1]: http://d.puremagic.com/issues/show_bug.cgi?id=5158
--
Simen
More information about the Digitalmars-d
mailing list