Boost logo

Boost Users :

From: Daryle Walker (darylew_at_[hidden])
Date: 2004-12-14 19:48:07


On 12/13/04 5:42 PM, "Jim Lear" <jim.lear_at_[hidden]> wrote:

[SNIP]
> So in the absolute most abhorently poor code example (let's just call it
> "meta-code"), the map operator would behave like:
>
> data_type &operator[](const iterator &i) { return i->second; }
>
> Am I just too ignorant to make any sense? :-) Maybe I'll crawl back into my
> hole. :-)

As other posters have stated, you're misunderstanding how iterators are
used. They gave better explanations, but I'm butting in anyway.

An iterator by itself already contains enough information to dereference its
pointed-to element, or any sub-part of that element. You're asking for
something like:

int const a[] = { 1, 2, 3, 4 };
int const * p = &a[0];

assert( a[p] == 1 );

Hopefully you know that the "a[p]" expression is nonsensical in C++ (or C).
The library containers and iterators are (mostly) supposed to act like
built-in arrays and pointers. So the dereferencing semantics of STL is kept
as close as possible, but no closer, to built-in operations. Note that "p"
already has enough information to utilize the first element without
involving "a".

-- 
Daryle Walker
Mac, Internet, and Video Game Junkie
darylew AT hotmail DOT com

Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net