2 // This file is (C) 2002-2004 Royce Mitchell III
3 // and released under the LGPL & BSD licenses
16 explicit auto_vector ( size_t capacity
= 0 )
17 : _arr(0), _capacity(0), _end(0)
20 _arr
= new auto_ptr
<T
>[capacity
];
34 const auto_ptr
<T
>& operator [] ( size_t i
) const
40 auto_ptr
<T
>& operator [] ( size_t i
)
46 void assign ( size_t i
, auto_ptr
<T
>& p
)
52 void assign_direct ( size_t i
, T
* p
)
56 _arr
[i
].reset ( ptr
);
59 void push_back ( auto_ptr
<T
>& p
)
71 void push_back ( T
* p
)
76 //GCC is pedantic, this is an error.
77 //_arr[_end++] = auto_ptr<T>(p);
80 auto_ptr
<T
> pop_back()
85 auto_ptr
<T
> tmp((T
*)0);
87 //GCC, this is an error.
88 //return auto_ptr<T>(NULL);
93 void resize ( size_t newSize
)
95 ASSERT ( newSize
>= 0 );
96 reserve ( newSize
); // make sure we have at least this much room
100 void reserve ( size_t reqCapacity
)
102 if ( reqCapacity
<= _capacity
)
104 size_t newCapacity
= 2 * _capacity
;
105 if ( reqCapacity
> newCapacity
)
106 newCapacity
= reqCapacity
;
107 // allocate new array
108 auto_ptr
<T
> * arrNew
= new auto_ptr
<T
> [newCapacity
];
109 // transfer all entries
110 for ( size_t i
= 0; i
< _capacity
; ++i
)
112 _capacity
= newCapacity
;
115 // substitute new array for old array
119 void remove ( size_t off
)
121 size_t last
= _end
-1;
124 else if ( off
< last
)
126 auto_ptr
<T
> tmp ( pop_back().release() );
131 //typedef const_auto_iterator<T> const_iterator;
132 //const_iterator begin () const { return _arr; }
133 //const_iterator end () const { return _arr + _end; }
141 #endif//AUTO_VECTOR_H