www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - "try" functions

I just finished reading Bartosz latest post:


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)
    return t;

the feature is that the function simply doesn't exist if it can't be
(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.

Apr 27 2009