Skip to content

Conversation

@oldnewthing
Copy link
Member

The built-in iterators for IVector and IVectorView (and more generally anything that has a GetAt method) now support random-access operations. They do not meet all the requirements of a random-access iterator, most notably:

  • reference is not value_type& or value_type const&.
  • operator-> is not supported.

Design notes:

  • The value_type had been misdeclared as T (e.g. IVector<Something>) rather than the element type (Something).
  • The reference is not actually a reference because the return value of operator* must be convertible to reference.
  • The element index is unsigned so that the relational operators like < produce correct results on large containers.
  • The difference_type is ptrdiff_t so that b-a and related operations work on large containers.
  • Return types for iterator operations are explicit to ensure they conform to iterator requirements.
  • We now rely on std::reverse_iterator to implement our reverse iterator.

The built-in iterators for IVector and IVectorView
(and more generally anything that has a GetAt method)
now support random-access operations. They do not
meet all the requirements of a random-access iterator,
most notably:
* `reference` is not `value_type&` or `value_type const&`.
* `operator->` is not supported.

Design notes:
* The `value_type` had been misdeclared as `T`
  (e.g. `IVector<Something>`) rather than the
  element type (`Something`).
* The `reference` is not actually a reference because
  the return value of `operator*` must be convertible
  to `reference`.
* The element index is unsigned so that
  the relational operators like `<` produce correct
  results on large containers.
* The `difference_type` is `ptrdiff_t` so that
  `b-a` and related operations work on large containers.
* Return types for iterator operations are explicit
  to ensure they conform to iterator requirements.
* We now rely on `std::reverse_iterator` to implement
  our reverse iterator.
@kennykerr
Copy link
Collaborator

/azp run

@azure-pipelines
Copy link

No pipelines are associated with this pull request.

@kennykerr kennykerr merged commit f3a2779 into microsoft:master Apr 8, 2020
@oldnewthing oldnewthing deleted the random-access-iterator branch April 8, 2020 19:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants