On 08/14/2015 06:09 PM, D_Learner wrote: > When writting a pure fucntion involving C non pure functions
If you want to live dangerously, you can use assumePure, which is found in one of the unittest blocks of std.traits:
import std.traits; auto assumePure(T)(T t) if (isFunctionPointer!T || isDelegate!T) { enum attrs = functionAttributes!T | FunctionAttribute.pure_; return cast(SetFunctionAttributes!(T, functionLinkage!T, attrs)) t; } int i = 0; void foo() { ++i; // foo accesses mutable module-level data } void bar() pure { auto pureFoo = assumePure(&foo); pureFoo(); // <-- pure function is calling impure function } void main() { assert(i == 0); bar(); assert(i == 1); // mutation through a pure function } Ali