diff options
author | mmoscicki2 <50666212+mmoscicki2@users.noreply.github.com> | 2019-05-16 20:49:01 +0200 |
---|---|---|
committer | Wouter van Oortmerssen <aardappel@gmail.com> | 2019-05-16 11:49:01 -0700 |
commit | 39bd667fd0a149c3bb428ccf35fa8c17fcafeccf (patch) | |
tree | bd415f0284bc831a05571ab84b8d588549cb4abc /include | |
parent | 0bb3ce69353d94f88da4658768fbac2934a035f0 (diff) | |
download | flatbuffers-39bd667fd0a149c3bb428ccf35fa8c17fcafeccf.tar.gz flatbuffers-39bd667fd0a149c3bb428ccf35fa8c17fcafeccf.tar.bz2 flatbuffers-39bd667fd0a149c3bb428ccf35fa8c17fcafeccf.zip |
Fix reverse_iterator in Vector and tests (#5344)
Before this commit tests for iterators passed, even if the code inside
the loop has not been executed.
Diffstat (limited to 'include')
-rw-r--r-- | include/flatbuffers/flatbuffers.h | 22 |
1 files changed, 12 insertions, 10 deletions
diff --git a/include/flatbuffers/flatbuffers.h b/include/flatbuffers/flatbuffers.h index a1a95f00..83dd09de 100644 --- a/include/flatbuffers/flatbuffers.h +++ b/include/flatbuffers/flatbuffers.h @@ -201,14 +201,16 @@ template<typename T, typename IT> struct VectorIterator { template<typename Iterator> struct VectorReverseIterator : public std::reverse_iterator<Iterator> { - explicit VectorReverseIterator(Iterator iter) : iter_(iter) {} + explicit VectorReverseIterator(Iterator iter) : + std::reverse_iterator<Iterator>(iter) {} - typename Iterator::value_type operator*() const { return *(iter_ - 1); } - - typename Iterator::value_type operator->() const { return *(iter_ - 1); } + typename Iterator::value_type operator*() const { + return *(std::reverse_iterator<Iterator>::current); + } - private: - Iterator iter_; + typename Iterator::value_type operator->() const { + return *(std::reverse_iterator<Iterator>::current); + } }; struct String; @@ -269,11 +271,11 @@ template<typename T> class Vector { iterator end() { return iterator(Data(), size()); } const_iterator end() const { return const_iterator(Data(), size()); } - reverse_iterator rbegin() { return reverse_iterator(end()); } - const_reverse_iterator rbegin() const { return const_reverse_iterator(end()); } + reverse_iterator rbegin() { return reverse_iterator(end() - 1); } + const_reverse_iterator rbegin() const { return const_reverse_iterator(end() - 1); } - reverse_iterator rend() { return reverse_iterator(end()); } - const_reverse_iterator rend() const { return const_reverse_iterator(end()); } + reverse_iterator rend() { return reverse_iterator(begin() - 1); } + const_reverse_iterator rend() const { return const_reverse_iterator(begin() - 1); } const_iterator cbegin() const { return begin(); } |