From 45acf665e36d4cbd57266899ef755e3e9b4bbc29 Mon Sep 17 00:00:00 2001 From: Crzyrndm Date: Thu, 31 May 2018 13:16:54 +1200 Subject: [PATCH] cell_iterator - operator* const overloads Users may still want to derederence a const iterator (note: not a const_iterator). Also use the "reference" typedef to ensure there is only 1 source of information --- include/xlnt/worksheet/cell_iterator.hpp | 14 +++++++++++++- source/worksheet/cell_iterator.cpp | 8 ++++++-- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/include/xlnt/worksheet/cell_iterator.hpp b/include/xlnt/worksheet/cell_iterator.hpp index 64e5c9b2..b11818f6 100644 --- a/include/xlnt/worksheet/cell_iterator.hpp +++ b/include/xlnt/worksheet/cell_iterator.hpp @@ -89,7 +89,13 @@ public: /// /// Dereferences this iterator to return the cell it points to. /// - cell operator*(); + reference operator*(); + + /// + /// Dereferences this iterator to return the cell it points to. + /// + const reference operator*() const; + /// /// Returns true if this iterator is equivalent to other. @@ -207,6 +213,12 @@ public: /// destructor for const_cell_iterator /// ~const_cell_iterator() = default; + + /// + /// Dereferences this iterator to return the cell it points to. + /// + const reference operator*() const; + /// /// Dereferences this iterator to return the cell it points to. /// diff --git a/source/worksheet/cell_iterator.cpp b/source/worksheet/cell_iterator.cpp index 25aa7196..e4c334e9 100644 --- a/source/worksheet/cell_iterator.cpp +++ b/source/worksheet/cell_iterator.cpp @@ -265,14 +265,18 @@ const_cell_iterator const_cell_iterator::operator++(int) return old; } -cell cell_iterator::operator*() +cell_iterator::reference cell_iterator::operator*() { return ws_.cell(cursor_); } -const cell const_cell_iterator::operator*() const +const cell_iterator::reference cell_iterator::operator*() const { return ws_.cell(cursor_); } +const const_cell_iterator::reference const_cell_iterator::operator*() const +{ + return ws_.cell(cursor_); +} } // namespace xlnt