-
Notifications
You must be signed in to change notification settings - Fork 1.6k
<deque>: _RERAISE -> scope guard #2308
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
Merged
StephanTLavavej
merged 17 commits into
microsoft:main
from
AlexGuteniev:usual_scope_guards
Mar 28, 2022
+140
−29
Merged
Changes from 15 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
3cb1f25
<deque>: _RERAISE -> scope guard
AlexGuteniev 7026f01
exit guard
AlexGuteniev ae22e86
exit guard right
AlexGuteniev 45160c5
test for strong exception guarantee preserved
AlexGuteniev f013e32
@miscco still does not like my bools
AlexGuteniev 14acbe5
data_x
AlexGuteniev 7b37da6
minor cleanup
AlexGuteniev 9396682
Persistent @miscco
AlexGuteniev 7759c95
no, it is not `static_assert` !
AlexGuteniev 6782baa
Merge remote-tracking branch 'upstream/main' into usual_scope_guards
AlexGuteniev e4e068b
Merge remote-tracking branch 'upstream/main' into usual_scope_guards
AlexGuteniev c81043d
review comments
AlexGuteniev 3c9a6ac
clang format
AlexGuteniev 5b897ab
Merge branch 'main' into usual_scope_guards
StephanTLavavej fc7967b
Merge branch 'main' into usual_scope_guards
StephanTLavavej db7822f
Merge remote-tracking branch 'upstream/main' into usual_scope_guards
AlexGuteniev f6592ef
Casey's review comments
CaseyCarter File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# Copyright (c) Microsoft Corporation. | ||
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
|
||
RUNALL_INCLUDE ..\usual_matrix.lst |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
|
||
#include <algorithm> | ||
#include <cassert> | ||
#include <cstring> | ||
#include <deque> | ||
#include <stdexcept> | ||
AlexGuteniev marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
using namespace std; | ||
|
||
struct countdown { | ||
int val; | ||
|
||
static int count; | ||
|
||
void tick() { | ||
if (count == 0) { | ||
throw runtime_error{"GO"}; | ||
} else { | ||
--count; | ||
} | ||
} | ||
|
||
countdown(const int init) : val(init) { | ||
CaseyCarter marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
tick(); | ||
} | ||
|
||
countdown(const countdown& other) : val(other.val) { | ||
tick(); | ||
} | ||
|
||
countdown& operator=(const countdown& other) { | ||
tick(); | ||
val = other.val; | ||
return *this; | ||
} | ||
|
||
bool operator==(int other) const { | ||
return val == other; | ||
} | ||
}; | ||
|
||
int countdown::count = 0; | ||
|
||
constexpr int init_data[] = {1, 2, 3, 4, 5, 6, 7}; | ||
constexpr int more_data[] = {10, 11, 12, 13, 14}; | ||
|
||
template <class Container> | ||
void check(const Container& c) { | ||
assert(equal(c.begin(), c.end(), begin(init_data), end(init_data))); | ||
} | ||
|
||
void check_exception(const runtime_error& ex) { | ||
assert(strcmp(ex.what(), "GO") == 0); | ||
} | ||
|
||
void test_deque() { | ||
countdown::count = 8; | ||
|
||
deque<countdown> dq(begin(init_data), end(init_data)); | ||
|
||
try { | ||
countdown::count = 3; | ||
dq.insert(dq.end() - 2, begin(more_data), end(more_data)); | ||
assert(false); // Should have thrown an exception | ||
} catch (const runtime_error& ex) { | ||
check_exception(ex); | ||
check(dq); | ||
} | ||
|
||
try { | ||
countdown::count = 3; | ||
dq.insert(dq.begin() + 2, begin(more_data), end(more_data)); | ||
assert(false); // Should have thrown an exception | ||
} catch (const runtime_error& ex) { | ||
check_exception(ex); | ||
check(dq); | ||
} | ||
|
||
try { | ||
countdown::count = 3; | ||
dq.insert(dq.end() - 2, 6, 10); | ||
assert(false); // Should have thrown an exception | ||
} catch (const runtime_error& ex) { | ||
check_exception(ex); | ||
check(dq); | ||
} | ||
|
||
try { | ||
countdown::count = 3; | ||
dq.insert(dq.begin() + 2, 6, 11); | ||
assert(false); // Should have thrown an exception | ||
} catch (const runtime_error& ex) { | ||
check_exception(ex); | ||
check(dq); | ||
} | ||
} | ||
|
||
int main() { | ||
test_deque(); | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.