fix collect() for move-only types
authorJames Sedgwick <jsedgwick@fb.com>
Tue, 21 Apr 2015 23:52:09 +0000 (16:52 -0700)
committerAlecs King <int@fb.com>
Mon, 27 Apr 2015 23:49:02 +0000 (16:49 -0700)
Summary:
as above. it never ends.

Test Plan: added unit

Reviewed By: hans@fb.com

Subscribers: folly-diffs@, jsedgwick, yfeldblum, chalfant

FB internal diff: D2011569

Signature: t1:2011569:1429660210:930cb17682d5c86a11881a23efe0a91f4c6a36b1

folly/futures/Future-inl.h
folly/futures/test/FutureTest.cpp

index fb110d096e41a5324d542e0ae2a2fb2e7a46b4f2..86883c6f02d6128c1ddf2c336e23fbf0e305360d 100644 (file)
@@ -602,8 +602,8 @@ template <class, class, typename = void> struct CollectContextHelper;
 template <class T, class VecT>
 struct CollectContextHelper<T, VecT,
     typename std::enable_if<std::is_same<T, VecT>::value>::type> {
-  static inline std::vector<T>& getResults(std::vector<VecT>& results) {
-    return results;
+  static inline std::vector<T>&& getResults(std::vector<VecT>& results) {
+    return std::move(results);
   }
 };
 
index edc9d3012b828775fa8b7d7d66a6773033e09bbf..08f13af1260c76017a3a3ca1203a14975b3123d9 100644 (file)
@@ -877,6 +877,18 @@ TEST(Future, collect) {
 
     EXPECT_THROW(allf.value(), eggs_t);
   }
+
+  // move only compiles
+  {
+    vector<Promise<unique_ptr<int>>> promises(10);
+    vector<Future<unique_ptr<int>>> futures;
+
+    for (auto& p : promises)
+      futures.push_back(p.getFuture());
+
+    collect(futures.begin(), futures.end());
+  }
+
 }
 
 struct NotDefaultConstructible {