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_TUPLE_TO_STRUCT_H
17 #define LIBPANDABASE_SERIALIZER_TUPLE_TO_STRUCT_H
18
19 #include <tuple>
20
21 namespace panda::serializer::internal {
22
23 template <typename Struct, size_t... Is, typename Tuple>
TupleToStructImpl(std::index_sequence<Is...> is,Tuple && tup)24 Struct TupleToStructImpl([[maybe_unused]] std::index_sequence<Is...> is, Tuple &&tup)
25 {
26 return {std::get<Is>(std::forward<Tuple>(tup))...};
27 }
28
29 template <typename Struct, typename Tuple>
TupleToStruct(Tuple && tup)30 Struct TupleToStruct(Tuple &&tup)
31 {
32 using T = std::remove_reference_t<Tuple>;
33 auto sequence = std::make_index_sequence<std::tuple_size_v<T>> {};
34
35 return TupleToStructImpl<Struct>(sequence, std::forward<Tuple>(tup));
36 }
37
38 } // namespace panda::serializer::internal
39
40 #endif // LIBPANDABASE_SERIALIZER_TUPLE_TO_STRUCT_H
41