static try catch construct would be helpful

Bruno Medeiros brunodomedeiros+spam at com.gmail
Wed Mar 26 06:30:53 PDT 2008


Bill Baxter wrote:
> Currently, the best way I've found to conditionalize that is:
> 
>    static if(is(typeof(_inner.doSomething(1,1,1,1)))) {
>    void doSomething(int a, int b, int c, int d)
>    {
>       _inner.doSomething(a,b,c,d);
>       // do something else here
>    }
>    }
> 
> Maybe there's a better way to write that one.. I'm not sure.  But the 
> signature of the thing that may or may not exist can be arbitrarily 
> complex.  It becomes difficult to think of an is-expression that can 
> test for what you want.  

I don't understand this. Why is it difficult to use an is-expression to 
test the condition you are checking? If you're just checking to see if a 
member exists, you can just do
   static if(is(typeof(_inner.doSomething))) {
If you're checking for the existence of a particular overload, then you 
will need an expression where that function overload is called.
Perhaps the problem is code duplication? (like having two function 
calls, such as "_inner.doSomething(1,1,1,1)" and 
"_inner.doSomething(a,b,c,d)" ?

-- 
Bruno Medeiros - MSc in CS/E student
http://www.prowiki.org/wiki4d/wiki.cgi?BrunoMedeiros#D



More information about the Digitalmars-d mailing list