Logical const

Peter Alexander peter.alexander.au at gmail.com
Sat Nov 20 06:21:04 PST 2010


D does not support logical const due to the weak guarantees that it 
provides.

So, without logical const, how are D users supposed to provide lazy 
evaluation and memoization in their interfaces, given that the interface 
should *seem* const, e.g.

class Matrix
{
   double getDeterminant() const { /* expensive calculation */ }
}

If it turns out that getDeterminant is called often with the raw matrix 
data remaining unchanged, how can we add caching to this class without 
rewriting the const-ness of all code that touches it?

And how do we write generic code when it's practically impossible to 
determine const-ness from a glance? e.g. getDeterminant looks like it 
should be const, but wouldn't be if it had caching, so writing generic 
code that uses getDeterminant would be very difficult.


More information about the Digitalmars-d mailing list