static try?

Don nospam at nospam.com
Tue Nov 1 23:55:02 PDT 2011


On 31.10.2011 02:21, Mehrdad wrote:
> I've written this piece of code a fair number of times:
>
> static if (is(typeof(foo()))) { foo(); }
> else { bar(); }
>
> When the expression inside the condition (i.e. the call to foo()) gets
> complicated, you get lots of code duplication and things become harder
> to read.

IMHO the only problem is the is(typeof()) syntax.
Otherwise I don't see how this has any more code duplication than:

if( foo(lots_of_parameters) )
     foo(lots_of_parameters);
else bar();


More information about the Digitalmars-d mailing list