New to STL. Want to create a vector of bitsets (or any templated class)

From: as mellow as a horse (mail_at_MICKmoss42.fslife.co.uk)
Date: 06/25/04


Date: Fri, 25 Jun 2004 14:51:02 +0100

If you want you can skip this bumph and go down to the summary.

I'm new to stl like I say, but I know how to create a vector of built-in
data-types or my own classes (only non-templated ones, more later). I'm
still very hazy on iterators, but that can wait a bit.

I've just discovered the bitset container and realised it would provide a
good solution to a program I wrote a few years ago where I created long
bit-strings (typically 80 bits) using char arrays. Because bitsets are
fixed in length, and because those bitstrings I mentioned were logically
divided into smaller segments (not necessarily all of equal length) I would
want an array of these. That's easily done, but I recall I would also have
liked the bitstring to be of a non-fixed length either by extending the size
of a segment or inserting/appending another segment (or both).

So that's where vector comes in. Given a total bitstring length of 80
divided into segments such as (for example) 10, 15, 6, 13, 16, 8, 12 (should
total 80), I would like to do something like

// vector container (v) of size 7 already created (but how exactly?)
v[0] = new bitset<10> (500,000); // ideally a random number between 0 and
2^10, but good enough here
v[1] = new bitset<15> (2000000); // ditto for 2^15
etc.

SUMMARY:
But I've just realised I can't even work out how to create a vector
containing objects of any templated class (including my own), let alone an
stl container!
e.g.

vector<int> x[10]; // works fine
vector<CMyObject<int>> x[10]; // can't work out syntax for this!
vector<bitset<10>> x[7]; // ditto, and not what I want even if not!

If you've read the full message, you'll see the particular problem with the
latter example is that even if it did work, I would be stuck with a
container of bitsets all of the same size which I don't want.



Relevant Pages

  • Re: OO Style with Ada Containers
    ... Can you convince me that Ada.Containers is closer to STL than to Java ... But the burden of proof is on you, to prove that the container library ... A generic algorithm in Ada would look something like: ... procedure Generic_Algorithm (C: Cursor); ...
    (comp.lang.ada)
  • Re: VC9: STL: hash_set/map : hash_compare without operator < ???
    ... hash class and for an equal_to class. ... You mean the C++ standard library, not the STL. ... while the other must yield false, provided that the elements are not equal. ... This requires that the container can store multiple ...
    (microsoft.public.vc.language)
  • Re: Ada Popularity: Comparison of Ada/Charles with C++ STL (and Perl)
    ... I fully agree that we need a container library inside ... Just like the STL did. ... > I think the STL killed off all the other container libraries because ... string::string (int value) ...
    (comp.lang.ada)
  • Re: Is there something basic that I have missed on the upgrade to VS2005?
    ... > I have quite a bit of legacy code that initialises stl containers ... > called I get a debug assertion in the stl code "ITERATOR LIST ... been invalidated (e.g. by modifying the underlying container). ...
    (microsoft.public.vc.stl)
  • Re: Iterators redux
    ... > I am referring to the sort of STL syntax quoted by Harris: ... Inheriting from STL container classes is generally frowned upon as ... In order to make the above loop work with your own container class, ... Depending on the kind of iterator, you may also want to provide ...
    (comp.object)