template specialization for arrays
Jonathan M Davis
jmdavisProg at gmx.com
Sat Oct 29 17:16:13 PDT 2011
On Saturday, October 29, 2011 16:44:16 J Arrizza wrote:
> On Sat, Oct 29, 2011 at 4:14 PM, Andrei Alexandrescu <
>
> SeeWebsiteForEmail at erdani.org> wrote:
> > What's wrong with isStaticArray? Also, OP may want to look at
> > isNarrowString.
> >
> >
> > Andrei
>
> Tried isStaticArray:
>
> void abc(T:U[], U) (T parm1)
> if (isDynamicArray!T)
> {
> writeln("dynamic array : ", parm1);
> }
> void abc(T:U[], U) (T parm1)
> if (isStaticArray!T)
> {
> writeln("static array : ", parm1);
> }
>
>
> It didn't match. The output was:
>
> simpleparm: 1
> dynamic array : str
> dynamic array : [1, 2]
> simpleparm: [3, 4]
>
>
> isNarrowString isn't in the traits online doc. Looked it up in std/traits.d
> and I tried it:
>
> void abc(T) (T parm1)
> if (isNarrowString!T)
> {
> writeln("string : ", parm1);
> }
> void abc(T:U[], U) (T parm1)
> if (isDynamicArray!T)
> {
> writeln("dynamic array : ", parm1);
> }
>
>
> and get compiler ambiguity for abc("str") between the two templates above.
Of course you do. A narrow string is a dynamic array, so it matches both. You
need to change the second constraint to if(isDynamicArray!T &&
!isNarrowString!T), then narrow strings won't match both.
- Jonathan M Davis
More information about the Digitalmars-d
mailing list