-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Specialize fill and fill_n for vector<bool> #879
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
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
a714e76
[vector] Add specialization of fill
miscco f477816
[vector] Add specialization of fill_n
miscco 1e014d8
Use static_casts instead of C-casts
miscco f64509e
Use const methods
miscco d9be996
Implement mnatsuhara comment
miscco 4d0b7ae
Merge remote-tracking branch 'origin/master' into vector_bool_fill
BillyONeal f694d12
Rename _UFirst -> _VbFirst, _ULast -> _VbLast.
BillyONeal 52cbae1
Guard forbidden full shift.
BillyONeal 6f2f109
Address STL comments
miscco ce674c5
Expand the _Is_vb_iterator to differentiate const and non-const itera…
miscco 8493d52
Go back to _FwdIt to stay consistent with incoming algorithms
miscco ff94d0b
Code review feedback.
StephanTLavavej acaef25
Merge branch 'master' into vector_bool_fill
StephanTLavavej 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
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 |
101 changes: 101 additions & 0 deletions
101
tests/std/tests/GH_000625_vector_bool_optimization/test.cpp
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,101 @@ | ||
| // Copyright (c) Microsoft Corporation. | ||
| // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
|
|
||
| #include <algorithm> | ||
| #include <assert.h> | ||
| #include <vector> | ||
miscco marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| using namespace std; | ||
|
|
||
| constexpr int blockSize = 32; | ||
| static_assert(blockSize == _VBITS, "Invalid block size"); | ||
|
|
||
| void test_fill_helper(const size_t length) { | ||
| // No offset | ||
| { | ||
| vector<bool> result_true(length, true); | ||
| result_true.resize(length + 3, false); | ||
| vector<bool> dest_true(length + 3, false); | ||
| fill(dest_true.begin(), prev(dest_true.end(), 3), true); | ||
| assert(dest_true == result_true); | ||
|
|
||
| vector<bool> result_false(length, false); | ||
| result_false.resize(length + 3, true); | ||
| vector<bool> dest_false(length + 3, true); | ||
| fill(dest_false.begin(), prev(dest_false.end(), 3), false); | ||
| assert(dest_false == result_false); | ||
|
|
||
| vector<bool> result_true_n(length, true); | ||
| result_true_n.resize(length + 3, false); | ||
| vector<bool> dest_true_n(length + 3, false); | ||
| const auto res_fill_n = fill_n(dest_true_n.begin(), length, true); | ||
| assert(dest_true_n == result_true_n); | ||
| assert(res_fill_n == prev(dest_true_n.end(), 3)); | ||
|
|
||
| vector<bool> result_false_n(length, false); | ||
| result_false_n.resize(length + 3, true); | ||
| vector<bool> dest_false_n(length + 3, true); | ||
| fill_n(dest_false_n.begin(), length, false); | ||
| assert(dest_false_n == result_false_n); | ||
| } | ||
|
|
||
| // With offset | ||
| { | ||
| vector<bool> result_true(length, true); | ||
| result_true.resize(length + 3, false); | ||
| result_true.insert(result_true.begin(), false); | ||
| vector<bool> dest_true(length + 4, false); | ||
| fill(next(dest_true.begin()), prev(dest_true.end(), 3), true); | ||
| assert(dest_true == result_true); | ||
|
|
||
| vector<bool> result_false(length, false); | ||
| result_false.resize(length + 3, true); | ||
| result_false.insert(result_false.begin(), true); | ||
| vector<bool> dest_false(length + 4, true); | ||
| fill(next(dest_false.begin()), prev(dest_false.end(), 3), false); | ||
| assert(dest_false == result_false); | ||
|
|
||
| vector<bool> result_true_n(length, true); | ||
| result_true_n.resize(length + 3, false); | ||
| result_true_n.insert(result_true_n.begin(), false); | ||
| vector<bool> dest_true_n(length + 4, false); | ||
| const auto res_fill_n = fill_n(next(dest_true_n.begin()), length, true); | ||
| assert(dest_true_n == result_true_n); | ||
| assert(res_fill_n == prev(dest_true_n.end(), 3)); | ||
|
|
||
| vector<bool> result_false_n(length, false); | ||
| result_false_n.resize(length + 3, true); | ||
| result_false_n.insert(result_false_n.begin(), true); | ||
| vector<bool> dest_false_n(length + 4, true); | ||
| fill_n(next(dest_false_n.begin()), length, false); | ||
| assert(dest_false_n == result_false_n); | ||
| } | ||
| } | ||
|
|
||
| bool test_fill() { | ||
| // Empty | ||
| test_fill_helper(0); | ||
|
|
||
| // One block, ends within block | ||
| test_fill_helper(15); | ||
|
|
||
| // One block, ends at block boundary | ||
| test_fill_helper(blockSize); | ||
|
|
||
| // Multiple blocks, no memset, within block | ||
| test_fill_helper(blockSize + 11); | ||
|
|
||
| // Multiple blocks, no memset, ends at block boundary | ||
| test_fill_helper(2 * blockSize); | ||
|
|
||
| // Multiple blocks, with memset, within block | ||
| test_fill_helper(3 * blockSize + 5); | ||
|
|
||
| // Multiple blocks, with memset, ends at block boundary | ||
| test_fill_helper(4 * blockSize); | ||
| return true; | ||
| } | ||
|
|
||
| int main() { | ||
| test_fill(); | ||
| } | ||
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.