-
Notifications
You must be signed in to change notification settings - Fork 1.6k
<deque>
: Make deque::shrink_to_fit
never relocate elements
#4091
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
c40a251
ba4c9b5
01d1101
a00c141
43f602f
e22c30f
8ae4199
67b52dd
24f3a0f
6d5e168
51aab9c
104bb93
b6e2732
1d0584d
881672e
6d57266
6a18ee3
87fee6d
85833f0
72eb93f
6e4b925
9ac04c9
66d308a
294ff2d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -259,11 +259,56 @@ void test_exception_safety_for_throwing_movable() { | |
assert(d == d_orig); | ||
} | ||
|
||
// Also test GH-4072: <deque>: shrink_to_fit() should follow the Standard | ||
void test_gh_4072() { | ||
{ | ||
constexpr int removed_count = 768; | ||
|
||
deque<ThrowingMovable> d; | ||
for (int i = 0; i < 1729; ++i) { | ||
d.emplace_back(i); | ||
} | ||
|
||
for (int i = 0; i < removed_count; ++i) { | ||
d.pop_front(); | ||
d.pop_back(); | ||
} | ||
|
||
deque<ThrowingMovable> d2; | ||
for (int i = removed_count; i < 1729 - removed_count; ++i) { | ||
d2.emplace_back(i); | ||
} | ||
|
||
d.shrink_to_fit(); // ensures that no constructor or assignment operator of the element type is called | ||
assert(d == d2); | ||
} | ||
|
||
// ensure that the circular buffer is correctly handled | ||
{ | ||
deque<ThrowingMovable> deq(128); | ||
deq.pop_back(); | ||
deq.emplace_front(0); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was having an assumption that the deque will be in all-full state. However, after debugging I realize that the
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, |
||
deq.shrink_to_fit(); | ||
} | ||
{ | ||
deque<ThrowingMovable> deq(128); | ||
for (int i = 0; i < 120; ++i) { | ||
deq.pop_back(); | ||
} | ||
for (int i = 0; i < 5; ++i) { | ||
deq.emplace_front(0); | ||
} | ||
deq.shrink_to_fit(); | ||
} | ||
} | ||
|
||
int main() { | ||
test_push_back_pop_front(); | ||
|
||
test_Dev10_391805(); | ||
|
||
test_exception_safety_for_nonswappable_movable(); | ||
test_exception_safety_for_throwing_movable(); | ||
|
||
test_gh_4072(); | ||
} |
Uh oh!
There was an error while loading. Please reload this page.