From: Nick Ambrose (nicka_at_[hidden])
Date: 1999-08-31 19:07:13


Reid Sweatman wrote:

> > If you follow the typedefs, you find that pointer is T* and
> > iterator has an implementation dependent type.
> >
> > Still, all implementations uses the moral equivalent of T*
> > for iterator, and hopefully contiguity will soon be required.
> >
> > I can see room for a helper function:
> >
> > #include <vector>
> >
> > // A::pointer shall be T*
> > // non precondition: v is _not_ required to have any elements
> > template <typename T, class A>
> > inline
> > T* data (std::vector<T,A>& v) // as string::data (), but non const
> > {
> > return !v.empty() ? &v.front() : NULL;
> > }
> >
> > // A::pointer shall be T*
> > // non precondition: v is _not_ required to have any elements
> > template <typename T, class A>
> > inline
> > const T* data (const std::vector<T,A>& v) // as string::data ()
> > {
> > return !v.empty() ? &v.front() : NULL;
> > }
>
> I think this is closer to what I meant, in that you *could* pass an
> A::pointer to an assembly routine without worrying how it might mangle the
> pointer implementation.
>

But you still need the internal data to be in contiguous memory, unless you
make implemenations possibly require copying the entire vector to a new
contiguous buffer which basically defeats the purpose (it's slow and you can't
update the original vector)

Nick