Required constness of opEquals (and opCmp) ?
Ali Çehreli
acehreli at yahoo.com
Wed Jan 2 10:23:11 PST 2013
On 01/02/2013 01:07 AM, monarch_dodra wrote:
> I was wondering: Does Phobos require that user defined opEquals (and
> opCmp) be const?
Sorry that I am not adding to this topic directly but I will repeat an
observation of mine. My experience is with C++ and D; if there are
solutions to this issue in other languages, I am not aware of them.
What business does an interface have to affect the implementation of a
subclass that it has no idea of? When I introduce a function in an
interface (or an abstract base class in C++) I am split between making
it const or non-const.
const seemingly results in safer user code but either constrains the
implementation or forces it to use unsafe casts (or the 'mutable'
keyword in C++).
non-const is seemingly not restrictive but it lowers the usability of
the type.
As has already been mentioned, we must embrace 'inout' as a solution and
fix issues with its semantics and implementation.
Ali
More information about the Digitalmars-d
mailing list