diff --git a/include/partition/cell_storage.hpp b/include/partition/cell_storage.hpp index 302ca5652..2541a225e 100644 --- a/include/partition/cell_storage.hpp +++ b/include/partition/cell_storage.hpp @@ -11,6 +11,7 @@ #include "storage/io.hpp" +#include #include #include @@ -83,9 +84,21 @@ template class CellStorageImpl using RowIterator = WeightPtrT; // Possibly replace with // http://www.boost.org/doc/libs/1_55_0/libs/range/doc/html/range/reference/adaptors/reference/strided.html - class ColumnIterator : public std::iterator + class ColumnIterator : public boost::iterator_facade { + typedef boost::iterator_facade + base_t; + public: + typedef typename base_t::value_type value_type; + typedef typename base_t::difference_type difference_type; + typedef typename base_t::reference reference; + typedef std::random_access_iterator_tag iterator_category; + explicit ColumnIterator() : current(nullptr), stride(1) {} explicit ColumnIterator(WeightPtrT begin, std::size_t row_length) @@ -94,36 +107,20 @@ template class CellStorageImpl BOOST_ASSERT(begin != nullptr); } - WeightRefT operator*() const - { - BOOST_ASSERT(current); - return *current; - } - - ColumnIterator &operator++() - { - current += stride; - return *this; - } - - ColumnIterator &operator+=(int amount) - { - current += stride * amount; - return *this; - } - - bool operator==(const ColumnIterator &other) const { return current == other.current; } - - bool operator!=(const ColumnIterator &other) const { return current != other.current; } - - std::int64_t operator-(const ColumnIterator &other) const - { - return (current - other.current) / stride; - } - private: + void increment() { current += stride; } + void decrement() { current -= stride; } + void advance(difference_type offset) { current += stride * offset; } + bool equal(const ColumnIterator &other) const { return current == other.current; } + reference dereference() const { return *current; } + difference_type distance_to(const ColumnIterator &other) const + { + return (other.current - current) / static_cast(stride); + } + + friend class ::boost::iterator_core_access; WeightPtrT current; - std::size_t stride; + const std::size_t stride; }; public: