How will we fix opEquals?

Jason House jason.james.house at gmail.com
Thu Feb 10 06:15:36 PST 2011


Don Wrote:

> Andrei once stated a worthy goal: as far as possible, const should be 
> opt-in: it should be possible to code without requiring const on everything.
> 
> opEquals() is in conflict with this, since it is a member function of 
> Object.
> 
> (1) If it is a const member function, then it will have a viral effect 
> on all objects -- any function called by opEquals will have to be marked 
> const.
> (2) If it is not const, then const objects cannot be compared!
> 
> Currently, it's not const,  but the problem isn't visible because of 
> compiler bug 5080. (Same problem applies to opCmp).
> 
> How will we break this dilemma?

class LazyObject{
  bool OpEquals(LazyObject);
}

class Object : LazyObject{
  override bool OpEquals(LazyObject) const;
  bool opEquals(const Object) const;
}

By default, all classes derive from Object, but those that want to ignore viral const or implement lazy calculations can derive from LazyObject.


More information about the Digitalmars-d mailing list