1 /*************************************************************************
3 * Copyright 2016 Realm Inc.
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
9 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 **************************************************************************/
19 #ifndef REALM_UTIL_CALL_WITH_TUPLE_HPP
20 #define REALM_UTIL_CALL_WITH_TUPLE_HPP
28 /// \cond doxygen_skip
29 /// Doxygen warns about a recursive class relation, but this is intentional.
34 template <size_t N, size_t... I>
35 struct GenIndexes : GenIndexes<N - 1, N - 1, I...> {
37 template <size_t... I>
38 struct GenIndexes<0, I...> {
39 typedef Indexes<I...> type;
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)...))
47 static_cast<void>(args); // Prevent GCC warning when tuple is empty
48 return func(std::get<I>(args)...);
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()))
60 return _impl::call_with_tuple(std::move(func), std::move(args), typename _impl::GenIndexes<sizeof...(A)>::type());
66 #endif // REALM_UTIL_CALL_WITH_TUPLE_HPP