By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,171 Members | 1,020 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,171 IT Pros & Developers. It's quick & easy.

Generic collection class in C++

P: n/a
I was thinking of writing a generic container (i.e. collection) class in
C++. It would have iterators etc to allow traversing and acessing the
dat items.

The only problem arose when I tried to implement it, as I realised that
most of the STL containers actually required a type at compile time. Any
ideas on how to proceed with this? (or am I re-inveting the wheel here?)

Snippet of class:

template <class T>
class Collection
{
<snip>
</snip>
private:
vector<Tm_items ; //just an illustration, wont work. I know
};

I don't want to use template specialization because then the class is
not generic enough. Also, I would like to be able to store pointers in
such a collection, using value semantics, if possible - anyone knows how
to do this ?
Nov 7 '06 #1
Share this Question
Share on Google+
1 Reply


P: n/a

Bit Byte wrote:
I was thinking of writing a generic container (i.e. collection) class in
C++. It would have iterators etc to allow traversing and acessing the
dat items.

The only problem arose when I tried to implement it, as I realised that
most of the STL containers actually required a type at compile time. Any
ideas on how to proceed with this? (or am I re-inveting the wheel here?)

Snippet of class:

template <class T>
class Collection
{
<snip>
</snip>
private:
vector<Tm_items ; //just an illustration, wont work. I know
};

I don't want to use template specialization because then the class is
not generic enough. Also, I would like to be able to store pointers in
such a collection, using value semantics, if possible - anyone knows how
to do this ?
Use Boost.Any and/or a smart pointer. See
<http://boost.org/doc/html/any.html>.

Cheers! --M

Nov 7 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.