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
This commit is contained in:
Crzyrndm 2018-05-31 16:00:40 +12:00
parent a47985b2db
commit 04b50d9b8e
2 changed files with 16 additions and 4 deletions

View File

@ -88,7 +88,14 @@ public:
/// If the iterator points to one-past-the-end of the workbook, an invalid_parameter /// If the iterator points to one-past-the-end of the workbook, an invalid_parameter
/// exception will be thrown. /// exception will be thrown.
/// </summary> /// </summary>
worksheet operator*(); reference operator*();
/// <summary>
/// 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.
/// </summary>
const reference operator*() const;
/// <summary> /// <summary>
/// Returns true if this iterator points to the same worksheet as comparand. /// 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 /// If the iterator points to one-past-the-end of the workbook, an invalid_parameter
/// exception will be thrown. /// exception will be thrown.
/// </summary> /// </summary>
const worksheet operator*(); const reference operator*() const;
/// <summary> /// <summary>
/// Returns true if this iterator points to the same worksheet as comparand. /// Returns true if this iterator points to the same worksheet as comparand.

View File

@ -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_]; 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_); return wb_->sheet_by_index(index_);
} }