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.
So I'm thinking, why not just introduce a 'static try'?
Something like:
static try
{
foo();
}
catch // (string ex) // perhaps let them know what the error is?
{
bar();
}
It's a clean and immensely readable improvement IMO, and it doesn't introduce any new keywords or any breaking changes to anything.
How's the idea?

Am 01.11.2011 17:46, schrieb Vladimir Panteleev:
> On Tue, 01 Nov 2011 18:33:56 +0200, dennis luehring<dl.soluz@gmx.net>
> wrote:
>>> introduces an compiletime scope - what would the following code mean?
>> "debug", "version", "static if" don't create scopes.
>
i know - wrong name for the block between the try{...}
static try
{
------------------
foo1();
foo2();
foo3();
------------------
}
catch
{
bar();
}
im missing a description of what should happen if any of the foos fails to compile? is then the catch part used in compilation?
the idea is too near to the syntax of the exceptionhandling and have total different semantic... is that good?

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();