Commit 32654ab1 authored by Louis Kruger's avatar Louis Kruger Committed by woo

Add folly::sorted_vector_map::at()

Summary: http://www.cplusplus.com/reference/map/map/at/

Test Plan: unittest

Reviewed By: ldbrandy@fb.com

Subscribers: trunkagent, jkong, folly-diffs@

FB internal diff: D1773996

Signature: t1:1773996:1421176834:33c8b39f03bf085ca2dd45df113cba948d0f2dd0
parent ba2a9e1b
......@@ -552,6 +552,22 @@ public:
return end();
}
mapped_type& at(const key_type& key) {
iterator it = find(key);
if (it != end()) {
return it->second;
}
throw std::out_of_range("sorted_vector_map::at");
}
const mapped_type& at(const key_type& key) const {
const_iterator it = find(key);
if (it != end()) {
return it->second;
}
throw std::out_of_range("sorted_vector_map::at");
}
size_type count(const key_type& key) const {
return find(key) == end() ? 0 : 1;
}
......
......@@ -149,10 +149,12 @@ TEST(SortedVectorTypes, SimpleMapTest) {
m[32] = 100.0;
check_invariant(m);
EXPECT_TRUE(m.count(32) == 1);
EXPECT_DOUBLE_EQ(100.0, m.at(32));
EXPECT_FALSE(m.find(32) == m.end());
m.erase(32);
EXPECT_TRUE(m.find(32) == m.end());
check_invariant(m);
EXPECT_THROW(m.at(32), std::out_of_range);
sorted_vector_map<int,float> m2 = m;
EXPECT_TRUE(m2 == m);
......@@ -300,6 +302,7 @@ TEST(SortedVectorTest, EmptyTest) {
sorted_vector_map<int,int> emptyMap;
EXPECT_TRUE(emptyMap.lower_bound(10) == emptyMap.end());
EXPECT_TRUE(emptyMap.find(10) == emptyMap.end());
EXPECT_THROW(emptyMap.at(10), std::out_of_range);
}
TEST(SortedVectorTest, MoveTest) {
......
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