DEVELOP > c-Plus-Plus > how to write a class that stores things in arbitrary stl container
| Topic: |
DEVELOP > c-Plus-Plus |
| User: |
"3doutpost" |
| Date: |
01 Dec 2004 02:45:24 PM |
| Object: |
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.
.
|
|
| User: "Xenos" |
|
| Title: Re: how to write a class that stores things in arbitrary stl container |
01 Dec 2004 02:55:58 PM |
|
|
"3doutpost" <info@3doutpost.com> wrote in message
news:acd01d3e.0412011245.3de6143b@posting.google.com...
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.
.
|
|
|
|
| User: "Daniel Mitchell" |
|
| Title: Re: how to write a class that stores things in arbitrary stl container |
05 Dec 2004 01:17:01 AM |
|
|
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
.
|
|
|
|

|
Related Articles |
|
|