473,410 Members | 1,908 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,410 software developers and data experts.

Container for different types of variables

m
Hello

I need to use sth. like container for different types of variables.
Is sth like this in c++ STL?

----|----------|--|----|------|etc.
var1| var2 |v3|var4| var5 |etc.
int | float |bo|int | char |etc.
m@j3R ;)
Jul 22 '05 #1
4 2747
On 5 Dec 2004 08:55:46 -0800, ma***@agdex.com (m@j3R ;) wrote:
I need to use sth. like container for different types of variables.
Is sth like this in c++ STL?


No, but a collection of boost::any's might do the job. http://www.boost.org

-- Mat.

Jul 22 '05 #2

"Mathew Hendry" <TJ**********@spammotel.com> wrote in message
news:7b********************************@4ax.com...
On 5 Dec 2004 08:55:46 -0800, ma***@agdex.com (m@j3R ;) wrote:
I need to use sth. like container for different types of variables.
Is sth like this in c++ STL?


No, but a collection of boost::any's might do the job. http://www.boost.org


It's possible, but you have to keep track somehow of the actual types of the
objects in the collection, or you can't get them back.

It really depends on what operations the OP needs to be able to perform on the
elements of the collection.

Jonathan
Jul 22 '05 #3
"m@j3R ;" <ma***@agdex.com> wrote in message
I need to use sth. like container for different types of variables.
Is sth like this in c++ STL?

----|----------|--|----|------|etc.
var1| var2 |v3|var4| var5 |etc.
int | float |bo|int | char |etc.


In C++, make a base abstract class Var. Now make classes Int, Float, etc
derived from it. Your container will be a std::deque<Var*>, or to make it
more easily memory safe std::deque<boost::shared_ptr<Var>>. Feel free to
add whatever pure virtual functions you want to class Var. You could make
your hierarchy more elaborate too, such as creating a class Float8 derived
from Float, Float16, etc.

You can use boost::any, as suggested in the other post. Looking at the
code, it seems the same as the above idea, except you don't have to create
class Var, Int, Float etc. So it should suffice in most circumstances.

Another thing is that one can think of std::ostringstream as a container of
heterogenous types.

std::ostringstream container;
container << intVal << ' ' << floatVal << ' ' << charVal << ' ' << boolVal;
Jul 22 '05 #4
On Sun, 05 Dec 2004 17:32:02 +0000, Mathew Hendry wrote:
On 5 Dec 2004 08:55:46 -0800, ma***@agdex.com (m@j3R ;) wrote:
I need to use sth. like container for different types of variables.
Is sth like this in c++ STL?


No, but a collection of boost::any's might do the job. http://www.boost.org


Or boost::variant.

--
I'm not a racist. I hate everyone equally!
Jul 22 '05 #5

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

Similar topics

5
by: Johan | last post by:
Hi, Hi like to create a linked list with a template class ( see below ). How to make one using the STL container list. I want to create a linked list with different kind of types i.e....
17
by: tuvok | last post by:
How can objects of different types be stored in a collection? For example: struct S1 { /*...*/ }; struct S2 { /*...*/ }; struct Sn { /*...*/ }; template<typename T> class X { public:
6
by: Robert | last post by:
Hello. I have been trying out the Lebans ToolTip Classes at http://www.lebans.com/tooltip.htm, to display "balloon" style help tips in a form. The classes I am using are located at...
1
by: glen stark | last post by:
Hi everyone. I would like to consider the following problem: I want to provide the ability to store and manipulate numeric container classes that provide 1) element wise access 2) size but...
21
by: aaragon | last post by:
Hello everyone, I would like to know if there is a way to use the std::map to store different types for one of its two types. That is, I'm trying to use it as: typedef...
5
by: fff_afafaf | last post by:
Do you know is it possible to put different kinds of tuples to one container? E.g. to a vector? (The lengths of the tuples are different, and also the types in the tuples are different.. -Is it...
6
by: Greg | last post by:
Is there a simple way to test if a control is a container type control (e.g. groupbox, panel etc) I realise that all container controls have to by definition, have the...
18
by: Goran | last post by:
Hi @ all! Again one small question due to my shakiness of what to use... What is better / smarter? private: vector<MyClass_t* itsVector; OR...
7
by: ademirzanetti | last post by:
Hi there !!! I would like to listen your opinions about inherit from a STL class like list. For example, do you think it is a good approach if I inherit from list to create something like...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
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
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,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.