primitives.hpp
Go to the documentation of this file.
1 // Copyright 2023-2024 Ekumen, Inc.
2 //
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 #ifndef BELUGA_PRIMITIVES_HPP
16 #define BELUGA_PRIMITIVES_HPP
17 
18 #include <tuple>
19 #include <type_traits>
20 
24 
30 namespace beluga {
31 
55 using Weight = Numeric<double, struct WeightTag>;
57 
60 
61 namespace state_detail {
62 
64 
65 template <class T, class = void>
66 struct has_member_variable_state : std::false_type {};
67 
68 template <class T>
69 struct has_member_variable_state<T, std::void_t<decltype(std::declval<T>().state)>> : std::true_type {};
70 
71 template <class T>
72 inline constexpr bool has_member_variable_state_v = has_member_variable_state<T>::value;
73 
74 template <class T, class = void>
75 struct has_member_state : std::false_type {};
76 
77 template <class T>
78 struct has_member_state<T, std::void_t<decltype(std::declval<T>().state())>> : std::true_type {};
79 
80 template <class T>
81 inline constexpr bool has_member_state_v = has_member_state<T>::value;
82 
83 template <class T, class = void>
84 struct has_non_member_state : std::false_type {};
85 
86 template <class T>
87 struct has_non_member_state<T, std::void_t<decltype(state(std::declval<T>()))>> : std::true_type {};
88 
89 template <class T>
90 inline constexpr bool has_non_member_state_v = has_non_member_state<T>::value;
91 
93 
95 
98 struct state_fn {
100  template <
101  class T,
102  std::enable_if_t<
103  std::conjunction_v<
104  has_member_variable_state<T>, //
105  std::negation<has_member_state<T>>, //
106  std::negation<has_non_member_state<T>>>,
107  int> = 0>
108  constexpr decltype(auto) operator()(T&& t) const noexcept {
109  return beluga::forward_like<T>(t.state);
110  }
111 
113  template <
114  class T,
115  std::enable_if_t<
116  std::conjunction_v<
117  std::negation<has_member_variable_state<T>>, //
118  has_member_state<T>, //
119  std::negation<has_non_member_state<T>>>,
120  int> = 0>
121  constexpr decltype(auto) operator()(T&& t) const noexcept(noexcept(std::forward<T>(t).state())) {
122  return std::forward<T>(t).state();
123  }
124 
126 
129  template <
130  class T,
131  std::enable_if_t<
132  std::conjunction_v<
133  std::negation<has_member_variable_state<T>>, //
134  std::negation<has_member_state<T>>, //
135  has_non_member_state<T>>,
136  int> = 0>
137  constexpr decltype(auto) operator()(T&& t) const noexcept(noexcept(state(std::forward<T>(t)))) {
138  return state(std::forward<T>(t));
139  }
140 
142 
145  template <
146  class T,
147  std::enable_if_t<
148  std::conjunction_v<
149  std::negation<has_member_variable_state<T>>, //
150  std::negation<has_member_state<T>>, //
151  std::negation<has_non_member_state<T>>, //
153  int> = 0,
154  std::enable_if_t<(std::tuple_size_v<std::decay_t<T>> > 1), int> = 0>
155  constexpr decltype(auto) operator()(T&& t) const noexcept(noexcept(std::get<0>(std::forward<T>(t)))) {
156  return std::get<0>(std::forward<T>(t));
157  }
158 };
159 
160 } // namespace state_detail
161 
163 inline constexpr state_detail::state_fn state;
164 
165 namespace weight_detail {
166 
168 
169 template <class T, class = void>
170 struct has_member_variable_weight : std::false_type {};
171 
172 template <class T>
173 struct has_member_variable_weight<T, std::void_t<decltype(std::declval<T>().weight)>> : std::true_type {};
174 
175 template <class T>
176 inline constexpr bool has_member_variable_weight_v = has_member_variable_weight<T>::value;
177 
178 template <class T, class = void>
179 struct has_member_weight : std::false_type {};
180 
181 template <class T>
182 struct has_member_weight<T, std::void_t<decltype(std::declval<T>().weight())>> : std::true_type {};
183 
184 template <class T>
185 inline constexpr bool has_member_weight_v = has_member_weight<T>::value;
186 
187 template <class T, class = void>
188 struct has_non_member_weight : std::false_type {};
189 
190 template <class T>
191 struct has_non_member_weight<T, std::void_t<decltype(weight(std::declval<T>()))>> : std::true_type {};
192 
193 template <class T>
194 inline constexpr bool has_non_member_weight_v = has_non_member_weight<T>::value;
195 
197 
199 
202 struct weight_fn {
204  template <
205  class T,
206  std::enable_if_t<
207  std::conjunction_v<
208  has_member_variable_weight<T>, //
209  std::negation<has_member_weight<T>>, //
210  std::negation<has_non_member_weight<T>>>,
211  int> = 0>
212  constexpr decltype(auto) operator()(T&& t) const noexcept {
213  return beluga::forward_like<T>(t.weight);
214  }
215 
217  template <
218  class T,
219  std::enable_if_t<
220  std::conjunction_v<
221  std::negation<has_member_variable_weight<T>>, //
222  has_member_weight<T>, //
223  std::negation<has_non_member_weight<T>>>,
224  int> = 0>
225  constexpr decltype(auto) operator()(T&& t) const noexcept(noexcept(std::forward<T>(t).weight())) {
226  return std::forward<T>(t).weight();
227  }
228 
230 
233  template <
234  class T,
235  std::enable_if_t<
236  std::conjunction_v<
237  std::negation<has_member_variable_weight<T>>, //
238  std::negation<has_member_weight<T>>, //
239  has_non_member_weight<T>>,
240  int> = 0>
241  constexpr decltype(auto) operator()(T&& t) const noexcept(noexcept(weight(std::forward<T>(t)))) {
242  return weight(std::forward<T>(t));
243  }
244 
246  template <
247  class T,
248  std::enable_if_t<
249  std::conjunction_v<
250  std::negation<has_member_variable_weight<T>>, //
251  std::negation<has_member_weight<T>>, //
252  std::negation<has_non_member_weight<T>>, //
253  is_tuple_like<T>, //
255  int> = 0>
256  constexpr decltype(auto) operator()(T&& t) const noexcept(noexcept(element<beluga::Weight>(std::forward<T>(t)))) {
257  return element<beluga::Weight>(std::forward<T>(t));
258  }
259 };
260 
261 } // namespace weight_detail
262 
265 
266 } // namespace beluga
267 
268 #endif
beluga::state_detail::state_fn::operator()
constexpr decltype(auto) operator()(T &&t) const noexcept(noexcept(std::get< 0 >(std::forward< T >(t))))
Overload for tuple-like types.
Definition: primitives.hpp:155
strongly_typed_numeric.hpp
Implementation of a strongly typed numeric helper.
forward_like.hpp
beluga::element
constexpr decltype(auto) element(TupleLike &&tuple) noexcept
Returns element of a tuple like object whose type is T (or a possibly const reference to T).
Definition: tuple_traits.hpp:169
beluga::state
constexpr state_detail::state_fn state
Customization point object for accessing the state of a particle.
Definition: primitives.hpp:163
beluga::weight
constexpr weight_detail::weight_fn weight
Customization point object for accessing the weight of a particle.
Definition: primitives.hpp:264
beluga::weight_detail::weight_fn
Customization point object type for accessing the weight of a particle.
Definition: primitives.hpp:202
beluga::Numeric
Helper for creating strongly typed numeric types.
Definition: strongly_typed_numeric.hpp:38
beluga::state_detail::state_fn
Customization point object type for accessing the state of a particle.
Definition: primitives.hpp:98
beluga::is_tuple_like
Meta-function that returns true if T is a tuple-like type.
Definition: tuple_traits.hpp:49
beluga::Weight
Numeric< double, struct WeightTag > Weight
Weight type, as a strongly typed double.
Definition: primitives.hpp:56
tuple_traits.hpp
Implementation of traits for tuple-like types.
beluga::has_single_element
Meta-function that returns true if there is a single element of type T in the tuple-like type.
Definition: tuple_traits.hpp:153
std
Definition: circular_array.hpp:529
beluga
The main Beluga namespace.
Definition: 3d_embedding.hpp:21


beluga
Author(s):
autogenerated on Tue Jul 16 2024 02:59:53