Purity with references and pointers

Simen kjaeraas simen.kjaras at gmail.com
Sat Sep 18 18:30:06 PDT 2010


Jonathan M Davis <jmdavisProg at gmx.com> wrote:

> Except that since when is anything implictly convertable to immutable?
> Implicitly converted to const, yes. That happens often enough, but  
> immutable?

Anything that does not contain pointers or references to non-immutable
data is implicitly convertible to immutable, if passed by value.


> And you definitely don't have to use immutable references with pure  
> functions.

That sounds like a bug. Unless you mean things like immutable(char)[],
which is implicitly convertible to immutable, according to the above rules.


> I have gotten some const-related errors when using pure on member  
> functions, so
> I get the impression that using pure on a member function implicitly  
> makes it
> const, but I'm not sure if that's enough.

The 'this' pointer is also a parameter to a function, so also needs to
be immutable.

-- 
Simen


More information about the Digitalmars-d-learn mailing list