Use a pointer instead of reference as a member.

This allows the assignment operator for the iterator to be generated
automatically by the compiler.
This commit is contained in:
Breno Guimaraes 2020-04-18 03:34:39 -03:00
parent c5d877f644
commit 38ffc4f577
1 changed files with 5 additions and 5 deletions

View File

@ -980,7 +980,7 @@ struct RideManager
friend RideManager; friend RideManager;
private: private:
RideManager& _rideManager; RideManager* _rideManager;
size_t _index{}; size_t _index{};
size_t _endIndex{}; size_t _endIndex{};
@ -993,11 +993,11 @@ struct RideManager
private: private:
Iterator(RideManager& rideManager, size_t beginIndex, size_t endIndex) Iterator(RideManager& rideManager, size_t beginIndex, size_t endIndex)
: _rideManager(rideManager) : _rideManager(&rideManager)
, _index(beginIndex) , _index(beginIndex)
, _endIndex(endIndex) , _endIndex(endIndex)
{ {
if (_index < _endIndex && _rideManager[static_cast<ride_id_t>(_index)] == nullptr) if (_index < _endIndex && (*_rideManager)[static_cast<ride_id_t>(_index)] == nullptr)
{ {
++(*this); ++(*this);
} }
@ -1009,7 +1009,7 @@ struct RideManager
do do
{ {
_index++; _index++;
} while (_index < _endIndex && _rideManager[static_cast<ride_id_t>(_index)] == nullptr); } while (_index < _endIndex && (*_rideManager)[static_cast<ride_id_t>(_index)] == nullptr);
return *this; return *this;
} }
Iterator operator++(int) Iterator operator++(int)
@ -1028,7 +1028,7 @@ struct RideManager
} }
Ride& operator*() Ride& operator*()
{ {
return *_rideManager[static_cast<ride_id_t>(_index)]; return *(*_rideManager)[static_cast<ride_id_t>(_index)];
} }
}; };