encoding+util: ensure move constructors are properly declared

This also fixes a race condition in scheduler::EventId::operator bool()

Change-Id: I468f0c46039a3d1a38c69c419ae45b4445d8205a
Refs: #3414
diff --git a/src/util/signal/connection.cpp b/src/util/signal/connection.cpp
index 7d46eb1..1d93326 100644
--- a/src/util/signal/connection.cpp
+++ b/src/util/signal/connection.cpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /*
- * Copyright (c) 2013-2017 Regents of the University of California.
+ * Copyright (c) 2013-2018 Regents of the University of California.
  *
  * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
  *
@@ -27,26 +27,22 @@
 
 BOOST_CONCEPT_ASSERT((boost::EqualityComparable<Connection>));
 
-Connection::Connection()
-{
-}
-
-Connection::Connection(weak_ptr<function<void()>> disconnect)
-  : m_disconnect(disconnect)
+Connection::Connection(weak_ptr<function<void()>> disconnect) noexcept
+  : m_disconnect(std::move(disconnect))
 {
 }
 
 void
 Connection::disconnect()
 {
-  shared_ptr<function<void()>> f = m_disconnect.lock();
+  auto f = m_disconnect.lock();
   if (f != nullptr) {
     (*f)();
   }
 }
 
 bool
-Connection::isConnected() const
+Connection::isConnected() const noexcept
 {
   return !m_disconnect.expired();
 }
@@ -54,8 +50,8 @@
 bool
 Connection::operator==(const Connection& other) const
 {
-  shared_ptr<function<void()>> f1 = m_disconnect.lock();
-  shared_ptr<function<void()>> f2 = other.m_disconnect.lock();
+  auto f1 = m_disconnect.lock();
+  auto f2 = other.m_disconnect.lock();
   return f1 == f2;
 }
 
diff --git a/src/util/signal/connection.hpp b/src/util/signal/connection.hpp
index 6ee8e1c..528dcba 100644
--- a/src/util/signal/connection.hpp
+++ b/src/util/signal/connection.hpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /*
- * Copyright (c) 2013-2017 Regents of the University of California.
+ * Copyright (c) 2013-2018 Regents of the University of California.
  *
  * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
  *
@@ -34,7 +34,8 @@
 class Connection
 {
 public:
-  Connection();
+  constexpr
+  Connection() noexcept = default;
 
   /** \brief disconnects from the signal
    *  \note If the connection is already disconnected, or if the Signal has been destructed,
@@ -49,7 +50,7 @@
    *  \return false if disconnected from the signal
    */
   bool
-  isConnected() const;
+  isConnected() const noexcept;
 
   /** \brief compare for equality
    *
@@ -66,7 +67,7 @@
   /** \param disconnect weak_ptr to a function that disconnects the handler
    */
   explicit
-  Connection(weak_ptr<function<void()>> disconnect);
+  Connection(weak_ptr<function<void()>> disconnect) noexcept;
 
   template<typename Owner, typename ...TArgs>
   friend class Signal;
