Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #pragma once
- #include <iostream>
- #include <forward_list>
- #include <string>
- #include <utility>
- using Value = std::string;
- using Iterator = std::forward_list<std::string>::const_iterator;
- using ZippedPair = std::pair<const Value&, const Value&>;
- class Zipped {
- public:
- class ZippedIterator {
- public:
- ZippedIterator(Iterator& first, Iterator& second) : first_(first), second_(second) {};
- ZippedIterator& operator++() {
- ++first_;
- ++second_;
- return *this;
- }
- ZippedIterator operator++(int) {
- ZippedIterator now(*this);
- ++first_;
- ++second_;
- return now;
- }
- bool operator!=(const ZippedIterator& rhs) {
- return first_ != rhs.first_ && second_ != rhs.second_;
- }
- ZippedPair& operator*() {
- return *new ZippedPair(std::make_pair(*first_, *second_));
- }
- private:
- Iterator& first_;
- Iterator& second_;
- };
- Zipped(Iterator a_begin, Iterator a_end, Iterator b_begin, Iterator b_end)
- : a_begin_(a_begin), a_end_(a_end), b_begin_(b_begin), b_end_(b_end) {}
- ZippedIterator begin() {
- return ZippedIterator(a_begin_, b_begin_);
- }
- ZippedIterator end() {
- return ZippedIterator(a_end_, b_end_);
- }
- private:
- Iterator a_begin_;
- Iterator a_end_;
- Iterator b_begin_;
- Iterator b_end_;
- };
- Zipped Zip(Iterator a_begin, Iterator a_end, Iterator b_begin, Iterator b_end) {
- return Zipped(a_begin, a_end, b_begin, b_end);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement