Array append performance 2

Sergey Gromov snake.scaly at gmail.com
Sun Aug 31 09:15:47 PDT 2008


dsimcha <dsimcha at yahoo.com> wrote:
> static if (IsType!(Mutable!(Types[0]), bool, byte, ubyte, short, ushort, int, uint,
>                            long, ulong, float, double, real, ifloat, idouble,
>                            ireal, cfloat, cdouble, creal, char, dchar, wchar) )
> 
> Also, although it may be the least bad way to do this (I can't think of a better
> one), the process of elimination method this relies on seems kind of brittle
> because it would have to be modified for any new type that is added.  If anyone
> knows of a less kludge-y way, please post.

I may be missing something, but the following seems to work:

template Category(T)
{
	static if (
		is(T == interface) ||
		is(T == class) ||
		is(T Base : Base*))
	{
		const Category = "reference";
	}
	else
		const Category = "value";
}

template Category(T : T[U], U)
{
	const Category = Category!(T);
}

You need to extend this for structs and unions but that seems routine...

-- 
SnakE



More information about the Digitalmars-d mailing list