Simplify some code with Boost.Operators

Change-Id: Ic873bcbaf6be00d5c35601cfc8090df534d815ee
diff --git a/daemon/common/counter.hpp b/daemon/common/counter.hpp
index 805ebdf..eeb98dc 100644
--- a/daemon/common/counter.hpp
+++ b/daemon/common/counter.hpp
@@ -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,
@@ -34,15 +34,15 @@
  * \brief Represents a counter that encloses an integer value.
  *
  * SimpleCounter is noncopyable, because increment should be called on the counter,
- * not a copy of it; it's implicitly convertible to an integral type to be observed.
+ * not a copy of it. It's implicitly convertible to an integral type to be observed.
  */
 class SimpleCounter : noncopyable
 {
 public:
-  typedef uint64_t rep;
+  using rep = uint64_t;
 
   /**
-   * \brief Observe the counter's value.
+   * \brief Return the counter's value.
    */
   operator rep() const noexcept
   {
@@ -62,14 +62,16 @@
   rep m_value = 0;
 };
 
-/** \brief Represents a counter of number of packets.
+/**
+ * \brief Represents a counter of number of packets.
  *
- *  \warning The counter value may wrap after exceeding the range of underlying integer type.
+ * \warning The counter value may wrap after exceeding the range of the underlying integer type.
  */
 class PacketCounter : public SimpleCounter
 {
 public:
-  /** \brief Increment the counter by one.
+  /**
+   * \brief Increment the counter by one.
    */
   PacketCounter&
   operator++() noexcept
@@ -77,17 +79,18 @@
     ++m_value;
     return *this;
   }
-  // postfix ++ operator is not provided because it's not needed
 };
 
-/** \brief Represents a counter of number of bytes.
+/**
+ * \brief Represents a counter of number of bytes.
  *
- *  \warning The counter value may wrap after exceeding the range of underlying integer type.
+ * \warning The counter value may wrap after exceeding the range of the underlying integer type.
  */
 class ByteCounter : public SimpleCounter
 {
 public:
-  /** \brief Increase the counter.
+  /**
+   * \brief Increase the counter.
    */
   ByteCounter&
   operator+=(rep n) noexcept
@@ -97,16 +100,17 @@
   }
 };
 
-/** \brief Provides a counter that observes the size of a table.
- *  \tparam T a type that provides a size() const member function
+/**
+ * \brief Provides a counter that observes the size of a table.
+ * \tparam T a type that provides a `size()` const member function
  *
- *  if table not specified in constructor, it can be added later by invoking observe()
+ * If the table is not specified in the constructor, it can be added later by calling observe().
  */
 template<typename T>
 class SizeCounter : noncopyable
 {
 public:
-  typedef size_t Rep;
+  using rep = size_t;
 
   explicit constexpr
   SizeCounter(const T* table = nullptr) noexcept
@@ -120,16 +124,17 @@
     m_table = table;
   }
 
-  /** \brief Observe the counter.
+  /**
+   * \brief Return the counter's value, i.e., the current size of the table being observed.
    */
-  operator Rep() const
+  operator rep() const
   {
     BOOST_ASSERT(m_table != nullptr);
     return m_table->size();
   }
 
 private:
-  const T* m_table;
+  const T* m_table = nullptr;
 };
 
 } // namespace nfd
diff --git a/daemon/face/network-predicate.hpp b/daemon/face/network-predicate.hpp
index 8e0bd52..3405f7c 100644
--- a/daemon/face/network-predicate.hpp
+++ b/daemon/face/network-predicate.hpp
@@ -28,12 +28,14 @@
 
 #include "core/common.hpp"
 
+#include <boost/operators.hpp>
 #include <boost/property_tree/ptree_fwd.hpp>
