diff --git a/core/base/iterator_factory.hpp b/core/base/iterator_factory.hpp index b7efd21dfe..5e4bddeb17 100644 --- a/core/base/iterator_factory.hpp +++ b/core/base/iterator_factory.hpp @@ -110,7 +110,7 @@ class IteratorFactory { ~Reference() {} - Reference(IteratorFactory &parent, array_index_type array_index) + Reference(IteratorFactory *parent, array_index_type array_index) : parent_(parent), arr_index_(array_index) {} @@ -143,10 +143,10 @@ class IteratorFactory { { // In C++11, it is legal for a nested class to access private // members of the parent class. - parent_.dominant_values_[arr_index_] = - std::move(other.parent_.dominant_values_[other.arr_index_]); - parent_.secondary_values_[arr_index_] = - std::move(other.parent_.secondary_values_[other.arr_index_]); + parent_->dominant_values_[arr_index_] = + std::move(other.parent_->dominant_values_[other.arr_index_]); + parent_->secondary_values_[arr_index_] = + std::move(other.parent_->secondary_values_[other.arr_index_]); return *this; } @@ -174,25 +174,25 @@ class IteratorFactory { return left.dominant < right.dominant(); } - ToSortType &dominant() { return parent_.dominant_values_[arr_index_]; } + ToSortType &dominant() { return parent_->dominant_values_[arr_index_]; } const ToSortType &dominant() const { - return parent_.dominant_values_[arr_index_]; + return parent_->dominant_values_[arr_index_]; } SecondaryType &secondary() { - return parent_.secondary_values_[arr_index_]; + return parent_->secondary_values_[arr_index_]; } const SecondaryType &secondary() const { - return parent_.secondary_values_[arr_index_]; + return parent_->secondary_values_[arr_index_]; } private: - IteratorFactory &parent_; + IteratorFactory *parent_; array_index_type arr_index_; }; @@ -214,9 +214,11 @@ class IteratorFactory { using reference = Reference; using iterator_category = std::random_access_iterator_tag; + Iterator() = default; + ~Iterator() {} - Iterator(IteratorFactory &parent, difference_type array_index) + Iterator(IteratorFactory *parent, difference_type array_index) : parent_(parent), arr_index_(array_index) {} @@ -298,12 +300,12 @@ class IteratorFactory { } // Comparable operators - bool operator==(const Iterator &other) + bool operator==(const Iterator &other) const { return arr_index_ == other.arr_index_; } - bool operator!=(const Iterator &other) + bool operator!=(const Iterator &other) const { return arr_index_ != other.arr_index_; } @@ -329,8 +331,8 @@ class IteratorFactory { } private: - IteratorFactory &parent_; - difference_type arr_index_; + IteratorFactory *parent_{}; + difference_type arr_index_{}; }; public: @@ -363,7 +365,7 @@ class IteratorFactory { * Creates an iterator pointing to the beginning of both arrays * @returns an iterator pointing to the beginning of both arrays */ - Iterator begin() { return {*this, 0}; } + Iterator begin() { return {this, 0}; } /** * Creates an iterator pointing to the (excluding) end of both arrays @@ -371,7 +373,7 @@ class IteratorFactory { */ Iterator end() { - return {*this, static_cast(size_)}; + return {this, static_cast(size_)}; } private: