tuple.h
Go to the documentation of this file.
1 /****************************************************************************
2  *
3  * fkie_message_filters
4  * Copyright © 2018-2020 Fraunhofer FKIE
5  * Author: Timo Röhling
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  ****************************************************************************/
20 
21 #ifndef INCLUDE_FKIE_MESSAGE_FILTERS_HELPERS_TUPLE_H_
22 #define INCLUDE_FKIE_MESSAGE_FILTERS_HELPERS_TUPLE_H_
23 
24 #include <tuple>
25 
26 namespace fkie_message_filters
27 {
28 namespace helpers
29 {
30 
31 template<std::size_t N, typename... Ts> using select_nth = std::tuple_element_t<N, std::tuple<Ts...>>;
32 
33 template<class Function, std::size_t... Is>
34 auto index_apply_impl (Function f, std::index_sequence<Is...>)
35 {
36  return f(std::integral_constant<std::size_t, Is>{}...);
37 }
38 
39 template<std::size_t N, class Function>
40 auto index_apply (Function f)
41 {
42  return index_apply_impl(f, std::make_index_sequence<N>{});
43 }
44 
45 template<class Function, std::size_t... Is>
46 void for_each_apply_impl(Function f, std::index_sequence<Is...>)
47 {
48  (void)std::initializer_list<int>{ (f(std::integral_constant<std::size_t, Is>{}), void(), 0)... };
49 }
50 
51 template<std::size_t N, class Function>
52 void for_each_apply (Function f)
53 {
54  for_each_apply_impl(f, std::make_index_sequence<N>{});
55 }
56 
57 template<std::size_t N, class Function>
58 void select_apply (std::size_t i, Function f)
59 {
60  for_each_apply<N>(
61  [&](auto&& Is)
62  {
63  if (Is == i) f(std::forward<decltype(Is)>(Is));
64  }
65  );
66 }
67 
68 } // namespace helpers
69 } // namespace fkie_message_filters
70 
71 #endif /* INCLUDE_FKIE_MESSAGE_FILTERS_HELPERS_TUPLE_H_ */
std::tuple_element_t< N, std::tuple< Ts... > > select_nth
Definition: tuple.h:31
auto index_apply_impl(Function f, std::index_sequence< Is... >)
Definition: tuple.h:34
void for_each_apply_impl(Function f, std::index_sequence< Is... >)
Definition: tuple.h:46
void for_each_apply(Function f)
Definition: tuple.h:52
Primary namespace.
Definition: buffer.h:33
void select_apply(std::size_t i, Function f)
Definition: tuple.h:58
auto index_apply(Function f)
Definition: tuple.h:40


fkie_message_filters
Author(s): Timo Röhling
autogenerated on Mon Feb 28 2022 22:21:43