Pure not acting pure.

Lars T. Kyllingstad public at kyllingen.NOSPAMnet
Thu Jun 16 08:42:21 PDT 2011


On Thu, 16 Jun 2011 06:52:45 -0400, Michel Fortin wrote:

> On 2011-06-15 23:29:46 -0400, Charles McAnany <mcanance at rose-hulman.edu>
> said:
> 
>> Ah, so does the compiler figure out which ones are strongly and weakly
>> pure and then optimize as
>> appropriate? Is there a way to indicate that a function is strongly
>> pure? Because it would seem odd
>> to call a function you thought was pure and wind up with a mutated
>> argument.
> 
> Just make sure all the parameters are either const or immutable or
> passed by copy and do not contain any pointer or reference. That'll make
> the function strongly pure, and the compiler will be able optimize.

If you want a strongly pure function, the parameters need to be immutable 
or implicitly convertible to immutable.  const references may be mutated 
elsewhere.

-Lars


More information about the Digitalmars-d-learn mailing list