Eradicate all uses of std::bind()

Change-Id: I6e1ccf2d87b76142e6d519c1a288d03022e4d167
diff --git a/tools/ping/client/main.cpp b/tools/ping/client/main.cpp
index 590c2db..f49c972 100644
--- a/tools/ping/client/main.cpp
+++ b/tools/ping/client/main.cpp
@@ -47,12 +47,9 @@
     , m_signalSetInt(m_face.getIoService(), SIGINT)
     , m_signalSetQuit(m_face.getIoService(), SIGQUIT)
   {
-    m_signalSetInt.async_wait(bind(&Runner::afterIntSignal, this, _1));
-    m_signalSetQuit.async_wait(bind(&Runner::afterQuitSignal, this, _1));
-
-    m_ping.afterFinish.connect([this] {
-        this->cancel();
-      });
+    m_signalSetInt.async_wait([this] (const auto& err, int) { onInterruptSignal(err); });
+    m_signalSetQuit.async_wait([this] (const auto& err, int) { onQuitSignal(err); });
+    m_ping.afterFinish.connect([this] { cancel(); });
   }
 
   int
@@ -68,8 +65,7 @@
     }
 
     Statistics statistics = m_statisticsCollector.computeStatistics();
-
-    std::cout << statistics << std::endl;
+    std::cout << statistics << "\n";
 
     if (statistics.nReceived == statistics.nSent) {
       return 0;
@@ -89,7 +85,7 @@
   }
 
   void
-  afterIntSignal(const boost::system::error_code& errorCode)
+  onInterruptSignal(const boost::system::error_code& errorCode)
   {
     if (errorCode == boost::asio::error::operation_aborted) {
       return;
@@ -99,14 +95,14 @@
   }
 
   void
-  afterQuitSignal(const boost::system::error_code& errorCode)
+  onQuitSignal(const boost::system::error_code& errorCode)
   {
     if (errorCode == boost::asio::error::operation_aborted) {
       return;
     }
 
     m_statisticsCollector.computeStatistics().printSummary(std::cout);
-    m_signalSetQuit.async_wait(bind(&Runner::afterQuitSignal, this, _1));
+    m_signalSetQuit.async_wait([this] (const auto& err, int) { onQuitSignal(err); });
   }
 
 private:
@@ -203,7 +199,7 @@
     }
 
     if (optVm.count("version") > 0) {
-      std::cout << "ndnping " << tools::VERSION << std::endl;
+      std::cout << "ndnping " << tools::VERSION << "\n";
       exit(0);
     }
 
@@ -211,14 +207,14 @@
       options.prefix = Name(optVm["prefix"].as<std::string>());
     }
     else {
-      std::cerr << "ERROR: No prefix specified" << std::endl;
+      std::cerr << "ERROR: No prefix specified\n";
       usage(visibleOptDesc);
     }
 
     options.interval = time::milliseconds(optVm["interval"].as<time::milliseconds::rep>());
     if (options.interval < getMinimumPingInterval()) {
-      std::cerr << "ERROR: Specified ping interval is less than the minimum " <<
-                   getMinimumPingInterval() << std::endl;
+      std::cerr << "ERROR: Specified ping interval is less than the minimum "
+                << getMinimumPingInterval() << "\n";
       usage(visibleOptDesc);
     }
 
@@ -226,7 +222,7 @@
 
     if (optVm.count("count") > 0) {
       if (options.nPings <= 0) {
-        std::cerr << "ERROR: Number of ping must be positive" << std::endl;
+        std::cerr << "ERROR: Number of ping must be positive\n";
         usage(visibleOptDesc);
       }
     }
@@ -238,7 +234,7 @@
     if (optVm.count("identifier") > 0) {
       bool isIdentifierAcceptable = std::all_of(identifier.begin(), identifier.end(), &isalnum);
       if (identifier.empty() || !isIdentifierAcceptable) {
-        std::cerr << "ERROR: Unacceptable client identifier" << std::endl;
+        std::cerr << "ERROR: Unacceptable client identifier\n";
         usage(visibleOptDesc);
       }
 
@@ -254,11 +250,11 @@
     }
   }
   catch (const po::error& e) {
-    std::cerr << "ERROR: " << e.what() << std::endl;
+    std::cerr << "ERROR: " << e.what() << "\n";
     usage(visibleOptDesc);
   }
 
