added iOS source code
[wl-app.git] / iOS / Pods / Realm / include / core / realm / util / call_with_tuple.hpp
1 /*************************************************************************
2  *
3  * Copyright 2016 Realm Inc.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  **************************************************************************/
18
19 #ifndef REALM_UTIL_CALL_WITH_TUPLE_HPP
20 #define REALM_UTIL_CALL_WITH_TUPLE_HPP
21
22 #include <cstddef>
23 #include <tuple>
24
25 namespace realm {
26 namespace _impl {
27
28 /// \cond doxygen_skip
29 /// Doxygen warns about a recursive class relation, but this is intentional.
30
31 template <size_t...>
32 struct Indexes {
33 };
34 template <size_t N, size_t... I>
35 struct GenIndexes : GenIndexes<N - 1, N - 1, I...> {
36 };
37 template <size_t... I>
38 struct GenIndexes<0, I...> {
39     typedef Indexes<I...> type;
40 };
41
42 /// \endcond
43
44 template <class F, class... A, size_t... I>
45 auto call_with_tuple(F func, std::tuple<A...> args, Indexes<I...>) -> decltype(func(std::get<I>(args)...))
46 {
47     static_cast<void>(args); // Prevent GCC warning when tuple is empty
48     return func(std::get<I>(args)...);
49 }
50
51 } // namespace _impl
52
53 namespace util {
54
55 template <class F, class... A>
56 auto call_with_tuple(F func, std::tuple<A...> args)
57     -> decltype(_impl::call_with_tuple(std::move(func), std::move(args),
58                                        typename _impl::GenIndexes<sizeof...(A)>::type()))
59 {
60     return _impl::call_with_tuple(std::move(func), std::move(args), typename _impl::GenIndexes<sizeof...(A)>::type());
61 }
62
63 } // namespace util
64 } // namespace realm
65
66 #endif // REALM_UTIL_CALL_WITH_TUPLE_HPP