Question about pure functions

Bienlein jeti890 at web.de
Mon Sep 16 01:39:00 PDT 2013


> Mark all parameters const to get a strong pure function. For 
> "this" const goes on the method:
>
> class Foo {
> 	int i = 0;
> 	
> 	void bar() const pure {
> 	    // can't mutate i here
> 	}
> }
>
> See also: http://dlang.org/function.html#pure-functions

I see, thanks a lot. I like this pure feature and was already
disappointed. Scala doesn't have it (has to remain interoperable
with Java), so I was really happy to see it in D. Your answer
saved my day :-)

-- Bienlein


More information about the Digitalmars-d-learn mailing list