Use the GTest portability headers
[folly.git] / folly / futures / test / ThenCompileTest.h
1 /*
2  * Copyright 2016 Facebook, Inc.
3  *
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
7  *
8  *   http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 #pragma once
18
19 #include <folly/futures/Future.h>
20 #include <folly/portability/GTest.h>
21
22 #include <memory>
23
24 namespace folly {
25
26 typedef std::unique_ptr<int> A;
27 struct B {};
28
29 template <class T>
30 using EnableIfFuture = typename std::enable_if<isFuture<T>::value>::type;
31
32 template <class T>
33 using EnableUnlessFuture = typename std::enable_if<!isFuture<T>::value>::type;
34
35 template <class T>
36 Future<T> someFuture() {
37   return makeFuture(T());
38 }
39
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());
45 }
46
47 template <class Ret, class... Params>
48 typename std::enable_if<!isFuture<Ret>::value, Ret>::type
49 aFunction(Params...) {
50   return Ret();
51 }
52
53 template <class Ret, class... Params>
54 std::function<Ret(Params...)>
55 aStdFunction(
56     typename std::enable_if<!isFuture<Ret>::value, bool>::type = false) {
57   return [](Params...) -> Ret { return Ret(); };
58 }
59
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()); };
65 }
66
67 class SomeClass {
68 public:
69   template <class Ret, class... Params>
70   static
71   typename std::enable_if<!isFuture<Ret>::value, Ret>::type
72   aStaticMethod(Params...) {
73     return Ret();
74   }
75
76   template <class Ret, class... Params>
77   static
78   typename std::enable_if<isFuture<Ret>::value, Ret>::type
79   aStaticMethod(Params...) {
80     typedef typename Ret::value_type T;
81     return makeFuture(T());
82   }
83
84   template <class Ret, class... Params>
85   typename std::enable_if<!isFuture<Ret>::value, Ret>::type
86   aMethod(Params...) {
87     return Ret();
88   }
89
90   template <class Ret, class... Params>
91   typename std::enable_if<isFuture<Ret>::value, Ret>::type
92   aMethod(Params...) {
93     typedef typename Ret::value_type T;
94     return makeFuture(T());
95   }
96 };
97
98 }