encoding+lp: declare constexpr and noexcept where possible

Change-Id: Icf708af0b77d62d7d8e75527aaf51c7178e47125
diff --git a/src/encoding/block.cpp b/src/encoding/block.cpp
index ed8f5c9..639ed68 100644
--- a/src/encoding/block.cpp
+++ b/src/encoding/block.cpp
@@ -50,7 +50,7 @@
 }
 
 Block::Block(const EncodingBuffer& buffer)
-  : Block(const_cast<EncodingBuffer&>(buffer).getBuffer(), buffer.begin(), buffer.end(), true)
+  : Block(buffer.getBuffer(), buffer.begin(), buffer.end(), true)
 {
 }
 
diff --git a/src/encoding/encoder.hpp b/src/encoding/encoder.hpp
index 06a7ca1..b253a8a 100644
--- a/src/encoding/encoder.hpp
+++ b/src/encoding/encoder.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).
  *
@@ -32,23 +32,10 @@
  * Interface of this class (mostly) matches interface of Estimator class
  * @sa Estimator
  */
-class Encoder
+class Encoder : noncopyable
 {
 public: // common interface between Encoder and Estimator
   /**
-   * @brief Create instance of the encoder with the specified reserved sizes
-   * @param totalReserve    initial buffer size to reserve
-   * @param reserveFromBack number of bytes to reserve for append* operations
-   */
-  explicit
-  Encoder(size_t totalReserve = MAX_NDN_PACKET_SIZE, size_t reserveFromBack = 400);
-
-  Encoder(const Encoder&) = delete;
-
-  Encoder&
-  operator=(const Encoder&) = delete;
-
-  /**
    * @brief Prepend a byte
    */
   size_t
@@ -144,6 +131,14 @@
   using const_iterator = Buffer::const_iterator;
 
   /**
+   * @brief Create instance of the encoder with the specified reserved sizes
+   * @param totalReserve    initial buffer size to reserve
+   * @param reserveFromBack number of bytes to reserve for append* operations
+   */
+  explicit
+  Encoder(size_t totalReserve = MAX_NDN_PACKET_SIZE, size_t reserveFromBack = 400);
+
+  /**
    * @brief Create EncodingBlock from existing block
    *
    * This is a dangerous constructor and should be used with caution.
@@ -188,16 +183,15 @@
    * @brief Get size of the underlying buffer
    */
   size_t
-  capacity() const;
+  capacity() const noexcept;
 
   /**
    * @brief Get underlying buffer
    */
   shared_ptr<Buffer>
-  getBuffer();
+  getBuffer() const noexcept;
 
 public: // accessors
-
   /**
    * @brief Get an iterator pointing to the first byte of the encoded buffer
    */
@@ -216,6 +210,9 @@
   const_iterator
   begin() const;
 
+  /**
+   * @brief Get an iterator pointing to the past-the-end byte of the encoded buffer
+   */
   const_iterator
   end() const;
 
@@ -232,10 +229,10 @@
   buf() const;
 
   /**
-   * @brief Get size of the encoded buffer
+   * @brief Get the size of the encoded buffer
    */
   size_t
-  size() const;
+  size() const noexcept;
 
   /**
    * @brief Create Block from the underlying buffer
@@ -256,21 +253,20 @@
   iterator m_end;
 };
 
-
 inline size_t
-Encoder::size() const
+Encoder::size() const noexcept
 {
   return m_end - m_begin;
 }
 
 inline shared_ptr<Buffer>
-Encoder::getBuffer()
+Encoder::getBuffer() const noexcept
 {
   return m_buffer;
 }
 
 inline size_t
-Encoder::capacity() const
+Encoder::capacity() const noexcept
 {
   return m_buffer->size();
 }
@@ -312,7 +308,7 @@
 }
 
 template<class Iterator>
-inline size_t
+size_t
 Encoder::prependRange(Iterator first, Iterator last)
 {
   using ValueType = typename std::iterator_traits<Iterator>::value_type;
@@ -326,9 +322,8 @@
   return length;
 }
 
-
 template<class Iterator>
-inline size_t
+size_t
 Encoder::appendRange(Iterator first, Iterator last)
 {
   using ValueType = typename std::iterator_traits<Iterator>::value_type;
@@ -342,7 +337,6 @@
   return length;
 }
 
-
 } // namespace encoding
 } // namespace ndn
 
diff --git a/src/encoding/encoding-buffer.hpp b/src/encoding/encoding-buffer.hpp
index 9b483c2..1f21379 100644
--- a/src/encoding/encoding-buffer.hpp
+++ b/src/encoding/encoding-buffer.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).
  *
@@ -58,7 +58,6 @@
 public:
   explicit
   EncodingImpl(size_t totalReserve = 0, size_t totalFromBack = 0)
-    : Estimator(totalReserve, totalFromBack)
   {
   }
 };
diff --git a/src/encoding/estimator.cpp b/src/encoding/estimator.cpp
index 9ec2336..0355646 100644
--- a/src/encoding/estimator.cpp
+++ b/src/encoding/estimator.cpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
- * Copyright (c) 2013-2015 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).
  *
@@ -24,37 +24,8 @@
 namespace ndn {
 namespace encoding {
 
-Estimator::Estimator(size_t totalReserve, size_t reserveFromBack)
-{
-}
-
 size_t
-Estimator::prependByte(uint8_t value)
-{
-  return 1;
-}
-
-size_t
-Estimator::appendByte(uint8_t value)
-{
-  return 1;
-}
-
-
-size_t
-Estimator::prependByteArray(const uint8_t* array, size_t length)
-{
-  return length;
-}
-
-size_t
-Estimator::appendByteArray(const uint8_t* array, size_t length)
-{
-  return prependByteArray(array, length);
-}
-
-size_t
-Estimator::prependVarNumber(uint64_t varNumber)
+Estimator::prependVarNumber(uint64_t varNumber) const noexcept
 {
   if (varNumber < 253) {
     return 1;
@@ -71,14 +42,13 @@
 }
 
 size_t
-Estimator::appendVarNumber(uint64_t varNumber)
+Estimator::appendVarNumber(uint64_t varNumber) const noexcept
 {
   return prependVarNumber(varNumber);
 }
 
-
 size_t
-Estimator::prependNonNegativeInteger(uint64_t varNumber)
+Estimator::prependNonNegativeInteger(uint64_t varNumber) const noexcept
 {
   if (varNumber <= std::numeric_limits<uint8_t>::max()) {
     return 1;
@@ -95,14 +65,13 @@
 }
 
 size_t
-Estimator::appendNonNegativeInteger(uint64_t varNumber)
+Estimator::appendNonNegativeInteger(uint64_t varNumber) const noexcept
 {
   return prependNonNegativeInteger(varNumber);
 }
 
-
 size_t
-Estimator::prependByteArrayBlock(uint32_t type, const uint8_t* array, size_t arraySize)
+Estimator::prependByteArrayBlock(uint32_t type, const uint8_t* array, size_t arraySize) const noexcept
 {
   size_t totalLength = arraySize;
   totalLength += prependVarNumber(arraySize);
@@ -112,14 +81,13 @@
 }
 
 size_t
-Estimator::appendByteArrayBlock(uint32_t type, const uint8_t* array, size_t arraySize)
+Estimator::appendByteArrayBlock(uint32_t type, const uint8_t* array, size_t arraySize) const noexcept
 {
   return prependByteArrayBlock(type, array, arraySize);
 }
 
-
 size_t
-Estimator::prependBlock(const Block& block)
+Estimator::prependBlock(const Block& block) const
 {
   if (block.hasWire()) {
     return block.size();
@@ -130,11 +98,10 @@
 }
 
 size_t
-Estimator::appendBlock(const Block& block)
+Estimator::appendBlock(const Block& block) const
 {
   return prependBlock(block);
 }
 
-
 } // namespace encoding
 } // namespace ndn
diff --git a/src/encoding/estimator.hpp b/src/encoding/estimator.hpp
index 364f953..11f9e39 100644
--- a/src/encoding/estimator.hpp
+++ b/src/encoding/estimator.hpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
- * Copyright (c) 2013-2015 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).
  *
@@ -22,7 +22,6 @@
 #ifndef NDN_ENCODING_ESTIMATOR_HPP
 #define NDN_ENCODING_ESTIMATOR_HPP
 
-#include "../common.hpp"
 #include "block.hpp"
 
 namespace ndn {
@@ -33,129 +32,118 @@
  * Interface of this class (mostly) matches interface of Encoder class
  * @sa Encoder
  */
-class Estimator
+class Estimator : noncopyable
 {
 public: // common interface between Encoder and Estimator
   /**
-   * @brief Create instance of the estimator
-   * @param totalReserve    not used (for compatibility with the Encoder)
-   * @param reserveFromBack not used (for compatibility with the Encoder)
-   */
-  explicit
-  Estimator(size_t totalReserve = 0, size_t reserveFromBack = 0);
-
-  Estimator(const Estimator&) = delete;
-
-  Estimator&
-  operator=(const Estimator&) = delete;
-
-  /**
    * @brief Prepend a byte
    */
-  size_t
-  prependByte(uint8_t value);
+  constexpr size_t
+  prependByte(uint8_t) const noexcept
+  {
+    return 1;
+  }
 
   /**
    * @brief Append a byte
    */
-  size_t
-  appendByte(uint8_t value);
+  constexpr size_t
+  appendByte(uint8_t) const noexcept
+  {
+    return 1;
+  }
 
   /**
    * @brief Prepend a byte array @p array of length @p length
    */
-  size_t
-  prependByteArray(const uint8_t* array, size_t length);
+  constexpr size_t
+  prependByteArray(const uint8_t*, size_t length) const noexcept
+  {
+    return length;
+  }
 
   /**
    * @brief Append a byte array @p array of length @p length
    */
-  size_t
-  appendByteArray(const uint8_t* array, size_t length);
+  constexpr size_t
+  appendByteArray(const uint8_t*, size_t length) const noexcept
+  {
+    return length;
+  }
 
   /**
    * @brief Prepend range of bytes from the range [@p first, @p last)
    */
   template<class Iterator>
   size_t
-  prependRange(Iterator first, Iterator last);
+  prependRange(Iterator first, Iterator last) const noexcept
+  {
+    return std::distance(first, last);
+  }
 
   /**
    * @brief Append range of bytes from the range [@p first, @p last)
    */
   template<class Iterator>
   size_t
-  appendRange(Iterator first, Iterator last);
+  appendRange(Iterator first, Iterator last) const noexcept
+  {
+    return std::distance(first, last);
+  }
 
   /**
    * @brief Prepend VarNumber @p varNumber of NDN TLV encoding
    * @sa http://named-data.net/doc/ndn-tlv/
    */
   size_t
-  prependVarNumber(uint64_t varNumber);
+  prependVarNumber(uint64_t varNumber) const noexcept;
 
   /**
    * @brief Prepend VarNumber @p varNumber of NDN TLV encoding
    * @sa http://named-data.net/doc/ndn-tlv/
    */
   size_t
-  appendVarNumber(uint64_t varNumber);
+  appendVarNumber(uint64_t varNumber) const noexcept;
 
   /**
    * @brief Prepend non-negative integer @p integer of NDN TLV encoding
    * @sa http://named-data.net/doc/ndn-tlv/
    */
   size_t
-  prependNonNegativeInteger(uint64_t integer);
+  prependNonNegativeInteger(uint64_t integer) const noexcept;
 
   /**
    * @brief Append non-negative integer @p integer of NDN TLV encoding
    * @sa http://named-data.net/doc/ndn-tlv/
    */
   size_t
-  appendNonNegativeInteger(uint64_t integer);
+  appendNonNegativeInteger(uint64_t integer) const noexcept;
 
   /**
    * @brief Prepend TLV block of type @p type and value from buffer @p array of size @p arraySize
    */
   size_t
-  prependByteArrayBlock(uint32_t type, const uint8_t* array, size_t arraySize);
+  prependByteArrayBlock(uint32_t type, const uint8_t* array, size_t arraySize) const noexcept;
 
   /**
    * @brief Append TLV block of type @p type and value from buffer @p array of size @p arraySize
    */
   size_t
-  appendByteArrayBlock(uint32_t type, const uint8_t* array, size_t arraySize);
+  appendByteArrayBlock(uint32_t type, const uint8_t* array, size_t arraySize) const noexcept;
 
   /**
    * @brief Prepend TLV block @p block
    */
   size_t
-  prependBlock(const Block& block);
+  prependBlock(const Block& block) const;
 
   /**
    * @brief Append TLV block @p block
    */
   size_t
-  appendBlock(const Block& block);
+  appendBlock(const Block& block) const;
 };
 
-
-template<class Iterator>
-inline size_t
-Estimator::prependRange(Iterator first, Iterator last)
-{
-  return std::distance(first, last);
-}
-
-
-template<class Iterator>
-inline size_t
-Estimator::appendRange(Iterator first, Iterator last)
-{
-  return prependRange(first, last);
-}
-
 } // namespace encoding
 } // namespace ndn
 
