Aliases

Bill Baxter wbaxter at gmail.com
Sun Oct 22 12:56:10 PDT 2006


Walter Bright wrote:
> 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];

test.d(13): non-constant expression & nodes
test.d(14): non-constant expression (& nodes+4)

> 
> Or:
> 
>     auto left = (){ return nodes[0]; }
>     auto right = (){ return nodes[1]; }

   auto left = (){ return nodes[0]; };
   auto right = (){ return nodes[1]; };

test.d(15): delegate properties.Props.__dgliteral1 literals cannot be 
class members
<COMPILER CRASH>

> 
>> 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;

test.d(32): non-constant expression &(myFoo).DoSomething


--bb



More information about the Digitalmars-d mailing list