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 

Policies in templates with "variable" number of parameters.

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





PostPosted: Fri Feb 27, 2004 2:35 pm    Post subject: Policies in templates with "variable" number of parameters. Reply with quote



What is the best way to add a policy to a template like tuple<>?

The most obvious option that I can see is:

//all tuple assignment policies must be derived from this class.
struct tuple_assignment_policy {};

template < typename T1 = empty, typename T2 = empty, ... >
struct tuple
{
struct default_tuple_assignment_policy : tuple_assignment_policy {...};

typedef typelist<T1, T2, ...> types;

//find_derived< TypeList, Type, DefaultType >
//searches the TypeList for a type that is derived from Type
//if no such type is found, DefaultType is returned
typedef
typename find_derived< types,
tuple_assignment_policy,
default_tuple_assignment_policy >::type assignment_policy;

//use assignement_policy
...
};

struct my_assignment_policy : tuple_assignment_policy {...};

tuple< int, double > t1; //uses default_tuple_assignment_policy
tuple< int, double, char, my_assignment_policy > t2; //uses
my_assignment_policy

Eugene


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