-  std::cout << "PING " << options.prefix << std::endl;
+  std::cout << "PING " << options.prefix << "\n";
   return Runner(options).run();
 }
 
diff --git a/tools/ping/client/ping.cpp b/tools/ping/client/ping.cpp
index e3cb20f..c52ed10 100644
--- a/tools/ping/client/ping.cpp
+++ b/tools/ping/client/ping.cpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /*
- * Copyright (c) 2014-2019,  Arizona Board of Regents.
+ * Copyright (c) 2014-2021,  Arizona Board of Regents.
  *
  * This file is part of ndn-tools (Named Data Networking Essential Tools).
  * See AUTHORS.md for complete list of ndn-tools authors and contributors.
@@ -22,6 +22,7 @@
  */
 
 #include "ping.hpp"
+
 #include <ndn-cxx/util/random.hpp>
 
 namespace ndn {
@@ -65,9 +66,9 @@
 
   auto now = time::steady_clock::now();
   m_face.expressInterest(interest,
-                         bind(&Ping::onData, this, m_nextSeq, now),
-                         bind(&Ping::onNack, this, _2, m_nextSeq, now),
-                         bind(&Ping::onTimeout, this, m_nextSeq));
+    [=, seq = m_nextSeq] (auto&&...) { onData(seq, now); },
+    [=, seq = m_nextSeq] (auto&&, const auto& nack) { onNack(seq, now, nack); },
+    [=, seq = m_nextSeq] (auto&&...) { onTimeout(seq); });
 
   ++m_nSent;
   ++m_nextSeq;
@@ -82,7 +83,7 @@
 }
 
 void
-Ping::onData(uint64_t seq, const time::steady_clock::TimePoint& sendTime)
+Ping::onData(uint64_t seq, const time::steady_clock::time_point& sendTime)
 {
   time::nanoseconds rtt = time::steady_clock::now() - sendTime;
   afterData(seq, rtt);
@@ -90,7 +91,7 @@
 }
 
 void
-Ping::onNack(const lp::Nack& nack, uint64_t seq, const time::steady_clock::TimePoint& sendTime)
+Ping::onNack(uint64_t seq, const time::steady_clock::time_point& sendTime, const lp::Nack& nack)
 {
   time::nanoseconds rtt = time::steady_clock::now() - sendTime;
   afterNack(seq, rtt, nack.getHeader());
diff --git a/tools/ping/client/ping.hpp b/tools/ping/client/ping.hpp
index 48f2485..a44ca0c 100644
--- a/tools/ping/client/ping.hpp
+++ b/tools/ping/client/ping.hpp
@@ -108,8 +108,6 @@
 private:
   /**
    * @brief Creates a ping Name from the sequence number
-   *
-   * @param seq ping sequence number
    */
   Name
   makePingName(uint64_t seq) const;
@@ -122,30 +120,18 @@
 
   /**
    * @brief Called when a Data packet is received in response to a ping
-   *
-   * @param seq ping sequence number
-   * @param sendTime time ping sent
    */
   void
-  onData(uint64_t seq, const time::steady_clock::TimePoint& sendTime);
+  onData(uint64_t seq, const time::steady_clock::time_point& sendTime);
 
   /**
    * @brief Called when a Nack is received in response to a ping
-   *
-   * @param interest NDN interest
-   * @param nack returned nack
-   * @param seq ping sequence number
-   * @param sendTime time ping sent
    */
   void
-  onNack(const lp::Nack& nack, uint64_t seq,
-         const time::steady_clock::TimePoint& sendTime);
+  onNack(uint64_t seq, const time::steady_clock::time_point& sendTime, const lp::Nack& nack);
 
   /**
    * @brief Called when ping timed out
-   *
-   * @param interest NDN interest
-   * @param seq ping sequence number
    */
   void
   onTimeout(uint64_t seq);
diff --git a/tools/ping/client/statistics-collector.cpp b/tools/ping/client/statistics-collector.cpp
index 7954e64..6c29405 100644
--- a/tools/ping/client/statistics-collector.cpp
+++ b/tools/ping/client/statistics-collector.cpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
- * Copyright (c) 2015-2016,  Arizona Board of Regents.
+/*
+ * Copyright (c) 2015-2021,  Arizona Board of Regents.
  *
  * This file is part of ndn-tools (Named Data Networking Essential Tools).
  * See AUTHORS.md for complete list of ndn-tools authors and contributors.
@@ -16,9 +16,9 @@
  * You should have received a copy of the GNU General Public License along with
  * ndn-tools, e.g., in COPYING.md file.  If not, see <http://www.gnu.org/licenses/>.
  *
- * @author: Eric Newberry <enewberry@email.arizona.edu>
- * @author: Jerald Paul Abraham <jeraldabraham@email.arizona.edu>
- * @author: Teng Liang <philoliang@email.arizona.edu>
+ * @author Eric Newberry <enewberry@email.arizona.edu>
+ * @author Jerald Paul Abraham <jeraldabraham@email.arizona.edu>
+ * @author Teng Liang <philoliang@email.arizona.edu>
  */
 
 #include "statistics-collector.hpp"
@@ -39,9 +39,9 @@
   , m_sumRtt(0.0)
   , m_sumRttSquared(0.0)
 {
-  m_ping.afterData.connect(bind(&StatisticsCollector::recordData, this, _2));
-  m_ping.afterNack.connect(bind(&StatisticsCollector::recordNack, this));
-  m_ping.afterTimeout.connect(bind(&StatisticsCollector::recordTimeout, this));
+  m_ping.afterData.connect([this] (auto&&, Rtt rtt) { recordData(rtt); });
+  m_ping.afterNack.connect([this] (auto&&...) { recordNack(); });
+  m_ping.afterTimeout.connect([this] (auto&&...) { recordTimeout(); });
 }
 
 void
@@ -53,7 +53,6 @@
   double rttMs = rtt.count();
 
   m_minRtt = std::min(m_minRtt, rttMs);
-
   m_maxRtt = std::max(m_maxRtt, rttMs);
 
   m_sumRtt += rttMs;
@@ -74,7 +73,7 @@
 }
 
 Statistics
