diff options
author | Peter Collingbourne <peter@pcc.me.uk> | 2016-01-15 02:19:20 +0000 |
---|---|---|
committer | Peter Collingbourne <peter@pcc.me.uk> | 2016-01-15 02:19:20 +0000 |
commit | df853a53f54d4463b73c5de08381a316f853a38d (patch) | |
tree | 92362a72e1432b2785b1354e9831143a2f71410b /lib/sanitizer_common/sanitizer_list.h | |
parent | 7fb99ae7f7f8b43e2f4cb5122edbfbe50673f623 (diff) | |
download | compiler-rt-df853a53f54d4463b73c5de08381a316f853a38d.tar.gz |
sanitizer_common: C++ify the IntrusiveList iterator interface.
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@257858 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/sanitizer_common/sanitizer_list.h')
-rw-r--r-- | lib/sanitizer_common/sanitizer_list.h | 30 |
1 files changed, 19 insertions, 11 deletions
diff --git a/lib/sanitizer_common/sanitizer_list.h b/lib/sanitizer_common/sanitizer_list.h index adbb97dc7..ac7e31b08 100644 --- a/lib/sanitizer_common/sanitizer_list.h +++ b/lib/sanitizer_common/sanitizer_list.h @@ -116,24 +116,32 @@ struct IntrusiveList { } } - template<class ListTy, class ItemTy> + template<class ItemTy> class IteratorBase { public: - explicit IteratorBase(ListTy *list) - : list_(list), current_(list->first_) { } - ItemTy *next() { - ItemTy *ret = current_; - if (current_) current_ = current_->next; - return ret; + explicit IteratorBase(ItemTy *current) : current_(current) {} + IteratorBase &operator++() { + current_ = current_->next; + return *this; + } + bool operator!=(IteratorBase other) const { + return current_ != other.current_; + } + ItemTy &operator*() { + return *current_; } - bool hasNext() const { return current_ != nullptr; } private: - ListTy *list_; ItemTy *current_; }; - typedef IteratorBase<IntrusiveList<Item>, Item> Iterator; - typedef IteratorBase<const IntrusiveList<Item>, const Item> ConstIterator; + typedef IteratorBase<Item> Iterator; + typedef IteratorBase<const Item> ConstIterator; + + Iterator begin() { return Iterator(first_); } + Iterator end() { return Iterator(0); } + + ConstIterator begin() const { return ConstIterator(first_); } + ConstIterator end() const { return ConstIterator(0); } // private, don't use directly. uptr size_; |