|
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 implementation...do 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 {
public:
size_t N;
// if carray is created by carray(n,elem), do not have ownership to elems.
T* elems;
// constructor
carray():N(0),elems(NULL){}
// create array
carray(size_t size):N(size){
elems = new T[size];
}
// destructor
~carray(){
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.
}
Bo
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net