Commit e7e82040 authored by Nick Terrell's avatar Nick Terrell Committed by Facebook Github Bot

Fix sorted_vector_types bulk insertion

Summary:
The `bulk_insert()` method left duplicates from the input range when the
container was empty.

Also, `bulk_insert()` relies on `std::inplace_merge()` to be stable, but
`libc++`s version of `std::inplace_merge()` was buggy until [August 2017](https://github.com/llvm-mirror/libcxx/commit/25a78dcd773ce509469a2b892adbeac0c230cdb9).
Since it is fixed upstream, and it is a library bug, I've not mitigated the bug.

Reviewed By: yfeldblum

Differential Revision: D6943195

fbshipit-source-id: 136caa52c21a9e0dbc09b0a47ad57e99d2fde380
parent 2e540877
......@@ -184,6 +184,7 @@ void bulk_insert(
}
if (middle != cont.begin() && !cmp(*(middle - 1), *middle)) {
std::inplace_merge(cont.begin(), middle, cont.end(), cmp);
}
cont.erase(
std::unique(
cont.begin(),
......@@ -193,7 +194,6 @@ void bulk_insert(
return !cmp(a, b) && !cmp(b, a);
}),
cont.end());
}
}
template <typename Container, typename Compare>
......
......@@ -714,3 +714,12 @@ TEST(SortedVectorTypes, TestMapCreationFromVector) {
});
EXPECT_EQ(contents, expected_contents);
}
TEST(SortedVectorTypes, TestBulkInsertionWithDuplicatesIntoEmptySet) {
sorted_vector_set<int> set;
{
std::vector<int> const vec = {0, 1, 0, 1};
set.insert(vec.begin(), vec.end());
}
EXPECT_THAT(set, testing::ElementsAreArray({0, 1}));
}
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