Boost logo

Boost :

From: Valentin Bonnard (Bonnard.V_at_[hidden])
Date: 1999-08-20 06:22:07


Greg Colvin wrote:

> My "moral equivalent" I meant that given a standard allocator if you follow
> out through all the typedefs you will hit a T*, on which all the indexing
> tricks will work. The standard does not yet require that, but I believe we
> are going to fix that.

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;
}

-- 
Valentin Bonnard

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