Logical const in D
D has two types of constness: immutable variables are ones that were declared immutable, and always will be immutable, while const variables are simply read only versions of an object. Logical const is when a function is marked as const , but allows write access to one or more member variables. The typical use of this is for lazy evaluation, e.g. (in C++) struct Matrix { double determinant() const { if ( m_dirty ) { m_determinant = /* expensive calculation */; m_dirty = false; } return m_determinant; } void set(int i, int j, double x) { m_dirty = true; ...; } mutable bool m_dirty; mutable