Login  Register

RE: Latest commits

Posted by Luigi Ballabio-2 on Jul 23, 2003; 5:27am
URL: http://quantlib.414.s1.nabble.com/Latest-commits-tp10269p10279.html

At 12:51 PM 7/23/03 +0200, Andre Louw wrote:
>Some questions on the so-called "named parameter paradigm" as per your
>comments on Scheduler.
>
>Scheduler s1 = MakeScheduler(mandatory parameters).withStubDate(d);
>Scheduler s2 = MakeScheduler(mandatory parameters).backwards();
>Scheduler s3 = MakeScheduler(mandatory
>parameters).withStubDate(d).backwards();

It would be something like:

class MakeScheduler {
   private:
     ... (mandatory parameters)
     Date stub;
     bool fromEnd;
     ... (other optional parameters)
   public:
     MakeScheduler(mandatory params) : copy mandatory parameters,
         fromEnd(false), ... {}
     MakeScheduler& withStubDate(const Date& d) { stub = d; return *this; }
     MakeScheduler& backwards() { fromEnd = true; return *this; }
     MakeScheduler& forwards() { fromEnd = false; return *this; }
     // when we're ready...
     operator Scheduler() {
         return Scheduler(mandatory params, stub, fromEnd, ...);
     }
};

i.e., no Scheduler is actually instantiated until the MakeScheduler thing
is assigned to one.

Bye,
         Luigi