Philippe Sigaud <[email protected]> wrote:
OK. I really like this possibility to test for members and activate
them
when possible. Maybe it could be abstracted away into a Select-like
template?
More detail please.
It's just that my code is full of these static ifs. They are clear but
I'd
like two things:
IfPossible!(someCode); // static if (is( typeof())) or
__traits(compiles, someCode), then someCode. It's becoming a chore to
repeat twice the same line.
and:
ConditionalCode!(cond1, code1, // static if cond1 then code1
cond2, code2, // else static if
cond2 then code2
...
optionalDefaultCode);
But I have no solution except by using q{} strings... Maybe with lazy
void()?
I see a solution to this in template lambdas.
mixin template ifPossible( alias code ) {
static if ( __traits( compiles, code ) ) {
mixin code;
}
}
mixin ifPossible!( !{ fn( d ); } );
Where !{} is the syntax for an inline-specified template, i.e. a
template lambda.
Not sure it is worth adding to the language, but I have occasionally
wanted it.
--
Simen