473,406 Members | 2,369 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Passing a list of types to a class template

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 !

Aug 24 '05 #1
1 1278
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
Aug 24 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: alg | last post by:
Is it possible to put different types of objects in a single STL list? If not what STL template should be used which will contains various objects of different types? Thanks for your help!
5
by: nifsmith | last post by:
Hi I am trying to learn about Queues and use templates at the same time. I have written the following code and I am getting a link error, stating "unresolved external symbol, "int__cdecl...
9
by: justanotherguy63 | last post by:
Hi, I am designing an application where to preserve the hierachy and for code substitability, I need to pass an array of derived class object in place of an array of base class object. Since I...
0
by: Jef Driesen | last post by:
I need some help to implement the adjacency list representation of a (undirected) graph. The data structure I need is something like the picture on the website...
6
by: Adam Hartshorne | last post by:
Hi All, I have the following setup. Two 'std::vector's which i iterate through in a for (iterate through vector1 of types X) { for (iterate through vector2 of types Y) { f(x) }
3
by: baumann | last post by:
hi all, Local classes and enumerations (in other words, types declared in a function definition) cannot be involved in template type arguments. Types that involve unnamed class types or...
5
by: Mark Stijnman | last post by:
I am trying to teach myself template metaprogramming and I have been trying to create lists of related types. I am however stuck when I want to make a template that gives me the last type in a...
3
by: Adam Nielsen | last post by:
Hi everyone, Yet another syntax problem that's baffling me with templates. I want to instantiate a template with a single parameter as per normal, however the parameter is actually a template...
4
by: colin | last post by:
Hi, Im trying to implement a generic list class for a number of 3d object types, that form a 3d solid model, take the easiest one Point for example, it contains a Vector3 and a list of other...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.