From 8b885c6a8db55b22678ed98ee2bd65d12080da92 Mon Sep 17 00:00:00 2001 From: Crzyrndm Date: Thu, 31 May 2018 16:00:40 +1200 Subject: [PATCH] worksheet_iterator - operator* const overloads Users may still want to dereference a const iterator (note: not a const_iterator). Also use the "reference" typedef to ensure there is only 1 source of information --- include/xlnt/workbook/worksheet_iterator.hpp | 11 +++++++++-- source/workbook/worksheet_iterator.cpp | 9 +++++++-- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/include/xlnt/workbook/worksheet_iterator.hpp b/include/xlnt/workbook/worksheet_iterator.hpp index c1b24a78..444b792f 100644 --- a/include/xlnt/workbook/worksheet_iterator.hpp +++ b/include/xlnt/workbook/worksheet_iterator.hpp @@ -88,7 +88,14 @@ public: /// If the iterator points to one-past-the-end of the workbook, an invalid_parameter /// exception will be thrown. /// - worksheet operator*(); + reference operator*(); + + /// + /// Dereferences the iterator to return the worksheet it is pointing to. + /// If the iterator points to one-past-the-end of the workbook, an invalid_parameter + /// exception will be thrown. + /// + const reference operator*() const; /// /// Returns true if this iterator points to the same worksheet as comparand. @@ -175,7 +182,7 @@ public: /// If the iterator points to one-past-the-end of the workbook, an invalid_parameter /// exception will be thrown. /// - const worksheet operator*(); + const reference operator*() const; /// /// Returns true if this iterator points to the same worksheet as comparand. diff --git a/source/workbook/worksheet_iterator.cpp b/source/workbook/worksheet_iterator.cpp index 0487cf33..3c981339 100644 --- a/source/workbook/worksheet_iterator.cpp +++ b/source/workbook/worksheet_iterator.cpp @@ -32,7 +32,12 @@ worksheet_iterator::worksheet_iterator(workbook &wb, std::size_t index) { } -worksheet worksheet_iterator::operator*() +worksheet_iterator::reference worksheet_iterator::operator*() +{ + return (*wb_)[index_]; +} + +const worksheet_iterator::reference worksheet_iterator::operator*() const { return (*wb_)[index_]; } @@ -65,7 +70,7 @@ const_worksheet_iterator::const_worksheet_iterator(const workbook &wb, std::size { } -const worksheet const_worksheet_iterator::operator*() +const const_worksheet_iterator::reference const_worksheet_iterator::operator*() const { return wb_->sheet_by_index(index_); }