2 * Copyright 2016 Facebook, Inc.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 #include <folly/futures/Future.h>
20 #include <folly/portability/GTest.h>
26 typedef std::unique_ptr<int> A;
30 using EnableIfFuture = typename std::enable_if<isFuture<T>::value>::type;
33 using EnableUnlessFuture = typename std::enable_if<!isFuture<T>::value>::type;
36 Future<T> someFuture() {
37 return makeFuture(T());
40 template <class Ret, class... Params>
41 typename std::enable_if<isFuture<Ret>::value, Ret>::type
42 aFunction(Params...) {
43 typedef typename Ret::value_type T;
44 return makeFuture(T());
47 template <class Ret, class... Params>
48 typename std::enable_if<!isFuture<Ret>::value, Ret>::type
49 aFunction(Params...) {
53 template <class Ret, class... Params>
54 std::function<Ret(Params...)>
56 typename std::enable_if<!isFuture<Ret>::value, bool>::type = false) {
57 return [](Params...) -> Ret { return Ret(); };
60 template <class Ret, class... Params>
61 std::function<Ret(Params...)>
62 aStdFunction(typename std::enable_if<isFuture<Ret>::value, bool>::type = true) {
63 typedef typename Ret::value_type T;
64 return [](Params...) -> Future<T> { return makeFuture(T()); };
69 template <class Ret, class... Params>
71 typename std::enable_if<!isFuture<Ret>::value, Ret>::type
72 aStaticMethod(Params...) {
76 template <class Ret, class... Params>
78 typename std::enable_if<isFuture<Ret>::value, Ret>::type
79 aStaticMethod(Params...) {
80 typedef typename Ret::value_type T;
81 return makeFuture(T());
84 template <class Ret, class... Params>
85 typename std::enable_if<!isFuture<Ret>::value, Ret>::type
90 template <class Ret, class... Params>
91 typename std::enable_if<isFuture<Ret>::value, Ret>::type
93 typedef typename Ret::value_type T;
94 return makeFuture(T());