"try" functions

BCS ao at pathlink.com
Mon Apr 27 12:02:19 PDT 2009


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?





More information about the Digitalmars-d mailing list