Double face templates

bearophile bearophileHUGS at lycos.com
Mon Sep 29 10:10:32 PDT 2008


I have created several templates, like one very simple named ArrayType1 that given the type of an array becomes an alias of the type of its items (there are other more complex templates too).

They can be used as:
ArrayType1!(TypeArray)
or:
ArrayType1!(typeof(somearray))

But to reduce code clutter if possible I'd like to create a template that works in both cases:
ArrayType1!(TypeArray)
ArrayType1!(somearray)

I know template "arguments" can be an alias too, so I may define a pair like this:
template ArrayType1!(T) {...}
template ArrayType1!(alias x) { ... }
but when I define both templates I always enter a swamp, with so many (sometimes strange) bugs that so far I have always thrown away the template version with alias and I have kept only the more normal template defined on a type.

Is what I am trying to do wrong/ unsafe/ philosophically bad?
If my purpose isn't bad, then can you suggest how to implement it much more reliably?

Thank you,
bearophile


More information about the Digitalmars-d-learn mailing list