diff --git a/src/encoding/tlv.hpp b/src/encoding/tlv.hpp
index 5fb2b24..77d62f5 100644
--- a/src/encoding/tlv.hpp
+++ b/src/encoding/tlv.hpp
@@ -22,12 +22,13 @@
 #ifndef NDN_ENCODING_TLV_HPP
 #define NDN_ENCODING_TLV_HPP
 
-#include "buffer.hpp"
+#include "../common.hpp"
 
 #include <cstring>
 #include <iterator>
 #include <ostream>
 #include <type_traits>
+#include <vector>
 
 #include <boost/endian/conversion.hpp>
 
@@ -165,8 +166,8 @@
 }
 
 /**
- * @brief Read VAR-NUMBER in NDN-TLV encoding
- * @tparam Iterator an iterator or pointer whose value is assignable to uint8_t
+ * @brief Read VAR-NUMBER in NDN-TLV encoding.
+ * @tparam Iterator an iterator or pointer that dereferences to uint8_t or compatible type
  *
  * @param [inout] begin  Begin of the buffer, will be incremented to point to the first byte after
  *                       the read VAR-NUMBER
@@ -174,15 +175,14 @@
  * @param [out]   number Read VAR-NUMBER
  *
  * @return true if number was successfully read from input, false otherwise
- * @note This call never throws exceptions
  */
 template<typename Iterator>
 bool
-readVarNumber(Iterator& begin, const Iterator& end, uint64_t& number);
+readVarNumber(Iterator& begin, Iterator end, uint64_t& number) noexcept;
 
 /**
- * @brief Read TLV-TYPE
- * @tparam Iterator an iterator or pointer whose value is assignable to uint8_t
+ * @brief Read TLV-TYPE.
+ * @tparam Iterator an iterator or pointer that dereferences to uint8_t or compatible type
  *
  * @param [inout] begin  Begin of the buffer, will be incremented to point to the first byte after
  *                       the read TLV-TYPE
@@ -190,17 +190,16 @@
  * @param [out]   type  Read TLV-TYPE
  *
  * @return true if TLV-TYPE was successfully read from input, false otherwise
- * @note This call never throws exceptions
- * @note This call is largely equivalent to tlv::readVarNumber, but it will return false if type
- *       is larger than 2^32-1 (TLV-TYPE in this library is implemented as uint32_t)
+ * @note This function is largely equivalent to readVarNumber(), except that it returns false if
+ *       the TLV-TYPE is larger than 2^32-1 (TLV-TYPE in this library is implemented as `uint32_t`)
  */
 template<typename Iterator>
 bool
-readType(Iterator& begin, const Iterator& end, uint32_t& type);
+readType(Iterator& begin, Iterator end, uint32_t& type) noexcept;
 
 /**
- * @brief Read VAR-NUMBER in NDN-TLV encoding
- * @tparam Iterator an iterator or pointer whose value is assignable to uint8_t
+ * @brief Read VAR-NUMBER in NDN-TLV encoding.
+ * @tparam Iterator an iterator or pointer that dereferences to uint8_t or compatible type
  *
  * @param [inout] begin Begin of the buffer, will be incremented to point to the first byte after
  *                      the read VAR-NUMBER
@@ -210,40 +209,40 @@
  */
 template<typename Iterator>
 uint64_t
