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 

Combining dynamic and static policies

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





PostPosted: Sun Nov 26, 2006 5:05 am    Post subject: Combining dynamic and static policies Reply with quote



[I've also posted this on boost-user some days ago]

Hi,

I have the following task: There is an algorithm where you can set
different behaviors for creating a BFS tree. Currently this is done by
setting a policy object (dynamic), a function of which is called to
perform the search.

I'd like to use static policies here (as is done in generic Boost
algorithms), but still keep the possibility of setting the behavior
manually. The reason for this is: You can set the behavior using a
command line parameter, and it would be impractical to instantiate all
templates and then use a huge switch (think of combinations of several
policies) to choose the appropriate instantiation. Here a wrapper
(dynamic polymorphism) would be needed anyway, or any code using the
algorithm would need to be duplicated as well.

So my idea is as follows: There is a template parameter for a policy
class. Static policy exist for each possible behavior, as well for a
dynamic behavior. The "dynamic" policy class has virtual member
functions and there exists an inheriting dynamic class for each behavior.[1]

The algorithm then has a named param for the policy class. Default value
if to default-construct an object of the policy class. (If useful, the
template might have a default value for the policy template parameter as
well, so the user needn't do anything).

Has someone already taken this or a similiar approach? If so, could you
point me to a reference? What do you think of the approach?


Greeting,

Jens




[1] Hmmm ... Could this inheriting class be used as template parameter
without overhead? Other solution would be:

class dyn_behavior{

public:
virtual void perform_search(something ...) = 0;
}


class specific_dyn_behavior<class T> : dyn_behavior {
T behavior;

public:
void perform_search(something ...){
behavior.perform_search(something ...);
}
}

--
[ 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.