Parent
Part of #5. Depends on #71.
Summary
Implement full iterator support for SmallVector compatible with std::vector iterator requirements.
Scope
SmallVector stores elements contiguously (inline buffer or heap — both flat arrays), so raw pointers are valid random-access iterators.
using iterator = T*;
using const_iterator = const T*;
using reverse_iterator = std::reverse_iterator<iterator>;
using const_reverse_iterator = std::reverse_iterator<const_iterator>;
iterator begin() { return data(); }
iterator end() { return data() + size_; }
// const, cbegin, cend, rbegin, rend, crbegin, crend variants
Invalidation rules (must be documented and tested)
| Operation |
Invalidates iterators? |
push_back — no reallocation |
No |
push_back — triggers heap transition |
Yes, all |
pop_back |
Only end() |
insert / emplace |
From insertion point to end() |
erase |
From erasure point to end() |
clear |
All |
| Move assignment |
All (into destination) |
STL algorithm compatibility
With raw pointer iterators, std::sort, std::find, std::copy, std::ranges::* all work out of the box. Add value_type, size_type, difference_type, pointer, reference type aliases for full Container concept compliance.
Testing requirements
- Range-based for loop
std::sort on SmallVector
std::copy into SmallVector via std::back_inserter
- Iterator remains valid after
push_back within inline capacity
- Iterator invalidated after heap transition
Parent
Part of #5. Depends on #71.
Summary
Implement full iterator support for
SmallVectorcompatible withstd::vectoriterator requirements.Scope
SmallVectorstores elements contiguously (inline buffer or heap — both flat arrays), so raw pointers are valid random-access iterators.Invalidation rules (must be documented and tested)
push_back— no reallocationpush_back— triggers heap transitionpop_backend()insert/emplaceend()eraseend()clearSTL algorithm compatibility
With raw pointer iterators,
std::sort,std::find,std::copy,std::ranges::*all work out of the box. Addvalue_type,size_type,difference_type,pointer,referencetype aliases for fullContainerconcept compliance.Testing requirements
std::sorton SmallVectorstd::copyinto SmallVector viastd::back_inserterpush_backwithin inline capacity