Static functions in immutable types...
michal.minich at gmail.com
Tue Dec 8 01:42:42 PST 2009
> Dnia 07-12-2009 o 11:34:52 Michal Minich <michal.minich at gmail.com>
>> 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?
>> 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
>> 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.
> If by the lot of text above you meant it's a compiler bug, I agree :-)
I'm glad we agreed it is a bug :-)
How about the semantics I proposed ? If you agree I would include it in the
More information about the Digitalmars-d-learn