[Dev] Josuttis vs Musser

M. Mueller (bhu5nji) dev@trilug.org
Thu, 14 Feb 2002 13:46:32 -0500


OK. Now I see the definition in the Container Ref. Guide in Musser et al, 
Section 21.3.8 Vector Element Access Member Functions:

reference operator[](size_type n);
const_reference operator[](size_type n) const;

  Returns the nth element from the begining of the vector in constant time.

operator[] defined for vector, deque, map.

[] is not defined for set (index is key, entry is key, [] is somewhat 
pointlesshere ), list (I would not have guessed that it doesn't exist because 
it's not RA), multiset (key is index, but multiple key values allowed, so [] 
is not determinate).

I was just getting to the point today of learning that lists are not RA.  
Thanks for saving me the headache.  I'll just use an iterator.

I'll be referring to my TODO list as my TODO vector from now on :-).

Mike


On Thursday 14 February 2002 01:17 pm, you wrote:
> Replace list with vector and I think it should work.  I don't
> think the operator[] is overloaded for list, because of the fact
> that it's not random access.  Everything else should work, though.
>
> Tanner
>
> On Thu, 2002-02-14 at 05:34, M. Mueller (bhu5nji) wrote:
> > I think I have some solid evidence to rank two STL books and it hinges on
> > example variety.
> >
> > The Josuttis book examples (downloaded from the web) often show that
> > sequence container (vector, deque, list) elements can be directly
> > accessed in a manner similar to arrays:
> >
> > list<string> a;
> >
> > if (a[3] == "blah") doSomething();
> >
> > I have a very simple language to parse.  I am told 4 position sensitive
> > things in a string.  I parse the string into a list, a,  of strings.  If
> > a.size() != 4 then I ignore the statement.  Otherwise, I start analysing
> > a[0]..a[3].
> >
> > A quick scan of Josuttis examples suggests this approach will work.  The
> > Musser et al book was not so helpful. The Musser et al book does use this
> > technique and the book's formal definition of the technique is still
> > hiding from me.
> >
> > These books are nearly $50 each.
> >
> >
> > _______________________________________________
> > Dev mailing list
> > Dev@trilug.org
> > http://www.trilug.org/mailman/listinfo/dev