From 484f642d69a28e91f1d8017721169ccd0af40465 Mon Sep 17 00:00:00 2001 From: XiaoMu Qin Date: Thu, 19 Feb 2026 23:47:25 +0800 Subject: [PATCH 1/4] coding style change about auto use --- src/core/include/scene/unit.hpp | 37 +++++++++++++++++---------------- 1 file changed, 19 insertions(+), 18 deletions(-) diff --git a/src/core/include/scene/unit.hpp b/src/core/include/scene/unit.hpp index 8cb5439..784d417 100644 --- a/src/core/include/scene/unit.hpp +++ b/src/core/include/scene/unit.hpp @@ -224,34 +224,34 @@ namespace gkit::scene { public: iterator(Unit* owner, size_t pos) : m_owner(owner), m_pos(pos) {} - reference operator*() const { + auto operator*() -> reference const { auto child_opt = m_owner->get_available_child(static_cast(m_pos)); return **child_opt; } - pointer operator->() const { + auto operator->() -> pointer const { auto child_opt = m_owner->get_available_child(static_cast(m_pos)); return *child_opt; } - iterator &operator++() { + auto operator++() -> iterator& { ++m_pos; return *this; } - iterator operator++(int) { + auto operator++(int) -> iterator { iterator tmp = *this; ++(*this); return tmp; } - iterator &operator--() { + auto operator--() -> iterator& { --m_pos; return *this; } - iterator operator--(int) { + auto operator--(int) -> iterator { iterator tmp = *this; --(*this); return tmp; } - bool operator==(const iterator& other) const { return m_owner == other.m_owner && m_pos == other.m_pos; } - bool operator!=(const iterator& other) const { return !(*this == other); } + auto operator==(const iterator& other) -> bool const { return m_owner == other.m_owner && m_pos == other.m_pos; } + auto operator!=(const iterator& other) -> bool const { return !(*this == other); } private: Unit* m_owner; @@ -259,6 +259,9 @@ namespace gkit::scene { friend class Unit; }; + // Why this part didn't use auto, because it need to have a const_iterator use + // but auto could not allow two same function but with different return + // but begin iterator begin() { update_index_cache(); return iterator(this, 0); @@ -281,39 +284,37 @@ namespace gkit::scene { const_iterator(const Unit* owner, size_t pos) : m_owner(owner), m_pos(pos) {} - reference operator*() const { + auto operator*() -> reference const { auto child_opt = const_cast(m_owner)->get_available_child(static_cast(m_pos)); return **child_opt; } - pointer operator->() const { + auto operator->() -> pointer const { auto child_opt = const_cast(m_owner)->get_available_child(static_cast(m_pos)); return *child_opt; } - const_iterator &operator++() { + auto operator++() -> const_iterator& { ++m_pos; return *this; } - const_iterator operator++(int) { + auto operator++(int) -> const_iterator { const_iterator tmp = *this; ++(*this); return tmp; } - const_iterator &operator--() { + auto operator--() -> const_iterator& { --m_pos; return *this; } - const_iterator operator--(int) { + auto operator--(int) -> const_iterator { const_iterator tmp = *this; --(*this); return tmp; } - bool operator==(const const_iterator& other) const { - return m_owner == other.m_owner && m_pos == other.m_pos; - } - bool operator!=(const const_iterator& other) const { return !(*this == other); } + auto operator==(const const_iterator& other) -> bool const { return m_owner == other.m_owner && m_pos == other.m_pos; } + auto operator!=(const const_iterator& other) -> bool const { return !(*this == other); } private: const Unit* m_owner; From e7c87174c2d90cccd66c97b1195a7968c5571d23 Mon Sep 17 00:00:00 2001 From: XiaoMu Qin Date: Fri, 20 Feb 2026 00:08:53 +0800 Subject: [PATCH 2/4] now cache would not update every begin() or end() --- src/core/include/scene/unit.hpp | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/core/include/scene/unit.hpp b/src/core/include/scene/unit.hpp index 784d417..4965fc5 100644 --- a/src/core/include/scene/unit.hpp +++ b/src/core/include/scene/unit.hpp @@ -261,14 +261,13 @@ namespace gkit::scene { // Why this part didn't use auto, because it need to have a const_iterator use // but auto could not allow two same function but with different return - // but begin + // but begin() and end() need those two return + // So I will not change it iterator begin() { - update_index_cache(); return iterator(this, 0); } iterator end() { - update_index_cache(); return iterator(this, active_index_cache.size()); } @@ -321,13 +320,13 @@ namespace gkit::scene { size_t m_pos; }; - const_iterator begin() const { - const_cast(this)->update_index_cache(); + const_iterator begin() const{ + const_cast(this); return const_iterator(this, 0); } const_iterator end() const { - const_cast(this)->update_index_cache(); + const_cast(this); return const_iterator(this, active_index_cache.size()); } From 1bde6eea9a018afe88d3ccae3d2ccd4a59eebe76 Mon Sep 17 00:00:00 2001 From: XiaoMu Qin Date: Sat, 21 Feb 2026 14:14:14 +0800 Subject: [PATCH 3/4] fix the header file problem --- src/core/include/scene/unit.hpp | 116 +++++++++----------------------- src/core/scene/unit.cpp | 98 +++++++++++++++++++++++++++ 2 files changed, 128 insertions(+), 86 deletions(-) diff --git a/src/core/include/scene/unit.hpp b/src/core/include/scene/unit.hpp index 5216053..4e2314a 100644 --- a/src/core/include/scene/unit.hpp +++ b/src/core/include/scene/unit.hpp @@ -220,35 +220,15 @@ namespace gkit::scene { using reference = Unit&; public: - iterator(Unit* owner, size_t pos) : m_owner(owner), m_pos(pos) {} - auto operator*() -> reference const { - auto child_opt = m_owner->get_available_child(static_cast(m_pos)); - return **child_opt; - } - auto operator->() -> pointer const { - auto child_opt = m_owner->get_available_child(static_cast(m_pos)); - return *child_opt; - } - auto operator++() -> iterator& { - ++m_pos; - return *this; - } - auto operator++(int) -> iterator { - iterator tmp = *this; - ++(*this); - return tmp; - } - auto operator--() -> iterator& { - --m_pos; - return *this; - } - auto operator--(int) -> iterator { - iterator tmp = *this; - --(*this); - return tmp; - } - auto operator==(const iterator& other) -> bool const { return m_owner == other.m_owner && m_pos == other.m_pos; } - auto operator!=(const iterator& other) -> bool const { return !(*this == other); } + iterator(Unit* owner, size_t pos); + auto operator*() -> reference const; + auto operator->() -> pointer const; + auto operator++() -> iterator&; + auto operator++(int) -> iterator; + auto operator--() -> iterator&; + auto operator--(int) -> iterator; + auto operator==(const iterator& other) const -> bool; + auto operator!=(const iterator& other) const -> bool; private: Unit* m_owner; @@ -260,13 +240,8 @@ namespace gkit::scene { // but auto could not allow two same function but with different return // but begin() and end() need those two return // So I will not change it - iterator begin() { - return iterator(this, 0); - } - - iterator end() { - return iterator(this, active_index_cache.size()); - } + auto begin() -> iterator; + auto end() -> iterator; public: // Next, we are going to write the const implementation of the iterator. @@ -278,71 +253,40 @@ namespace gkit::scene { using pointer = const Unit*; using reference = const Unit&; - const_iterator(const Unit* owner, size_t pos) : m_owner(owner), m_pos(pos) {} - - auto operator*() -> reference const { - auto child_opt = const_cast(m_owner)->get_available_child(static_cast(m_pos)); - return **child_opt; - } - - auto operator->() -> pointer const { - auto child_opt = const_cast(m_owner)->get_available_child(static_cast(m_pos)); - return *child_opt; - } - - auto operator++() -> const_iterator& { - ++m_pos; - return *this; - } - auto operator++(int) -> const_iterator { - const_iterator tmp = *this; - ++(*this); - return tmp; - } - auto operator--() -> const_iterator& { - --m_pos; - return *this; - } - auto operator--(int) -> const_iterator { - const_iterator tmp = *this; - --(*this); - return tmp; - } - - auto operator==(const const_iterator& other) -> bool const { return m_owner == other.m_owner && m_pos == other.m_pos; } - auto operator!=(const const_iterator& other) -> bool const { return !(*this == other); } + const_iterator(const Unit* owner, size_t pos); + auto operator*() -> reference const; + auto operator->() -> pointer const; + auto operator++() -> const_iterator&; + auto operator++(int) -> const_iterator; + auto operator--() -> const_iterator&; + auto operator--(int) -> const_iterator; + auto operator==(const const_iterator& other) const -> bool; + auto operator!=(const const_iterator& other) const -> bool; private: const Unit* m_owner; size_t m_pos; }; - const_iterator begin() const{ - const_cast(this); - return const_iterator(this, 0); - } - - const_iterator end() const { - const_cast(this); - return const_iterator(this, active_index_cache.size()); - } + auto begin() const -> const_iterator; + auto end() const -> const_iterator; - const_iterator cbegin() const { return begin(); } - const_iterator cend() const { return end(); } + const_iterator cbegin() const; + const_iterator cend() const; public: // This is a reverse iterator, implemented using std::reverse_iterator. using reverse_iterator = std::reverse_iterator; using const_reverse_iterator = std::reverse_iterator; - reverse_iterator rbegin() { return reverse_iterator(end()); } - reverse_iterator rend() { return reverse_iterator(begin()); } + reverse_iterator rbegin(); + reverse_iterator rend(); - const_reverse_iterator rbegin() const { return const_reverse_iterator(end()); } - const_reverse_iterator rend() const { return const_reverse_iterator(begin()); } + const_reverse_iterator rbegin() const; + const_reverse_iterator rend() const; - const_reverse_iterator crbegin() const { return rbegin(); } - const_reverse_iterator crend() const { return rend(); } + const_reverse_iterator crbegin() const; + const_reverse_iterator crend() const; }; // class Unit diff --git a/src/core/scene/unit.cpp b/src/core/scene/unit.cpp index 63ba2c7..21ac794 100644 --- a/src/core/scene/unit.cpp +++ b/src/core/scene/unit.cpp @@ -184,3 +184,101 @@ auto gkit::scene::Unit::get_parent() noexcept -> std::optiona if (parent == nullptr) return std::nullopt; return std::ref(*parent); } + + +// iterator part use +gkit::scene::Unit::iterator::iterator(Unit* owner, size_t pos) : m_owner(owner), m_pos(pos) {} +auto gkit::scene::Unit::iterator::operator*() -> reference const { +auto child_opt = m_owner->get_available_child(static_cast(m_pos)); + return **child_opt; +} +auto gkit::scene::Unit::iterator::operator->() -> pointer const { + auto child_opt = m_owner->get_available_child(static_cast(m_pos)); + return *child_opt; +} +auto gkit::scene::Unit::iterator::operator++() -> iterator& { + ++m_pos; + return *this; +} +auto gkit::scene::Unit::iterator::operator++(int) -> iterator { + iterator tmp = *this; + ++(*this); + return tmp; +} +auto gkit::scene::Unit::iterator::operator--() -> iterator& { + --m_pos; + return *this; +} +auto gkit::scene::Unit::iterator::operator--(int) -> iterator { + iterator tmp = *this; + --(*this); + return tmp; +} +auto gkit::scene::Unit::iterator::operator==(const iterator& other) const -> bool { return m_owner == other.m_owner && m_pos == other.m_pos; } +auto gkit::scene::Unit::iterator::operator!=(const iterator& other) const -> bool { return !(*this == other); } + +auto gkit::scene::Unit::begin() -> iterator{ + return iterator(this, 0); +} + +auto gkit::scene::Unit::end() -> iterator{ + return iterator(this, active_index_cache.size()); +} + +// now is const_iterator use +gkit::scene::Unit::const_iterator::const_iterator(const Unit* owner, size_t pos) : m_owner(owner), m_pos(pos) {} + +auto gkit::scene::Unit::const_iterator::operator*() -> reference const { + auto child_opt = const_cast(m_owner)->get_available_child(static_cast(m_pos)); + return **child_opt; +} + +auto gkit::scene::Unit::const_iterator::operator->() -> pointer const { + auto child_opt = const_cast(m_owner)->get_available_child(static_cast(m_pos)); + return *child_opt; +} + +auto gkit::scene::Unit::const_iterator::operator++() -> const_iterator& { + ++m_pos; + return *this; +} +auto gkit::scene::Unit::const_iterator::operator++(int) -> const_iterator { + const_iterator tmp = *this; + ++(*this); + return tmp; +} +auto gkit::scene::Unit::const_iterator::operator--() -> const_iterator& { + --m_pos; + return *this; +} +auto gkit::scene::Unit::const_iterator::operator--(int) -> const_iterator { + const_iterator tmp = *this; + --(*this); + return tmp; +} + +auto gkit::scene::Unit::const_iterator::operator==(const const_iterator& other) const -> bool { return m_owner == other.m_owner && m_pos == other.m_pos; } +auto gkit::scene::Unit::const_iterator::operator!=(const const_iterator& other) const -> bool { return !(*this == other); } + +auto gkit::scene::Unit::begin() const -> const_iterator { + const_cast(this); + return const_iterator(this, 0); +} + +auto gkit::scene::Unit::end() const -> const_iterator { + const_cast(this); + return const_iterator(this, active_index_cache.size()); +} + +auto gkit::scene::Unit::cbegin() const -> const_iterator { return begin(); } +auto gkit::scene::Unit::cend() const -> const_iterator { return end(); } + +// This is a reverse iterator, implemented using std::reverse_iterator. +using reverse_iterator = std::reverse_iterator; +using const_reverse_iterator = std::reverse_iterator; +reverse_iterator gkit::scene::Unit::rbegin() { return reverse_iterator(end()); } +reverse_iterator gkit::scene::Unit::rend() { return reverse_iterator(begin()); } +const_reverse_iterator gkit::scene::Unit::rbegin() const { return const_reverse_iterator(end()); } +const_reverse_iterator gkit::scene::Unit::rend() const { return const_reverse_iterator(begin()); } +const_reverse_iterator gkit::scene::Unit::crbegin() const { return rbegin(); } +const_reverse_iterator gkit::scene::Unit::crend() const { return rend(); } \ No newline at end of file From 9ea508bba13caa1cac27e02b6ca109b16ed59e04 Mon Sep 17 00:00:00 2001 From: XiaoMu Qin Date: Sat, 21 Feb 2026 14:21:57 +0800 Subject: [PATCH 4/4] find some auto not use problem and fixed it --- src/core/include/scene/unit.hpp | 16 ++++++++-------- src/core/scene/unit.cpp | 12 ++++++------ 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/core/include/scene/unit.hpp b/src/core/include/scene/unit.hpp index 4e2314a..41ad459 100644 --- a/src/core/include/scene/unit.hpp +++ b/src/core/include/scene/unit.hpp @@ -271,22 +271,22 @@ namespace gkit::scene { auto begin() const -> const_iterator; auto end() const -> const_iterator; - const_iterator cbegin() const; - const_iterator cend() const; + auto cbegin() const -> const_iterator; + auto cend() const -> const_iterator; public: // This is a reverse iterator, implemented using std::reverse_iterator. using reverse_iterator = std::reverse_iterator; using const_reverse_iterator = std::reverse_iterator; - reverse_iterator rbegin(); - reverse_iterator rend(); + auto rbegin() -> reverse_iterator; + auto rend() -> reverse_iterator; - const_reverse_iterator rbegin() const; - const_reverse_iterator rend() const; + auto rbegin() const -> const_reverse_iterator; + auto rend() const -> const_reverse_iterator; - const_reverse_iterator crbegin() const; - const_reverse_iterator crend() const; + auto crbegin() const -> const_reverse_iterator; + auto crend() const -> const_reverse_iterator; }; // class Unit diff --git a/src/core/scene/unit.cpp b/src/core/scene/unit.cpp index 21ac794..2c21eaa 100644 --- a/src/core/scene/unit.cpp +++ b/src/core/scene/unit.cpp @@ -276,9 +276,9 @@ auto gkit::scene::Unit::cend() const -> const_iterator { return end(); } // This is a reverse iterator, implemented using std::reverse_iterator. using reverse_iterator = std::reverse_iterator; using const_reverse_iterator = std::reverse_iterator; -reverse_iterator gkit::scene::Unit::rbegin() { return reverse_iterator(end()); } -reverse_iterator gkit::scene::Unit::rend() { return reverse_iterator(begin()); } -const_reverse_iterator gkit::scene::Unit::rbegin() const { return const_reverse_iterator(end()); } -const_reverse_iterator gkit::scene::Unit::rend() const { return const_reverse_iterator(begin()); } -const_reverse_iterator gkit::scene::Unit::crbegin() const { return rbegin(); } -const_reverse_iterator gkit::scene::Unit::crend() const { return rend(); } \ No newline at end of file +auto gkit::scene::Unit::rbegin() -> reverse_iterator { return reverse_iterator(end()); } +auto gkit::scene::Unit::rend() -> reverse_iterator { return reverse_iterator(begin()); } +auto gkit::scene::Unit::rbegin() const -> const_reverse_iterator { return const_reverse_iterator(end()); } +auto gkit::scene::Unit::rend() const -> const_reverse_iterator { return const_reverse_iterator(begin()); } +auto gkit::scene::Unit::crbegin() const -> const_reverse_iterator { return rbegin(); } +auto gkit::scene::Unit::crend() const -> const_reverse_iterator { return rend(); } \ No newline at end of file