Boost logo

Boost Users :

From: Bo Peng (bpeng_at_[hidden])
Date: 2004-06-15 01:11:05

On Mon, Jun 14, 2004 at 10:51:12PM -0700, Victor A. Wagner Jr. wrote:
> that's the answer on YOUR NOT make assumptions about
> how all are implemented.

I am aware of this. The implementation I checked is for gcc 3.2.2.
However, there has to be some overheads (several pointers at least) in
any vector implementation. Something between boost::array and
std::vector can be useful.

What is in my mind is a version of boost::array that can has 0 or a
fixed length. It might look like:

template<class T>
class carray {
  size_t N;
  // if carray is created by carray(n,elem), do not have ownership to elems.
  T* elems;
  // constructor

  // create array
  carray(size_t size):N(size){
    elems = new T[size];
  // destructor
    if(elems!=NULL) delete[] elems;
  // copy constructor,
  // can copy from carray, boost::array or vector
  // maybe some constructors as those in vector (vec(ptr1, ptr2))
  // or things like carray(int n, T* t) to assemble carray
  // from existing array t without copying things...
  // resize, can be called only when N=0.
  resize(int n){ .... }

  // iterators and everything else can be copied directly
  // from boost::array.



Boost-users list run by williamkempf at, kalb at, bjorn.karlsson at, gregod at, wekempf at