Fully transitive const is not necessary
Steven Schveighoffer
schveiguy at yahoo.com
Thu Apr 3 08:31:10 PDT 2008
"Janice Caron" wrote
> On 03/04/2008, Steven Schveighoffer wrote:
>> > Can you give me a counterexample of a logically const (muty) class in
>> > which the non-mutable subset is actually useful?
>>
>> Certainly:
>> <snip>
>
> In the example you just gave me, the non-mutable subset consisted of
> the empty set - i.e. no members whatsoever. I don't call that useful.
>
> Given that, the function pure f could just have easily have been taken
> outside the class altogether and been a standalone function.
>
> Do you want to try again?
Have you no imagination? :)
class SuperIntensiveCalculator
{
private mutable int[int] cache;
private int configParameterThatIsNecessaryForIntenseCalculation;
int f(int x) const
{
int *result = x in cache;
if(result !is null)
return result;
/* do really intense calculation, cache the value */
}
pure int puref(int x) invariant
{
/* do really intense calculation, do not use cache */
}
}
More information about the Digitalmars-d
mailing list