-StatisticsCollector::computeStatistics()
+StatisticsCollector::computeStatistics() const
 {
   Statistics statistics;
 
@@ -123,7 +122,7 @@
        << " ms";
   }
 
-  return os << std::endl;
+  return os << "\n";
 }
 
 std::ostream&
diff --git a/tools/ping/client/statistics-collector.hpp b/tools/ping/client/statistics-collector.hpp
index ee67f80..9622717 100644
--- a/tools/ping/client/statistics-collector.hpp
+++ b/tools/ping/client/statistics-collector.hpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
- * Copyright (c) 2015-2016,  Arizona Board of Regents.
+/*
+ * Copyright (c) 2015-2021,  Arizona Board of Regents.
  *
  * This file is part of ndn-tools (Named Data Networking Essential Tools).
  * See AUTHORS.md for complete list of ndn-tools authors and contributors.
@@ -16,9 +16,9 @@
  * You should have received a copy of the GNU General Public License along with
  * ndn-tools, e.g., in COPYING.md file.  If not, see <http://www.gnu.org/licenses/>.
  *
- * @author: Eric Newberry <enewberry@email.arizona.edu>
- * @author: Jerald Paul Abraham <jeraldabraham@email.arizona.edu>
- * @author: Teng Liang <philoliang@email.arizona.edu>
+ * @author Eric Newberry <enewberry@email.arizona.edu>
+ * @author Jerald Paul Abraham <jeraldabraham@email.arizona.edu>
+ * @author Teng Liang <philoliang@email.arizona.edu>
  */
 
 #ifndef NDN_TOOLS_PING_CLIENT_STATISTICS_COLLECTOR_HPP
@@ -41,7 +41,7 @@
   int nSent;                                    //!< number of pings sent
   int nReceived;                                //!< number of pings received
   int nNacked;                                  //!< number of nacks received
-  time::steady_clock::TimePoint pingStartTime;  //!< time pings started
+  time::steady_clock::time_point pingStartTime; //!< time pings started
   double minRtt;                                //!< minimum round trip time
   double maxRtt;                                //!< maximum round trip time
   double packetLossRate;                        //!< packet loss rate
@@ -67,16 +67,14 @@
   StatisticsCollector(Ping& ping, const Options& options);
 
   /**
-   * @brief Compute ping statistics as structure
+   * @brief Compute and return ping statistics as structure
    */
   Statistics
