equivariant functions

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Tue Oct 21 08:03:21 PDT 2008


ore-sama wrote:
> 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;
> }

Yah that was discussed under the name of PassQual. One problem is 
defining a palatable syntax for member functions.

Andrei



More information about the Digitalmars-d mailing list