Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 5 additions & 14 deletions src/prevector.h
Original file line number Diff line number Diff line change
Expand Up @@ -298,9 +298,8 @@ class prevector {
}

void resize(size_type new_size) {
while (size() > new_size) {
item_ptr(size() - 1)->~T();
_size--;
if (size() > new_size) {
erase(item_ptr(new_size), end());
}
if (new_size > capacity()) {
change_capacity(new_size);
Expand Down Expand Up @@ -368,10 +367,7 @@ class prevector {
}

iterator erase(iterator pos) {
(*pos).~T();
memmove(&(*pos), &(*pos) + 1, ((char*)&(*end())) - ((char*)(1 + &(*pos))));
_size--;
return pos;
return erase(pos, pos + 1);
}

iterator erase(iterator first, iterator last) {
Expand All @@ -396,7 +392,7 @@ class prevector {
}

void pop_back() {
_size--;
erase(end() - 1, end());
}

T& front() {
Expand All @@ -416,12 +412,7 @@ class prevector {
}

void swap(prevector<N, T, Size, Diff>& other) {
if (_size & other._size & 1) {
std::swap(_union.capacity, other._union.capacity);
std::swap(_union.indirect, other._union.indirect);
} else {
std::swap(_union, other._union);
}
std::swap(_union, other._union);
std::swap(_size, other._size);
}

Expand Down
15 changes: 13 additions & 2 deletions src/test/prevector_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,11 @@ template<unsigned int N, typename T>
class prevector_tester {
typedef std::vector<T> realtype;
realtype real_vector;
realtype real_vector_alt;

typedef prevector<N, T> pretype;
pretype pre_vector;
pretype pre_vector_alt;

typedef typename pretype::size_type Size;

Expand Down Expand Up @@ -149,6 +151,12 @@ class prevector_tester {
pre_vector.shrink_to_fit();
test();
}

void swap() {
real_vector.swap(real_vector_alt);
pre_vector.swap(pre_vector_alt);
test();
}
};

BOOST_AUTO_TEST_CASE(PrevectorTestInt)
Expand Down Expand Up @@ -204,12 +212,15 @@ BOOST_AUTO_TEST_CASE(PrevectorTestInt)
if (test.size() > 0) {
test.update(insecure_rand() % test.size(), insecure_rand());
}
if (((r >> 11) & 1024) == 11) {
if (((r >> 11) % 1024) == 11) {
test.clear();
}
if (((r >> 21) & 512) == 12) {
if (((r >> 21) % 512) == 12) {
test.assign(insecure_rand() % 32, insecure_rand());
}
if (((r >> 15) % 64) == 3) {
test.swap();
}
}
}
}
Expand Down