Pure functions in D

Sean Kelly sean at invisibleduck.org
Mon Sep 29 15:38:32 PDT 2008


== Quote from bearophile (bearophileHUGS at lycos.com)'s article
> Sean Kelly:
> > Otherwise, something like this should work:
> > void debugln_(...) { /* forward to writefln */ }
> > alias pure void function(...) SomeFn;
> > SomeFn debugln = cast(pure SomeFn) &debugln_;
> I think you have written a static cast from the function pointer of an impure function to a function
pointer of a pure function. I kind of hope the compiler will forbid a cast like that, I think it may give
troubles :-)

The compiler allows one to add "invariant" with a cast, so why not "pure?"  Casting
is basically a sledgehammer emblazoned with the label "trust me, I know what I'm
doing."


Sean



More information about the Digitalmars-d mailing list