diff --git a/include/fastgltf/tools.hpp b/include/fastgltf/tools.hpp index 8dce74243..82754589c 100644 --- a/include/fastgltf/tools.hpp +++ b/include/fastgltf/tools.hpp @@ -471,10 +471,10 @@ class IterableAccessor; template class AccessorIterator { protected: - const IterableAccessor* accessor; - std::size_t idx; - std::size_t sparseIdx = 0; - std::size_t nextSparseIndex = 0; + const IterableAccessor* accessor = nullptr; + std::size_t idx = std::numeric_limits::max(); + mutable std::size_t sparseIdx = 0; + mutable std::size_t nextSparseIndex = 0; public: using value_type = ElementType; @@ -486,6 +486,8 @@ class AccessorIterator { // some things that these come with (e.g. std::distance using operator-). using iterator_category = std::random_access_iterator_tag; + AccessorIterator() = default; + AccessorIterator(const IterableAccessor* accessor, std::size_t idx = 0) : accessor(accessor), idx(idx) { if (accessor->accessor.sparse.has_value()) { @@ -512,7 +514,8 @@ class AccessorIterator { [[nodiscard]] bool operator==(const AccessorIterator& iterator) const noexcept { // We don't compare sparse properties - return idx == iterator.idx && + return accessor == iterator.accessor && + idx == iterator.idx && accessor->bufferBytes.data() == iterator.accessor->bufferBytes.data() && accessor->stride == iterator.accessor->stride && accessor->componentType == iterator.accessor->componentType; @@ -522,7 +525,7 @@ class AccessorIterator { return !(*this == iterator); } - [[nodiscard]] ElementType operator*() noexcept { + [[nodiscard]] ElementType operator*() const noexcept { if (accessor->accessor.sparse.has_value()) { if (idx == nextSparseIndex) { // Get the sparse value for this index @@ -546,6 +549,10 @@ class AccessorIterator { } }; +#if FASTGLTF_HAS_CONCEPTS +static_assert(std::input_iterator>, "AccessorIterator needs to satisfy input_iterator"); +#endif + template class IterableAccessor { friend class AccessorIterator; @@ -602,6 +609,10 @@ class IterableAccessor { } }; +#if FASTGLTF_HAS_CONCEPTS +static_assert(std::ranges::input_range>, "IterableAccessor needs to satisfy input_range"); +#endif + FASTGLTF_EXPORT template #if FASTGLTF_HAS_CONCEPTS requires Element