Commit db2eae0e authored by Hans Fugal's avatar Hans Fugal Committed by Praveen Kumar Ramakrishnan

Future<Unit>::Future()

Summary: Allow `makeFuture()`-like default ctor for `Future<Unit>`

Test Plan: new unit test

Reviewed By: jsedgwick@fb.com

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

FB internal diff: D2029677

Signature: t1:2029677:1430417794:5ec7fca839294316957803229f4783f2ee875027
parent 5623085a
...@@ -51,11 +51,13 @@ Future<T>::Future(T2&& val) : core_(nullptr) { ...@@ -51,11 +51,13 @@ Future<T>::Future(T2&& val) : core_(nullptr) {
*this = p.getFuture(); *this = p.getFuture();
} }
template <> template <class T>
template <class F, template <class T2,
typename std::enable_if<std::is_void<F>::value, int>::type> typename std::enable_if<
Future<void>::Future() : core_(nullptr) { folly::is_void_or_unit<T2>::value,
Promise<void> p; int>::type>
Future<T>::Future() : core_(nullptr) {
Promise<T> p;
p.setValue(); p.setValue();
*this = p.getFuture(); *this = p.getFuture();
} }
......
...@@ -58,8 +58,10 @@ class Future { ...@@ -58,8 +58,10 @@ class Future {
/* implicit */ /* implicit */
template <class T2 = T> Future(T2&& val); template <class T2 = T> Future(T2&& val);
template <class F = T, template <class T2 = T,
typename std::enable_if<std::is_void<F>::value, int>::type = 0> typename std::enable_if<
folly::is_void_or_unit<T2>::value,
int>::type = 0>
Future(); Future();
~Future(); ~Future();
......
...@@ -18,4 +18,11 @@ namespace folly { ...@@ -18,4 +18,11 @@ namespace folly {
struct Unit {}; struct Unit {};
template <class T>
struct is_void_or_unit : public std::conditional<
std::is_void<T>::value || std::is_same<Unit, T>::value,
std::true_type,
std::false_type>::type
{};
} }
/*
* Copyright 2015 Facebook, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <folly/futures/Future.h>
#include <gtest/gtest.h>
using namespace folly;
TEST(Unit, FutureDefaultCtor) {
Future<Unit>();
}
TEST(Unit, voidOrUnit) {
EXPECT_TRUE(is_void_or_unit<void>::value);
EXPECT_TRUE(is_void_or_unit<Unit>::value);
EXPECT_FALSE(is_void_or_unit<int>::value);
}
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