File indexing completed on 2025-01-18 09:11:10
0001
0002
0003
0004
0005
0006
0007
0008
0009 #pragma once
0010
0011 #include <tuple>
0012 #include <utility>
0013
0014 namespace Acts {
0015
0016
0017
0018
0019
0020
0021
0022
0023 template <typename container_type,
0024 typename container_type_iter =
0025 decltype(std::begin(std::declval<container_type>())),
0026 typename = decltype(std::end(std::declval<container_type>()))>
0027 constexpr auto enumerate(container_type &&iterable) {
0028 struct iterator {
0029 std::size_t i;
0030 container_type_iter iter;
0031
0032 bool operator!=(const iterator &rhs) const { return iter != rhs.iter; }
0033
0034
0035 void operator++() {
0036 ++i;
0037 ++iter;
0038 }
0039
0040
0041 auto operator*() const { return std::tie(i, *iter); }
0042 };
0043 struct iterable_wrapper {
0044 container_type iterable;
0045 auto begin() { return iterator{0, std::begin(iterable)}; }
0046 auto end() { return iterator{0, std::end(iterable)}; }
0047 };
0048 return iterable_wrapper{std::forward<container_type>(iterable)};
0049 }
0050
0051 }