+
 #include <ndn-cxx/net/network-interface.hpp>
 
 namespace nfd::face {
 
-class NetworkPredicateBase
+class NetworkPredicateBase : private boost::equality_comparable<NetworkPredicateBase>
 {
 public:
   NetworkPredicateBase();
@@ -78,12 +80,6 @@
            lhs.m_blacklist == rhs.m_blacklist;
   }
 
-  friend bool
-  operator!=(const NetworkPredicateBase& lhs, const NetworkPredicateBase& rhs)
-  {
-    return !(lhs == rhs);
-  }
-
 NFD_PUBLIC_WITH_TESTS_ELSE_PROTECTED:
   std::set<std::string> m_whitelist;
   std::set<std::string> m_blacklist;
diff --git a/daemon/fw/face-table.cpp b/daemon/fw/face-table.cpp
index 75b1190..fe3a6ab 100644
--- a/daemon/fw/face-table.cpp
+++ b/daemon/fw/face-table.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,
@@ -28,12 +28,8 @@
 #include "common/logger.hpp"
 #include "face/channel.hpp"
 
-#include <ndn-cxx/util/concepts.hpp>
-
 namespace nfd {
 
-NDN_CXX_ASSERT_FORWARD_ITERATOR(FaceTable::const_iterator);
-
 NFD_LOG_INIT(FaceTable);
 
 Face*
diff --git a/daemon/rib/fib-update.hpp b/daemon/rib/fib-update.hpp
index fd80b89..edf6c00 100644
--- a/daemon/rib/fib-update.hpp
+++ b/daemon/rib/fib-update.hpp
@@ -28,12 +28,14 @@
 
 #include "core/common.hpp"
 
+#include <boost/operators.hpp>
+
 namespace nfd::rib {
 
 /**
  * \brief Represents a FIB update.
  */
-class FibUpdate
+class FibUpdate : private boost::equality_comparable<FibUpdate>
 {
 public:
   enum Action {
@@ -57,12 +59,6 @@
            lhs.action == rhs.action;
   }
 
-  friend bool
-  operator!=(const FibUpdate& lhs, const FibUpdate& rhs) noexcept
-  {
-    return !(lhs == rhs);
-  }
-
 public:
   Name name;
   uint64_t faceId = 0;
diff --git a/daemon/rib/readvertise/readvertised-route.hpp b/daemon/rib/readvertise/readvertised-route.hpp
index a57fe70..bc2d8c1 100644
--- a/daemon/rib/readvertise/readvertised-route.hpp
+++ b/daemon/rib/readvertise/readvertised-route.hpp
@@ -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,
@@ -33,7 +33,8 @@
 
 namespace nfd::rib {
 
-/** \brief State of a readvertised route.
+/**
+ * \brief State of a readvertised route.
  */
 class ReadvertisedRoute : noncopyable
 {
@@ -41,25 +42,23 @@
   explicit
   ReadvertisedRoute(const Name& prefix)
     : prefix(prefix)
-    , nRibRoutes(0)
-    , retryDelay(0)
   {
   }
 
+  friend bool
+  operator<(const ReadvertisedRoute& lhs, const ReadvertisedRoute& rhs)
+  {
+    return lhs.prefix < rhs.prefix;
+  }
+
 public:
   Name prefix; ///< readvertised prefix
   mutable ndn::security::SigningInfo signer; ///< signer for commands
-  mutable size_t nRibRoutes; ///< number of RIB routes that cause the readvertisement
-  mutable time::milliseconds retryDelay; ///< retry interval (not used for refresh)
+  mutable size_t nRibRoutes = 0; ///< number of RIB routes that cause the readvertisement
+  mutable time::milliseconds retryDelay = 0_ms; ///< retry interval (not used for refresh)
   mutable scheduler::ScopedEventId retryEvt; ///< retry or refresh event
 };
 
-inline bool
-operator<(const ReadvertisedRoute& lhs, const ReadvertisedRoute& rhs)
-{
-  return lhs.prefix < rhs.prefix;
-}
-
 using ReadvertisedRouteContainer = std::set<ReadvertisedRoute>;
 
 } // namespace nfd::rib
diff --git a/daemon/rib/rib.cpp b/daemon/rib/rib.cpp
index 952cc9a..7288c9a 100644
--- a/daemon/rib/rib.cpp
+++ b/daemon/rib/rib.cpp
@@ -31,13 +31,6 @@
 
 NFD_LOG_INIT(Rib);
 
-bool
-operator<(const RibRouteRef& lhs, const RibRouteRef& rhs)
-{
-  return std::tie(lhs.entry->getName(), lhs.route->faceId, lhs.route->origin) <
-         std::tie(rhs.entry->getName(), rhs.route->faceId, rhs.route->origin);
-}
-
 static inline bool
 sortRoutes(const Route& lhs, const Route& rhs)
 {
diff --git a/daemon/rib/rib.hpp b/daemon/rib/rib.hpp
index ddfa591..795222c 100644
--- a/daemon/rib/rib.hpp
+++ b/daemon/rib/rib.hpp
@@ -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,
@@ -37,16 +37,21 @@
 
 class FibUpdater;
 
-/** \brief References a route.
+/**
+ * \brief References a route.
  */
 struct RibRouteRef
 {
   shared_ptr<RibEntry> entry;
   RibEntry::const_iterator route;
-};
 
-bool
-operator<(const RibRouteRef& lhs, const RibRouteRef& rhs);
+  friend bool
+  operator<(const RibRouteRef& lhs, const RibRouteRef& rhs) noexcept
+  {
+    return std::tie(lhs.entry->getName(), lhs.route->faceId, lhs.route->origin) <
+           std::tie(rhs.entry->getName(), rhs.route->faceId, rhs.route->origin);
+  }
+};
 
 /**
  * \brief Represents the Routing Information Base.
diff --git a/daemon/rib/route.hpp b/daemon/rib/route.hpp
index 5179dbf..f460487 100644
--- a/daemon/rib/route.hpp
+++ b/daemon/rib/route.hpp
@@ -40,7 +40,7 @@
 /**
  * \brief Represents a route for a name prefix.
  */
-class Route : public ndn::nfd::RouteFlagsTraits<Route>
+class Route : public ndn::nfd::RouteFlagsTraits<Route>, private boost::equality_comparable<Route>
 {
 public:
   /** \brief Default constructor.
@@ -89,12 +89,6 @@
            lhs.announcement == rhs.announcement;
   }
 
-  friend bool
-  operator!=(const Route& lhs, const Route& rhs)
-  {
-    return !(lhs == rhs);
-  }
-
 public:
   uint64_t faceId = 0;
   ndn::nfd::RouteOrigin origin = ndn::nfd::ROUTE_ORIGIN_APP;
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;