one step towards unification of std.algorithm and std.string

Simen kjaeraas simen.kjaras at gmail.com
Thu Dec 31 00:18:32 PST 2009


On Wed, 30 Dec 2009 23:44:16 +0100, Steven E. Harris <seh at panix.com> wrote:

> Andrei Alexandrescu <SeeWebsiteForEmail at erdani.org> writes:
>
>> I think opEquals for classes is at fault for requiring const.
>
> Something seems different from C++'s const here. One can always call a
> const member function on a class instance in C++, regardless of whether
> the instance is referred to through a const or non-const reference. Is
> this bug saying that you can't call a const member function through a
> non-const reference to an instance?
>
> Or maybe it's complaining that your opEquals() declaration isn't const?
> If it's declared non-const, can one then not call it through a const
> reference to an instance? That would be bad.
>

Anything is implicitly castable to const in D, so it's the latter. This
is correct D:

struct foo {
   bool opEquals( const ref foo rhs ) const {
     return true;
   }
}

As long as that function is defined though, one may add as many other
opEquals signatures as one fancies.

-- 
Simen



More information about the Digitalmars-d mailing list