diff --git a/include/xlnt/workbook/worksheet_iterator.hpp b/include/xlnt/workbook/worksheet_iterator.hpp
index b2830f88..c1b24a78 100644
--- a/include/xlnt/workbook/worksheet_iterator.hpp
+++ b/include/xlnt/workbook/worksheet_iterator.hpp
@@ -61,12 +61,27 @@ public:
///
/// Copy constructs a worksheet iterator from another iterator.
///
- worksheet_iterator(const worksheet_iterator &);
+ worksheet_iterator(const worksheet_iterator &) = default;
///
/// Assigns the iterator so that it points to the same worksheet in the same workbook.
///
- worksheet_iterator &operator=(const worksheet_iterator &);
+ worksheet_iterator &operator=(const worksheet_iterator &) = default;
+
+ ///
+ /// Copy constructs a worksheet iterator from another iterator.
+ ///
+ worksheet_iterator(worksheet_iterator &&) = default;
+
+ ///
+ /// Assigns the iterator so that it points to the same worksheet in the same workbook.
+ ///
+ worksheet_iterator &operator=(worksheet_iterator &&) = default;
+
+ ///
+ /// Default destructor
+ ///
+ ~worksheet_iterator() = default;
///
/// Dereferences the iterator to return the worksheet it is pointing to.
@@ -101,7 +116,7 @@ private:
///
/// The target workbook of this iterator.
///
- workbook &wb_;
+ workbook *wb_;
///
/// The index of the worksheet in wb_ this iterator is currently pointing to.
@@ -133,12 +148,27 @@ public:
///
/// Copy constructs a worksheet iterator from another iterator.
///
- const_worksheet_iterator(const const_worksheet_iterator &);
+ const_worksheet_iterator(const const_worksheet_iterator &) = default;
///
/// Assigns the iterator so that it points to the same worksheet in the same workbook.
///
- const_worksheet_iterator &operator=(const const_worksheet_iterator &);
+ const_worksheet_iterator &operator=(const const_worksheet_iterator &) = default;
+
+ ///
+ /// Move constructs a worksheet iterator from another iterator.
+ ///
+ const_worksheet_iterator(const_worksheet_iterator &&) = default;
+
+ ///
+ /// Assigns the iterator from a temporary
+ ///
+ const_worksheet_iterator &operator=(const_worksheet_iterator &&) = default;
+
+ ///
+ /// Default destructor
+ ///
+ ~const_worksheet_iterator() = default;
///
/// Dereferences the iterator to return the worksheet it is pointing to.
@@ -173,7 +203,7 @@ private:
///
/// The target workbook of this iterator.
///
- const workbook &wb_;
+ const workbook *wb_;
///
/// The index of the worksheet in wb_ this iterator is currently pointing to.
diff --git a/source/workbook/worksheet_iterator.cpp b/source/workbook/worksheet_iterator.cpp
index daee7a64..0487cf33 100644
--- a/source/workbook/worksheet_iterator.cpp
+++ b/source/workbook/worksheet_iterator.cpp
@@ -28,18 +28,13 @@
namespace xlnt {
worksheet_iterator::worksheet_iterator(workbook &wb, std::size_t index)
- : wb_(wb), index_(index)
-{
-}
-
-worksheet_iterator::worksheet_iterator(const worksheet_iterator &rhs)
- : wb_(rhs.wb_), index_(rhs.index_)
+ : wb_(&wb), index_(index)
{
}
worksheet worksheet_iterator::operator*()
{
- return wb_[index_];
+ return (*wb_)[index_];
}
worksheet_iterator &worksheet_iterator::operator++()
@@ -50,7 +45,7 @@ worksheet_iterator &worksheet_iterator::operator++()
worksheet_iterator worksheet_iterator::operator++(int)
{
- worksheet_iterator old(wb_, index_);
+ worksheet_iterator old(*wb_, index_);
++*this;
return old;
}
@@ -65,25 +60,14 @@ bool worksheet_iterator::operator!=(const worksheet_iterator &comparand) const
return !(*this == comparand);
}
-worksheet_iterator &worksheet_iterator::operator=(const worksheet_iterator &other)
-{
- index_ = other.index_;
- return *this;
-}
-
const_worksheet_iterator::const_worksheet_iterator(const workbook &wb, std::size_t index)
- : wb_(wb), index_(index)
-{
-}
-
-const_worksheet_iterator::const_worksheet_iterator(const const_worksheet_iterator &rhs)
- : wb_(rhs.wb_), index_(rhs.index_)
+ : wb_(&wb), index_(index)
{
}
const worksheet const_worksheet_iterator::operator*()
{
- return wb_.sheet_by_index(index_);
+ return wb_->sheet_by_index(index_);
}
const_worksheet_iterator &const_worksheet_iterator::operator++()
@@ -94,7 +78,7 @@ const_worksheet_iterator &const_worksheet_iterator::operator++()
const_worksheet_iterator const_worksheet_iterator::operator++(int)
{
- const_worksheet_iterator old(wb_, index_);
+ const_worksheet_iterator old(*wb_, index_);
++*this;
return old;
}