Gazebo Physics

API Reference

9.2.0
TemplateHelpers.hh
Go to the documentation of this file.
1/*
2 * Copyright (C) 2017 Open Source Robotics Foundation
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *
16*/
17
18#ifndef GZ_PHYSICS_TEMPLATEHELPERS_HH_
19#define GZ_PHYSICS_TEMPLATEHELPERS_HH_
20
21#include <tuple>
22#include <type_traits>
23
24namespace gz
25{
26 namespace physics
27 {
29 struct Empty { };
30
33 template <class... T> struct type { };
34
39 template <typename... Ts>
40 struct TypeList {
41 static constexpr std::size_t size = sizeof...(Ts);
42 };
43
53 template <typename... Lists>
55
56 template <>
57 struct TypeListCat<> {
59 };
60
61 template <typename... Ts>
62 struct TypeListCat<TypeList<Ts...>> {
63 using type = TypeList<Ts...>;
64 };
65
66 template <typename... T1, typename... T2>
67 struct TypeListCat<TypeList<T1...>, TypeList<T2...>> {
68 using type = TypeList<T1..., T2...>;
69 };
70
71 // We explicitly require at least 3 lists (L1, L2, L3) to use this
72 // recursive specialization. This prevents an ambiguity error with the
73 // 2-element base case `TypeListCat<TypeList<T1...>, TypeList<T2...>>`
74 // when exactly 2 lists are provided.
75 template <typename L1, typename L2, typename L3, typename... Rest>
76 struct TypeListCat<L1, L2, L3, Rest...> {
77 using type = typename TypeListCat<
79 typename TypeListCat<L3, Rest...>::type>::type;
80 };
81
82 namespace detail
83 {
85 template <typename T>
86 struct ToTuple;
87
88 template <typename... Ts>
89 struct ToTuple<TypeList<Ts...>> {
90 using type = std::tuple<Ts...>;
91 };
92
94 template <typename T>
95 struct TupleToTypeList;
96
97 template <typename... Ts>
98 struct TupleToTypeList<std::tuple<Ts...>> {
99 using type = TypeList<Ts...>;
100 };
101 }
102
121 template <typename To, typename From>
123
124 template <typename To, typename From>
125 struct ConstCompatible<To, const From>
126 : std::integral_constant<bool, std::is_const<To>::value> { };
127 }
128}
129
145#define GZ_PHYSICS_CREATE_SELECTOR(X) \
146 template<typename InFeature> \
147 struct Select ## X \
148 { \
149 template<typename F, typename PolicyT, typename FeaturesT, \
150 typename = std::void_t<>> \
151 struct Implementation \
152 { \
153 using type = ::gz::physics::Empty; \
154 }; \
155 \
156 template<typename F, typename PolicyT, typename FeaturesT> \
157 struct Implementation<F, PolicyT, FeaturesT, \
158 std::void_t< \
159 typename F::template X <PolicyT, FeaturesT>>> \
160 { \
161 using type = typename F::template X <PolicyT, FeaturesT>; \
162 }; \
163 \
164 template <typename PolicyT, typename FeaturesT> \
165 using type = typename Implementation<InFeature, PolicyT, FeaturesT>::type; \
166 };
167
168#endif