Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using namespace std;
- template<typename T>
- class CIter {
- private:
- const T& container;
- typename T::const_iterator cit;
- typename T::value_type::const_iterator valcit;
- public:
- CIter(const T& container, typename T::const_iterator cit,
- typename T::value_type::const_iterator valcit)
- : container(container), cit(cit), valcit(valcit) {
- while (cit != container.end() && cit->empty()) {
- ++cit;
- }
- if (container.empty() == false) {
- if (cit == container.end()) {
- valcit = container.back().end();
- } else {
- valcit = cit->begin();
- }
- }
- }
- const typename T::value_type::value_type& operator*() const {
- return *valcit;
- }
- bool operator==(const CIter& other) const {
- if (cit == other.cit) {
- if (valcit == other.valcit) {
- if (&container == &other.container)
- return true;
- }
- }
- return false;
- }
- bool operator!=(const CIter &other) const {
- if (*this == other) {
- return false;
- }
- return true;
- }
- CIter<T>& operator++() {
- if (valcit == typename T::value_type::const_iterator() || cit->empty() ||
- ++valcit == cit->end()) {
- ++cit;
- while (cit != container.end() && cit->empty()) {
- ++cit;
- }
- if (container.empty() == false) {
- if (cit == container.end()) {
- valcit = container.back().end();
- } else {
- valcit = cit->begin();
- }
- }
- }
- return *this;
- }
- };
- template<typename T>
- class Iterator {
- private:
- const T& container;
- public:
- Iterator(const T& temp) : container(temp) {}
- CIter<T> begin() {
- if (container.empty() == true) {
- CIter<T> it(container, container.begin(), typename T::value_type::const_iterator());
- return it;
- } else {
- CIter<T> it(container, container.begin(), container.front().begin());
- return it;
- }
- }
- CIter<T> end() {
- if (container.empty() == true) {
- CIter<T> it(container, container.end(), typename T::value_type::const_iterator());
- return it;
- } else {
- CIter<T> it(container, container.end(), container.back().end());
- return it;
- }
- }
- };
- template<typename OuterCollection>
- Iterator<OuterCollection> MakeRange(const OuterCollection &container) {
- return Iterator<OuterCollection>(container);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement