Re: vector acces by index/iterator
From: SaltPeter (SaltPeter_at_Jupiter.sys)
Date: 07/20/04
- Next message: Omid: "Redirect COUT to file"
- Previous message: Connell Gauld: "Visual C++ 6 Compile Error"
- In reply to: Richard Herring: "Re: vector acces by index/iterator"
- Next in thread: Richard Herring: "Re: vector acces by index/iterator"
- Reply: Richard Herring: "Re: vector acces by index/iterator"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Tue, 20 Jul 2004 10:09:06 -0400
"Richard Herring" <junk@[127.0.0.1]> wrote in message
news:NH0bNVc2tP$AFwSQ@baesystems.com...
> In message <kF3Lc.16349$Gf7.528126@news20.bellglobal.com>, SaltPeter
> <SaltPeter@Jupiter.sys> writes
> >
> >"DaKoadMunky" <dakoadmunky@aol.com> wrote in message
> >news:20040719222806.10778.00001547@mb-m25.aol.com...
> [...]
>
> >> My thinking is that since both an array and a vector use a single
> >contiguous
> >> block of memory and that to access an individual element in either an
> >array or
> >> vector requires the same pointer arithmetic that the performance would
be
> >> comparable in the presence of inlining for the vector operator[].
> >
> >The standard guarentees that *any* element of the vector container is
> >accessed using a constant time period (so any element is accessed with
the
> >same access period as the container's first element). There is a
> >misconception out there that a vector is like a list where each element
> >pointing to the next. This is not the case.
>
> It's not a misconception I've noticed. YMMV.
>
> > Vectors use random iterators.
> >These aren't available to either the array or std::list.
>
> Arrays have random-access iterators. They're called pointers.
>
> A {random-access, bidirectional, forward, input, output} iterator is
> anything satisfying the requirements of {random-access, bidirectional,
> forward, input, output} iterator (24.1). A pointer into an array does
> everything that's needed for a random-access iterator, therefore it is
> one. As witness the fact that many implementations of std::vector use
> raw pointers as their iterators.
>
> >And the array
> >doesn't even have a conception of what an iterator is.
>
> The only iterator-related things that arrays lack are the functions
> which return them.
Yep, well i deserved that response.
What i was refering to was the support for the said iterators as your last
comment mentions. In other words, an array doesn't have an end(). :)
>
> [...]
>
> --
> Richard Herring
- Next message: Omid: "Redirect COUT to file"
- Previous message: Connell Gauld: "Visual C++ 6 Compile Error"
- In reply to: Richard Herring: "Re: vector acces by index/iterator"
- Next in thread: Richard Herring: "Re: vector acces by index/iterator"
- Reply: Richard Herring: "Re: vector acces by index/iterator"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|