template type check syntax

gzp galap at freemail.hu
Fri Nov 20 10:29:44 PST 2009


Which is the preferred form ? Shall I place the static assert into the 
in part or into the body directly ?

Is there any difference ? Is there a way to toggle if the in part is 
executed/compiled or not ?  - Like in eifel it can be turned on and off 
by a compiler flag.

template check1(T) {
	enum check1 = ...;
}

bool check2(T t) {
	return ...;
}


void foo(T)(ref T t)
in {
	static assert( check1!(T) );
	assert(check2(t);
}
body {
	static assert( check1!(T) );
...
}


Or is there a form like (As i've seen mentioned with future coming opBinary)
void foo(T)(ref T t) if check1!(T)
{
	in {
		assert(check2(t);
	}
	body {
		...
	}
}


Thanks,
Gzp


More information about the Digitalmars-d-learn mailing list