From db2eae0e1dee4612585fa673da49b303906e4c4f Mon Sep 17 00:00:00 2001 From: Hans Fugal Date: Thu, 30 Apr 2015 11:59:36 -0700 Subject: [PATCH] Future::Future() Summary: Allow `makeFuture()`-like default ctor for `Future` 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 --- folly/futures/Future-inl.h | 12 +++++++----- folly/futures/Future.h | 6 ++++-- folly/futures/Unit.h | 7 +++++++ folly/futures/test/UnitTest.cpp | 30 ++++++++++++++++++++++++++++++ 4 files changed, 48 insertions(+), 7 deletions(-) create mode 100644 folly/futures/test/UnitTest.cpp diff --git a/folly/futures/Future-inl.h b/folly/futures/Future-inl.h index 135440a9..f6abe7b4 100644 --- a/folly/futures/Future-inl.h +++ b/folly/futures/Future-inl.h @@ -51,11 +51,13 @@ Future::Future(T2&& val) : core_(nullptr) { *this = p.getFuture(); } -template <> -template ::value, int>::type> -Future::Future() : core_(nullptr) { - Promise p; +template +template ::value, + int>::type> +Future::Future() : core_(nullptr) { + Promise p; p.setValue(); *this = p.getFuture(); } diff --git a/folly/futures/Future.h b/folly/futures/Future.h index 3111fbf9..cc0bd36a 100644 --- a/folly/futures/Future.h +++ b/folly/futures/Future.h @@ -58,8 +58,10 @@ class Future { /* implicit */ template Future(T2&& val); - template ::value, int>::type = 0> + template ::value, + int>::type = 0> Future(); ~Future(); diff --git a/folly/futures/Unit.h b/folly/futures/Unit.h index a01aa20d..cb0b92c1 100644 --- a/folly/futures/Unit.h +++ b/folly/futures/Unit.h @@ -18,4 +18,11 @@ namespace folly { struct Unit {}; +template +struct is_void_or_unit : public std::conditional< + std::is_void::value || std::is_same::value, + std::true_type, + std::false_type>::type +{}; + } diff --git a/folly/futures/test/UnitTest.cpp b/folly/futures/test/UnitTest.cpp new file mode 100644 index 00000000..ea7cda7c --- /dev/null +++ b/folly/futures/test/UnitTest.cpp @@ -0,0 +1,30 @@ +/* + * 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 +#include + +using namespace folly; + +TEST(Unit, FutureDefaultCtor) { + Future(); +} + +TEST(Unit, voidOrUnit) { + EXPECT_TRUE(is_void_or_unit::value); + EXPECT_TRUE(is_void_or_unit::value); + EXPECT_FALSE(is_void_or_unit::value); +} -- 2.34.1