Request: (T) == T
Sean Kelly
sean at f4.ca
Wed Dec 12 07:18:41 PST 2007
Janice Caron wrote:
> Wherever T is a type expression, please could (T) also be a type
> expression, evaluating to T. That is, please could (T) be made to
> compile, as if the brackets weren't there. For example, let
>
> (int) x;
>
> be the same thing as
>
> int x;
>
> declaring x to be an int, and let
>
> (int)[] p;
>
> be the same thing as
>
> int[] p;
>
> declaring p to be an array of ints. For that matter ((((T)))) should
> also evaluate to T, and const(const(T)) should evaluate to const(T),
> and so on.
>
> This would be useful for generic programming, mixin strings, etc.
I personally think it's kind of nice to be able to distinguish between a
declaration and an invalid expression without doing too much work.
Though fortunately, D isn't a victim of C++'s "most vexing parse" as
described by Scott Meyers, so adding this feature wouldn't be ruinous.
Sean
More information about the Digitalmars-d
mailing list