Michael Le Barbier Grünewald <
mich...@googlemail.com> writes:
> Hye!
>
> On Thursday, May 31, 2012 9:50:53 AM UTC+2, gwowen wrote:
>> On May 31, 7:23 am, Michael Le Barbier Grünewald
>> <
michip...@googlemail.com> wrote:
>> > If not, what is the best way to add memoisation?
>>
>> I've implemented a very simple memoisation like this: [code not
>> checked...]
>
> Thank you for your answer, yet it leadsd me to a few other questions.
>
> 1. If we write Btype::reallyEval(), does it mean `the *very* method
> defined by Btype'
Yes, the very method.
> or the overriden one? In the first case it means this memoisation
> scheme can only be used for leaf (final) classes, in the second that
> it does not work!
Well, the simple design is that a memoised<Btype> is a direct
replacement for a Btype. If your inheritance looks like this
A
|
B1-----memo<B1>
|
B1a----memo<B1a>
you can certainly have a memoised<B1> and a memoised<B1A>. But note that
a memoised<B1a> is not derived from a memoised<B1a>. In practice,
though, the fact a class is memoised<> should be completely transparent
for the code.
So you never derive from memoised<> -- each is a leaf class derived from
every non-abstract Bclass. Just replace a Btype_foo with a
memoised<Btype_foo> when each object is first instantiated.
> 2. reallyEval() is typically a private member, so we need to let
> memoise be a friend of Btype
Yes, or alternatively you may to have reallyEval() be protected, and not
private. It depends on whether you can change the definition of A.