On 8/17/21 2:59 AM, Rekel wrote:

> template TFoo(T)        { void foo(){writeln("1");} } // #1
> template TFoo(T : T[])  { void foo(){writeln("2");} } // #2

I don't have such problems because I am not smart enough to understand that syntax so I don't use it. :) I use template constraints (which have other problems).

import std.traits;
import std.stdio;

template TFoo(T)
if (!isArray!T)
{
  void foo(){
    writeln("not array");
  }
}

template TFoo(T)
if (isArray!T)
{
  void foo(){
    writeln("array");
  }
}

void main() {
  TFoo!(int).foo();
  TFoo!(int[]).foo();
}

If you want 2 dimensional arrays, then you can use

import std.range;

  isArray!T && (isArray!(ElementType!T))

Ali

Reply via email to