-readVarNumber(Iterator& begin, const Iterator& end);
+readVarNumber(Iterator& begin, Iterator end);
 
 /**
- * @brief Read TLV Type
- * @tparam Iterator an iterator or pointer whose value is assignable to uint8_t
+ * @brief Read TLV-TYPE.
+ * @tparam Iterator an iterator or pointer that dereferences to uint8_t or compatible type
  *
  * @param [inout] begin Begin of the buffer, will be incremented to point to the first byte after
  *                      the read TLV-TYPE
  * @param [in]    end   End of the buffer
  *
- * @throw tlv::Error VAR-NUMBER cannot be read
- * @note This call is largely equivalent to tlv::readVarNumber, but exception will be thrown if type
- *       is larger than 2^32-1 (TLV-TYPE in this library is implemented as uint32_t)
+ * @throw tlv::Error TLV-TYPE cannot be read
+ * @note This function is largely equivalent to readVarNumber(), except that it throws if
+ *       the TLV-TYPE is larger than 2^32-1 (TLV-TYPE in this library is implemented as `uint32_t`)
  */
 template<typename Iterator>
 uint32_t
-readType(Iterator& begin, const Iterator& end);
+readType(Iterator& begin, Iterator end);
 
 /**
- * @brief Get number of bytes necessary to hold value of VAR-NUMBER
+ * @brief Get the number of bytes necessary to hold the value of @p number encoded as VAR-NUMBER.
  */
 constexpr size_t