-  computeStatistics();
+  computeStatistics() const;
 
 PUBLIC_WITH_TESTS_ELSE_PRIVATE:
   /**
    * @brief Called when a Data packet is received
-   *
-   * @param rtt round trip time
    */
   void
   recordData(Rtt rtt);
@@ -99,7 +97,7 @@
   int m_nSent;
   int m_nReceived;
   int m_nNacked;
-  time::steady_clock::TimePoint m_pingStartTime;
+  time::steady_clock::time_point m_pingStartTime;
   double m_minRtt;
   double m_maxRtt;
   double m_sumRtt;
diff --git a/tools/ping/client/tracer.cpp b/tools/ping/client/tracer.cpp
index 9510af8..7db5085 100644
--- a/tools/ping/client/tracer.cpp
+++ b/tools/ping/client/tracer.cpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
- * Copyright (c) 2015-2016,  Arizona Board of Regents.
+/*
+ * Copyright (c) 2015-2021,  Arizona Board of Regents.
  *
  * This file is part of ndn-tools (Named Data Networking Essential Tools).
  * See AUTHORS.md for complete list of ndn-tools authors and contributors.
@@ -16,8 +16,8 @@
  * You should have received a copy of the GNU General Public License along with
  * ndn-tools, e.g., in COPYING.md file.  If not, see <http://www.gnu.org/licenses/>.
  *
- * @author: Eric Newberry <enewberry@email.arizona.edu>
- * @author: Teng Liang <philoliang@email.arizona.edu>
+ * @author Eric Newberry <enewberry@email.arizona.edu>
+ * @author Teng Liang <philoliang@email.arizona.edu>
  */
 
 #include "tracer.hpp"
@@ -29,9 +29,9 @@
 Tracer::Tracer(Ping& ping, const Options& options)
   : m_options(options)
 {
-  ping.afterData.connect(bind(&Tracer::onData, this, _1, _2));
-  ping.afterNack.connect(bind(&Tracer::onNack, this, _1, _2, _3));
-  ping.afterTimeout.connect(bind(&Tracer::onTimeout, this, _1));
+  ping.afterData.connect(FORWARD_TO_MEM_FN(onData));
+  ping.afterNack.connect(FORWARD_TO_MEM_FN(onNack));
+  ping.afterTimeout.connect(FORWARD_TO_MEM_FN(onTimeout));
 }
 
 void
@@ -42,7 +42,7 @@
   }
 
   std::cout << "content from " << m_options.prefix << ": seq=" << seq << " time="
-            << rtt.count() << " ms" << std::endl;
+            << rtt.count() << " ms\n";
 }
 
 void
@@ -53,7 +53,7 @@
   }
 
   std::cout << "nack from " << m_options.prefix << ": seq=" << seq << " time="
-            << rtt.count() << " ms" << " reason=" << header.getReason() << std::endl;
+            << rtt.count() << " ms" << " reason=" << header.getReason() << "\n";
 }
 
 void
@@ -63,13 +63,13 @@
     std::cout << time::toIsoString(time::system_clock::now()) << " - ";
   }
 
-  std::cout << "timeout from " << m_options.prefix << ": seq=" << seq << std::endl;
+  std::cout << "timeout from " << m_options.prefix << ": seq=" << seq << "\n";
 }
 
 void
-Tracer::onError(std::string msg)
+Tracer::onError(const std::string& msg)
 {
-  std::cerr << "ERROR: " << msg << std::endl;
+  std::cerr << "ERROR: " << msg << "\n";
 }
 
 } // namespace client
diff --git a/tools/ping/client/tracer.hpp b/tools/ping/client/tracer.hpp
index ca75fb5..b6b4812 100644
--- a/tools/ping/client/tracer.hpp
+++ b/tools/ping/client/tracer.hpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
- * Copyright (c) 2015-2016,  Arizona Board of Regents.
+/*
+ * Copyright (c) 2015-2021,  Arizona Board of Regents.
  *
  * This file is part of ndn-tools (Named Data Networking Essential Tools).
  * See AUTHORS.md for complete list of ndn-tools authors and contributors.
@@ -16,8 +16,8 @@
  * You should have received a copy of the GNU General Public License along with
  * ndn-tools, e.g., in COPYING.md file.  If not, see <http://www.gnu.org/licenses/>.
  *
- * @author: Eric Newberry <enewberry@email.arizona.edu>
- * @author: Teng Liang <philoliang@email.arizona.edu>
+ * @author Eric Newberry <enewberry@email.arizona.edu>
+ * @author Teng Liang <philoliang@email.arizona.edu>
  */
 
 #ifndef NDN_TOOLS_PING_CLIENT_TRACER_HPP
