Serving the Quantitative Finance Community

 
User avatar
Cuchulainn
Topic Author
Posts: 23029
Joined: July 16th, 2004, 7:38 am

Ask Luigi

October 19th, 2005, 7:36 pm

Luigi,I would like to define pointers to member functions in as nice a way as possible. I have seen how Dr. Bjarne has done this with an example in his book (of course u know the page number) but I would like to do it in general. Is there some nice template/policy class solution?Here is test caseclass Option{// datapublic: double Price(double S) const = 0;double Delta(double S) const = 0;double Gamma(double S) const = 0;// etc.};Then I can select members at run-time (like in C# delegates).ThanksDD
Last edited by Cuchulainn on March 22nd, 2006, 11:00 pm, edited 1 time in total.
 
User avatar
lballabio
Posts: 0
Joined: January 19th, 2004, 12:34 pm

Ask Luigi

October 20th, 2005, 6:45 am

What do you mean with "select"? What should the client code look like?
 
User avatar
Cuchulainn
Topic Author
Posts: 23029
Joined: July 16th, 2004, 7:38 am

Ask Luigi

October 20th, 2005, 7:41 am

QuoteOriginally posted by: lballabioWhat do you mean with "select"? What should the client code look like?Ideallly, I sayopt.Execute('Price", 100.0);but this needs Reflection.But in V1 we could sayFunP = Option'::'Price;cout << FunP(100.0);
Last edited by Cuchulainn on October 19th, 2005, 10:00 pm, edited 1 time in total.
 
User avatar
janzen

Ask Luigi

October 20th, 2005, 8:14 am

Er, see below...
Last edited by janzen on October 19th, 2005, 10:00 pm, edited 1 time in total.
 
User avatar
ckarakus
Posts: 1
Joined: October 28th, 2004, 8:05 am

Ask Luigi

October 20th, 2005, 8:54 am

why dont u use boost function template.it handles- member funcctions- plain odd functions- function objectsin a uniform way. I call it "function convergence". It does it so through TMP techniques
 
User avatar
Cuchulainn
Topic Author
Posts: 23029
Joined: July 16th, 2004, 7:38 am

Ask Luigi

October 20th, 2005, 9:02 am

QuoteOriginally posted by: ckarakuswhy dont u use boost function template.it handles- member funcctions- plain odd functions- function objectsin a uniform way. I call it "function convergence". It does it so through TMP techniquesThe solution must be ANSI C++. Many compilers have difficulty with of because of the exotic use of templates.I would like a standard mini version, one that is easy to implement and apply without any hassle.
 
User avatar
janzen

Ask Luigi

October 20th, 2005, 9:14 am

(Oops, sorry for blank post earlier; I'm new here...)Boost function templates would certainly work, as would plain old std::mem_fun.You could try the method I use in this little example program, which selects the function either by a string containing its name, or by an expression such as 'std::mem_fun(&Option::Price)'. (This could be made a bit prettier by a small 'getFunction(&Option::Price)' wrapper, I suppose.)Unfortunately, to select by a string containing the name one still ends up having to invent some sort of homebrew reflection mechanism.
Attachments
mem_fun.cpp.zip
(980 Bytes) Downloaded 123 times
 
User avatar
lballabio
Posts: 0
Joined: January 19th, 2004, 12:34 pm

Ask Luigi

October 20th, 2005, 9:25 am

Ckarakus is right, boost::function would be the best solution. Otherwise, you can writeoption.execute(&Option::Price, 100.0);if you define execute as:double Option::execute(double (Option::*f)(double), double x) {return (this->*f)(x);}but the problem is that you want the choice to be made at run-time. The call to execute above implies that you know what function to call at compile-time.To select the method at run-time you'd have to initialize and store somewhere a mapping between strings and methods.Luigi
Last edited by lballabio on October 19th, 2005, 10:00 pm, edited 1 time in total.
 
User avatar
Cuchulainn
Topic Author
Posts: 23029
Joined: July 16th, 2004, 7:38 am

Ask Luigi

October 20th, 2005, 11:10 am

Thanks everyone here.
 
User avatar
Cuchulainn
Topic Author
Posts: 23029
Joined: July 16th, 2004, 7:38 am

Ask Luigi

November 10th, 2005, 3:55 pm

Luigi,Do you know where I can find a compact overview for novices on the basics of hpp and cpp files, include paths and source files? Basically, building a project and FAQs, Not rocket science but not gettting it right means we lose a lot of time. Counterexample: copy all files into local directory, It's not pretty, it works and people do this because the better way has not been documented?thanksDD
Last edited by Cuchulainn on November 9th, 2005, 11:00 pm, edited 1 time in total.
 
User avatar
lballabio
Posts: 0
Joined: January 19th, 2004, 12:34 pm

Ask Luigi

November 11th, 2005, 8:01 am

QuoteOriginally posted by: CuchulainnDo you know where I can find a compact overview for novices on the basics of hpp and cpp files, include paths and source files?No, I can't recall any. I might try and Google a bit later...
 
User avatar
Cuchulainn
Topic Author
Posts: 23029
Joined: July 16th, 2004, 7:38 am

Ask Luigi

November 11th, 2005, 10:16 am

QuoteOriginally posted by: lballabioQuoteOriginally posted by: CuchulainnDo you know where I can find a compact overview for novices on the basics of hpp and cpp files, include paths and source files?No, I can't recall any. I might try and Google a bit later...Ok, it's a recurring theme that I see all over the place,Wilmott, Quantlib, courses, projects etc.Don't suppose you feel like writing on in the weekend?Maybe some Wilmotter could write it?
Last edited by Cuchulainn on November 10th, 2005, 11:00 pm, edited 1 time in total.
 
User avatar
lballabio
Posts: 0
Joined: January 19th, 2004, 12:34 pm

Ask Luigi

November 11th, 2005, 10:44 am

QuoteOriginally posted by: CuchulainnDon't suppose you feel like writing on in the weekend?No---I'm already writing QuantLib documentation (surprise, surprise)Luigi
 
User avatar
TraderJoe
Posts: 1
Joined: February 1st, 2005, 11:21 pm

Ask Luigi

November 11th, 2005, 9:44 pm

QuoteOriginally posted by: CuchulainnQuoteOriginally posted by: lballabioQuoteOriginally posted by: CuchulainnDo you know where I can find a compact overview for novices on the basics of hpp and cpp files, include paths and source files?No, I can't recall any. I might try and Google a bit later...Ok, it's a recurring theme that I see all over the place,Wilmott, Quantlib, courses, projects etc.Don't suppose you feel like writing on in the weekend?Maybe some Wilmotter could write it?Why can't you do it?
 
User avatar
Cuchulainn
Topic Author
Posts: 23029
Joined: July 16th, 2004, 7:38 am

Ask Luigi

November 12th, 2005, 1:42 pm

> Why can't you do it?Yes, will do now. I had not planned on it, that's the point. Will have to get in the mood Mind above matter Even Luigi is making excuses for not doing it Seriously, it's amazing that this doc. does not exist. Novices lose sooooooooo much time just setting up a project.