Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #ifndef __01_ITERATOR_HELPER_H__
- #define __01_ITERATOR_HELPER_H__
- #include <memory>
- /* We need a concreate iterator class */
- template<typename It, typename Vt = typename It::valuetype>
- class IteratorPointerWrapper {
- public:
- IteratorPointerWrapper(It* iter_ptr) : iter_ptr_(iter_ptr) {}
- const Vt& operator*() const {
- return **iter_ptr_;
- }
- const Vt* operator->() const {
- return &(**iter_ptr_);
- }
- IteratorPointerWrapper& operator++() {
- ++(*iter_ptr_);
- return *this;
- }
- bool operator!=(const IteratorPointerWrapper& other) const {
- return (*other.iter_ptr_) != (*iter_ptr_);
- }
- private:
- std::unique_ptr<It> iter_ptr_;
- };
- /* Helper base class to ensure all need methods are implemented. */
- template<typename VT>
- struct BaseIterator
- {
- typedef VT valuetype;
- typedef BaseIterator<VT> base_iterator_type;
- virtual const valuetype& operator*() const = 0;
- virtual const valuetype* operator->() const = 0;
- virtual base_iterator_type& operator++() = 0;
- virtual bool operator!=(const base_iterator_type& other) const = 0;
- };
- #endif // __01_ITERATOR_HELPER_H__
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement