equivariant functions

ore-sama spam at here.lot
Tue Oct 21 02:00:18 PDT 2008


ore-sama Wrote:

> Andrei Alexandrescu Wrote:
> > S stripl(S s) if (is(S : const(char)[]) { stmts }
> >
> try to template this
> const?(X) fun(const?(Y) y);

just a thought:

class A{} class B{ A a; }
DeriveConst!(I,A) fun(I)(I b)
{
	return b.a;
}

unittest
{
	B m;
	fun(m);
	const B c;
	fun(c);
	invariant B i;
	invariant A a=fun(i);
}

template DeriveConst(A,B)
{
	static if(is(A==invariant))alias invariant(B) DeriveConst;
	else static if(is(A==const))alias const(B) DeriveConst;
	else alias B DeriveConst;
}



More information about the Digitalmars-d mailing list