property aliases to existing functions
Jonathan M Davis
jmdavisProg at gmx.com
Sat Sep 24 15:32:59 PDT 2011
On Sunday, September 25, 2011 00:00:33 Andrej Mitrovic wrote:
> I'm guessing the following is an accepts-invalid bug:
>
> void test(int) {}
> void main() { test = 4; }
>
> Anyway, if/when the above stops being legal I'd be nice if I could
> create property functions using aliases. Something like this:
>
> struct Bar
> {
> int getFoo() { return 0; }
> void setFoo(int i) { }
>
> @property alias getFoo foo;
> @property alias setFoo foo;
> }
>
> void main()
> {
> Bar bar;
> bar.foo = 4;
> }
>
> I'm not sure if this is *actually* making "foo" a property right now
> or if DMD completely ignores the property keyword there, it's hard to
> tell since regular functions already act as properties.
>
> But do you think this code should be legal and maybe create properties
> like that? It sure looks handy (admittedly it's not a to-die-for
> feature, just a convenience when porting code).
Actually, there was code like that in core.time until it was pointed out that
it didn't actually work. As I understand it (though I haven't tested it),
pretty much _no_ attributes have an affect on aliases (including deprecated,
which could be a problem). So, yeah. I'd like for this to work, but it
doesn't.
- Jonathan M Davis
More information about the Digitalmars-d-learn
mailing list