Add iterator traits aliases to ConstPointerContainer::ConstIterator (#634)

* Add iterator traits aliases.

* Add a few more pieces to make more compliant with the input iterator requirements.
This commit is contained in:
Scott McKay 2019-03-21 15:45:58 +10:00 committed by GitHub
parent 2f1c3028b7
commit a3499083da
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -20,17 +20,41 @@ class ConstPointerContainer {
class ConstIterator {
public:
using const_iterator = typename Container::const_iterator;
using iterator_category = std::input_iterator_tag;
using value_type = T*;
using difference_type = std::ptrdiff_t;
using pointer = T**;
using reference = T*&;
/** Construct iterator for container that will return const T* entries.*/
explicit ConstIterator(const_iterator position) noexcept : current_(position) {}
explicit ConstIterator(const_iterator position) noexcept : current_{position}, item_{nullptr} {}
ConstIterator(const ConstIterator& other) = default;
ConstIterator& operator=(const ConstIterator& other) = default;
bool operator==(const ConstIterator& other) const noexcept { return current_ == other.current_; }
bool operator!=(const ConstIterator& other) const noexcept { return current_ != other.current_; }
void operator++() { ++current_; }
const T* operator*() { return *current_; }
ConstIterator& operator++() {
++current_;
return *this;
}
ConstIterator operator++(int) {
ConstIterator tmp{*this};
++(*this);
return tmp;
}
const T*& operator*() const {
item_ = *current_;
return item_;
}
const T** operator->() const { return &(operator*()); };
private:
const_iterator current_;
mutable const T* item_;
};
/**