From: James Sedgwick <jsedgwick@fb.com>
Date: Tue, 21 Apr 2015 23:52:09 +0000 (-0700)
Subject: fix collect() for move-only types
X-Git-Tag: v0.36.0~16
X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=5904c0ae09ef871328812d6eaed859b1b88796ef;p=folly.git

fix collect() for move-only types

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
---

diff --git a/folly/futures/Future-inl.h b/folly/futures/Future-inl.h
index fb110d09..86883c6f 100644
--- a/folly/futures/Future-inl.h
+++ b/folly/futures/Future-inl.h
@@ -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);
   }
 };
 
diff --git a/folly/futures/test/FutureTest.cpp b/folly/futures/test/FutureTest.cpp
index edc9d301..08f13af1 100644
--- a/folly/futures/test/FutureTest.cpp
+++ b/folly/futures/test/FutureTest.cpp
@@ -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 {