template class

E

er

Hi all,

template<class P,template<class> class TC> class A{
typedef TC<P> tc_type;
/*...*/
};

template<class P1,class P2 > class B{/*...*/};

If I want to use B as a parameter in A, for each P2=p2, I need

template<class P1>
class B_p2: public B<P1,p2>{
typedef B<P1,p2> parent_type;
/* may have to write constructors such as B_p2(...):parent_type(...)
{} */
};

I can use it as:

A<P,B_p2> a_p_t2;

Is there a better way/more generic way than writing a new template
class for each P2?
 
G

gnuyuva

Hi all,

template<class P,template<class> class TC> class A{
typedef TC<P> tc_type;
/*...*/

};

template<class P1,class P2 > class B{/*...*/};

If I want to use B as a parameter in A, for each P2=p2, I need

template<class P1>
class B_p2: public B<P1,p2>{
typedef B<P1,p2> parent_type;
/* may have to write constructors such as B_p2(...):parent_type(...)
{} */

};

I can use it as:

A<P,B_p2> a_p_t2;

Is there a better way/more generic way than writing a new template
class for each P2?

How about this:

template <typename P1>
struct BindP2toB
{
typedef p2 P2;
typedef B<P1, P2> base_type;
};

template <typename P1, template<typename> class TC >
class A
{
typedef TC<P1>::base_type tc_type;
};

So, you can use it like:
A<P1, BindP2toB> a_p_t2;

Make sure that you get all 'base_type's defined for each class used
inside A.
 
E

er

How about this:

template <typename P1>
struct BindP2toB
{
typedef p2 P2;
typedef B<P1, P2> base_type;

};

template <typename P1, template<typename> class TC >
class A
{
typedef TC<P1>::base_type tc_type;

};

So, you can use it like:
A<P1, BindP2toB> a_p_t2;

Make sure that you get all 'base_type's defined for each class used
inside A.

Great, thanks!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,431
Messages
2,571,679
Members
48,796
Latest member
Greg L.

Latest Threads

Top