Aliases
Walter Bright
newshound at digitalmars.com
Sun Oct 22 12:26:59 PDT 2006
Reiner Pope wrote:
> What's the purpose of the restriction of alias in the specs -- 'Aliases
> cannot be used for expressions'; it prevents some useful things like this:
>
> int[2] nodes;
> alias nodes[0] left;
> alias nodes[1] right;
How about:
auto left = &nodes[0];
auto right = &nodes[1];
Or:
auto left = (){ return nodes[0]; }
auto right = (){ return nodes[1]; }
> It could also be used for function forwarding, as Frank Benoit requested
> earlier ('Feat. RQ: delegation alias'):
>
> class Foo
> {
> void DoSomething() {...}
> }
>
> class FooHandle
> {
> Foo myFoo;
> alias myFoo.DoSomething DoSomething;
> }
Or:
auto DoSomething = &myFoo.DoSomething;
> Maybe someone can explain why this restriction is necessary.
More information about the Digitalmars-d
mailing list