Passing a list of types to a class template


A

Alfonso Morra

Hi,

I want to be pass a list (1..N) of (different) types to a class template
- and I wonder if this can be done. Actually, because there are
different types, I think I will have to use the set STL container
instead. Additionaly, I want to im[pose a restriction (trait?/policy?)
that the elements of this set are derived from a particular base class Base

So, I want to be able to write something like this :

class RestrictedSet {


};

template <RestrictedSet T1, typename T2 ec=ZLIB, typename T3 cp=ADLER>
// <- this looks plain wrong !
class A {

};


For those who may be wondering what I'm up to.. I'm writing a class
template wrapper around a communication library. There are 1..N
(actually N = 5) possible transports that could be used at any one time.
I want to write a clas template which efectively acts as a class
factory, that allows nme to instantiate an object that is correctly set
up (as per my specifications) for communications.

The more I think of possible solutions, the more (unnecessarily?)
complicated it seems to get ... Help !
 
Ad

Advertisements

G

Giulio Guarnone

Alfonso Morra ha scritto:
Hi,

I want to be pass a list (1..N) of (different) types to a class template
- and I wonder if this can be done. Actually, because there are
different types, I think I will have to use the set STL container
instead. Additionaly, I want to im[pose a restriction (trait?/policy?)
that the elements of this set are derived from a particular base class Base

So, I want to be able to write something like this :

class RestrictedSet {


};

template <RestrictedSet T1, typename T2 ec=ZLIB, typename T3 cp=ADLER>
// <- this looks plain wrong !
class A {

};


For those who may be wondering what I'm up to.. I'm writing a class
template wrapper around a communication library. There are 1..N
(actually N = 5) possible transports that could be used at any one time.
I want to write a clas template which efectively acts as a class
factory, that allows nme to instantiate an object that is correctly set
up (as per my specifications) for communications.

The more I think of possible solutions, the more (unnecessarily?)
complicated it seems to get ... Help !

I think you can.

std::string is a typdef of basic_string, something similar to :

namespace std
{
typedef string basic_string<char, char_traits<char>, allocator<char>);
}

bye, Giulio
 

Top