@@ -74,7 +74,7 @@
    * @brief Outputs ping errors to cerr
    */
   void
-  onError(std::string msg);
+  onError(const std::string& msg);
 
 private:
   const Options& m_options;
diff --git a/tools/ping/server/ping-server.cpp b/tools/ping/server/ping-server.cpp
index ad8177c..5ceeb76 100644
--- a/tools/ping/server/ping-server.cpp
+++ b/tools/ping/server/ping-server.cpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /*
- * Copyright (c) 2015-2019,  Arizona Board of Regents.
+ * Copyright (c) 2015-2021,  Arizona Board of Regents.
  *
  * This file is part of ndn-tools (Named Data Networking Essential Tools).
  * See AUTHORS.md for complete list of ndn-tools authors and contributors.
@@ -42,12 +42,11 @@
 void
 PingServer::start()
 {
-  m_registeredPrefix = m_face.setInterestFilter(
-                       Name(m_options.prefix).append("ping"),
-                       bind(&PingServer::onInterest, this, _2),
-                       [] (const auto&, const auto& reason) {
-                         NDN_THROW(std::runtime_error("Failed to register prefix: " + reason));
-                       });
+  m_registeredPrefix = m_face.setInterestFilter(Name(m_options.prefix).append("ping"),
+                         [this] (const auto&, const auto& interest) { onInterest(interest); },
+                         [] (const auto&, const auto& reason) {
+                           NDN_THROW(std::runtime_error("Failed to register prefix: " + reason));
+                         });
 }
 
 void
diff --git a/tools/ping/server/tracer.cpp b/tools/ping/server/tracer.cpp
index 51b191c..c6b30b9 100644
--- a/tools/ping/server/tracer.cpp
+++ b/tools/ping/server/tracer.cpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /*
- * Copyright (c) 2015-2018,  Arizona Board of Regents.
+ * Copyright (c) 2015-2021,  Arizona Board of Regents.
  *
  * This file is part of ndn-tools (Named Data Networking Essential Tools).
  * See AUTHORS.md for complete list of ndn-tools authors and contributors.
@@ -29,20 +29,15 @@
   : m_options(options)
 {
   if (!m_options.wantQuiet) {
-    pingServer.afterReceive.connect([this] (const Name& name) { onReceive(name); });
+    pingServer.afterReceive.connect([this] (const Name& name) {
+      if (m_options.wantTimestamp) {
+        std::cout << time::toIsoString(time::system_clock::now()) << " - ";
+      }
+      std::cout << "interest received: seq=" << name.at(-1) << "\n";
+    });
   }
 }
 
-void
-Tracer::onReceive(const Name& name)
-{
-  if (m_options.wantTimestamp) {
-    std::cout << time::toIsoString(time::system_clock::now()) << " - ";
-  }
-
-  std::cout << "interest received: seq=" << name.at(-1) << std::endl;
-}
-
 } // namespace server
 } // namespace ping
 } // namespace ndn
diff --git a/tools/ping/server/tracer.hpp b/tools/ping/server/tracer.hpp
index b8b6952..a84b72e 100644
--- a/tools/ping/server/tracer.hpp
+++ b/tools/ping/server/tracer.hpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
- * Copyright (c) 2015,  Arizona Board of Regents.
+/*
+ * Copyright (c) 2015-2021,  Arizona Board of Regents.
  *
  * This file is part of ndn-tools (Named Data Networking Essential Tools).
  * See AUTHORS.md for complete list of ndn-tools authors and contributors.
@@ -31,20 +31,13 @@
 namespace server {
 
 /**
- * @brief logs ping responses
+ * @brief Logs ping responses
  */
 class Tracer : noncopyable
 {
 public:
   Tracer(PingServer& pingServer, const Options& options);
 
-  /**
-   * @brief Prints ping information when interest received
-   * @param name interest name received
-   */
-  void
-  onReceive(const Name& name);
-
 private:
   const Options& m_options;
 };