Marking a delegate as pure, nothrow, etc.

Dicebot public at
Sun Apr 13 11:10:18 PDT 2014

On Sunday, 13 April 2014 at 18:02:15 UTC, Joseph Rushton Wakeling 
> On 13/04/14 19:58, Joseph Rushton Wakeling wrote:
>> Is it possible to mark a delegate as pure, @safe, nothrow, 
>> etc.?  And if so, how?
> ... just answered my own question with a bit more 
> experimentation.  The declarations need to come _after_ the 
> delegate:
>     void foo(int delegate(int) @safe nothrow pure dg)
>     {
>         ...
>     }

I'd actually recommend to put all function attributes after 
parameter list even for normal function declarations. It is not 
widely accepted practice but helps avoid some confusion:

// `const` does not apply to return param here but to foo itself
const int* foo() { return null; }
// makes it obvious
int* foo() const { return null; }

More information about the Digitalmars-d-learn mailing list