10 #ifndef LARCOREALG_COREUTILS_ZIP_H 11 #define LARCOREALG_COREUTILS_ZIP_H 19 #include <type_traits> 73 template <std::size_t Lead,
typename... Iterables>
74 auto zip(Iterables&&... iterables);
77 template <
typename... Iterables>
78 auto zip(Iterables&&... iterables)
80 return zip<0U>(std::forward<Iterables>(iterables)...);
97 template <std::size_t Lead,
typename... Iters>
100 static_assert(Lead <
sizeof...(Iters),
"The index (Lead) of the leading iterator is invalid.");
111 using reference = std::tuple<typename std::iterator_traits<Iters>::reference...>;
113 using pointer = std::add_pointer_t<std::remove_reference_t<reference>>;
140 template <std::
size_t Index>
141 decltype(
auto)
get()
const 177 template <std::size_t OtherLead,
typename... OtherIter>
180 return get<Lead>() != other.template get<OtherLead>();
184 template <std::size_t OtherLead,
typename... OtherIter>
187 return get<Lead>() == other.template get<OtherLead>();
197 template <
typename... Args>
201 template <std::size_t... Indices>
207 template <std::size_t... Indices>
216 return std::tuple<decltype(*std::get<Indices>(
fIterators))...>(
224 template <std::
size_t Lead>
234 using pointer = std::add_pointer_t<std::remove_reference_t<reference>>;
252 template <std::size_t OtherLead,
typename... OtherIter>
259 template <std::size_t OtherLead,
typename... OtherIter>
268 template <std::size_t Lead,
typename... Iterables>
278 template <std::size_t Lead,
typename... Iterables>
292 template <std::size_t Lead ,
typename... Iterables>
296 return util::span(details::make_zip_begin_iterator<Lead>(iterables...),
297 details::make_zip_end_iterator<Lead>(iterables...));
303 #endif // LARCOREALG_COREUTILS_ZIP_H std::tuple operator*() const
void increment_impl(std::index_sequence< Indices... >)
Namespace for general, non-LArSoft-specific utilities.
zip_iterator()=default
Constructor: all iterators are default-constructed.
bool operator!=(zip_iterator< OtherLead, OtherIter... > const &other) const
Comparison (based on the Lead iterator only).
An object with a begin and end iterator.
std::tuple< Iters... > fIterators
Tuple of all zipped iterators.
bool operator!=(zip_iterator< OtherLead, OtherIter... > const &other) const
std::add_pointer_t< std::remove_reference_t< reference >> pointer
auto dereference_impl(std::index_sequence< Indices... >) const
bool operator==(zip_iterator< OtherLead, OtherIter... > const &other) const
Comparison (based on the Lead iterator only).
auto make_zip_begin_iterator(Iterables &&...iterables)
decltype(auto) get() const
Returns the iterator at the specified Index.
std::ptrdiff_t difference_type
std::remove_cv_t< reference > value_type
std::tuple< typename std::iterator_traits< Iters >::reference... > reference
std::add_pointer_t< std::remove_reference_t< reference >> pointer
decltype(auto) constexpr end(T &&obj)
ADL-aware version of std::end.
static void expandStatements(Args &...args)
Helper to trigger parameter pack expansion in expressions.
this_iterator_t operator++(int)
std::forward_iterator_tag iterator_category
auto operator*() const
Returns a tuple with values from all dereferenced iterators.
bool operator==(zip_iterator< OtherLead, OtherIter... > const &other) const
this_iterator_t & operator++()
Increments all the iterators.
std::ptrdiff_t difference_type
std::remove_cv_t< reference > value_type
span(IterB &&b, IterE &&e, Adaptor &&adaptor) -> span< decltype(adaptor(std::forward< IterB >(b))), decltype(adaptor(std::forward< IterE >(e))) >
this_iterator_t & operator++()
Increments all the iterators.
auto zip(Iterables &&...iterables)
Range-for loop helper iterating across many collections at the same time.
decltype(auto) constexpr begin(T &&obj)
ADL-aware version of std::begin.
zip_iterator(Iters &&...iterators)
Constructor: copies all iterator values.
auto make_zip_end_iterator(Iterables &&...iterables)
this_iterator_t operator++(int)
std::forward_iterator_tag iterator_category