[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 02:15:23 PST 2008


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





------- Comment #1 from andrei at metalanguage.com  2008-02-12 04:15 -------
(In reply to comment #0)
> I decided to put my proposal from news list (posted some time ago) as
>  I think it can really improve current situation with templates.
> After implementing quite a big piece of template code I can only say
> that currently the whole system is quite inconsistent, but situation
> can be easily improved, keeping a lot of backward compatibility.

Thanks for your thoughts. They closely reflect some ideas that I brought forth
with Walter a short while ago.

> I did not get any replays for my proposals and it's difficult for me
> to say why: - proposal is so bad? - proposal is so good, so there is
> no need to comment on it? - no one is interested?

Where was the proposal?

> --- I wonder if you ever try to define something like this:
> 
> void parse(T : T == char[] || T == wchar[] || T == dchar[])(T str) {
>  }

You mean match a type if a Boolean condition is satisfied? Yes, I also felt a
need for that.

> or match associative array in template declaration?

Well this works today.

> Or maybe you got annoyed with different syntaxes for template 
> definitions and is() expression?
> 
> static if (is(T : U[N], U, size_t N)) ...; //ok 
> void parse(T : U[N], U, size_t N) ...; //doesn't work
> void parse(T U: U*)(T val) {}; 
> //doesn't work

I think the intent is that at least the first two work.

> or wonder why symbol T gets redefined into array element like below:
>  void parse(T : T[]) {}

This is bar none the fugliest hack ever since eunuchs have been invented. I
have argued many times with Walter to remove it, and probably de facto it will
- none of the book's code samples will feature it.

> or wants to define template like below: void parse(T : isString!(T)) 
> {}

This is again the case of instantiating a template depending on a Boolean
condition.

> If yes, please read on.
[snip]

I think the proposal has good merit. I like the separation between introduced
types and constraints. The separation is diminished by the presence of =T
constraints on the left-hand side of ":". 

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) { ... }

Walter likes this. I'm not sure what he'd say about your syntax; my guess is
that he'll take the path of least resistance. I don't know what that is :o).


Andrei


-- 



More information about the Digitalmars-d-bugs mailing list