Commit a6fc9c0a authored by Stepan Palamarchuk's avatar Stepan Palamarchuk Committed by Facebook Github Bot

Add const versions of begin/end

Summary:
`ConcurrentHashMap` provides `cbegin` and `cend`, but they are not suitable for range-based loops.
This diff adds const versions of `begin` and `end` that are required for range-based loops.

Reviewed By: yfeldblum

Differential Revision: D8131142

fbshipit-source-id: b3af164d403c86ddfe4d27aaca293fbc4e2bb9d2
parent dfa07dcd
......@@ -194,6 +194,14 @@ class ConcurrentHashMap {
return ConstIterator(this);
}
ConstIterator end() const noexcept {
return cend();
}
ConstIterator begin() const noexcept {
return cbegin();
}
std::pair<ConstIterator, bool> insert(
std::pair<key_type, mapped_type>&& foo) {
auto segment = pickSegment(foo.first);
......
......@@ -696,3 +696,15 @@ TEST(ConcurrentHashMap, DeletionMultipleMaps) {
EXPECT_TRUE(del1);
EXPECT_TRUE(del2);
}
TEST(ConcurrentHashMap, ForEachLoop) {
ConcurrentHashMap<int, int> map;
map.insert(1, 2);
size_t iters = 0;
for (const auto& kv : map) {
EXPECT_EQ(kv.first, 1);
EXPECT_EQ(kv.second, 2);
++iters;
}
EXPECT_EQ(iters, 1);
}
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