Alias Expressions
Eldar Insafutdinov
e.insafutdinov at gmail.com
Mon Apr 23 07:53:37 PDT 2012
On Monday, 23 April 2012 at 12:25:21 UTC, Peter Alexander wrote:
> On Monday, 23 April 2012 at 03:17:49 UTC, Xinok wrote:
>> I know this has probably been asked for a hundred times
>> before, but I don't understand why D doesn't support this.
>> Template alias parameters can accept nearly anything as an
>> argument that standard aliases don't. I think standard aliases
>> should be equally as powerful as their template counterpart.
>>
>> If you can write this:
>> template Eval(alias arg){ alias arg Eval; }
>> alias Eval!(cond ? a : b) al;
>>
>> Why not simply allow this?
>> alias (cond ? a : b) al;
>>
>> Or perhaps this:
>> alias al = cond ? a : b;
>
> Do equivalent expressions instantiate the same template?
>
> class Foo(alias E) {}
> int x, y;
> alias (x + y) A;
> alias (x + y) B;
> alias (y + x) C;
>
> Are Foo!A and Foo!B the same type? What about Foo!C?
>
> Either way, it will require name-mangling of arbitrary
> expressions, which is just plain nasty.
I think you've misunderstood the poster as "cond ? a : b" must
fold and Eval(alias arg) receives a compile time value. That
makes it no different from doing just enum al = cond ? a: b;
Which brings us to an interesting point that alias and enum
should be brought together:
alias x = 1;
alias y = int;
should replace current
enum x = 1;
alias int y;
respectively. This is makes it a consistent syntax and behavior
for alias declarations(no reverse order compared to normal
assignments which is a legacy of C's typedef) and also fixes enum
storage class which name is not relevant anymore.
More information about the Digitalmars-d
mailing list