Purity, @safety, etc., in generic code
kenji hara
k.hara.pg at gmail.com
Fri Feb 22 22:47:20 PST 2013
2013/2/23 deadalnix <deadalnix at gmail.com>
> On Friday, 22 February 2013 at 18:55:58 UTC, kenji hara wrote:
>
>> No, const/inout overload does not intend to solve 'method hiding' problem.
>>
>> To clarify the situation, I try to explain.
>>
>> class A {
>> void foo() {}
>> void foo() const {}
>> }
>>
>>
> You missed the important part. I'm talking about overload, not override.
> IE, not method hiding.
>
> What you have in class A here is useful for use cases that are now solved
> by inout (getting ranges/iterator from collection for instance).
>
What you intend is:
class A {
void foo() inout { bar() }
void bar() {}
void bar() const {}
}
void main() {
auto ma = new A();
ma.foo(); // call foo() inout, and bar() is called in it.
auto ca = new const A();
ca.foo(); // call foo() inout, and bar() const is called in it.
}
? If so, it is just *impossible*. Inout method does not work as like that.
Inside inout function, all inout qualified objects are treated as like
const. In there, you never call mutable method from inout object. It is the
inout design.
Kenji Hara
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20130223/dc5a4567/attachment-0001.html>
More information about the Digitalmars-d
mailing list