On Wed, 2008-04-09 at 15:40 +0200, Facchinetti Giorgio wrote:
> I am trying to use the LazyObject pattern, but I don't understand the
> reason behind the constness of calculate method.
Ciao Giorgio,
apologies for the delay. I agree that LazyObject::calculate doesn't
look much const. Unfortunately, it's going to be called inside methods
such as Instrument::NPV or YieldTermStructure::discount. These methods
must be const (conceptually, an instrument shouldn't change if you ask
for its value, so one should be able to call NPV on a const Instrument)
so they force LazyObject::calculate to be const as well. In turn, this
causes any cached data members to be mutable. It's not pretty, but it's
a common problem when caching calculations...
Luigi
--
Innovation is hard to schedule.
-- Dan Fylstra
-------------------------------------------------------------------------
This SF.net email is sponsored by the 2008 JavaOne(SM) Conference
Don't miss this year's exciting event. There's still time to save $100.
Use priority code J8TL2D2.
http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users