@@ -49,26 +49,22 @@ struct IteratorWrapper {
4949 }
5050};
5151
52- template <typename Range>
53- using IteratorTypeOf = decltype (std::begin(std::declval<Range&>()));
54-
55- template <typename Range>
56- using SentinelTypeOf = decltype (std::end(std::declval<Range&>()));
57-
5852template <typename Container>
5953struct ContainerWrapper {
60- constexpr IteratorWrapper<IteratorTypeOf<Container>> begin () {
61- return {.iterator = std::begin (container), .pos = 0 };
54+ constexpr auto begin () {
55+ return IteratorWrapper {.iterator = std::begin (container), .pos = 0 };
6256 }
6357
64- constexpr IteratorWrapper<SentinelTypeOf<Container>> end () { return {.iterator = std::end (container), .pos = 0 }; }
58+ constexpr auto end () {
59+ return IteratorWrapper{.iterator = std::end (container), .pos = 0 };
60+ }
6561
66- constexpr IteratorWrapper<IteratorTypeOf< const Container>> begin () const {
67- return {.iterator = std::begin (container), .pos = 0 };
62+ constexpr auto begin () const {
63+ return IteratorWrapper {.iterator = std::begin (std::as_const ( container) ), .pos = 0 };
6864 }
6965
70- constexpr IteratorWrapper<SentinelTypeOf< const Container>> end () const {
71- return {.iterator = std::end (container), .pos = 0 };
66+ constexpr auto end () const {
67+ return IteratorWrapper {.iterator = std::end (std::as_const ( container) ), .pos = 0 };
7268 }
7369
7470 Container container;
@@ -81,9 +77,9 @@ namespace utils {
8177// / @brief Implementation of python-style enumerate function for range-for loops
8278// / @param iterable: Container to iterate
8379// / @returns ContainerWrapper, which iterator after dereference returns pair
84- // / of index and (!!!)non-const reference to element(it seems impossible to make
85- // / this reference const). It can be used in "range based for loop" with
86- // / "structured binding" like this
80+ // / of index and reference to element. The reference is const-qualified if either
81+ // / the wrapper itself or the underlying container is const; otherwise, it is non-const.
82+ // / It can be used in "range based for loop" with "structured binding" like this
8783// / @code
8884// / for (auto [pos, elem] : enumerate(someContainer)) {...}
8985// / @endcode
0 commit comments