Commit 34eb6ecb authored by Jan Wilken Dörrie's avatar Jan Wilken Dörrie Committed by Commit Bot

[base] Ranges: Support multiple projections

This change adds support for multiple projections to util::ranges by
improving the capabilities of the ProjectedBinaryPredicate. The
resulting object will now consider several permutations of the provided
projections, and choose an appropriate one. This change required the
introduction of a few internal helpers.

Bug: 1071094
Change-Id: I46b05e1e0ddf0b15b0ed1518fb6de263bb23b8a2
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2310533
Commit-Queue: Jan Wilken Dörrie <jdoerrie@chromium.org>
Reviewed-by: default avatarDaniel Cheng <dcheng@chromium.org>
Cr-Commit-Position: refs/heads/master@{#791787}
parent 184a072c
This diff is collapsed.
......@@ -275,6 +275,11 @@ TEST(RangesTest, IsPermutation) {
EXPECT_TRUE(
ranges::is_permutation(ints1, ints2, ranges::equal_to{}, &Int::value));
EXPECT_FALSE(ranges::is_permutation(array1, ints2, ranges::equal_to{}, {},
&Int::value));
EXPECT_TRUE(ranges::is_permutation(array3, ints2, ranges::equal_to{}, {},
&Int::value));
}
TEST(RangesTest, Search) {
......@@ -816,14 +821,18 @@ TEST(RangesTest, PartialSortCopy) {
Int ints[] = {3, 1, 2, 0, 4};
Int outs[] = {0, 0, 0};
EXPECT_EQ(outs + 3, ranges::partial_sort_copy(ints, outs, {}, &Int::value));
EXPECT_EQ(outs + 3, ranges::partial_sort_copy(ints, outs, {}, &Int::value,
&Int::value));
EXPECT_THAT(ints, ElementsAre(3, 1, 2, 0, 4));
EXPECT_THAT(outs, ElementsAre(0, 1, 2));
EXPECT_EQ(outs + 3, ranges::partial_sort_copy(ints, outs, ranges::greater(),
&Int::value));
&Int::value, &Int::value));
EXPECT_THAT(ints, ElementsAre(3, 1, 2, 0, 4));
EXPECT_THAT(outs, ElementsAre(4, 3, 2));
EXPECT_EQ(outs + 3,
ranges::partial_sort_copy(input, outs, {}, {}, &Int::value));
}
TEST(RangesTest, IsSorted) {
......@@ -867,7 +876,7 @@ TEST(RangesTest, LowerBound) {
EXPECT_EQ(ints + 4, ranges::lower_bound(ints, 2, {}, &Int::value));
EXPECT_EQ(ints + 6, ranges::lower_bound(ints, 3, {}, &Int::value));
const auto proj = [](const auto& i) { return 2 - i.value; };
const auto proj = [](const Int& i) { return 2 - i.value; };
EXPECT_EQ(ints, ranges::lower_bound(ints, 3, ranges::greater{}, proj));
EXPECT_EQ(ints, ranges::lower_bound(ints, 2, ranges::greater{}, proj));
EXPECT_EQ(ints + 2, ranges::lower_bound(ints, 1, ranges::greater{}, proj));
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment