6template <
class T>
inline void BCP_vec<T>::destroy(iterator pos)
11template <
class T>
inline void BCP_vec<T>::destroy_range(iterator first, iterator last)
13 while (first != last) {
18template <
class T>
inline void BCP_vec<T>::construct(iterator pos)
20 ::new(
static_cast<void*
>(pos)) T();
23template <
class T>
inline void BCP_vec<T>::construct(iterator pos, const_reference x)
25 ::new(
static_cast<void*
>(pos)) T(x);
32 return static_cast<iterator>(::operator
new(len *
sizeof(T)));
39 ::operator
delete(
start);
51 const size_t len = (2*
size() + 0x100);
53 iterator tmp_finish = std::uninitialized_copy(
start, position, tmp);
54 construct(tmp_finish++, x);
55 tmp_finish = std::uninitialized_copy(position,
finish, tmp_finish);
81 std::uninitialized_fill_n(
start, n, value);
89 const size_t len = last - first;
102 const T*
const lastx = x + num;
104 construct(
finish++, *x++);
134 const size_t x_size = x.
size();
144 destroy_range(
finish, oldfinish);
164 destroy_range(start, finish);
168 const char* charx =
static_cast<const char*
>(x);
169 for (
int i = num; i > 0; --i) {
170 memcpy(&
entry, charx,
sizeof(T));
177 const void* first,
const size_t n)
181 const char* charx =
static_cast<const char*
>(first);
183 const size_t to_move =
finish - position;
185 std::uninitialized_copy(position,
finish, position + n);
188 for ( ; i > to_move; --i) {
189 memcpy(&
entry, charx,
sizeof(T));
190 construct(position++,
entry);
193 for ( ; i > 0; --i) {
199 std::uninitialized_copy(finish - n, finish, finish);
200 std::copy_backward(position, finish - n, finish);
202 for (
int i = n; i > 0; --i) {
203 memcpy(&entry, charx,
sizeof(T));
209 const size_t new_size = (2*size() + n);
211 iterator tmp_finish = std::uninitialized_copy(
start, position, tmp);
212 for (
int i = n; i > 0; --i) {
213 memcpy(&
entry, charx,
sizeof(T));
214 construct(tmp_finish++,
entry);
217 tmp_finish = std::uninitialized_copy(position, finish, tmp_finish);
221 end_of_storage = tmp + new_size;
229 if (first == last)
return;
230 const size_t n = last - first;
232 const size_t to_move =
finish - position;
234 std::uninitialized_copy(position,
finish, position + n);
235 std::copy(first, first + to_move, position);
236 std::uninitialized_copy(first + to_move, last,
finish);
238 std::uninitialized_copy(finish - n, finish, finish);
239 std::copy_backward(position, finish - n, finish);
240 std::copy(first, last, position);
244 const size_t new_size = (2*size() + n);
245 iterator tmp = allocate(new_size);
246 iterator tmp_finish = std::uninitialized_copy(start, position, tmp);
247 tmp_finish = std::uninitialized_copy(first, last, tmp_finish);
248 tmp_finish = std::uninitialized_copy(position, finish, tmp_finish);
252 end_of_storage = tmp + new_size;
261 const size_t to_move =
finish - position;
263 std::uninitialized_copy(position,
finish, position + n);
264 std::fill_n(position, to_move, x);
265 std::uninitialized_fill_n(
finish, n - to_move, x);
269 std::fill_n(position, n, x);
273 const size_t new_size = (2*
size() + n);
275 iterator tmp_finish = std::uninitialized_copy(
start, position, tmp);
276 std::uninitialized_fill_n(tmp_finish, n, x);
278 tmp_finish = std::uninitialized_copy(position,
finish, tmp_finish);
289 const size_t n = position -
start;
323template <
class T>
void
327 if (positions.
size() == 0)
332 while (pos != lastpos)
339 if (positions.
size() != values.
size())
340 throw BCP_fatal_error(
"BCP_vec::update() called with unequal sizes.\n");
351 destroy_range(
finish, oldfinish);
358 destroy_range(
finish, oldfinish);
361template <
class T>
inline void
368template <
class T>
inline void
374template <
class T>
inline void
379 unchecked_keep_by_index(firstpos, lastpos);
382template <
class T>
void
386 if (firstpos == lastpos) {
389 iterator target = start;
390 while ( firstpos != lastpos )
391 *target++ = operator[](*firstpos++);
392 destroy_range(target, finish);
401 if (position + 1 !=
finish)
402 std::copy(position + 1,
finish, position);
410 destroy_range(
finish, oldfinish);
413template <
class T>
inline void
420template <
class T>
inline void
426template <
class T>
inline void
431 unchecked_erase_by_index(firstpos, lastpos);
434template <
class T>
void
438 if (firstpos == lastpos)
442 iterator target = entry(*firstpos);
443 while (firstpos != lastpos){
444 source = *firstpos + 1;
446 if (*firstpos > source)
447 target = std::copy( entry(source), entry(*firstpos), target );
449 iterator oldfinish = finish;
450 finish = std::copy( entry(*firstpos + 1), end(), target );
451 destroy_range(finish, oldfinish);
void BCP_vec_sanity_check(BCP_vec< int >::const_iterator firstpos, BCP_vec< int >::const_iterator lastpos, const int maxsize)
A helper function to test whether a set positions is sane for a vector.
Currently there isn't any error handling in BCP.
void deallocate()
Destroy the entries in the vector and free the memory allocated for the vector.
void clear()
Delete every entry.
void unchecked_keep_by_index(const BCP_vec< int > &positions)
Same as the previous method but without the sanity checks.
void pop_back()
Delete the last entry.
const T & const_reference
void push_back(const_reference x)
Append x to the end of the vector.
iterator end_of_storage
Iterator pointing to right after the last memory location usable by the vector without reallocation.
void keep_by_index(const BCP_vec< int > &positions)
Keep the entries indexed by indices.
void unchecked_push_back(const_reference x)
Append x to the end of the vector.
void erase_by_index(const BCP_vec< int > &positions)
Erase the entries indexed by indices.
iterator end()
Return an iterator to the end of the object.
size_t size() const
Return the current number of entries.
void keep(iterator pos)
Keep only the entry pointed to by pos.
reference operator[](const size_t i)
Return a reference to the i-th entry.
BCP_vec< T > & operator=(const BCP_vec< T > &x)
Copy the contents of x into the object and return a reference the the object itself.
void erase(iterator pos)
Erase the entry pointed to by pos.
iterator entry(const int i)
Return an iterator to the i-th entry.
size_t capacity() const
Return the capacity of the object (space allocated for this many entries).
iterator start
Iterator pointing to the beginning of the memory array where the vector is stored.
iterator finish
Iterator pointing to right after the last entry in the vector.
iterator begin()
Return an iterator to the beginning of the object.
void update(const BCP_vec< int > &positions, const BCP_vec< T > &values)
Update those entries listed in positions to the given values.
void unchecked_update(const BCP_vec< int > &positions, const BCP_vec< T > &values)
Same as the previous method but without sanity checks.
BCP_vec()
The default constructor initializes the data members as 0 pointers.
void reserve(const size_t n)
Reallocate the object to make space for n entries.
void swap(BCP_vec< T > &x)
Exchange the contents of the object with that of x.
iterator allocate(size_t len)
allocate raw, uninitialized memory for len entries.
void unchecked_erase_by_index(const BCP_vec< int > &positions)
Same as the previous method but without the sanity check.
void insert(iterator position, const void *first, const size_t num)
Insert num entries starting from memory location first into the vector from position pos.
void assign(const void *x, const size_t num)
Copy num entries of type T starting at the memory location x into the object.
void insert_aux(iterator position, const_reference x)
insert x into the given position in the vector.