E. Gladyshev Guest
|
Posted: Fri Feb 27, 2004 2:35 pm Post subject: Policies in templates with "variable" number of parameters. |
|
|
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! ]
|
|