Do not construct a Future<T> from a Future<Something> value
authorHans Fugal <fugalh@fb.com>
Thu, 30 Apr 2015 22:09:05 +0000 (15:09 -0700)
committerPraveen Kumar Ramakrishnan <praveenr@fb.com>
Tue, 12 May 2015 00:01:41 +0000 (17:01 -0700)
Summary: The value constructor can be nice. But when it matches on Future<Something> it just confuses everybody.

Test Plan:
building and running tests
contbuild

Reviewed By: jsedgwick@fb.com

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

FB internal diff: D2036455

Tasks: 6925951

Signature: t1:2036455:1430423503:73906f748318c4ebec13f45ad3761f104e2ef888

folly/futures/Future-inl.h
folly/futures/Future.h

index f6abe7b4575cd6de9c474fbfd985a6d540b72a3a..927a3142b8ed94a056b3d3f8beac50359d039878 100644 (file)
@@ -44,7 +44,8 @@ Future<T>& Future<T>::operator=(Future<T>&& other) noexcept {
 }
 
 template <class T>
-template <class T2>
+template <class T2,
+          typename std::enable_if<!isFuture<T2>::value, void*>::type>
 Future<T>::Future(T2&& val) : core_(nullptr) {
   Promise<T> p;
   p.setValue(std::forward<T2>(val));
index cc0bd36ae2d3aa9ad4028bde7f1635d2153aaff9..06572c6306fc4818bfbfd5ff5966af8d5667b2c2 100644 (file)
@@ -56,7 +56,9 @@ class Future {
 
   /// Construct a Future from a value (perfect forwarding)
   /* implicit */
-  template <class T2 = T> Future(T2&& val);
+  template <class T2 = T,
+            typename std::enable_if<!isFuture<T2>::value, void*>::type = nullptr>
+  Future(T2&& val);
 
   template <class T2 = T,
             typename std::enable_if<