On Tuesday, 26 June 2012 at 18:35:31 UTC, Jonathan M Davis wrote:
You could try std.traits.SetFunctionAttributes (it was recently
added and is
not in 2.59 IIRC). David Nadlinger created it specifically for
being able to
create easily add function attributes such as pure to a
function. I haven't
messed around with it yet, but it looks very easy to use.
I created it specifically for a related use case, but on its own,
SetFunctionAttributes is strictly for manipulating
function/delegate _types_ in terms of linkage. This is helpful
because the D grammar for function types is quite clumsy.
For example, the following is not valid D code, and can't
trivially be corrected (in the first case, creating a separate
alias for the function type would work, but that's clumsy
especially in generic and/or generated code):
---
void foo(extern(C) void function() nothrow cb);
auto assumePure(T)(T t) { return cast(pure T)(t); }
---
As mentioned in
https://github.com/D-Programming-Language/phobos/pull/555, it
would be easy to add »high-level primitives« on top of
SetFunctionAttributes; assumePure and ExternC templates are
included as examples its the documentation. Specifically for
declaring »trusted pure« functions, making »alias
assumePure!funcImpl func;« work would not be hard either.
I just was not sure which of those tools are needed frequently
enough to warrant inclusion in Phobos, if any.
David