Simplify some code with Boost.Operators
Change-Id: Ic873bcbaf6be00d5c35601cfc8090df534d815ee
diff --git a/daemon/table/pit-iterator.hpp b/daemon/table/pit-iterator.hpp
index bfe0e8e..e1647ff 100644
--- a/daemon/table/pit-iterator.hpp
+++ b/daemon/table/pit-iterator.hpp
@@ -34,42 +34,32 @@
/**
* \brief PIT iterator.
*/
-class Iterator
+class Iterator : public boost::forward_iterator_helper<Iterator, const Entry>
{
public:
- using iterator_category = std::forward_iterator_tag;
- using value_type = const Entry;
- using difference_type = std::ptrdiff_t;
- using pointer = value_type*;
- using reference = value_type&;
-
- /** \brief Constructor.
- * \param ntIt a name tree iterator that visits name tree entries with one or more PIT entries
- * \param iPitEntry make this iterator to dereference to the i-th PIT entry in name tree entry
+ /**
+ * \brief Constructor.
+ * \param ntIt a name tree iterator that visits name tree entries with one or more PIT entries
+ * \param iPitEntry make this iterator to dereference to the i-th PIT entry in name tree entry
*/
explicit
- Iterator(const NameTree::const_iterator& ntIt = {}, size_t iPitEntry = 0);
-
- const Entry&
- operator*() const
+ Iterator(const NameTree::const_iterator& ntIt = {}, size_t iPitEntry = 0)
+ : m_ntIt(ntIt)
+ , m_iPitEntry(iPitEntry)
{
- return *this->operator->();
}
- const shared_ptr<Entry>&
- operator->() const
+ const Entry&
+ operator*() const noexcept
{
BOOST_ASSERT(m_ntIt != NameTree::const_iterator());
BOOST_ASSERT(m_iPitEntry < m_ntIt->getPitEntries().size());
- return m_ntIt->getPitEntries()[m_iPitEntry];
+ return *m_ntIt->getPitEntries()[m_iPitEntry];
}
Iterator&
operator++();
- Iterator
- operator++(int);
-
friend bool
operator==(const Iterator& lhs, const Iterator& rhs) noexcept
{
@@ -77,12 +67,6 @@
lhs.m_iPitEntry == rhs.m_iPitEntry;
}
- friend bool
- operator!=(const Iterator& lhs, const Iterator& rhs) noexcept
- {
- return !(lhs == rhs);
- }
-
private:
NameTree::const_iterator m_ntIt; ///< current name tree entry
size_t m_iPitEntry; ///< current PIT entry within m_ntIt->getPitEntries()