diff --git a/src/supertux/game_object_iterator.hpp b/src/supertux/game_object_iterator.hpp index 5931925da5a..1bef5e52390 100644 --- a/src/supertux/game_object_iterator.hpp +++ b/src/supertux/game_object_iterator.hpp @@ -35,24 +35,28 @@ class GameObjectIterator { if (m_it != m_end) { + // A dynamic_cast is needed to perform sidecasts (a.k.a. crosscasts) + // T may be one of multiple base classes of the object and need not inherit GameObject m_object = dynamic_cast(*m_it); - if (!m_object) - { - skip_to_next(); - } + assert(m_object); } } GameObjectIterator& operator++() { - skip_to_next(); + ++m_it; + if (m_it != m_end) + { + m_object = dynamic_cast(*m_it); + assert(m_object); + } return *this; } GameObjectIterator operator++(int) { GameObjectIterator tmp(*this); - skip_to_next(); + operator++(); return tmp; } @@ -82,24 +86,6 @@ class GameObjectIterator return !(*this == other); } -private: - void skip_to_next() - { - do - { - ++m_it; - if (m_it == m_end) - { - break; - } - else - { - m_object = dynamic_cast(*m_it); - } - } - while (!m_object); - } - private: Iterator m_it; Iterator m_end;