diff --git a/src/util/signal/scoped-connection.cpp b/src/util/signal/scoped-connection.cpp
index 3fed4a3..7a231b0 100644
--- a/src/util/signal/scoped-connection.cpp
+++ b/src/util/signal/scoped-connection.cpp
@@ -25,35 +25,24 @@
 namespace util {
 namespace signal {
 
-static_assert(std::is_nothrow_move_constructible<ScopedConnection>::value,
-              "ScopedConnection must be MoveConstructible with noexcept");
-
-ScopedConnection::ScopedConnection() = default;
-
-ScopedConnection::ScopedConnection(const Connection& connection)
-  : m_connection(connection)
+ScopedConnection::ScopedConnection(Connection connection) noexcept
+  : m_connection(std::move(connection))
 {
 }
 
-ScopedConnection::ScopedConnection(ScopedConnection&& other) noexcept
-  : m_connection(other.m_connection)
-{
-  other.release();
-}
-
 ScopedConnection&
-ScopedConnection::operator=(const Connection& connection)
+ScopedConnection::operator=(Connection connection)
 {
   if (m_connection != connection) {
-    m_connection.disconnect();
-    m_connection = connection;
+    disconnect();
+    m_connection = std::move(connection);
   }
   return *this;
 }
 
-ScopedConnection::~ScopedConnection() noexcept
+ScopedConnection::~ScopedConnection()
 {
-  m_connection.disconnect();
+  disconnect();
 }
 
 void
@@ -63,13 +52,13 @@
 }
 
 bool
-ScopedConnection::isConnected() const
+ScopedConnection::isConnected() const noexcept
 {
   return m_connection.isConnected();
 }
 
 void
-ScopedConnection::release()
+ScopedConnection::release() noexcept
 {
   m_connection = {};
 }
diff --git a/src/util/signal/scoped-connection.hpp b/src/util/signal/scoped-connection.hpp
index 5c77c2f..f352be0 100644
--- a/src/util/signal/scoped-connection.hpp
+++ b/src/util/signal/scoped-connection.hpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /*
- * Copyright (c) 2013-2017 Regents of the University of California.
+ * Copyright (c) 2013-2018 Regents of the University of California.
  *
  * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
  *
@@ -28,56 +28,73 @@
 namespace util {
 namespace signal {
 
-/** \brief disconnects a Connection automatically upon destruction
+/** \brief Disconnects a Connection automatically upon destruction.
  */
-class ScopedConnection : noncopyable
+class ScopedConnection
 {
 public:
-  ScopedConnection();
+  constexpr
+  ScopedConnection() noexcept = default;
 
-  /** \brief implicit constructor from Connection
+  ScopedConnection(const ScopedConnection&) = delete;
+
+  ScopedConnection&
+  operator=(const ScopedConnection&) = delete;
+
+  /** \brief Move constructor.
+   */
+  ScopedConnection(ScopedConnection&&) noexcept;
+
+  /** \brief Move assignment operator.
+   */
+  ScopedConnection&
+  operator=(ScopedConnection&&) noexcept;
+
+  /** \brief Implicit constructor from Connection.
    *  \param connection the Connection to be disconnected upon destruction
    */
-  ScopedConnection(const Connection& connection);
+  ScopedConnection(Connection connection) noexcept;
 
-  /** \brief move constructor
-   */
-  ScopedConnection(ScopedConnection&& other) noexcept;
-
-  /** \brief assigns a connection
+  /** \brief Assign a connection.
    *
    *  If a different connection has been assigned to this instance previously,
    *  that connection will be disconnected immediately.
    */
   ScopedConnection&
-  operator=(const Connection& connection);
+  operator=(Connection connection);
 
-  /** \brief disconnects the connection
+  /** \brief Destructor, automatically disconnects the connection.
    */
-  ~ScopedConnection() noexcept;
+  ~ScopedConnection();
 
-  /** \brief disconnects the connection manually
+  /** \brief Manually disconnect the connection.
    */
   void
   disconnect();
 
-  /** \brief check if the connection is connected to the signal
+  /** \brief Check if the connection is connected to the signal.
    *  \return false when a default-constructed connection is used, the connection is released,
    *          or the connection is disconnected
    */
   bool
-  isConnected() const;
+  isConnected() const noexcept;
 
-  /** \brief releases the connection so that it won't be disconnected
-   *         when this ScopedConnection is destructed
+  /** \brief Release the connection so that it won't be disconnected
+   *         when this ScopedConnection is destructed.
    */
   void
-  release();
+  release() noexcept;
 
 private:
   Connection m_connection;
 };
 
+inline
+ScopedConnection::ScopedConnection(ScopedConnection&&) noexcept = default;
+
+inline ScopedConnection&
+ScopedConnection::operator=(ScopedConnection&&) noexcept = default;
+
 } // namespace signal
 } // namespace util
 } // namespace ndn