Improve and simplify code with modern C++ features

Change-Id: I83bf5513c2a1f90ba5a59e93c473306864b27d94
diff --git a/daemon/table/cs-policy-priority-fifo.cpp b/daemon/table/cs-policy-priority-fifo.cpp
index 934d759..7984739 100644
--- a/daemon/table/cs-policy-priority-fifo.cpp
+++ b/daemon/table/cs-policy-priority-fifo.cpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
- * Copyright (c) 2014-2017,  Regents of the University of California,
+/*
+ * Copyright (c) 2014-2018,  Regents of the University of California,
  *                           Arizona Board of Regents,
  *                           Colorado State University,
  *                           University Pierre & Marie Curie, Sorbonne University,
@@ -118,7 +118,7 @@
   else {
     entryInfo->queueType = QUEUE_FIFO;
     entryInfo->moveStaleEventId = scheduler::schedule(i->getData().getFreshnessPeriod(),
-                                                      bind(&PriorityFifoPolicy::moveToStaleQueue, this, i));
+                                                      [=] { moveToStaleQueue(i); });
   }
 
   Queue& queue = m_queues[entryInfo->queueType];
diff --git a/daemon/table/cs.cpp b/daemon/table/cs.cpp
index 00dc9ee..1663d8f 100644
--- a/daemon/table/cs.cpp
+++ b/daemon/table/cs.cpp
@@ -155,7 +155,7 @@
 iterator
 Cs::findLeftmost(const Interest& interest, iterator first, iterator last) const
 {
-  return std::find_if(first, last, bind(&cs::EntryImpl::canSatisfy, _1, interest));
+  return std::find_if(first, last, [&interest] (const auto& entry) { return entry.canSatisfy(interest); });
 }
 
 iterator
@@ -193,7 +193,7 @@
 iterator
 Cs::findRightmostAmongExact(const Interest& interest, iterator first, iterator last) const
 {
-  return find_last_if(first, last, bind(&EntryImpl::canSatisfy, _1, interest));
+  return find_last_if(first, last, [&interest] (const auto& entry) { return entry.canSatisfy(interest); });
 }
 
 void
diff --git a/daemon/table/dead-nonce-list.cpp b/daemon/table/dead-nonce-list.cpp
index d732a90..144e68e 100644
--- a/daemon/table/dead-nonce-list.cpp
+++ b/daemon/table/dead-nonce-list.cpp
@@ -31,8 +31,8 @@
 
 NFD_LOG_INIT(DeadNonceList);
 
-const time::nanoseconds DeadNonceList::DEFAULT_LIFETIME = time::seconds(6);
-const time::nanoseconds DeadNonceList::MIN_LIFETIME = time::milliseconds(1);
+const time::nanoseconds DeadNonceList::DEFAULT_LIFETIME = 6_s;
+const time::nanoseconds DeadNonceList::MIN_LIFETIME = 1_ms;
 const size_t DeadNonceList::INITIAL_CAPACITY = (1 << 7);
 const size_t DeadNonceList::MIN_CAPACITY = (1 << 3);
 const size_t DeadNonceList::MAX_CAPACITY = (1 << 24);
@@ -58,9 +58,8 @@
     m_queue.push_back(MARK);
   }
 
-  m_markEvent = scheduler::schedule(m_markInterval, bind(&DeadNonceList::mark, this));
-  m_adjustCapacityEvent = scheduler::schedule(m_adjustCapacityInterval,
-                                              bind(&DeadNonceList::adjustCapacity, this));
+  m_markEvent = scheduler::schedule(m_markInterval, [this] { mark(); });
+  m_adjustCapacityEvent = scheduler::schedule(m_adjustCapacityInterval, [this] { adjustCapacity(); });
 }
 
 DeadNonceList::~DeadNonceList()
@@ -125,15 +124,13 @@
 
   NFD_LOG_TRACE("mark nMarks=" << nMarks);
 
-  scheduler::schedule(m_markInterval, bind(&DeadNonceList::mark, this));
+  m_markEvent = scheduler::schedule(m_markInterval, [this] { mark(); });
 }
 
 void
 DeadNonceList::adjustCapacity()
 {
-  std::pair<std::multiset<size_t>::iterator, std::multiset<size_t>::iterator> equalRange =
-    m_actualMarkCounts.equal_range(EXPECTED_MARK_COUNT);
-
+  auto equalRange = m_actualMarkCounts.equal_range(EXPECTED_MARK_COUNT);
   if (equalRange.second == m_actualMarkCounts.begin()) {
     // all counts are above expected count, adjust down
     m_capacity = std::max(MIN_CAPACITY,
@@ -148,11 +145,9 @@
   }
 
   m_actualMarkCounts.clear();
-
   this->evictEntries();
 
-  m_adjustCapacityEvent = scheduler::schedule(m_adjustCapacityInterval,
-                                              bind(&DeadNonceList::adjustCapacity, this));
+  m_adjustCapacityEvent = scheduler::schedule(m_adjustCapacityInterval, [this] { adjustCapacity(); });
 }
 
 void
diff --git a/daemon/table/fib.cpp b/daemon/table/fib.cpp
index 0a9522a..7b6d21a 100644
--- a/daemon/table/fib.cpp
+++ b/daemon/table/fib.cpp
@@ -93,12 +93,12 @@
   name_tree::Entry& nte = m_nameTree.lookup(prefix);
   Entry* entry = nte.getFibEntry();
   if (entry != nullptr) {
-    return std::make_pair(entry, false);
+    return {entry, false};
   }
 
   nte.setFibEntry(make_unique<Entry>(prefix));
   ++m_nItems;
-  return std::make_pair(nte.getFibEntry(), true);
+  return {nte.getFibEntry(), true};
 }
 
 void
diff --git a/daemon/table/measurements.cpp b/daemon/table/measurements.cpp
index 4d84746..651a83b 100644
--- a/daemon/table/measurements.cpp
+++ b/daemon/table/measurements.cpp
@@ -50,8 +50,7 @@
   entry = nte.getMeasurementsEntry();
 
   entry->m_expiry = time::steady_clock::now() + getInitialLifetime();
-  entry->m_cleanup = scheduler::schedule(getInitialLifetime(),
-                                         bind(&Measurements::cleanup, this, ref(*entry)));
+  entry->m_cleanup = scheduler::schedule(getInitialLifetime(), [=] { cleanup(*entry); });
 
   return *entry;
 }
@@ -137,7 +136,7 @@
 
   scheduler::cancel(entry.m_cleanup);
   entry.m_expiry = expiry;
-  entry.m_cleanup = scheduler::schedule(lifetime, bind(&Measurements::cleanup, this, ref(entry)));
+  entry.m_cleanup = scheduler::schedule(lifetime, [&] { cleanup(entry); });
 }
 
 void
diff --git a/daemon/table/measurements.hpp b/daemon/table/measurements.hpp
index d110ed6..c72ba28 100644
--- a/daemon/table/measurements.hpp
+++ b/daemon/table/measurements.hpp
@@ -167,7 +167,7 @@
 inline time::nanoseconds
 Measurements::getInitialLifetime()
 {
-  return time::seconds(4);
+  return 4_s;
 }
 
 inline size_t
diff --git a/daemon/table/name-tree-iterator.cpp b/daemon/table/name-tree-iterator.cpp
index 56c0360..f295d9c 100644
--- a/daemon/table/name-tree-iterator.cpp
+++ b/daemon/table/name-tree-iterator.cpp
@@ -46,7 +46,7 @@
 }
 
 Iterator::Iterator(shared_ptr<EnumerationImpl> impl, const Entry* ref)
-  : m_impl(impl)
+  : m_impl(std::move(impl))
   , m_entry(nullptr)
   , m_ref(ref)
   , m_state(0)
diff --git a/daemon/table/name-tree-iterator.hpp b/daemon/table/name-tree-iterator.hpp
index 87a93f7..973c961 100644
--- a/daemon/table/name-tree-iterator.hpp
+++ b/daemon/table/name-tree-iterator.hpp
@@ -69,9 +69,15 @@
 
 /** \brief NameTree iterator
  */
-class Iterator : public std::iterator<std::forward_iterator_tag, const Entry>
+class Iterator
 {
 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);
diff --git a/daemon/table/pit-iterator.hpp b/daemon/table/pit-iterator.hpp
index 434dfd0..35e02c5 100644
--- a/daemon/table/pit-iterator.hpp
+++ b/daemon/table/pit-iterator.hpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
- * Copyright (c) 2014-2016,  Regents of the University of California,
+/*
+ * Copyright (c) 2014-2018,  Regents of the University of California,
  *                           Arizona Board of Regents,
  *                           Colorado State University,
  *                           University Pierre & Marie Curie, Sorbonne University,
@@ -34,9 +34,15 @@
 
 /** \brief PIT iterator
  */
-class Iterator : public std::iterator<std::forward_iterator_tag, const Entry>
+class Iterator
 {
 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