www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - "try" functions

I just finished reading Bartosz latest post:

http://bartoszmilewski.wordpress.com/2009/04/26/multithreading-with-d/

and I thought of a feature that would be interesting to explore. To give 
it a handle I'm going to call them "try functions" (derived from try/catch) 
and as for syntax:


try T Foo(T)(T t)
{
    *t++;
    return t;
}

the feature is that the function simply doesn't exist if it can't be
specialized 
(for debugging you could have flags to generate error messages but still 
ignore them). The real utility would be for things like const and shared 
with regards to containers or what not. Rather than, for example, wrap mutater 
methods in static ifs to turn them off when the type is const, you would 
just prefix the method with "try" and if the code odes something illegal, 
it is removed from the template.

Thoughts?
Apr 27 2009