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

Michel Fortin michel.fortin at michelf.com
Wed Dec 30 15:28:37 PST 2009


On 2009-12-30 17:44:16 -0500, "Steven E. Harris" <seh at panix.com> said:

> 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.

The thing is that const is transitive in D. That and you can't make a 
variable mutable in a const object; you can in C++ with the mutable 
keyword. So you want to use const only when you know you won't change 
anything through that reference.

-- 
Michel Fortin
michel.fortin at michelf.com
http://michelf.com/




More information about the Digitalmars-d mailing list