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

Janice Caron caron800 at googlemail.com
Wed Feb 13 00:07:35 PST 2008


The nastiest hack that I see is

    template MyTemplate(T:T)

Hands up everyone who knows what that means, and in what way  (T:T) is
different from (T)? If you don't know, can you guess?

Well, the answer is that (T) will match int, const(int) and
invariant(int), but in all three cases, T will be int. Whereas, (T:T)
will match the same three things, but now T will be int, const(int)
and invariant(int) respectively.

It's a nasty hack, because, even when you've learned it, you still
can't do much with it. It doesn't generalize. You can't say "match
only arrays, but preserve constancy", for example.

There are also circumstances where it doesn't work. I never nailed it
down to the obligatory ten line example, but I have encountered a
situation in my own development where I was using a string mixin with
a template, and no matter what I did, I just couldn't get the
constancy transferred to where it needed to go.

Something else that gets lost in the translation to template
parameters is the referentiality of the original. If the original is
"ref", "in", "out" or "inout", that part of the description is not
communicated to T. I haven't actually needed this, but I can certainly
imagine that one day I might want to.

Similarly, it would be nice to know whether T was public, private,
protected or whatever. It would be nice to know if it was static. In
the future, it will be nice to know if it's pure.

Essentially, I would like for the template code to somehow be able to
"get at", and test for, all of the metadata about the original type -
and preferably with a better syntax than (T:T).

Thanks for listening


More information about the Digitalmars-d-bugs mailing list