Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- template<typename... Cs>
- struct zipped
- {
- zipped(Cs&... containers)
- : _M_containers(containers...)
- { }
- template<typename... Ts>
- struct iterator_impl
- {
- iterator_impl(std::tuple<Ts...> its)
- : _M_its(its)
- { }
- std::tuple<typename Ts::reference...> operator*() {
- return std::apply([](auto&... it){ return std::tuple<typename Ts::reference...> { *it... }; }, _M_its);
- }
- iterator_impl& operator++() {
- std::apply([](auto&... it){ (++it, ...); } , _M_its);
- return *this;
- }
- bool operator==(const iterator_impl& other) {
- return std::apply([&](auto&... it1){
- return std::apply([&](auto&... it2) {
- return (true && ... && (it1 == it2));
- }, other._M_its);
- }, _M_its);
- }
- bool operator!=(const iterator_impl& other) {
- return !(*this == other);
- }
- private:
- std::tuple<Ts...> _M_its;
- };
- using iterator = iterator_impl<typename Cs::iterator...>;
- iterator begin() {
- return iterator(std::apply([](auto&... containers){ return std::tuple { containers.begin()... }; }, _M_containers)); }
- iterator end() {
- return iterator(std::apply([](auto&... containers){ return std::tuple { containers.end()... }; }, _M_containers)); }
- private:
- std::tuple<Cs&...> _M_containers;
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement