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 !
 
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
 

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
473,755
Messages
2,569,537
Members
45,022
Latest member
MaybelleMa

Latest Threads

Top