Changeset View
Changeset View
Standalone View
Standalone View
src/prevector.h
Show First 20 Lines • Show All 471 Lines • ▼ Show 20 Lines | void insert(iterator pos, InputIterator first, InputIterator last) { | ||||
change_capacity(new_size + (new_size >> 1)); | change_capacity(new_size + (new_size >> 1)); | ||||
} | } | ||||
T *ptr = item_ptr(p); | T *ptr = item_ptr(p); | ||||
memmove(ptr + count, ptr, (size() - p) * sizeof(T)); | memmove(ptr + count, ptr, (size() - p) * sizeof(T)); | ||||
_size += count; | _size += count; | ||||
fill(ptr, first, last); | fill(ptr, first, last); | ||||
} | } | ||||
inline void resize_uninitialized(size_type new_size) { | |||||
// resize_uninitialized changes the size of the prevector but does not | |||||
// initialize it. If size < new_size, the added elements must be | |||||
// initialized explicitly. | |||||
if (capacity() < new_size) { | |||||
change_capacity(new_size); | |||||
_size += new_size - size(); | |||||
return; | |||||
} | |||||
if (new_size < size()) { | |||||
erase(item_ptr(new_size), end()); | |||||
} else { | |||||
_size += new_size - size(); | |||||
} | |||||
} | |||||
iterator erase(iterator pos) { return erase(pos, pos + 1); } | iterator erase(iterator pos) { return erase(pos, pos + 1); } | ||||
iterator erase(iterator first, iterator last) { | iterator erase(iterator first, iterator last) { | ||||
// Erase is not allowed to the change the object's capacity. That means | // Erase is not allowed to the change the object's capacity. That means | ||||
// that when starting with an indirectly allocated prevector with | // that when starting with an indirectly allocated prevector with | ||||
// size and capacity > N, the result may be a still indirectly allocated | // size and capacity > N, the result may be a still indirectly allocated | ||||
// prevector with size <= N and capacity > N. A shrink_to_fit() call is | // prevector with size <= N and capacity > N. A shrink_to_fit() call is | ||||
// necessary to switch to the (more efficient) directly allocated | // necessary to switch to the (more efficient) directly allocated | ||||
▲ Show 20 Lines • Show All 108 Lines • Show Last 20 Lines |