Optional tags and attributes

Stanislav Blinov stanislav.blinov at gmail.com
Fri Jan 17 16:20:26 PST 2014


Hopefully, now I'm posting to the right place (instead of 
.announce like last time >_<).

Is there a way to make function tags and attributes optional? For 
example, C++ has noexcept tag that takes an optional bool that 
actually enables or desables the whole specifier. I find its uses 
in C++ somewhat painful due to clumsy template syntax, but the 
value is there.

I found a discussion from 2010 about doing something similar in 
D, but it doesn't seem to have went far, and I don't know if 
anything has been done in this direction.



In essence, here's what I mean:

import std.traits;

template isNoThrow(alias func) {
   enum bool isNoThrow = (functionAttributes!func & nothrow_) != 0;
}

void thisIsSoPolymorphic(T)(T t) nothrow(isNoThrow!(T.unsure)) {
   // ...
   t.unsure();
   // ...
}

Without this behavior, I basically have to either drop nothrow 
entirely (bummer), or make two functions enclosed in static if 
checks, which obviously blows up if I want to make more tags 
optional.


More information about the Digitalmars-d mailing list