Skip to content

Commit

Permalink
Fix the constness issues around autovector::iterator_impl's dereferen…
Browse files Browse the repository at this point in the history
…ce operators (facebook#6057)

Summary:
As described in detail in issue facebook#6048, iterators' dereference operators
(`*`, `->`, and `[]`) should return `pointer`s/`reference`s (as opposed to
`const_pointer`s/`const_reference`s) even if the iterator itself is `const`
to be in sync with the standard's iterator concept.
Pull Request resolved: facebook#6057

Test Plan: make check

Differential Revision: D18623235

Pulled By: ltamasi

fbshipit-source-id: 04e82d73bc0c67fb0ded018383af8dfc332050cc
  • Loading branch information
ltamasi authored and facebook-github-bot committed Nov 23, 2019
1 parent c8ff6db commit b98dc75
Showing 1 changed file with 3 additions and 18 deletions.
21 changes: 3 additions & 18 deletions util/autovector.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,35 +120,20 @@ class autovector {
}

// -- Reference
reference operator*() {
reference operator*() const {
assert(vect_->size() >= index_);
return (*vect_)[index_];
}

const_reference operator*() const {
assert(vect_->size() >= index_);
return (*vect_)[index_];
}

pointer operator->() {
assert(vect_->size() >= index_);
return &(*vect_)[index_];
}

const_pointer operator->() const {
pointer operator->() const {
assert(vect_->size() >= index_);
return &(*vect_)[index_];
}

reference operator[](difference_type len) {
return *(*this + len);
}

const_reference operator[](difference_type len) const {
reference operator[](difference_type len) const {
return *(*this + len);
}


// -- Logical Operators
bool operator==(const self_type& other) const {
assert(vect_ == other.vect_);
Expand Down

0 comments on commit b98dc75

Please sign in to comment.