Re: Faking a non-pure function as pure

2018-02-17 Thread Nordlöw via Digitalmars-d-learn
On Friday, 16 February 2018 at 18:03:40 UTC, Ali Çehreli wrote: auto pureF = assumePure(); pureF(42); Ali Thanks!

Re: Faking a non-pure function as pure

2018-02-16 Thread Ali Çehreli via Digitalmars-d-learn
On 02/16/2018 09:58 AM, Nordlöw wrote: void g() pure {     static assert(!__traits(compiles, { auto x = f(42); }));     alias pureF = assumePure!(typeof());     // TODO: how do I call pureF?     // auto x = (*pureF)(42);     // auto x = pureF(42); } auto pureF = assumePure();

Faking a non-pure function as pure

2018-02-16 Thread Nordlöw via Digitalmars-d-learn
I'm struggling with my definition of assumePure that should make a non-pure function `f` callable as pure `pureF`. I've copied the definition of assumePure from the Phobos docs at https://dlang.org/phobos/std_traits.html#SetFunctionAttributes and managed to define pureF using it but I cannot