Fix SimplerObservable build with -Werror=unused-local-typedefs
[folly.git] / folly / fibers / WhenN.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 #pragma once
17
18 #include <memory>
19
20 namespace folly {
21 namespace fibers {
22
23 /**
24  * Schedules several tasks and blocks until n of these tasks are completed.
25  * If any of these n tasks throws an exception, this exception will be
26  * re-thrown, but only when n tasks are complete. If several tasks throw
27  * exceptions one of them will be re-thrown.
28  *
29  * @param first Range of tasks to be scheduled
30  * @param last
31  * @param n Number of tasks to wait for
32  *
33  * @return vector of pairs (task index, return value of task)
34  */
35 template <class InputIterator>
36 typename std::vector<
37     typename std::enable_if<
38         !std::is_same<
39             typename std::result_of<typename std::iterator_traits<
40                 InputIterator>::value_type()>::type,
41             void>::value,
42         typename std::pair<
43             size_t,
44             typename std::result_of<typename std::iterator_traits<
45                 InputIterator>::value_type()>::type>>::
46         type> inline collectN(InputIterator first, InputIterator last, size_t n);
47
48 /**
49  * collectN specialization for functions returning void
50  *
51  * @param first Range of tasks to be scheduled
52  * @param last
53  * @param n Number of tasks to wait for
54  *
55  * @return vector of completed task indices
56  */
57 template <class InputIterator>
58 typename std::enable_if<
59     std::is_same<
60         typename std::result_of<
61             typename std::iterator_traits<InputIterator>::value_type()>::type,
62         void>::value,
63     std::vector<size_t>>::
64     type inline collectN(InputIterator first, InputIterator last, size_t n);
65
66 /**
67  * Schedules several tasks and blocks until all of these tasks are completed.
68  * If any of the tasks throws an exception, this exception will be re-thrown,
69  * but only when all the tasks are complete. If several tasks throw exceptions
70  * one of them will be re-thrown.
71  *
72  * @param first Range of tasks to be scheduled
73  * @param last
74  *
75  * @return vector of values returned by tasks
76  */
77 template <class InputIterator>
78 typename std::vector<typename std::enable_if<
79     !std::is_same<
80         typename std::result_of<
81             typename std::iterator_traits<InputIterator>::value_type()>::type,
82         void>::value,
83     typename std::result_of<
84         typename std::iterator_traits<InputIterator>::value_type()>::
85         type>::type> inline collectAll(InputIterator first, InputIterator last);
86
87 /**
88  * collectAll specialization for functions returning void
89  *
90  * @param first Range of tasks to be scheduled
91  * @param last
92  */
93 template <class InputIterator>
94 typename std::enable_if<
95     std::is_same<
96         typename std::result_of<
97             typename std::iterator_traits<InputIterator>::value_type()>::type,
98         void>::value,
99     void>::type inline collectAll(InputIterator first, InputIterator last);
100
101 /**
102  * Schedules several tasks and blocks until one of them is completed.
103  * If this task throws an exception, this exception will be re-thrown.
104  * Exceptions thrown by all other tasks will be ignored.
105  *
106  * @param first Range of tasks to be scheduled
107  * @param last
108  *
109  * @return pair of index of the first completed task and its return value
110  */
111 template <class InputIterator>
112 typename std::enable_if<
113     !std::is_same<
114         typename std::result_of<
115             typename std::iterator_traits<InputIterator>::value_type()>::type,
116         void>::value,
117     typename std::pair<
118         size_t,
119         typename std::result_of<typename std::iterator_traits<
120             InputIterator>::value_type()>::type>>::
121     type inline collectAny(InputIterator first, InputIterator last);
122
123 /**
124  * WhenAny specialization for functions returning void.
125  *
126  * @param first Range of tasks to be scheduled
127  * @param last
128  *
129  * @return index of the first completed task
130  */
131 template <class InputIterator>
132 typename std::enable_if<
133     std::is_same<
134         typename std::result_of<
135             typename std::iterator_traits<InputIterator>::value_type()>::type,
136         void>::value,
137     size_t>::type inline collectAny(InputIterator first, InputIterator last);
138 }
139 }
140
141 #include <folly/fibers/WhenN-inl.h>