insert(list.begin(), list.end());
}
+ // Construct a sorted_vector_set by stealing the storage of a prefilled
+ // container. The container need not be sorted already. This supports
+ // bulk construction of sorted_vector_set with zero allocations, not counting
+ // those performed by the caller. (The iterator range constructor performs at
+ // least one allocation).
+ //
+ // Note that `sorted_vector_set(const ContainerT& container)` is not provided,
+ // since the purpose of this constructor is to avoid an unnecessary copy.
+ explicit sorted_vector_set(
+ ContainerT&& container,
+ const Compare& comp = Compare())
+ : m_(comp, container.get_allocator()) {
+ std::sort(container.begin(), container.end(), value_comp());
+ m_.cont_.swap(container);
+ }
+
key_compare key_comp() const { return m_; }
value_compare value_comp() const { return m_; }
insert(list.begin(), list.end());
}
+ // Construct a sorted_vector_map by stealing the storage of a prefilled
+ // container. The container need not be sorted already. This supports
+ // bulk construction of sorted_vector_map with zero allocations, not counting
+ // those performed by the caller. (The iterator range constructor performs at
+ // least one allocation).
+ //
+ // Note that `sorted_vector_map(const ContainerT& container)` is not provided,
+ // since the purpose of this constructor is to avoid an unnecessary copy.
+ explicit sorted_vector_map(
+ ContainerT&& container,
+ const Compare& comp = Compare())
+ : m_(value_compare(comp), container.get_allocator()) {
+ std::sort(container.begin(), container.end(), value_comp());
+ m_.cont_.swap(container);
+ }
+
key_compare key_comp() const { return m_; }
value_compare value_comp() const { return m_; }
vmap.insert(
std::make_move_iterator(s.begin()), std::make_move_iterator(s.end()));
}
+
+TEST(SortedVectorTypes, TestSetCreationFromVector) {
+ std::vector<int> vec = {3, 1, -1, 5, 0};
+ sorted_vector_set<int> vset(std::move(vec));
+ check_invariant(vset);
+ EXPECT_THAT(vset, testing::ElementsAreArray({-1, 0, 1, 3, 5}));
+}
+
+TEST(SortedVectorTypes, TestMapCreationFromVector) {
+ std::vector<std::pair<int, int>> vec = {
+ {3, 1}, {1, 5}, {-1, 2}, {5, 3}, {0, 3}};
+ sorted_vector_map<int, int> vmap(std::move(vec));
+ check_invariant(vmap);
+ auto contents = std::vector<std::pair<int, int>>(vmap.begin(), vmap.end());
+ auto expected_contents = std::vector<std::pair<int, int>>({
+ {-1, 2}, {0, 3}, {1, 5}, {3, 1}, {5, 3},
+ });
+ EXPECT_EQ(contents, expected_contents);
+}