#include <iostream>
#include <vector>
#include <string>
template <class T>
class iterator {
public:
iterator() {}
iterator(std::vector<T> vec) {
container = vec;
}
bool hasNext() {
if (curr_pos == container.size()) {
return false;
} else {
if (curr_pos < container.size()) {
return true;
}
}
return false;
}
T& next(){
if (hasNext()) {
curr_pos += 1;
return container.at(curr_pos-1);
}
}
private:
std::vector<T> container;
int curr_pos = 0;
};
int main() {
std::vector<int> int_vec {1,2,3,4};
iterator<int> int_it(int_vec);
while (int_it.hasNext()) {
std::cout << int_it.next() << " ";
}
std::cout << std::endl;
std::vector<std::string> str_vec {"a", "b", "c","d"};
iterator<std::string> str_it(str_vec);
while(str_it.hasNext()) {
std::cout << str_it.next() << " ";
}
std::cout << std::endl;
std::vector<int> empty_vec;
iterator<int> empty_it(empty_vec);
while(empty_it.hasNext()) {
std::cout << empty_it.next() << " ";
}
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8dmVjdG9yPgojaW5jbHVkZSA8c3RyaW5nPgoKdGVtcGxhdGUgPGNsYXNzIFQ+CmNsYXNzIGl0ZXJhdG9yIHsKcHVibGljOgoJaXRlcmF0b3IoKSB7fQoJaXRlcmF0b3Ioc3RkOjp2ZWN0b3I8VD4gdmVjKSB7CgkJY29udGFpbmVyID0gdmVjOwoJfQoJYm9vbCBoYXNOZXh0KCkgewoJCWlmIChjdXJyX3BvcyA9PSBjb250YWluZXIuc2l6ZSgpKSB7CgkJCXJldHVybiBmYWxzZTsKCQl9IGVsc2UgewoJCQlpZiAoY3Vycl9wb3MgPCBjb250YWluZXIuc2l6ZSgpKSB7CgkJCQlyZXR1cm4gdHJ1ZTsKCQkJfQoJCX0KCQlyZXR1cm4gZmFsc2U7Cgl9CglUJiBuZXh0KCl7CgkJaWYgKGhhc05leHQoKSkgewoJCQljdXJyX3BvcyArPSAxOwoJCQlyZXR1cm4gY29udGFpbmVyLmF0KGN1cnJfcG9zLTEpOwkKCQl9Cgl9CnByaXZhdGU6CglzdGQ6OnZlY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