12#include "detray/definitions/detail/qualifiers.hpp"
13#include "detray/utils/ranges/ranges.hpp"
14#include "detray/utils/tuple.hpp"
19namespace detray::ranges {
23template <std::input_iterator...
T>
34template <detray::ranges::range... range_ts>
36 cartesian_product_view<range_ts...>> {
41 detray::ranges::iterator_t<range_ts>...>;
53 requires((
sizeof...(deduced_range_ts) > 1) ||
54 ((!std::same_as<cartesian_product_view, deduced_range_ts>) && ...))
56 deduced_range_ts... ranges)
82 template <int I = static_cast<int>(
sizeof...(range_ts)) - 1>
83 DETRAY_HOST_DEVICE
constexpr auto size(std::size_t s = 1u) const noexcept
88 s *=
static_cast<std::size_t
>(detray::ranges::distance(
begin,
end));
90 if constexpr (I > 0) {
91 return size<I - 1>(s);
106template <detray::ranges::range... range_ts>
111 constexpr cartesian_product() =
default;
117 requires((
sizeof...(deduced_range_ts) > 1) ||
118 ((!std::same_as<cartesian_product, deduced_range_ts>) && ...))
119 DETRAY_HOST_DEVICE constexpr explicit cartesian_product(
120 deduced_range_ts &&...ranges)
121 :
base_type(std::forward<deduced_range_ts>(ranges)...) {}
126DETRAY_HOST_DEVICE_DEDUCTION_GUIDE cartesian_product(ranges_ts &&...ranges)
127 -> cartesian_product<ranges_ts...>;
134template <std::input_iterator... iterator_ts>
139 using value_type = std::tuple<std::iter_reference_t<iterator_ts>...>;
157 : m_begins(begins), m_ends(ends), m_itrs(begins) {}
208 constexpr decltype(
auto)
operator*()
const {
209 return unroll_values(
210 std::make_integer_sequence<std::size_t,
sizeof...(iterator_ts)>{});
218 template <int I = static_cast<int>(
sizeof...(iterator_ts)) - 1>
219 DETRAY_HOST_DEVICE
constexpr void unroll_increment() {
222 if constexpr (I > 0) {
225 unroll_increment<I - 1>();
234 template <int I = static_cast<int>(
sizeof...(iterator_ts)) - 1>
235 DETRAY_HOST_DEVICE
constexpr void unroll_decrement() {
238 if constexpr (I > 0) {
241 unroll_decrement<I - 1>();
249 template <std::size_t... I>
250 DETRAY_HOST_DEVICE
constexpr auto unroll_values(
251 std::index_sequence<I...> )
const {
252 return std::tuple<std::iter_reference_t<iterator_ts>...>(
257 dtuple<iterator_ts...> m_begins;
258 dtuple<iterator_ts...> m_ends;
260 dtuple<iterator_ts...> m_itrs;
Defines a detray 'view'.
Definition ranges.hpp:190
Range concept.
Definition ranges.hpp:97
constexpr double T
Magnetic field, native unit (eV*s)/(e*m²).
Definition Units.hpp:168
Detray include(s).
Definition array_operators.hpp:18
const auto & get(const detray::tuple< Ts... > &t) noexcept
Get a tuple element by index from a const tuple.
Definition tuple.hpp:152
detray::tuple< types... > dtuple
Tuple type used by detray storage and dispatch.
Definition containers.hpp:46
Range adaptor that generates a cartesian product from the given input ranges.
Definition cartesian_product.hpp:36
constexpr cartesian_product_view()=default
Default constructor.
dtuple< detray::ranges::iterator_t< range_ts >... > iterator_coll_t
Tuple of the begin or end iterator for each input range.
Definition cartesian_product.hpp:38
dtuple< std::iter_reference_t< detray::ranges::iterator_t< range_ts > >... > value_type
Tuple of references to the current element of each input range.
Definition cartesian_product.hpp:43
constexpr auto begin() const -> iterator_t
Definition cartesian_product.hpp:62
constexpr auto data()
Definition cartesian_product.hpp:76
constexpr auto end() const -> iterator_t
Definition cartesian_product.hpp:66
detray::ranges::detail::cartesian_product_iterator< detray::ranges::iterator_t< range_ts >... > iterator_t
Iterator that advances through the Cartesian product.
Definition cartesian_product.hpp:40
constexpr auto data() const
Definition cartesian_product.hpp:71
constexpr auto size(std::size_t s=1u) const noexcept -> std::size_t
Definition cartesian_product.hpp:83
Iterator implementation for the cartesian product view.
Definition cartesian_product.hpp:135
constexpr bool operator==(const cartesian_product_iterator &rhs) const
Definition cartesian_product.hpp:163
detray::ranges::bidirectional_iterator_tag iterator_category
Definition cartesian_product.hpp:146
std::tuple< std::iter_reference_t< iterator_ts >... > value_type
Definition cartesian_product.hpp:139
constexpr auto operator++() -> cartesian_product_iterator &
Increment iterators.
Definition cartesian_product.hpp:171
value_type reference
Definition cartesian_product.hpp:143
std::ptrdiff_t difference_type
Definition cartesian_product.hpp:137
constexpr auto operator--() -> cartesian_product_iterator &
Decrement iterators.
Definition cartesian_product.hpp:190
constexpr auto operator++(int) -> cartesian_product_iterator
Advance to the next product element and return the previous iterator.
Definition cartesian_product.hpp:179
value_type * pointer
Definition cartesian_product.hpp:141
constexpr cartesian_product_iterator()=default
Default constructor required by LegacyIterator trait.
constexpr cartesian_product_iterator(dtuple< iterator_ts... > begins, dtuple< iterator_ts... > ends)
Construct from a collection of begins and ends positions.
Definition cartesian_product.hpp:155
constexpr auto operator--(int) -> cartesian_product_iterator
Move to the previous product element and return the previous iterator.
Definition cartesian_product.hpp:198
ranges::cartesian_product_view< range_ts... > base_type
Base Cartesian-product view.
Definition cartesian_product.hpp:109