-sizeOfVarNumber(uint64_t number);
+sizeOfVarNumber(uint64_t number) noexcept;
 
 /**
- * @brief Write VAR-NUMBER to the specified stream
+ * @brief Write VAR-NUMBER to the specified stream.
  * @return length of written VAR-NUMBER
  */
 size_t
 writeVarNumber(std::ostream& os, uint64_t number);
 
 /**
- * @brief Read nonNegativeInteger in NDN-TLV encoding
- * @tparam Iterator an iterator or pointer whose value is assignable to uint8_t
+ * @brief Read nonNegativeInteger in NDN-TLV encoding.
+ * @tparam Iterator an iterator or pointer that dereferences to uint8_t or compatible type
  *
  * @param [in]    size  size of the nonNegativeInteger
  * @param [inout] begin Begin of the buffer, will be incremented to point to the first byte after
@@ -252,20 +251,20 @@
  *
  * @throw tlv::Error number cannot be read
  * @note How many bytes to read is directly controlled by \p size, which can be either 1, 2, 4, or 8.
- *       If \p size differs from \p std::distance(begin, end), tlv::Error exception will be thrown.
+ *       If \p size differs from `std::distance(begin, end)`, tlv::Error exception will be thrown.
  */
 template<typename Iterator>
 uint64_t
-readNonNegativeInteger(size_t size, Iterator& begin, const Iterator& end);
+readNonNegativeInteger(size_t size, Iterator& begin, Iterator end);
 
 /**
- * @brief Get number of bytes necessary to hold value of nonNegativeInteger
+ * @brief Get the number of bytes necessary to hold the value of @p integer encoded as nonNegativeInteger.
  */
 constexpr size_t
-sizeOfNonNegativeInteger(uint64_t integer);
+sizeOfNonNegativeInteger(uint64_t integer) noexcept;
 
 /**
- * @brief Write nonNegativeInteger to the specified stream
+ * @brief Write nonNegativeInteger to the specified stream.
  * @return length of written nonNegativeInteger
  */
 size_t
