Optional tags and attributes

Rikki Cattermole alphaglosined at gmail.com
Fri Jan 17 17:52:55 PST 2014


On Saturday, 18 January 2014 at 00:57:27 UTC, Stanislav Blinov 
wrote:
> Obviously I didn't explain myself clearly. I know how to 
> determine if a function is nothrow or pure or @safe or anything 
> else thanks to D's awesomeness :) But what I want is a way to 
> *use* that knowledge when declaring my own functions. Or 
> rather, tell the compiler "Wait, I really want this to be 
> nothrow, but I don't know if that function will throw. Here's a 
> check for you, please make me nothrow if it passes". After all, 
> tags are not just for enforcing correctness at compile time, 
> they can be used (once verified) for optimization too. So it'd 
> be nice to find a way to provide all the nice info to the 
> compiler whenever possible. It's not just about nothrow, but 
> also pure, @safe/@system/@trusted, hell, even 
> public/protected/private for that matter. :)
>
>> That way you can have two declarations but with one being 
>> opposite of the if.
>
> ...Or four in case I'd also want pure/not pure, or nine if I'd 
> also want @safe/not @safe...

Okay, I'll explain what I was inferring. If the methods your 
calling are lets say nothrow which can be checked by a pure 
function lets say. Using the template if statement we can check 
that it does throw. For example:

void myfunc(T)(T arg) nothrow if (checkIfNothrow!T) {}
void myfunc(T)(T arg) if (checkIfNoModifiers!T) {}
void myfunc(T)(T arg) pure if (checkIfPure!T) {}

Basically you have to define all combinations. That is what I was 
meaning.
Preferably you'll use q{} your code that is actually used. And 
use a template mixin to generate all these statements, so you 
don't have to!


More information about the Digitalmars-d mailing list