Length of fixed size arrays
Benjamin Thaut
code at benjamin-thaut.de
Sat Nov 17 08:44:39 PST 2012
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
More information about the Digitalmars-d
mailing list