template specialization for arrays

J Arrizza cppgent0 at gmail.com
Sat Oct 29 16:44:16 PDT 2011


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.

John
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20111029/70e93e6c/attachment.html>


More information about the Digitalmars-d mailing list