[Issue 1827] Uniform syntax for is(), static if, alias, template definition & static assert

d-bugmail at puremagic.com d-bugmail at puremagic.com
Tue Feb 12 09:13:45 PST 2008


http://d.puremagic.com/issues/show_bug.cgi?id=1827





------- Comment #4 from andrei at metalanguage.com  2008-02-12 11:13 -------
(In reply to comment #2)
> > The syntax we had in mind, that would also apply to templates, is(), etc., is:
> 
> > T if condition
> 
> > where "condition" is a compile-time expression that must evaluate to true if T
> > is to be matched. Then you'd write:
> > S toupper(S if isSomeString!(S))(S input) { ... }
> 
> Drawback of this syntax is that it will completely break source compatibility.

Nonono, the ":" stays. In general, a type constraint looks like this:

T [: pattern] [if condition]

Both the : pattern and the if condition may or may not be there

> -----
> 
> I am very curious what do you think about my 'alias' part of proposal? I found
> a few places in my code where I wanted just to decompose type without checking
> condition (condition was already checked before). But it is currently not
> possible...
> 
> And what do you think about 'alias' as a way to define manifest constant? 
> 
> Initially I liked most 'alias', then when Walter decided to use 'enum' I
> thought: "Ok. Enum is not so bad, as enums are definitely too simplistic for
> higher level language.". But now, when I discovered the case with static array,
> where N should be defined as unsigned integer value, I think that alias is much
> better for that purpose. And 'enum' can be extended in better ways with other
> features...

Walter wanted to introduce parameterized alias for quite a while, as they are a
very often-seen pattern in code. Since, as you noted, they were hard to read,
the notation

alias symbol(patterns) = replacement;

would be needed.


Andrei


-- 



More information about the Digitalmars-d-bugs mailing list