#ifndef FOLLY_SORTED_VECTOR_TYPES_H_
#define FOLLY_SORTED_VECTOR_TYPES_H_
-#include <vector>
#include <algorithm>
-#include <utility>
+#include <initializer_list>
#include <iterator>
+#include <utility>
+#include <vector>
#include <boost/operators.hpp>
#include <boost/bind.hpp>
#include <boost/type_traits/is_same.hpp>
insert(first, last);
}
+ explicit sorted_vector_set(
+ std::initializer_list<value_type> list,
+ const Compare& comp = Compare(),
+ const Allocator& alloc = Allocator())
+ : m_(comp, alloc)
+ {
+ insert(list.begin(), list.end());
+ }
+
key_compare key_comp() const { return m_; }
value_compare value_comp() const { return m_; }
insert(first, last);
}
+ explicit sorted_vector_map(
+ std::initializer_list<value_type> list,
+ const Compare& comp = Compare(),
+ const Allocator& alloc = Allocator())
+ : m_(value_compare(comp), alloc)
+ {
+ insert(list.begin(), list.end());
+ }
+
key_compare key_comp() const { return m_; }
value_compare value_comp() const { return m_; }
EXPECT_EQ(sizeof(MapT), sizeof(std::vector<std::pair<int,int> >));
}
+TEST(SortedVectorTypes, InitializerLists) {
+ sorted_vector_set<int> empty_initialized_set{};
+ EXPECT_TRUE(empty_initialized_set.empty());
+
+ sorted_vector_set<int> singleton_initialized_set{1};
+ EXPECT_EQ(1, singleton_initialized_set.size());
+ EXPECT_EQ(1, *singleton_initialized_set.begin());
+
+ sorted_vector_set<int> forward_initialized_set{1, 2};
+ sorted_vector_set<int> backward_initialized_set{2, 1};
+ EXPECT_EQ(2, forward_initialized_set.size());
+ EXPECT_EQ(1, *forward_initialized_set.begin());
+ EXPECT_EQ(2, *forward_initialized_set.rbegin());
+ EXPECT_TRUE(forward_initialized_set == backward_initialized_set);
+
+ sorted_vector_map<int,int> empty_initialized_map{};
+ EXPECT_TRUE(empty_initialized_map.empty());
+
+ sorted_vector_map<int,int> singleton_initialized_map{{1,10}};
+ EXPECT_EQ(1, singleton_initialized_map.size());
+ EXPECT_EQ(10, singleton_initialized_map[1]);
+
+ sorted_vector_map<int,int> forward_initialized_map{{1,10}, {2,20}};
+ sorted_vector_map<int,int> backward_initialized_map{{2,20}, {1,10}};
+ EXPECT_EQ(2, forward_initialized_map.size());
+ EXPECT_EQ(10, forward_initialized_map[1]);
+ EXPECT_EQ(20, forward_initialized_map[2]);
+ EXPECT_TRUE(forward_initialized_map == backward_initialized_map);
+}
+
TEST(SortedVectorTypes, CustomCompare) {
sorted_vector_set<int,less_invert<int> > s;
for (int i = 0; i < 200; ++i)