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

how to write a class that stores things in arbitrary stl container

is there a way to write a class that will be used to store a list of
things so that you can pass in the STL container type and it will be
filled with the right thing - something like (if it were legal) ...

std::vector < std::string > aList;

funkyList* theList = new funkyList < aList >;

theList->populate ();

std::vector < std::string >::iterator iter = theList->getIterator ();

.... hmmm.. as i'm writing that i realzie it's not making sense...
what i'm trying to do is allow consumers of the class to use any
storage they like and not enforce a std::vector, std::list etc...

maybe i need to just return my own iterator to the list and allow the
class consumer to do with each element what it wants rather than
returning the whole list.

comments appreciated.
Jul 22 '05 #1
2 1116

"3doutpost" <in**@3doutpost.com> wrote in message
news:ac**************************@posting.google.c om...
what i'm trying to do is allow consumers of the class to use any
storage they like and not enforce a std::vector, std::list etc...

Take a look at how std::queue is declared.

Jul 22 '05 #2
3doutpost wrote:
is there a way to write a class that will be used to store a list of
things so that you can pass in the STL container type and it will be
filled with the right thing - something like (if it were legal) ...

std::vector < std::string > aList;

funkyList* theList = new funkyList < aList >;

theList->populate ();

std::vector < std::string >::iterator iter = theList->getIterator ();

... hmmm.. as i'm writing that i realzie it's not making sense...
what i'm trying to do is allow consumers of the class to use any
storage they like and not enforce a std::vector, std::list etc...

maybe i need to just return my own iterator to the list and allow the
class consumer to do with each element what it wants rather than
returning the whole list.

comments appreciated.


template<template<class> class Container>
struct List {
Container<std::string> c;
};

Daniel
Jul 22 '05 #3

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

Similar topics

20
by: syd | last post by:
In my project, I've got dozens of similar classes with hundreds of description variables in each. In my illustrative example below, I have a Library class that contains a list of Nation classes. ...
1
by: Aaron Walker | last post by:
Hey folks, I've got some code for an options class that stores user run time options (as static members) so that they are availably any time an instance is created; currently the code has a...
6
by: Jon Slaughter | last post by:
Is there any way to get the class type from a pointer? I'm working on a class that acts as a set: I have two classes, one called FSet and the other called Element. FSet inherets Element and...
8
by: Zheng Da | last post by:
I don't know where should I ask the question, so send the email to this group. I choose this group, because I want to write the program with c++ :) I want to write a program which support...
21
by: Jon Slaughter | last post by:
I have a class that is basicaly duplicated throughout several files with only members names changing according to the class name yet with virtually the exact same coding going on. e.g. class...
11
by: food4uk | last post by:
Dear all : I am not good at programming, please give a hand. My data structure is very similar as an array. I actually can use the std::vector as container to organize my data objects. However,...
0
by: Buddy Home | last post by:
Hello, I'm trying to upload a file programatically and occasionally I get the following error message. Unable to write data to the transport connection: An established connection was aborted...
3
by: Buddy Home | last post by:
Hello, I'm trying to upload a file programatically and occasionally I get the following error message. Unable to write data to the transport connection: An established connection was aborted...
15
by: Juha Nieminen | last post by:
I'm sure this is not a new idea, but I have never heard about it before. I'm wondering if this could work: Assume that you have a common base class and a bunch of classes derived from it, and...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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...
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
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,...

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.