Array append performance 2

Sergey Gromov snake.scaly at gmail.com
Sun Aug 31 09:46:43 PDT 2008


Sergey Gromov <snake.scaly at gmail.com> wrote:
> 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);
> }

Fixed arrays: dynamic and associative arrays always contain references, 
static arrays must be checked recursively:

template Category(T)
{
	static if (
		is(T == interface) ||
		is(T == class) ||
		is(T Elem : Elem[]) ||	// dyn array
		is(T Base : Base*))
	{
		const Category = "reference";
	}
	else
		const Category = "value";
}

template Category(T : T[U], U)
{
	// AAs always contain references
	const Category = "reference";
}

template Category(T : T[U], size_t U)
{
	// Static arrays may or may not contain references
	const Category = Category!(T);
}

-- 
SnakE



More information about the Digitalmars-d mailing list