1 /**
2 * Copyright (c) 2021-2022 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #ifndef LIBPANDABASE_SERIALIZER_FOR_EACH_TUPLE_H
17 #define LIBPANDABASE_SERIALIZER_FOR_EACH_TUPLE_H
18
19 #include <tuple>
20
21 namespace panda::serializer::internal {
22
23 template <typename Tuple, typename F, size_t... Index>
ForEachTupleImpl(Tuple && tuple,F && f,std::index_sequence<Index...>)24 void ForEachTupleImpl(Tuple &&tuple, F &&f, std::index_sequence<Index...> /* unused */)
25 {
26 [[maybe_unused]] auto unused = {true, (f(std::get<Index>(std::forward<Tuple>(tuple))), void(), true)...};
27 }
28
29 template <typename Tuple, typename F>
ForEachTuple(Tuple && tuple,F && f)30 void ForEachTuple(Tuple &&tuple, F &&f)
31 {
32 using T = std::remove_reference_t<Tuple>;
33 auto sequence = std::make_index_sequence<std::tuple_size_v<T>> {};
34
35 ForEachTupleImpl(std::forward<Tuple>(tuple), std::forward<F>(f), sequence);
36 }
37
38 } // namespace panda::serializer::internal
39
40 #endif // LIBPANDABASE_SERIALIZER_FOR_EACH_TUPLE_H
41