On Sun, Oct 30, 2011 at 7:36 AM, Andrei Alexandrescu <
seewebsiteforem...@erdani.org> wrote:

> The code as above is canonical. I think restricted templates are the way
> to go for most code.
>

Yes, they are much simpler to use.

I went back to traits.d to see how isDynamicArray and isStaticArray were
built mostly to figure out the patterns used for them. I  found a couple
more  isArray!T  and isSomeString which simplify and generalize the code
just a little more:

import std.stdio;
import std.traits;
void abc(T) (T parm1)
  if (isSomeString!T || !isArray!T)
  {
  writeln("simpleparm: ", parm1);
  }
void abc(T) (T parm1)
  if (!isSomeString!T && isArray!T)
  {
  writeln("array : ", parm1);
  }
void main(string[] args)
  {
    writeln("v4");
    abc(1);
    abc("str");
    int[] arr = [1, 2];
    abc(arr);
    int[2] arr2 = [3, 4];
    abc(arr2);
  }


Another one that looked promising is isIterable() for the array.

All of this begs the question, where do I find the latest doc? Since these
are not showing up in the online doc but are clearly in traits.d.
http://d-programming-language.org/traits.html

Thanks again for your help,
John

Reply via email to