Boost logo

Boost :

From: Valentin Bonnard (Bonnard.V_at_[hidden])
Date: 1999-09-05 16:47:30


Reid Sweatman wrote:

> No need to be insulting about it.

Of course not. I just wanted to end this thread.

> As has been pointed out, there is no
> guarantee that 1) the memory allocated by vector is in fact contiguous;

It's virtually guarantied (will be garantied by the next
Technical Corrigendum), and all implementation do it this
way, and knowing that it will be garantied no one sane
will do it any other way.

> and
> 2) the object returned as an iterator isn't guaranteed to fit in a pointer
> register on the target machine.

The iterator is implementation defined. It can be almost
anything. But vector<T, allocator<T>>::pointer is T*. I
have written two helper functions to get pointers instead
of iterators:

vb=Valentin Bonnard

vb> #include <vector>
vb>
vb> // A::pointer shall be T*
vb> // non precondition: v is _not_ required to have any elements
vb> template <typename T, class A>
vb> inline
vb> T* data (std::vector<T,A>& v) // as string::data (), but non const
vb> {
vb> return !v.empty() ? &v.front() : NULL;
vb> }
vb>
vb> // A::pointer shall be T*
vb> // non precondition: v is _not_ required to have any elements
vb> template <typename T, class A>
vb> inline
vb> const T* data (const std::vector<T,A>& v) // as string::data ()
vb> {
vb> return !v.empty() ? &v.front() : NULL;
vb> }

> If you can put my mind at ease on those two
> issues,

I hope it's done.

> I'll happily concede the point.

Thank you.

Valentin Bonnard wrote:

> > Reid Sweatman wrote:
> >
> > > To live
> > > with code that always expects to be handed pure pointers to
> > > raw arrays, you
> > > need a class like I was asking after. Unfortunately, none
> > > of the standard
> > > STL containers fit that bill.
> >
> > Once again, can you spell std::vector ?

-- 
Valentin Bonnard

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk