template specialization for arrays
Steven Schveighoffer
schveiguy at yahoo.com
Wed Nov 2 05:40:47 PDT 2011
On Tue, 01 Nov 2011 14:55:45 -0400, J Arrizza <cppgent0 at gmail.com> wrote:
> Steven,
>
> I see, but here's IsStaticArray from traits.d
>
> template isStaticArray(T : U[N], U, size_t N)
> {
> enum bool isStaticArray = true;
> }
>
> template isStaticArray(T)
> {
> enum bool isStaticArray = false;
> }
>
> It looks like the first version is using the "[]" format. It is different
> in that it has the [N] and then goes on to specify that N is a size_t.
Template specification is weird, similar looking things can have
*completely different* meanings.
The compiler uses a lot of deduction to match template parameters. There
are many forms of specialization and comparison.
The equivalent for your case would be:
void abc(T : U[], U) (T parm1)
In other words, "type T is a form of U[], where U is another type".
You should read the spec on how templates work here:
http://www.d-programming-language.org/template.html
Pay close attention to argument deduction.
Another good section to read is the "is expression":
http://www.d-programming-language.org/expression.html#IsExpression
-Steve
More information about the Digitalmars-d
mailing list