Commit b4c51441 authored by Ying Hu's avatar Ying Hu Committed by Facebook Github Bot

add emplace to folly sorted_vector_map

Summary: add emplace for folly::sorted_vector_map

Reviewed By: yfeldblum

Differential Revision: D15789529

fbshipit-source-id: 2afccd4553cc53afd0e92729841120722f72b1ae
parent ad1889b2
......@@ -855,6 +855,22 @@ class sorted_vector_map : detail::growth_policy_wrapper<GrowthPolicy> {
insert(ilist.begin(), ilist.end());
}
// emplace isn't better than insert for sorted_vector_map, but aids
// compatibility
template <typename... Args>
std::pair<iterator, bool> emplace(Args&&... args) {
value_type v(std::forward<Args>(args)...);
return insert(std::move(v));
}
std::pair<iterator, bool> emplace(const value_type& value) {
return insert(value);
}
std::pair<iterator, bool> emplace(value_type&& value) {
return insert(std::move(value));
}
size_type erase(const key_type& key) {
iterator it = find(key);
if (it == end()) {
......
......@@ -303,6 +303,21 @@ TEST(SortedVectorTypes, SimpleMapTest) {
EXPECT_TRUE(m3 == m2);
EXPECT_FALSE(m3 == m);
sorted_vector_map<int, float> m4;
m4.emplace(1, 2.0f);
m4.emplace(3, 1.0f);
m4.emplace(2, 1.5f);
check_invariant(m4);
EXPECT_TRUE(m4.size() == 3);
sorted_vector_map<int, float> m5;
for (auto& kv : m2) {
m5.emplace(kv);
}
check_invariant(m5);
EXPECT_TRUE(m5 == m2);
EXPECT_FALSE(m5 == m);
EXPECT_TRUE(m != m2);
EXPECT_TRUE(m2 == m3);
EXPECT_TRUE(m3 != m);
......@@ -318,9 +333,9 @@ TEST(SortedVectorTypes, SimpleMapTest) {
m.insert(m.begin() + 3, std::make_pair(1 << 15, 1.0f));
check_invariant(m);
sorted_vector_map<int, float> m4 = {};
m4.insert({{1, 1.0f}, {2, 2.0f}, {1, 2.0f}});
EXPECT_EQ(m4.at(2), 2.0f);
sorted_vector_map<int, float> m6 = {};
m6.insert({{1, 1.0f}, {2, 2.0f}, {1, 2.0f}});
EXPECT_EQ(m6.at(2), 2.0f);
}
TEST(SortedVectorTypes, TransparentMapTest) {
......
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