Skip to content

SmallVector: Iterator support #73

Description

@jsrivaya

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions