From: Dan Schatzberg Date: Wed, 7 Dec 2016 16:08:34 +0000 (-0800) Subject: Add EvictingCacheMap MoveConstructor X-Git-Tag: v2016.12.12.00~16 X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=9b816e8962112104f06a0bd59721e3750222bc18;p=folly.git 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 --- diff --git a/folly/EvictingCacheMap.h b/folly/EvictingCacheMap.h index 8a4240bd..4ecfa64f 100644 --- a/folly/EvictingCacheMap.h +++ b/folly/EvictingCacheMap.h @@ -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 EvictingCacheMap : private boost::noncopyable { - +template > +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); diff --git a/folly/test/EvictingCacheMapTest.cpp b/folly/test/EvictingCacheMapTest.cpp index 0c305907..6de40390 100644 --- a/folly/test/EvictingCacheMapTest.cpp +++ b/folly/test/EvictingCacheMapTest.cpp @@ -616,3 +616,20 @@ TEST(EvictingCacheMap, IteratorOrderingTest) { EXPECT_EQ(-1, expected); } } + +TEST(EvictingCacheMap, MoveTest) { + const int nItems = 1000; + EvictingCacheMap 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 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)); + } +}