Commit 9b816e89 authored by Dan Schatzberg's avatar Dan Schatzberg Committed by Facebook Github Bot

Add EvictingCacheMap MoveConstructor

Summary:
Add the default move constructor and move operator
to EvictingCacheMap so it can be moved.

Reviewed By: markisaa, luciang

Differential Revision: D4287472

fbshipit-source-id: 130e9d5467d6da14ba95a9e769cf8e8d541a704c
parent 99994d0a
......@@ -90,9 +90,8 @@ namespace folly {
* unless evictions of LRU items are triggered by calling prune() by clients
* (using their own eviction criteria).
*/
template <class TKey, class TValue, class THash = std::hash<TKey> >
class EvictingCacheMap : private boost::noncopyable {
template <class TKey, class TValue, class THash = std::hash<TKey>>
class EvictingCacheMap {
private:
// typedefs for brevity
struct Node;
......@@ -148,6 +147,10 @@ class EvictingCacheMap : private boost::noncopyable {
maxSize_(maxSize),
clearSize_(clearSize) { }
EvictingCacheMap(const EvictingCacheMap&) = delete;
EvictingCacheMap& operator=(const EvictingCacheMap&) = delete;
EvictingCacheMap(EvictingCacheMap&&) = default;
EvictingCacheMap& operator=(EvictingCacheMap&&) = default;
~EvictingCacheMap() {
setPruneHook(nullptr);
......
......@@ -616,3 +616,20 @@ TEST(EvictingCacheMap, IteratorOrderingTest) {
EXPECT_EQ(-1, expected);
}
}
TEST(EvictingCacheMap, MoveTest) {
const int nItems = 1000;
EvictingCacheMap<int, int> map(nItems);
for (int i = 0; i < nItems; i++) {
map.set(i, i);
EXPECT_TRUE(map.exists(i));
EXPECT_EQ(i, map.get(i));
}
EvictingCacheMap<int, int> map2 = std::move(map);
EXPECT_TRUE(map.empty());
for (int i = 0; i < nItems; i++) {
EXPECT_TRUE(map2.exists(i));
EXPECT_EQ(i, map2.get(i));
}
}
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