particle_traits.hpp
Go to the documentation of this file.
1 // Copyright 2022-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_TYPE_TRAITS_PARTICLE_TRAITS_HPP
16 #define BELUGA_TYPE_TRAITS_PARTICLE_TRAITS_HPP
17 
18 #include <beluga/primitives.hpp>
20 #include <range/v3/range/traits.hpp>
21 
27 namespace beluga {
28 
30 template <class T>
33  using state_type = std::decay_t<decltype(beluga::state(std::declval<T>()))>;
35  using weight_type = std::decay_t<decltype(beluga::weight(std::declval<T>()))>;
36 };
37 
39 template <class T>
41 
43 template <class T>
45 
47 
48 template <class T, class = void>
49 struct has_state : public std::false_type {};
50 
51 template <class T>
52 struct has_state<T, std::void_t<decltype(beluga::state(std::declval<T>()))>> : std::true_type {};
53 
54 template <class T>
55 inline constexpr bool has_state_v = has_state<T>::value;
56 
57 template <class T, class = void>
58 struct has_weight : public std::false_type {};
59 
60 template <class T>
61 struct has_weight<T, std::void_t<decltype(beluga::weight(std::declval<T>()))>> : std::true_type {};
62 
63 template <class T>
64 inline constexpr bool has_weight_v = has_weight<T>::value;
65 
66 template <class T, class = void>
67 struct is_particle : public std::false_type {};
68 
69 template <class T>
70 struct is_particle<T, std::enable_if_t<std::conjunction_v<has_state<T>, has_weight<T>>>> : std::true_type {};
71 
72 template <class T>
73 inline constexpr bool is_particle_v = is_particle<T>::value;
74 
75 template <class R>
76 inline constexpr bool is_particle_range_v = is_particle_v<ranges::range_value_t<R>>;
77 
79 
80 namespace detail {
81 
83 template <class Particle, class State = state_t<Particle>>
86 
92  constexpr auto operator()(State value) const {
93  static_assert(is_particle_v<Particle>);
94  auto particle = []() {
95  if constexpr (is_tuple_like_v<Particle>) {
96  // Support for zipped ranges composed with views that don't
97  // propagate the tuple value type of the original range
98  // (ranges::views::const_).
100  } else {
101  return Particle{};
102  }
103  }();
104  beluga::state(particle) = std::move(value);
105  beluga::weight(particle) = 1.0;
106  return particle;
107  }
108 };
109 
110 } // namespace detail
111 
113 
119 template <class Particle>
121 
122 } // namespace beluga
123 
124 #endif
primitives.hpp
Implementation of library primitives to abstract member access.
beluga::particle_traits::weight_type
std::decay_t< decltype(beluga::weight(std::declval< T >()))> weight_type
The particle weight type.
Definition: particle_traits.hpp:35
beluga::particle_traits
Common traits of all particle types. See Page requirements as well.
Definition: particle_traits.hpp:31
beluga::state
constexpr state_detail::state_fn state
Customization point object for accessing the state of a particle.
Definition: primitives.hpp:163
enable_if_t
typename std::enable_if< B, T >::type enable_if_t
beluga::weight
constexpr weight_detail::weight_fn weight
Customization point object for accessing the weight of a particle.
Definition: primitives.hpp:264
beluga::weight_t
typename particle_traits< T >::weight_type weight_t
Type trait that returns the weight type given a particle type.
Definition: particle_traits.hpp:44
beluga::particle_traits::state_type
std::decay_t< decltype(beluga::state(std::declval< T >()))> state_type
The particle state type.
Definition: particle_traits.hpp:33
beluga::detail::make_from_state_fn::operator()
constexpr auto operator()(State value) const
Returns a new particle from the given state.
Definition: particle_traits.hpp:92
beluga::make_from_state
constexpr detail::make_from_state_fn< Particle > make_from_state
A function object to create a particle from a given state.
Definition: particle_traits.hpp:120
tuple_traits.hpp
Implementation of traits for tuple-like types.
beluga::detail::make_from_state_fn
Function object type to create a particle from a given state.
Definition: particle_traits.hpp:84
beluga::decay_tuple_like_t
typename decay_tuple_like< T >::type decay_tuple_like_t
Convenience template type alias for decay_tuple_like.
Definition: tuple_traits.hpp:187
std
Definition: circular_array.hpp:529
beluga::state_t
typename particle_traits< T >::state_type state_t
Type trait that returns the state type given a particle type.
Definition: particle_traits.hpp:40
beluga
The main Beluga namespace.
Definition: 3d_embedding.hpp:21


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