Do we already have something like this in phobos? If not should we add it? I'm not quite sure if the .length property of a static array is always a compile time constant.

I use something similar in C++ quite often.

template staticLength(alias symbol)
{
  enum size_t staticLength = staticLengthImpl!(typeof(symbol));
}

template staticLengthImpl(T : U[N], U, size_t N)
{
  enum size_t staticLengthImpl = N;
}

template staticLengthImpl(T)
{
  static assert(0, T.stringof ~ " is not an static array");
}

Kind Regards
Benjamin Thaut

Reply via email to