@@ -289,8 +288,8 @@
 class ReadNumberSlow
 {
 public:
-  bool
-  operator()(size_t size, Iterator& begin, const Iterator& end, uint64_t& number) const
+  constexpr bool
+  operator()(size_t size, Iterator& begin, Iterator end, uint64_t& number) const noexcept
   {
     number = 0;
     size_t count = 0;
@@ -307,8 +306,8 @@
 class ReadNumberFast
 {
 public:
-  bool
-  operator()(size_t size, Iterator& begin, const Iterator& end, uint64_t& number) const
+  constexpr bool
+  operator()(size_t size, Iterator& begin, Iterator end, uint64_t& number) const noexcept
   {
     if (begin + size > end) {
       return false;
@@ -377,7 +376,7 @@
 
 template<typename Iterator>
 bool
-readVarNumber(Iterator& begin, const Iterator& end, uint64_t& number)
+readVarNumber(Iterator& begin, Iterator end, uint64_t& number) noexcept
 {
   if (begin == end)
     return false;
@@ -396,7 +395,7 @@
 
 template<typename Iterator>
 bool
-readType(Iterator& begin, const Iterator& end, uint32_t& type)
+readType(Iterator& begin, Iterator end, uint32_t& type) noexcept
 {
   uint64_t number = 0;
   bool isOk = readVarNumber(begin, end, number);
@@ -410,15 +409,16 @@
 
 template<typename Iterator>
 uint64_t
-readVarNumber(Iterator& begin, const Iterator& end)
+readVarNumber(Iterator& begin, Iterator end)
 {
-  if (begin == end)
-    BOOST_THROW_EXCEPTION(Error("Empty buffer during TLV processing"));
+  if (begin == end) {
+    BOOST_THROW_EXCEPTION(Error("Empty buffer during TLV parsing"));
+  }
 
   uint64_t value = 0;
   bool isOk = readVarNumber(begin, end, value);
   if (!isOk) {
-    BOOST_THROW_EXCEPTION(Error("Insufficient data during TLV processing"));
+    BOOST_THROW_EXCEPTION(Error("Insufficient data during TLV parsing"));
   }
 
   return value;
@@ -426,7 +426,7 @@
 
 template<typename Iterator>
 uint32_t
-readType(Iterator& begin, const Iterator& end)
+readType(Iterator& begin, Iterator end)
 {
   uint64_t type = readVarNumber(begin, end);
   if (type > std::numeric_limits<uint32_t>::max()) {
@@ -437,7 +437,7 @@
 }
 
 constexpr size_t
-sizeOfVarNumber(uint64_t number)
+sizeOfVarNumber(uint64_t number) noexcept
 {
   return number < 253 ? 1 :
          number <= std::numeric_limits<uint16_t>::max() ? 3 :
@@ -473,7 +473,7 @@
 
 template<typename Iterator>
 uint64_t
-readNonNegativeInteger(size_t size, Iterator& begin, const Iterator& end)
+readNonNegativeInteger(size_t size, Iterator& begin, Iterator end)
 {
   if (size != 1 && size != 2 && size != 4 && size != 8) {
     BOOST_THROW_EXCEPTION(Error("Invalid length for nonNegativeInteger "
@@ -483,14 +483,14 @@
   uint64_t number = 0;
   bool isOk = detail::ReadNumber<Iterator>()(size, begin, end, number);
   if (!isOk) {
-    BOOST_THROW_EXCEPTION(Error("Insufficient data during TLV processing"));
+    BOOST_THROW_EXCEPTION(Error("Insufficient data during TLV parsing"));
   }
 
   return number;
 }
 
 constexpr size_t
-sizeOfNonNegativeInteger(uint64_t integer)
+sizeOfNonNegativeInteger(uint64_t integer) noexcept
 {
   return integer <= std::numeric_limits<uint8_t>::max() ? 1 :
          integer <= std::numeric_limits<uint16_t>::max() ? 2 :
diff --git a/src/lp/packet.cpp b/src/lp/packet.cpp
index a3062b6..e5fc8f3 100644
--- a/src/lp/packet.cpp
+++ b/src/lp/packet.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).
  *
@@ -33,18 +33,18 @@
 
 template<typename TAG>
 int
-getLocationSortOrder();
+getLocationSortOrder() noexcept;
 
 template<>
-int
-getLocationSortOrder<field_location_tags::Header>()
+constexpr int
+getLocationSortOrder<field_location_tags::Header>() noexcept
 {
   return 1;
 }
 
 template<>
-int
-getLocationSortOrder<field_location_tags::Fragment>()
+constexpr int
+getLocationSortOrder<field_location_tags::Fragment>() noexcept
 {
   return 2;
 }
@@ -52,17 +52,18 @@
 class FieldInfo
 {
 public:
-  FieldInfo();
+  constexpr
+  FieldInfo() noexcept = default;
 
   explicit
-  FieldInfo(uint64_t tlv);
+  FieldInfo(uint64_t tlv) noexcept;
 
 public:
-  uint64_t tlvType;       ///< TLV-TYPE of the field; 0 if field does not exist
-  bool isRecognized;      ///< is this field known
-  bool canIgnore;         ///< can this unknown field be ignored
-  bool isRepeatable;      ///< is the field repeatable
-  int locationSortOrder;  ///< sort order of field_location_tag
+  uint64_t tlvType = 0;       ///< TLV-TYPE of the field; 0 if field does not exist
+  bool isRecognized = false;  ///< is this field known
+  bool canIgnore = false;     ///< can this unknown field be ignored
+  bool isRepeatable = false;  ///< is the field repeatable
+  int locationSortOrder = getLocationSortOrder<field_location_tags::Header>(); ///< sort order of field_location_tag
 };
 
 class ExtractFieldInfo
@@ -71,8 +72,8 @@
   using result_type = void;
 
   template<typename T>
-  void
-  operator()(FieldInfo* info, T) const
+  constexpr void
+  operator()(FieldInfo* info, const T&) const noexcept
   {
     if (T::TlvType::value != info->tlvType) {
       return;
@@ -84,21 +85,8 @@
   }
 };
 
-FieldInfo::FieldInfo()
-  : tlvType(0)
-  , isRecognized(false)
-  , canIgnore(false)
-  , isRepeatable(false)
-  , locationSortOrder(getLocationSortOrder<field_location_tags::Header>())
-{
-}
-
-FieldInfo::FieldInfo(uint64_t tlv)
+FieldInfo::FieldInfo(uint64_t tlv) noexcept
   : tlvType(tlv)
-  , isRecognized(false)
-  , canIgnore(false)
-  , isRepeatable(false)
-  , locationSortOrder(getLocationSortOrder<field_location_tags::Header>())
 {
   boost::mpl::for_each<FieldSet>(boost::bind(ExtractFieldInfo(), this, _1));
   if (!isRecognized) {
@@ -108,8 +96,8 @@
   }
 }
 
-bool
-compareFieldSortOrder(const FieldInfo& first, const FieldInfo& second)
+constexpr bool
+compareFieldSortOrder(const FieldInfo& first, const FieldInfo& second) noexcept
 {
   return (first.locationSortOrder < second.locationSortOrder) ||
          (first.locationSortOrder == second.locationSortOrder && first.tlvType < second.tlvType);
@@ -183,7 +171,7 @@
 }
 
 bool
-Packet::comparePos(uint64_t first, const Block& second)
+Packet::comparePos(uint64_t first, const Block& second) noexcept
 {
   FieldInfo firstInfo(first);
   FieldInfo secondInfo(second.type());
diff --git a/src/lp/packet.hpp b/src/lp/packet.hpp
index eb30485..1aba8b1 100644
--- a/src/lp/packet.hpp
+++ b/src/lp/packet.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).
  *
@@ -204,7 +204,7 @@
 
 private:
   static bool
-  comparePos(uint64_t first, const Block& second);
+  comparePos(uint64_t first, const Block& second) noexcept;
 
 private:
   mutable Block m_wire;