Hello Tomek,

... don't make sense. So is there a reason why they aren't excluded
from  the "everything in an immutable is immutable" rule?

Tomek


Immutable static member function could be useful...

marking struct or class as const or immutable is the same as marking every its member so. The problem I see is in definition of what const or immutable member function means:

from D specs: "Immutable member functions are guaranteed that the object and anything referred to by the this reference is immutable."

Which applies both to instance and s static functions. I think the above definition should apply only to instance functions. Static const or immutable functions should be defined as:

Immutable static member functions are guaranteed that the static variables of object and anything referred to by these variables is immutable.

static member function cannot modify member variables already, because they do not have this pointer. They would be only allowed to modify its arguments and global variables; they would be something like pure functions for the congaing type, but not for other world.

I'm not sure how this semantics could be useful in practice, but it seems definitely better to me than erroring out on static function inside immutable type.


Reply via email to