Commit 03f51db9 authored by Yedidya Feldblum's avatar Yedidya Feldblum Committed by Facebook Github Bot

Assignment for sorted-vector types from initializer-list

Summary: [Folly] Assignment operators for `sorted_vector_set` and `sorted_vector_map` from `std::initializer_list`.

Reviewed By: nbronson

Differential Revision: D10457311

fbshipit-source-id: cd50963066ee89f2aa314b7cad089242fbc10d84
parent dd8181f0
......@@ -314,6 +314,12 @@ class sorted_vector_set : detail::growth_policy_wrapper<GrowthPolicy> {
m_.cont_.swap(container);
}
sorted_vector_set& operator=(std::initializer_list<value_type> ilist) {
clear();
insert(ilist.begin(), ilist.end());
return *this;
}
key_compare key_comp() const {
return m_;
}
......@@ -692,6 +698,12 @@ class sorted_vector_map : detail::growth_policy_wrapper<GrowthPolicy> {
m_.cont_.swap(container);
}
sorted_vector_map& operator=(std::initializer_list<value_type> ilist) {
clear();
insert(ilist.begin(), ilist.end());
return *this;
}
key_compare key_comp() const {
return m_;
}
......
......@@ -98,6 +98,26 @@ struct Opaque {
} // namespace
TEST(SortedVectorTypes, SetAssignmentInitListTest) {
sorted_vector_set<int> s{3, 4, 5};
EXPECT_THAT(s, testing::ElementsAreArray({3, 4, 5}));
s = {}; // empty ilist assignment
EXPECT_THAT(s, testing::IsEmpty());
s = {7, 8, 9}; // non-empty ilist assignment
EXPECT_THAT(s, testing::ElementsAreArray({7, 8, 9}));
}
TEST(SortedVectorTypes, MapAssignmentInitListTest) {
using v = std::pair<int, const char*>;
v p = {3, "a"}, q = {4, "b"}, r = {5, "c"};
sorted_vector_map<int, const char*> m{p, q, r};
EXPECT_THAT(m, testing::ElementsAreArray({p, q, r}));
m = {}; // empty ilist assignment
EXPECT_THAT(m, testing::IsEmpty());
m = {p, q, r}; // non-empty ilist assignment
EXPECT_THAT(m, testing::ElementsAreArray({p, q, r}));
}
TEST(SortedVectorTypes, SimpleSetTest) {
sorted_vector_set<int> s;
EXPECT_TRUE(s.empty());
......
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