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>>;
137 template <std::
size_t Index>
138 decltype(
auto)
get()
const 174 template <std::size_t OtherLead,
typename... OtherIter>
177 return get<Lead>() != other.template get<OtherLead>();
181 template <std::size_t OtherLead,
typename... OtherIter>
184 return get<Lead>() == other.template get<OtherLead>();
194 template <
typename... Args>
198 template <std::size_t... Indices>
204 template <std::size_t... Indices>
208 return std::tie(*std::get<Indices>(
fIterators)...);
214 template <std::size_t Lead,
typename... Iterables>
222 template <std::size_t Lead,
typename... Iterables>
231 template <std::size_t Lead ,
typename... Iterables>
234 static_assert(
sizeof...(Iterables) > 0,
"Must zip at least one iterable.");
235 return span{details::make_zip_begin_iterator<Lead>(iterables...),
236 details::make_zip_end_iterator<Lead>(iterables...)};
241 #endif // LARCOREALG_COREUTILS_ZIP_H void increment_impl(std::index_sequence< Indices... >)
Namespace for general, non-LArSoft-specific utilities.
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.
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.
Simple class with a begin and an end.
std::tuple< typename std::iterator_traits< Iters >::reference... > reference
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)
auto operator*() const
Returns a tuple with values from all dereferenced iterators.
std::ptrdiff_t difference_type
std::remove_cv_t< reference > value_type
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)
std::forward_iterator_tag iterator_category