Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C++ typedef for partial templates

i need to do a typedef like this.

template< class A, class B, class C >
class X
{
};

template< class B, class C >
typedef X< std::vector<B>, B, C >  Y;

I just found that it is not supported in C++. Can someone advise me on how to achieve the same through alternative means?

Thanks, Gokul.

like image 342
Gokul Avatar asked Jun 08 '10 11:06

Gokul


1 Answers

If you have a C++0x/C++1x compiler, that will be allowed with a slightly different syntax (it seems as if compilers don't still support this feature):

template <typename B, typename C>
using Y = X< std::vector<B>, B, C >;

You can use other techniques, like defining an enclosed type in a templated struct (like Pieter suggests), or abusing inheritance (avoid if possible):

template <typename B, typename C>
class Y : public X< std::vector<B>, B, C > {};
like image 170
David Rodríguez - dribeas Avatar answered Oct 22 '22 07:10

David Rodríguez - dribeas