Marking a delegate as pure, nothrow, etc.

Meta jared771 at gmail.com
Sun Apr 13 11:09:35 PDT 2014


On Sunday, 13 April 2014 at 17:58:27 UTC, Joseph Rushton Wakeling 
wrote:
> Is it possible to mark a delegate as pure, @safe, nothrow, 
> etc.?  And if so, how?

If it's while creating a delegate literal, it's valid to mark it 
with @safe pure nothrow:

auto n = delegate int() @safe pure nothrow { return 1; };

If it's an already-existing delegate, you can use a cast:

auto m = 0;
auto del = delegate int() @system { throw new Exception("test"); 
return m; }
cast(int delegate() @safe pure nothrow)del //del is now @safe 
pure nothrow


More information about the Digitalmars-d-learn mailing list