On Mar 4, 10:20 am, gnuyuva <gnuy...@[EMAIL PROTECTED]
> wrote:
> On Mar 4, 6:24 pm, er <erwann.rog...@[EMAIL PROTECTED]
> wrote:
>
>
>
> > 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.
Great, thanks!


|