Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions stl/inc/algorithm
Original file line number Diff line number Diff line change
Expand Up @@ -4460,6 +4460,7 @@ namespace ranges {

for (;; ++_Current) {
if (++_First == _Last) {
++_Current;
return {_STD move(_Current), _STD move(_First)};
}

Expand Down
18 changes: 18 additions & 0 deletions tests/std/tests/P0896R4_ranges_alg_unique/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,15 @@ struct instantiator {
assert(comparisonCounter == size(input) - 1);
}

{ // Validate already unique range returns empty subrange
P input[4] = {{0, 99}, {1, 47}, {3, 99}, {4, 47}};
ReadWrite wrapped_input{input};

auto result = unique(wrapped_input.begin(), wrapped_input.end(), countedEq, get_second);
STATIC_ASSERT(same_as<decltype(result), subrange<iterator_t<ReadWrite>>>);
assert(result.empty());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Observation, no change requested: This could be more strict, by verifying that the empty subrange is at the end. However, it's unlikely that we'll damage this (and this PR certainly isn't), so it's just something to keep in mind for future tests.

}

comparisonCounter = 0;

{ // Validate range overload
Expand All @@ -58,6 +67,15 @@ struct instantiator {
assert(equal(expected, span{input}.first<4>()));
assert(comparisonCounter == size(input) - 1);
}

{ // Validate already unique range returns empty subrange
P input[4] = {{0, 99}, {1, 47}, {3, 99}, {4, 47}};
ReadWrite wrapped_input{input};

auto result = unique(wrapped_input, countedEq, get_second);
STATIC_ASSERT(same_as<decltype(result), subrange<iterator_t<ReadWrite>>>);
assert(result.empty());
}
}
};

Expand Down
86 changes: 56 additions & 30 deletions tests/std/tests/P0896R4_ranges_alg_unique_copy/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,21 +34,34 @@ struct test_iterator_overload {
static constexpr void call() {
using ranges::unique_copy, ranges::unique_copy_result, ranges::equal, ranges::equal_to, ranges::iterator_t,
ranges::size;
// Validate iterator + sentinel overload
P input[6] = {{0, 99}, {0, 47}, {0, 47}, {0, 99}, {0, 47}, {0, 47}};
P output[4] = {{-1, -1}, {-1, -1}, {-1, -1}, {-1, -1}};
Read wrapped_input{input};

const same_as<unique_copy_result<iterator_t<Read>, Write>> auto result =
unique_copy(wrapped_input.begin(), wrapped_input.end(), Write{output}, equal_to{}, countedProjection);
assert(result.in == wrapped_input.end());
assert(result.out.peek() == end(output));
if constexpr (input_iterator<Write> || !ranges::forward_range<Read>) {
assert(equal(output, expectedOutputRead));
assert(equal(input, expectedInputRead));
} else {
assert(equal(output, expectedOutput));
assert(equal(input, expectedInput));
{ // Validate iterator + sentinel overload
P input[6] = {{0, 99}, {0, 47}, {0, 47}, {0, 99}, {0, 47}, {0, 47}};
P output[4] = {{-1, -1}, {-1, -1}, {-1, -1}, {-1, -1}};
Read wrapped_input{input};

const same_as<unique_copy_result<iterator_t<Read>, Write>> auto result =
unique_copy(wrapped_input.begin(), wrapped_input.end(), Write{output}, equal_to{}, countedProjection);
assert(result.in == wrapped_input.end());
assert(result.out.peek() == end(output));
if constexpr (input_iterator<Write> || !ranges::forward_range<Read>) {
assert(equal(output, expectedOutputRead));
assert(equal(input, expectedInputRead));
} else {
assert(equal(output, expectedOutput));
assert(equal(input, expectedInput));
}
}

{ // Validate already unique range
P input[4] = {{0, 99}, {0, 47}, {0, 99}, {0, 47}};
P output[4] = {{-1, -1}, {-1, -1}, {-1, -1}, {-1, -1}};
Read wrapped_input{input};

const same_as<unique_copy_result<iterator_t<Read>, Write>> auto result =
unique_copy(wrapped_input.begin(), wrapped_input.end(), Write{output}, equal_to{});
assert(result.in == wrapped_input.end());
assert(result.out.peek() == end(output));
assert(equal(output, input));
}
}
};
Expand All @@ -58,21 +71,34 @@ struct test_range_overload {
static constexpr void call() {
using ranges::unique_copy, ranges::unique_copy_result, ranges::equal, ranges::equal_to, ranges::iterator_t,
ranges::size;
// Validate range overload
P input[6] = {{0, 99}, {0, 47}, {0, 47}, {0, 99}, {0, 47}, {0, 47}};
P output[4] = {{-1, -1}, {-1, -1}, {-1, -1}, {-1, -1}};
Read wrapped_input{input};

const same_as<unique_copy_result<iterator_t<Read>, Write>> auto result =
unique_copy(wrapped_input, Write{output}, equal_to{}, countedProjection);
assert(result.in == wrapped_input.end());
assert(result.out.peek() == end(output));
if constexpr (input_iterator<Write> || !ranges::forward_range<Read>) {
assert(equal(output, expectedOutputRead));
assert(equal(input, expectedInputRead));
} else {
assert(equal(output, expectedOutput));
assert(equal(input, expectedInput));
{ // Validate range overload
P input[6] = {{0, 99}, {0, 47}, {0, 47}, {0, 99}, {0, 47}, {0, 47}};
P output[4] = {{-1, -1}, {-1, -1}, {-1, -1}, {-1, -1}};
Read wrapped_input{input};

const same_as<unique_copy_result<iterator_t<Read>, Write>> auto result =
unique_copy(wrapped_input, Write{output}, equal_to{}, countedProjection);
assert(result.in == wrapped_input.end());
assert(result.out.peek() == end(output));
if constexpr (input_iterator<Write> || !ranges::forward_range<Read>) {
assert(equal(output, expectedOutputRead));
assert(equal(input, expectedInputRead));
} else {
assert(equal(output, expectedOutput));
assert(equal(input, expectedInput));
}
}

{ // Validate already unique range
P input[4] = {{0, 99}, {0, 47}, {0, 99}, {0, 47}};
P output[4] = {{-1, -1}, {-1, -1}, {-1, -1}, {-1, -1}};
Read wrapped_input{input};

const same_as<unique_copy_result<iterator_t<Read>, Write>> auto result =
unique_copy(wrapped_input, Write{output}, equal_to{});
assert(result.in == wrapped_input.end());
assert(result.out.peek() == end(output));
assert(equal(output, input));
}
}
};
Expand Down