Discussion Thread: DIP 1037--Add Unary Operator ...--Community Review Round 1

Stefan Koch uplink.coder at googlemail.com
Tue Nov 3 16:34:39 UTC 2020


On Tuesday, 3 November 2020 at 13:46:20 UTC, Andrei Alexandrescu 
wrote:
> On 11/3/20 2:05 AM, Manu wrote:
>>    MyTemplate!(expr...) <-- appearance in template parameter 
>> lists
>
> By the way in C++ the expansion applies to so-called patterns, 
> not expressions:
>
> pattern...
>
> The pattern allowed depends on the context in which it's seen. 
> E.g., if it's in a function call arguments, it's the largest 
> expression to the left of "...".
>
> The difficulty in D is that it's not always clear if something 
> is meant to be an expression or a type. Consider:
>
> template X(T...) { }
> X!(pattern...);
>
> It's unclear whether the pattern is meant to expand into types 
> or expressions. I don't know whether there's a case in D where 
> that could create a confusion.

A Type in practice is just an expression.

Consider:

alias A(T) = T;

pragma(msg, A!int); // prints int;
pragma(msg, !A!int); // prints false.
If you can use ! on something, it's an expression.




More information about the Digitalmars-d mailing list