Made Deque copy constructor and assignment operator consistent

This commit is contained in:
sfc-gh-tclinkenbeard 2020-06-12 15:02:19 -07:00
parent 9f0487506c
commit f7835ee2cf
1 changed files with 3 additions and 5 deletions

View File

@ -53,7 +53,6 @@ public:
// r.begin is always < capacity(), and r.end is always >= r.begin. Mask is used for wrapping r.end.
// but if r.end >= r.capacity(), the deque wraps around so the
// copy must be performed in two parts
auto partOneSize = r.capacity() - r.begin;
auto partTwo = std::copy(r.arr + r.begin, r.arr + r.capacity(), arr);
std::copy(r.arr, r.arr + (r.end & r.mask), partTwo);
}
@ -74,12 +73,11 @@ public:
if (r.end < r.capacity()) {
std::copy(r.arr + r.begin, r.arr + r.begin + r.size(), arr);
} else {
// Mask is used for wrapping, so r.end is always >= r.begin,
// r.begin is always < capacity(), and r.end is always >= r.begin. Mask is used for wrapping r.end.
// but if r.end >= r.capacity(), the deque wraps around so the
// copy must be performed in two parts
auto partOneSize = r.capacity() - r.begin;
std::copy(r.arr + r.begin, r.arr + r.begin + partOneSize, arr);
std::copy(r.arr, r.arr + (r.end & r.mask), arr + partOneSize);
auto partTwo = std::copy(r.arr + r.begin, r.arr + r.capacity(), arr);
std::copy(r.arr, r.arr + (r.end & r.mask), partTwo);
}
}