-
Notifications
You must be signed in to change notification settings - Fork 1.6k
P1223R5: find_last, et al. #3268
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
11 commits
Select commit
Hold shift + click to select a range
576e045
Implement P1223R5 find_last, et al.
SuperWig b078274
Fix whoopsie daisies
SuperWig cba7e78
Properly rewrap
SuperWig 03174d6
Utilise _Get_final_iterator_unwrapped
SuperWig c6282cd
Correct terrible case
SuperWig 938e09e
Add newlines.
StephanTLavavej 8641fb6
This ICE doesn't appear to repro anymore.
StephanTLavavej 20ae24c
Add test coverage for multiple values.
StephanTLavavej e349138
CR comments
SuperWig 2d59ba0
simplify branching to remove code duplication
CaseyCarter ec18ebe
switch to `_Search_for`, use `invoke_r`
strega-nil 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
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 ..\concepts_latest_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,77 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
|
||
#include <algorithm> | ||
#include <cassert> | ||
#include <ranges> | ||
#include <span> | ||
#include <utility> | ||
|
||
#include <range_algorithm_support.hpp> | ||
using namespace std; | ||
using P = pair<int, int>; | ||
|
||
// Validate dangling story | ||
STATIC_ASSERT(same_as<decltype(ranges::find_last(borrowed<false>{}, 42)), ranges::dangling>); | ||
STATIC_ASSERT(same_as<decltype(ranges::find_last(borrowed<true>{}, 42)), ranges::subrange<int*>>); | ||
|
||
template <class T, class U> | ||
constexpr void check_value(const T& found, const U& value) { | ||
if constexpr (same_as<T, P>) { | ||
assert(found.first == value); | ||
assert(found.second == 1729); | ||
} else { | ||
assert(found.peek().first == value); | ||
assert(found.peek().second == 1729); | ||
} | ||
} | ||
|
||
struct instantiator { | ||
static constexpr P haystack[6] = {{0, 42}, {2, 42}, {4, 42}, {0, 1729}, {2, 1729}, {4, 1729}}; | ||
|
||
template <ranges::forward_range Read> | ||
static constexpr void call() { | ||
using ranges::find_last, ranges::common_range, ranges::iterator_t; | ||
|
||
for (const auto& [value, _] : haystack) { | ||
{ // Validate range overload [found case] | ||
Read wrapped_input{haystack}; | ||
const auto result = find_last(wrapped_input, value, get_first); | ||
STATIC_ASSERT(same_as<decltype(result), const ranges::subrange<iterator_t<Read>>>); | ||
check_value(result.front(), value); | ||
} | ||
{ // Validate iterator + sentinel overload [found case] | ||
Read wrapped_input{haystack}; | ||
const auto result = find_last(wrapped_input.begin(), wrapped_input.end(), value, get_first); | ||
STATIC_ASSERT(same_as<decltype(result), const ranges::subrange<iterator_t<Read>>>); | ||
check_value(result.front(), value); | ||
} | ||
} | ||
{ // Validate range overload [not found case] | ||
Read wrapped_input{haystack}; | ||
auto result = find_last(wrapped_input, 42, get_first); | ||
STATIC_ASSERT(same_as<iterator_t<decltype(result)>, iterator_t<Read>>); | ||
STATIC_ASSERT(common_range<decltype(result)>); | ||
assert(result.begin() == wrapped_input.end()); | ||
} | ||
{ // Validate iterator + sentinel overload [not found case] | ||
Read wrapped_input{haystack}; | ||
auto result = find_last(wrapped_input.begin(), wrapped_input.end(), 42, get_first); | ||
STATIC_ASSERT(same_as<iterator_t<decltype(result)>, iterator_t<Read>>); | ||
STATIC_ASSERT(common_range<decltype(result)>); | ||
assert(result.begin() == wrapped_input.end()); | ||
} | ||
{ // Validate empty range | ||
Read wrapped_empty{span<P, 0>{}}; | ||
auto iter_result = find_last(wrapped_empty.begin(), wrapped_empty.end(), 0, get_first); | ||
auto range_result = find_last(wrapped_empty, 0, get_first); | ||
assert(iter_result.begin() == wrapped_empty.end()); | ||
assert(range_result.begin() == wrapped_empty.end()); | ||
} | ||
} | ||
}; | ||
|
||
int main() { | ||
STATIC_ASSERT((test_fwd<instantiator, const P>(), true)); | ||
test_fwd<instantiator, const P>(); | ||
} |
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 ..\concepts_latest_matrix.lst |
Oops, something went wrong.
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.