if (!std::is_sorted(middle, cont.end(), cmp)) {
std::sort(middle, cont.end(), cmp);
}
- if (middle != cont.begin() && cmp(*middle, *(middle - 1))) {
+ if (middle != cont.begin() && !cmp(*(middle - 1), *middle)) {
std::inplace_merge(cont.begin(), middle, cont.end(), cmp);
cont.erase(
std::unique(
testing::ElementsAreArray({1, 2, 4, 5, 6, 7, 8, 10}));
}
+TEST(SortedVectorTypes, TestSetBulkInsertionMiddleValuesEqualDuplication) {
+ auto s = makeVectorOfWrappers<CountCopyCtor, int>({4, 6, 8});
+
+ sorted_vector_set<CountCopyCtor> vset(s.begin(), s.end());
+ check_invariant(vset);
+
+ s = makeVectorOfWrappers<CountCopyCtor, int>({8, 10, 12});
+
+ vset.insert(s.begin(), s.end());
+ check_invariant(vset);
+ EXPECT_EQ(vset.rbegin()->count_, 1);
+
+ EXPECT_THAT(
+ extractValues(vset),
+ testing::ElementsAreArray({4, 6, 8, 10, 12}));
+}
+
TEST(SortedVectorTypes, TestSetBulkInsertionSortMergeDups) {
auto s = makeVectorOfWrappers<CountCopyCtor, int>({6, 4, 8, 2});