2 * Copyright 2015 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.
18 #include <gtest/gtest.h>
20 #include <folly/futures/Future.h>
21 #include <folly/Executor.h>
23 using namespace folly;
25 using namespace testing;
27 typedef unique_ptr<int> A;
31 using EnableIfFuture = typename std::enable_if<isFuture<T>::value>::type;
34 using EnableUnlessFuture = typename std::enable_if<!isFuture<T>::value>::type;
37 Future<T> someFuture() {
38 return makeFuture(T());
41 template <class Ret, class... Params>
42 typename std::enable_if<isFuture<Ret>::value, Ret>::type
43 aFunction(Params...) {
44 typedef typename Ret::value_type T;
45 return makeFuture(T());
48 template <class Ret, class... Params>
49 typename std::enable_if<!isFuture<Ret>::value, Ret>::type
50 aFunction(Params...) {
54 template <class Ret, class... Params>
55 std::function<Ret(Params...)>
57 typename std::enable_if<!isFuture<Ret>::value, bool>::type = false) {
58 return [](Params...) -> Ret { return Ret(); };
61 template <class Ret, class... Params>
62 std::function<Ret(Params...)>
63 aStdFunction(typename std::enable_if<isFuture<Ret>::value, bool>::type = true) {
64 typedef typename Ret::value_type T;
65 return [](Params...) -> Future<T> { return makeFuture(T()); };
70 template <class Ret, class... Params>
72 typename std::enable_if<!isFuture<Ret>::value, Ret>::type
73 aStaticMethod(Params...) {
77 template <class Ret, class... Params>
79 typename std::enable_if<isFuture<Ret>::value, Ret>::type
80 aStaticMethod(Params...) {
81 typedef typename Ret::value_type T;
82 return makeFuture(T());
85 template <class Ret, class... Params>
86 typename std::enable_if<!isFuture<Ret>::value, Ret>::type
91 template <class Ret, class... Params>
92 typename std::enable_if<isFuture<Ret>::value, Ret>::type
94 typedef typename Ret::value_type T;
95 return makeFuture(T());