C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Runtime selection of inlined function

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ Language (Moderated)
View previous topic :: View next topic  
Author Message
Guest






PostPosted: Sat Dec 16, 2006 10:10 am    Post subject: Runtime selection of inlined function Reply with quote



I'm attempting to devise a way of selecting an inlined function to call
depending on the value of a variable at runtime without having to make
changes to the calling code when changing the called functions or
adding new functions.

To be clear, the goal is to have the call inlined and to not have to
change code at the call site to maintain the set of callable functions.

If changing the calling code on an ongoing basis was an option I could
obviously do:

switch (conf.fctnum) {
case 1: a(); break;
case 2: b(); break;
...
}

What I imagine I want to do is define and "register" functions in
separate header files before including header containing the calling
code.

Thank you for any help.

/Kim


--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
Back to top
Carl Barron
Guest





PostPosted: Sun Dec 17, 2006 12:22 am    Post subject: Re: Runtime selection of inlined function Reply with quote



In article <1166227595.073947.305680 (AT) 73g2000cwn (DOT) googlegroups.com>,
<scheibel (AT) gmail (DOT) com> wrote:

Quote:
I'm attempting to devise a way of selecting an inlined function to call
depending on the value of a variable at runtime without having to make
changes to the calling code when changing the called functions or
adding new functions.

To be clear, the goal is to have the call inlined and to not have to
change code at the call site to maintain the set of callable functions.

See boost [or tr1] function.

If your compile once function also has a boost::function argument
then you can overload it in the various headers to be callled with
a specific boost::function instance.

void bar(boost::function<void(void)>);

namespace
{
inline void foo() {/**/}
inline void bar() { bar(foo);}
}
if you want different headers in different compilation units of the
program.
void bar(boost::function<void(void) call_me)
{
//...
call_me();
// ...
}
needs to be compiled once. But the calls are not really inlined.

--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
Back to top
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ Language (Moderated) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.