#ifndef __CXXMPH_HOLLOW_ITERATOR_H__ #define __CXXMPH_HOLLOW_ITERATOR_H__ #include namespace cxxmph { template struct hollow_iterator_base : public std::iterator { typedef presence_type presence; typedef container_type container; typedef iterator_type iterator; typedef hollow_iterator_base& self_reference; typedef typename iterator::reference reference; typedef typename iterator::pointer pointer; hollow_iterator_base(container* c, presence* p, iterator it) : c_(c), p_(p), it_(it) { find_present(); } self_reference operator++() { ++it_; find_present(); } reference operator*() { return *it_; } pointer operator->() { return &(*it_); } // TODO find syntax to make this less permissible at compile time template bool operator==(const T& rhs) { return rhs.it_ == this->it_; } template bool operator!=(const T& rhs) { return rhs.it_ != this->it_; } public: // TODO find syntax to make this friend of const iterator void find_present() { while (it_ != c_->end() && !((*p_)[it_-c_->begin()])) ++it_; } container* c_; presence* p_; iterator it_; }; template struct hollow_iterator : public hollow_iterator_base< container_type, std::vector, typename container_type::iterator> { typedef hollow_iterator_base< container_type, std::vector, typename container_type::iterator> parent_class; hollow_iterator(typename parent_class::container* c, typename parent_class::presence* p, typename parent_class::iterator it) : parent_class(c, p, it) { } }; template struct hollow_const_iterator : public hollow_iterator_base< const container_type, const std::vector, typename container_type::const_iterator> { typedef hollow_iterator_base< const container_type, const std::vector, typename container_type::const_iterator> parent_class; typedef hollow_const_iterator self_type; typedef hollow_iterator non_const_type; hollow_const_iterator(non_const_type rhs) : parent_class(rhs.c_, rhs.p_, typename container_type::const_iterator(rhs.it_)) { } hollow_const_iterator(const typename parent_class::container* c, const typename parent_class::presence* p, typename parent_class::iterator it) : parent_class(c, p, it) { } }; } // namespace cxxmph #endif // __CXXMPH_HOLLOW_ITERATOR_H__