Andrej Mitrovic wrote:
> ...snip...
> I want to avoid writing "check()" twice. I only have to statically
> check a field of a member if it's of a certain type (Foo).
>
> One solution would be to use a boolean:
> void test(T)(T t)
> {
> bool isTrue = true;
> static if (is(T == Foo))
> isTrue = t.isTrue;
>
> if (isTrue)
> check();
> }
>
> But that kind of defeats the purpose of static if (avoiding runtime
> overhead). Does anyone have a trick up their sleeve for these types of
> situations? :)
There's always this:
void test(T)(T t)
{
static if (is (T == Foo))
if (!t.isTrue)
return;
check();
}
Jerome
--
mailto:[email protected]
http://jeberger.free.fr
Jabber: [email protected]
signature.asc
Description: OpenPGP digital signature
