|
From: Luigi B. <lui...@gm...> - 2024-12-18 15:25:57
|
Here is one introduction: https://www.fluentcpp.com/2021/08/13/how-template-template-parameters-can-simplify-template-classes/ There is one difference with our case, though: in the post above, template template parameters are used to simplify the declaration but ordinary templates would work as well. In our case, we could not use ordinary templates because we would run into an infinite cycle: - the PiecewiseYieldCurve class needs Bootstrap as a template argument, because we might use different algorithms (the default, IterativeBootstrap, but also others); - IterativeBootstrap also needs the curve as a template argument, because it works with interest-rate curves but also default-probability curves, inflation curves etc.. Thus, using simple templates would lead to an infinite declaration: auto curve = PiecewiseYieldCurve<Discount, Linear, IterativeBootstrap<PiecewiseYieldCurve<Discount, Linear, IterativeBootstrap<... Passing the bootstrap class as a template template parameter breaks the cycle, Hope this helps, Luigi On Wed, Dec 18, 2024 at 1:44 PM Ming Zhu <mag...@ou...> wrote: > Dear all, > > In the definition of the PiecewiseYieldCurve class, I am puzzled by the > type definitions below: > > typedef PiecewiseYieldCurve<Traits,Interpolator,Bootstrap> this_curve; > > typedef Bootstrap<this_curve> bootstrap_type; > > Bootstrap is a template class taking one parameter. What template > parameter is used for Bootstrap in this_curve (i.e. > PiecewiseYieldCurve<Traits,Interpolator,Bootstrap>) in typedef > Bootstrap<this_curve> bootstrap_type? Can anyone recommend any reference > or book which explains the technique used here? > > Many thanks and happy holidays! > > Ming > > template <class Traits, class Interpolator, > template <class> class Bootstrap = IterativeBootstrap> > class PiecewiseYieldCurve > : public Traits::template curve<Interpolator>::type, > public LazyObject { > private: > typedef typename Traits::template curve<Interpolator>::type > base_curve; > typedef PiecewiseYieldCurve<Traits,Interpolator,Bootstrap> this_curve; > public: > typedef Traits traits_type; > typedef Interpolator interpolator_type; > typedef Bootstrap<this_curve> bootstrap_type; > > > > _______________________________________________ > QuantLib-users mailing list > Qua...@li... > https://lists.sourceforge.net/lists/listinfo/quantlib-users > |