Eradicate all uses of std::bind()

Change-Id: I6e1ccf2d87b76142e6d519c1a288d03022e4d167
diff --git a/tools/chunks/catchunks/consumer.cpp b/tools/chunks/catchunks/consumer.cpp
index c1be8e8..ac83227 100644
--- a/tools/chunks/catchunks/consumer.cpp
+++ b/tools/chunks/catchunks/consumer.cpp
@@ -46,7 +46,7 @@
 
   m_discover->onDiscoverySuccess.connect([this] (const Name& versionedName) {
     m_pipeline->run(versionedName,
-                    [this] (const Data& data) { handleData(data); },
+                    FORWARD_TO_MEM_FN(handleData),
                     [] (const std::string& msg) { NDN_THROW(std::runtime_error(msg)); });
   });
   m_discover->onDiscoveryFailure.connect([] (const std::string& msg) {
diff --git a/tools/chunks/catchunks/data-fetcher.cpp b/tools/chunks/catchunks/data-fetcher.cpp
index 43d5076..baed34f 100644
--- a/tools/chunks/catchunks/data-fetcher.cpp
+++ b/tools/chunks/catchunks/data-fetcher.cpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /*
- * Copyright (c) 2016-2019, Regents of the University of California,
+ * Copyright (c) 2016-2021, Regents of the University of California,
  *                          Colorado State University,
  *                          University Pierre & Marie Curie, Sorbonne University.
  *
@@ -85,9 +85,9 @@
 {
   m_nCongestionRetries = 0;
   m_pendingInterest = m_face.expressInterest(interest,
-                                             bind(&DataFetcher::handleData, this, _1, _2, self),
-                                             bind(&DataFetcher::handleNack, this, _1, _2, self),
-                                             bind(&DataFetcher::handleTimeout, this, _1, self));
+    [=] (auto&&... args) { handleData(std::forward<decltype(args)>(args)..., self); },
+    [=] (auto&&... args) { handleNack(std::forward<decltype(args)>(args)..., self); },
+    [=] (auto&&... args) { handleTimeout(std::forward<decltype(args)>(args)..., self); });
 }
 
 void
@@ -113,7 +113,7 @@
 
   if (m_isVerbose)
     std::cerr << "Received Nack with reason " << nack.getReason()
-              << " for Interest " << interest << std::endl;
+              << " for Interest " << interest << "\n";
 
   if (m_nNacks <= m_maxNackRetries || m_maxNackRetries == MAX_RETRIES_INFINITE) {
     Interest newInterest(interest);
@@ -162,7 +162,7 @@
     ++m_nTimeouts;
 
   if (m_isVerbose)
-    std::cerr << "Timeout for Interest " << interest << std::endl;
+    std::cerr << "Timeout for Interest " << interest << "\n";
 
   if (m_nTimeouts <= m_maxTimeoutRetries || m_maxTimeoutRetries == MAX_RETRIES_INFINITE) {
     Interest newInterest(interest);
diff --git a/tools/chunks/catchunks/discover-version.cpp b/tools/chunks/catchunks/discover-version.cpp
index 1efe3b2..e35fc21 100644
--- a/tools/chunks/catchunks/discover-version.cpp
+++ b/tools/chunks/catchunks/discover-version.cpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /*
- * Copyright (c) 2016-2019, Regents of the University of California,
+ * Copyright (c) 2016-2021, Regents of the University of California,
  *                          Colorado State University,
  *                          University Pierre & Marie Curie, Sorbonne University.
  *
@@ -53,12 +53,13 @@
                       .setInterestLifetime(m_options.interestLifetime);
 
   m_fetcher = DataFetcher::fetch(m_face, interest,
-                                 m_options.maxRetriesOnTimeoutOrNack, m_options.maxRetriesOnTimeoutOrNack,
-                                 bind(&DiscoverVersion::handleData, this, _1, _2),
-                                 [this] (const Interest&, const std::string& reason) {
+                                 m_options.maxRetriesOnTimeoutOrNack,
+                                 m_options.maxRetriesOnTimeoutOrNack,
+                                 FORWARD_TO_MEM_FN(handleData),
+                                 [this] (const auto&, const auto& reason) {
                                    onDiscoveryFailure(reason);
                                  },
-                                 [this] (const Interest&, const std::string& reason) {
+                                 [this] (const auto&, const auto& reason) {
                                    onDiscoveryFailure(reason);
                                  },
                                  m_options.isVerbose);
@@ -68,7 +69,7 @@
 DiscoverVersion::handleData(const Interest& interest, const Data& data)
 {
   if (m_options.isVerbose)
-    std::cerr << "Data: " << data << std::endl;
+    std::cerr << "Data: " << data << "\n";
 
   // make a metadata object from received metadata packet
   MetadataObject mobject;
@@ -86,7 +87,7 @@
   }
 
   if (m_options.isVerbose) {
-    std::cerr << "Discovered Data version: " << mobject.getVersionedName()[-1] << std::endl;
+    std::cerr << "Discovered Data version: " << mobject.getVersionedName()[-1] << "\n";
   }
 
   onDiscoverySuccess(mobject.getVersionedName());
diff --git a/tools/chunks/catchunks/pipeline-interests-adaptive.cpp b/tools/chunks/catchunks/pipeline-interests-adaptive.cpp
index 29e0d27..595dcdc 100644
--- a/tools/chunks/catchunks/pipeline-interests-adaptive.cpp
+++ b/tools/chunks/catchunks/pipeline-interests-adaptive.cpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /*
- * Copyright (c) 2016-2019, Regents of the University of California,
+ * Copyright (c) 2016-2021, Regents of the University of California,
  *                          Colorado State University,
  *                          University Pierre & Marie Curie, Sorbonne University.
  *
@@ -133,7 +133,7 @@
 
   if (m_options.isVerbose) {
     std::cerr << (isRetransmission ? "Retransmitting" : "Requesting")
-              << " segment #" << segNo << std::endl;
+              << " segment #" << segNo << "\n";
   }
 
   if (isRetransmission) {
@@ -150,7 +150,7 @@
 
       if (m_options.isVerbose) {
         std::cerr << "# of retries for segment #" << segNo
-                  << " is " << m_retxCount[segNo] << std::endl;
+                  << " is " << m_retxCount[segNo] << "\n";
       }
     }
   }
@@ -163,9 +163,9 @@
 
   SegmentInfo& segInfo = m_segmentInfo[segNo];
   segInfo.interestHdl = m_face.expressInterest(interest,
-                                               bind(&PipelineInterestsAdaptive::handleData, this, _1, _2),
-                                               bind(&PipelineInterestsAdaptive::handleNack, this, _1, _2),
-                                               bind(&PipelineInterestsAdaptive::handleLifetimeExpiration, this, _1));
+                                               FORWARD_TO_MEM_FN(handleData),
+                                               FORWARD_TO_MEM_FN(handleNack),
+                                               FORWARD_TO_MEM_FN(handleLifetimeExpiration));
   segInfo.timeSent = time::steady_clock::now();
   segInfo.rto = m_rttEstimator.getEstimatedRto();
 
@@ -239,7 +239,7 @@
   if (m_options.isVerbose) {
     std::cerr << "Received segment #" << recvSegNo
               << ", rtt=" << rtt.count() / 1e6 << "ms"
-              << ", rto=" << segInfo.rto.count() / 1e6 << "ms" << std::endl;
+              << ", rto=" << segInfo.rto.count() / 1e6 << "ms\n";
   }
 
   if (m_highData < recvSegNo) {
@@ -265,7 +265,7 @@
 
         if (m_options.isVerbose) {
           std::cerr << "Received congestion mark, value = " << data.getCongestionMark()
-                    << ", new cwnd = " << m_cwnd << std::endl;
+                    << ", new cwnd = " << m_cwnd << "\n";
         }
       }
     }
@@ -314,7 +314,7 @@
 
   if (m_options.isVerbose)
     std::cerr << "Received Nack with reason " << nack.getReason()
-              << " for Interest " << interest << std::endl;
+              << " for Interest " << interest << "\n";
 
   uint64_t segNo = getSegmentFromPacket(interest);
 
@@ -360,7 +360,7 @@
 
     if (m_options.isVerbose) {
       std::cerr << "Packet loss event, new cwnd = " << m_cwnd
-                << ", ssthresh = " << m_ssthresh << std::endl;
+                << ", ssthresh = " << m_ssthresh << "\n";
     }
   }
 }
diff --git a/tools/chunks/catchunks/pipeline-interests-adaptive.hpp b/tools/chunks/catchunks/pipeline-interests-adaptive.hpp
index 158656e..596c70e 100644
--- a/tools/chunks/catchunks/pipeline-interests-adaptive.hpp
+++ b/tools/chunks/catchunks/pipeline-interests-adaptive.hpp
@@ -60,7 +60,7 @@
 struct SegmentInfo
 {
   ScopedPendingInterestHandle interestHdl;
-  time::steady_clock::TimePoint timeSent;
+  time::steady_clock::time_point timeSent;
   time::nanoseconds rto;
   SegmentState state;
 };
diff --git a/tools/chunks/catchunks/pipeline-interests-cubic.hpp b/tools/chunks/catchunks/pipeline-interests-cubic.hpp
index 078560c..daa59eb 100644
--- a/tools/chunks/catchunks/pipeline-interests-cubic.hpp
+++ b/tools/chunks/catchunks/pipeline-interests-cubic.hpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /*
- * Copyright (c) 2016-2019, Regents of the University of California,
+ * Copyright (c) 2016-2021, Regents of the University of California,
  *                          Colorado State University,
  *                          University Pierre & Marie Curie, Sorbonne University.
  *
@@ -52,7 +52,7 @@
 private:
   double m_wmax = 0.0; ///< window size before last window decrease
   double m_lastWmax = 0.0; ///< last wmax
-  time::steady_clock::TimePoint m_lastDecrease; ///< time of last window decrease
+  time::steady_clock::time_point m_lastDecrease; ///< time of last window decrease
 };
 
 } // namespace chunks
diff --git a/tools/chunks/catchunks/pipeline-interests-fixed.cpp b/tools/chunks/catchunks/pipeline-interests-fixed.cpp
index ce11295..7fab8e3 100644
--- a/tools/chunks/catchunks/pipeline-interests-fixed.cpp
+++ b/tools/chunks/catchunks/pipeline-interests-fixed.cpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /*
- * Copyright (c) 2016-2019, Regents of the University of California,
+ * Copyright (c) 2016-2021, Regents of the University of California,
  *                          Colorado State University,
  *                          University Pierre & Marie Curie, Sorbonne University.
  *
@@ -79,7 +79,7 @@
 
   // send interest for next segment
   if (m_options.isVerbose)
-    std::cerr << "Requesting segment #" << nextSegmentNo << std::endl;
+    std::cerr << "Requesting segment #" << nextSegmentNo << "\n";
 
   auto interest = Interest()
                   .setName(Name(m_prefix).appendSegment(nextSegmentNo))
@@ -90,9 +90,15 @@
   auto fetcher = DataFetcher::fetch(m_face, interest,
                                     m_options.maxRetriesOnTimeoutOrNack,
                                     m_options.maxRetriesOnTimeoutOrNack,
-                                    bind(&PipelineInterestsFixed::handleData, this, _1, _2, pipeNo),
-                                    bind(&PipelineInterestsFixed::handleFail, this, _2, pipeNo),
-                                    bind(&PipelineInterestsFixed::handleFail, this, _2, pipeNo),
+                                    [=] (const auto& interest, const auto& data) {
+                                      handleData(interest, data, pipeNo);
+                                    },
+                                    [=] (const auto&, const auto& reason) {
+                                      handleFail(reason, pipeNo);
+                                    },
+                                    [=] (const auto&, const auto& reason) {
+                                      handleFail(reason, pipeNo);
+                                    },
                                     m_options.isVerbose);
 
   BOOST_ASSERT(!m_segmentFetchers[pipeNo].first || !m_segmentFetchers[pipeNo].first->isRunning());
@@ -122,7 +128,7 @@
   BOOST_ASSERT(data.getName().equals(interest.getName()));
 
   if (m_options.isVerbose)
-    std::cerr << "Received segment #" << getSegmentFromPacket(data) << std::endl;
+    std::cerr << "Received segment #" << getSegmentFromPacket(data) << "\n";
 
   onData(data);
 
diff --git a/tools/chunks/catchunks/pipeline-interests.hpp b/tools/chunks/catchunks/pipeline-interests.hpp
index dd8b5de..9fc3389 100644
--- a/tools/chunks/catchunks/pipeline-interests.hpp
+++ b/tools/chunks/catchunks/pipeline-interests.hpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /*
- * Copyright (c) 2016-2019, Regents of the University of California,
+ * Copyright (c) 2016-2021, Regents of the University of California,
  *                          Colorado State University,
  *                          University Pierre & Marie Curie, Sorbonne University.
  *
@@ -80,7 +80,7 @@
   cancel();
 
 protected:
-  time::steady_clock::TimePoint
+  time::steady_clock::time_point
   getStartTime() const
   {
     return m_startTime;
@@ -166,7 +166,7 @@
   DataCallback m_onData;
   FailureCallback m_onFailure;
   uint64_t m_nextSegmentNo;
-  time::steady_clock::TimePoint m_startTime;
+  time::steady_clock::time_point m_startTime;
   bool m_isStopping;
 };
 
diff --git a/tools/chunks/putchunks/producer.cpp b/tools/chunks/putchunks/producer.cpp
index ff4bafb..0a39c3b 100644
--- a/tools/chunks/putchunks/producer.cpp
+++ b/tools/chunks/putchunks/producer.cpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /*
- * Copyright (c) 2016-2019, Regents of the University of California,
+ * Copyright (c) 2016-2021, Regents of the University of California,
  *                          Colorado State University,
  *                          University Pierre & Marie Curie, Sorbonne University.
  *
@@ -53,24 +53,32 @@
   populateStore(is);
 
   if (m_options.wantShowVersion)
-    std::cout << m_versionedPrefix[-1] << std::endl;
+    std::cout << m_versionedPrefix[-1] << "\n";
 
   // register m_prefix without interest handler
-  m_face.registerPrefix(m_prefix, nullptr, bind(&Producer::onRegisterFailed, this, _1, _2));
+  m_face.registerPrefix(m_prefix, nullptr, [this] (const Name& prefix, const auto& reason) {
+    std::cerr << "ERROR: Failed to register prefix '" << prefix << "' (" << reason << ")\n";
+    m_face.shutdown();
+  });
 
   // match Interests whose name starts with m_versionedPrefix
-  face.setInterestFilter(m_versionedPrefix, bind(&Producer::processSegmentInterest, this, _2));
+  face.setInterestFilter(m_versionedPrefix, [this] (const auto&, const auto& interest) {
+    processSegmentInterest(interest);
+  });
 
   // match Interests whose name is exactly m_prefix
-  face.setInterestFilter(InterestFilter(m_prefix, ""),
-                         bind(&Producer::processSegmentInterest, this, _2));
+  face.setInterestFilter(InterestFilter(m_prefix, ""), [this] (const auto&, const auto& interest) {
+    processSegmentInterest(interest);
+  });
 
   // match discovery Interests
-  face.setInterestFilter(MetadataObject::makeDiscoveryInterest(m_prefix).getName(),
-                         bind(&Producer::processDiscoveryInterest, this, _2));
+  auto discoveryName = MetadataObject::makeDiscoveryInterest(m_prefix).getName();
+  face.setInterestFilter(discoveryName, [this] (const auto&, const auto& interest) {
+    processDiscoveryInterest(interest);
+  });
 
   if (!m_options.isQuiet)
-    std::cerr << "Data published with name: " << m_versionedPrefix << std::endl;
+    std::cerr << "Data published with name: " << m_versionedPrefix << "\n";
 }
 
 void
@@ -83,11 +91,11 @@
 Producer::processDiscoveryInterest(const Interest& interest)
 {
   if (m_options.isVerbose)
-    std::cerr << "Discovery Interest: " << interest << std::endl;
+    std::cerr << "Discovery Interest: " << interest << "\n";
 
   if (!interest.getCanBePrefix()) {
     if (m_options.isVerbose)
-      std::cerr << "Discovery Interest lacks CanBePrefix, sending Nack" << std::endl;
+      std::cerr << "Discovery Interest lacks CanBePrefix, sending Nack\n";
     m_face.put(lp::Nack(interest));
     return;
   }
@@ -99,7 +107,7 @@
   Data mdata(mobject.makeData(interest.getName(), m_keyChain, m_options.signingInfo));
 
   if (m_options.isVerbose)
-    std::cerr << "Sending metadata: " << mdata << std::endl;
+    std::cerr << "Sending metadata: " << mdata << "\n";
 
   m_face.put(mdata);
 }
@@ -110,7 +118,7 @@
   BOOST_ASSERT(m_store.size() > 0);
 
   if (m_options.isVerbose)
-    std::cerr << "Interest: " << interest << std::endl;
+    std::cerr << "Interest: " << interest << "\n";
 
   const Name& name = interest.getName();
   shared_ptr<Data> data;
@@ -129,13 +137,13 @@
 
   if (data != nullptr) {
     if (m_options.isVerbose)
-      std::cerr << "Data: " << *data << std::endl;
+      std::cerr << "Data: " << *data << "\n";
 
     m_face.put(*data);
   }
   else {
     if (m_options.isVerbose)
-      std::cerr << "Interest cannot be satisfied, sending Nack" << std::endl;
+      std::cerr << "Interest cannot be satisfied, sending Nack\n";
     m_face.put(lp::Nack(interest));
   }
 }
@@ -146,7 +154,7 @@
   BOOST_ASSERT(m_store.empty());
 
   if (!m_options.isQuiet)
-    std::cerr << "Loading input ..." << std::endl;
+    std::cerr << "Loading input ...\n";
 
   std::vector<uint8_t> buffer(m_options.maxSegmentSize);
   while (is.good()) {
@@ -174,15 +182,7 @@
   }
 
   if (!m_options.isQuiet)
-    std::cerr << "Created " << m_store.size() << " chunks for prefix " << m_prefix << std::endl;
-}
-
-void
-Producer::onRegisterFailed(const Name& prefix, const std::string& reason)
-{
-  std::cerr << "ERROR: Failed to register prefix '"
-            << prefix << "' (" << reason << ")" << std::endl;
-  m_face.shutdown();
+    std::cerr << "Created " << m_store.size() << " chunks for prefix " << m_prefix << "\n";
 }
 
 } // namespace chunks
diff --git a/tools/chunks/putchunks/producer.hpp b/tools/chunks/putchunks/producer.hpp
index 77365ed..aad6245 100644
--- a/tools/chunks/putchunks/producer.hpp
+++ b/tools/chunks/putchunks/producer.hpp
@@ -96,9 +96,6 @@
   void
   processSegmentInterest(const Interest& interest);
 
-  void
-  onRegisterFailed(const Name& prefix, const std::string& reason);
-
 PUBLIC_WITH_TESTS_ELSE_PRIVATE:
   std::vector<shared_ptr<Data>> m_store;