Simplify some code with Boost.Operators
Change-Id: Ic873bcbaf6be00d5c35601cfc8090df534d815ee
diff --git a/daemon/table/fib.cpp b/daemon/table/fib.cpp
index f30b976..87e180a 100644
--- a/daemon/table/fib.cpp
+++ b/daemon/table/fib.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2014-2022, Regents of the University of California,
+ * Copyright (c) 2014-2023, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
@@ -27,12 +27,8 @@
#include "pit-entry.hpp"
#include "measurements-entry.hpp"
-#include <ndn-cxx/util/concepts.hpp>
-
namespace nfd::fib {
-NDN_CXX_ASSERT_FORWARD_ITERATOR(Fib::const_iterator);
-
const unique_ptr<Entry> Fib::s_emptyEntry = make_unique<Entry>(Name());
static inline bool
diff --git a/daemon/table/name-tree-iterator.cpp b/daemon/table/name-tree-iterator.cpp
index 24c1422..b085bb7 100644
--- a/daemon/table/name-tree-iterator.cpp
+++ b/daemon/table/name-tree-iterator.cpp
@@ -27,14 +27,8 @@
#include "name-tree.hpp"
#include "common/logger.hpp"
-#include <boost/range/concepts.hpp>
-#include <ndn-cxx/util/concepts.hpp>
-
namespace nfd::name_tree {
-NDN_CXX_ASSERT_FORWARD_ITERATOR(Iterator);
-BOOST_CONCEPT_ASSERT((boost::ForwardRangeConcept<Range>));
-
NFD_LOG_INIT(NameTreeIterator);
Iterator::Iterator() = default;
@@ -56,14 +50,6 @@
return *this;
}
-Iterator
-Iterator::operator++(int)
-{
- Iterator copy = *this;
- this->operator++();
- return copy;
-}
-
std::ostream&
operator<<(std::ostream& os, const Iterator& i)
{
diff --git a/daemon/table/name-tree-iterator.hpp b/daemon/table/name-tree-iterator.hpp
index fef3e6e..2399826 100644
--- a/daemon/table/name-tree-iterator.hpp
+++ b/daemon/table/name-tree-iterator.hpp
@@ -28,6 +28,7 @@
#include "name-tree-hashtable.hpp"
+#include <boost/operators.hpp>
#include <boost/range/iterator_range_core.hpp>
namespace nfd::name_tree {
@@ -74,15 +75,9 @@
/**
* \brief NameTree 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&;
-
Iterator();
Iterator(shared_ptr<EnumerationImpl> impl, const Entry* ref);
@@ -94,31 +89,15 @@
return *m_entry;
}
- const Entry*
- operator->() const noexcept
- {
- BOOST_ASSERT(m_impl != nullptr);
- return m_entry;
- }
-
Iterator&
operator++();
- Iterator
- operator++(int);
-
friend bool
operator==(const Iterator& lhs, const Iterator& rhs) noexcept
{
return lhs.m_entry == rhs.m_entry;
}
- friend bool
- operator!=(const Iterator& lhs, const Iterator& rhs) noexcept
- {
- return !(lhs == rhs);
- }
-
private:
/** \brief Enumeration implementation; nullptr for end iterator.
*/
diff --git a/daemon/table/pit-iterator.cpp b/daemon/table/pit-iterator.cpp
index f0d0c8a..f3680f8 100644
--- a/daemon/table/pit-iterator.cpp
+++ b/daemon/table/pit-iterator.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2014-2022, Regents of the University of California,
+ * Copyright (c) 2014-2023, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
@@ -25,18 +25,8 @@
#include "pit-iterator.hpp"
-#include <ndn-cxx/util/concepts.hpp>
-
namespace nfd::pit {
-NDN_CXX_ASSERT_FORWARD_ITERATOR(Iterator);
-
-Iterator::Iterator(const NameTree::const_iterator& ntIt, size_t iPitEntry)
- : m_ntIt(ntIt)
- , m_iPitEntry(iPitEntry)
-{
-}
-
Iterator&
Iterator::operator++()
{
@@ -48,16 +38,7 @@
m_iPitEntry = 0;
BOOST_ASSERT(m_ntIt == NameTree::const_iterator() || m_ntIt->hasPitEntries());
}
-
return *this;
}
-Iterator
-Iterator::operator++(int)
-{
- Iterator copy = *this;
- this->operator++();
- return copy;
-}
-
} // namespace nfd::pit
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()
diff --git a/daemon/table/strategy-choice.cpp b/daemon/table/strategy-choice.cpp
index cefb245..c7b7a1a 100644
--- a/daemon/table/strategy-choice.cpp
+++ b/daemon/table/strategy-choice.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2014-2022, Regents of the University of California,
+ * Copyright (c) 2014-2023, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
@@ -30,12 +30,8 @@
#include "common/logger.hpp"
#include "fw/strategy.hpp"
-#include <ndn-cxx/util/concepts.hpp>
-
namespace nfd::strategy_choice {
-NDN_CXX_ASSERT_FORWARD_ITERATOR(StrategyChoice::const_iterator);
-
NFD_LOG_INIT(StrategyChoice);
using fw::Strategy;