name: add append() overload that takes a span

Refs: #5186
Change-Id: I5fa8ac6c5da82424ac0566d0a21f72b75082af2f
diff --git a/ndn-cxx/mgmt/nfd/control-command.cpp b/ndn-cxx/mgmt/nfd/control-command.cpp
index 794856d..cc6fa13 100644
--- a/ndn-cxx/mgmt/nfd/control-command.cpp
+++ b/ndn-cxx/mgmt/nfd/control-command.cpp
@@ -63,7 +63,7 @@
   return Name(commandPrefix)
          .append(m_module)
          .append(m_verb)
-         .append(tlv::GenericNameComponent, parameters.wireEncode());
+         .append(parameters.wireEncode());
 }
 
 ControlCommand::FieldValidator::FieldValidator()
diff --git a/ndn-cxx/mgmt/nfd/status-dataset.cpp b/ndn-cxx/mgmt/nfd/status-dataset.cpp
index 616f16e..005d1e5 100644
--- a/ndn-cxx/mgmt/nfd/status-dataset.cpp
+++ b/ndn-cxx/mgmt/nfd/status-dataset.cpp
@@ -113,7 +113,7 @@
 void
 FaceQueryDataset::addParameters(Name& name) const
 {
-  name.append(tlv::GenericNameComponent, m_filter.wireEncode());
+  name.append(m_filter.wireEncode());
 }
 
 ChannelDataset::ChannelDataset()
diff --git a/ndn-cxx/name.hpp b/ndn-cxx/name.hpp
index 2f72503..98a9d7d 100644
--- a/ndn-cxx/name.hpp
+++ b/ndn-cxx/name.hpp
@@ -17,10 +17,6 @@
  * <http://www.gnu.org/licenses/>.
  *
  * See AUTHORS.md for complete list of ndn-cxx authors and contributors.
- *
- * @author Jeff Thompson <jefft0@remap.ucla.edu>
- * @author Alexander Afanasyev <http://lasr.cs.ucla.edu/afanasyev/index.html>
- * @author Zhenkai Zhu <http://irl.cs.ucla.edu/~zhenkai/>
  */
 
 #ifndef NDN_CXX_NAME_HPP
@@ -303,6 +299,16 @@
   }
 
   /**
+   * @brief Append a GenericNameComponent, copying the TLV-VALUE from @p value.
+   * @return a reference to this name, to allow chaining.
+   */
+  Name&
+  append(span<const uint8_t> value)
+  {
+    return append(Component(tlv::GenericNameComponent, value));
+  }
+
+  /**
    * @brief Append a NameComponent of TLV-TYPE @p type, copying @p count bytes at @p value as TLV-VALUE.
    * @return a reference to this name, to allow chaining.
    * @deprecated Use append(uint32_t, span<const uint8_t>)
@@ -311,19 +317,19 @@
   Name&
   append(uint32_t type, const uint8_t* value, size_t count)
   {
-    return append(Component(type, make_span(value, count)));
+    return append(type, make_span(value, count));
   }
 
   /**
    * @brief Append a GenericNameComponent, copying @p count bytes at @p value as TLV-VALUE.
    * @return a reference to this name, to allow chaining.
-   * @deprecated Use append(uint32_t, span<const uint8_t>) or append(const Component&)
+   * @deprecated Use append(span<const uint8_t>)
    */
-  [[deprecated]]
+  [[deprecated("use the overload that takes a span<>")]]
   Name&
   append(const uint8_t* value, size_t count)
   {
-    return append(Component(make_span(value, count)));
+    return append(make_span(value, count));
   }
 
   /** @brief Append a NameComponent of TLV-TYPE @p type, copying TLV-VALUE from a range.
@@ -352,7 +358,7 @@
   Name&
   append(Iterator first, Iterator last)
   {
-    return append(Component(first, last));
+    return append(Component(tlv::GenericNameComponent, first, last));
   }
 
   /** @brief Append a GenericNameComponent, copying TLV-VALUE from a null-terminated string.
@@ -524,8 +530,9 @@
                                                         std::char_traits<char>::length(keyword)}));
   }
 
-  /** @brief Append a component
-   *  @note This makes push_back an alias of append, giving Name a similar API as STL vector.
+  /**
+   * @brief Append a component.
+   * @note This makes push_back an alias of append, giving Name a similar API as `std::vector`.
    */
   template<class T>
   void
@@ -534,16 +541,18 @@
     append(component);
   }
 
-  /** @brief Erase the component at the specified index.
-   *  @param i zero-based index of the component to replace;
-   *           if negative, it is interpreted as offset from the end of the name
-   *  @warning No bounds checking is performed, using an out-of-range index is undefined behavior.
+  /**
+   * @brief Erase the component at the specified index.
+   * @param i zero-based index of the component to erase;
+   *          if negative, it is interpreted as offset from the end of the name
+   * @warning No bounds checking is performed, using an out-of-range index is undefined behavior.
    */
   void
   erase(ssize_t i);
 
-  /** @brief Remove all components.
-   *  @post `empty() == true`
+  /**
+   * @brief Remove all components.
+   * @post `empty() == true`
    */
   void
   clear();
diff --git a/ndn-cxx/security/key-chain.cpp b/ndn-cxx/security/key-chain.cpp
index 2cc22ed..f00a505 100644
--- a/ndn-cxx/security/key-chain.cpp
+++ b/ndn-cxx/security/key-chain.cpp
@@ -473,12 +473,12 @@
 
     // We encode in Data format because this is the format used prior to Packet Specification v0.3
     const auto& sigInfoBlock = sigInfo.wireEncode(SignatureInfo::Type::Data);
-    signedName.append(sigInfoBlock.begin(), sigInfoBlock.end()); // SignatureInfo
+    signedName.append(sigInfoBlock); // SignatureInfo
 
     Block sigValue(tlv::SignatureValue,
                    sign({signedName.wireEncode().value_bytes()}, keyName, params.getDigestAlgorithm()));
     sigValue.encode();
-    signedName.append(sigValue.begin(), sigValue.end()); // SignatureValue
+    signedName.append(sigValue); // SignatureValue
 
     interest.setName(signedName);
   }
diff --git a/tests/unit/mgmt/nfd/status-dataset.t.cpp b/tests/unit/mgmt/nfd/status-dataset.t.cpp
index 2c8c7f7..b9cc84d 100644
--- a/tests/unit/mgmt/nfd/status-dataset.t.cpp
+++ b/tests/unit/mgmt/nfd/status-dataset.t.cpp
@@ -301,7 +301,7 @@
   this->advanceClocks(500_ms);
 
   Name prefix("/localhost/nfd/faces/query");
-  prefix.append(filter.wireEncode().begin(), filter.wireEncode().end());
+  prefix.append(filter.wireEncode());
   FaceStatus payload;
   payload.setFaceId(8795);
   this->sendDataset(prefix, payload);
@@ -330,7 +330,7 @@
   this->advanceClocks(500_ms);
 
   Name prefix("/localhost/nfd/faces/query");
-  prefix.append(filter.wireEncode().begin(), filter.wireEncode().end());
+  prefix.append(filter.wireEncode());
   FaceStatus payload;
   payload.setFaceId(14022);
   this->sendDataset(prefix, payload);
diff --git a/tests/unit/name-component.t.cpp b/tests/unit/name-component.t.cpp
index 2743514..bd0a553 100644
--- a/tests/unit/name-component.t.cpp
+++ b/tests/unit/name-component.t.cpp
@@ -271,78 +271,63 @@
 
 BOOST_AUTO_TEST_SUITE_END() // Decode
 
-BOOST_AUTO_TEST_CASE(Compare)
+BOOST_AUTO_TEST_CASE(ConstructFromSpan)
 {
-  const std::vector<Component> comps = {
-    Component("0120 0000000000000000000000000000000000000000000000000000000000000000"_block),
-    Component("0120 0000000000000000000000000000000000000000000000000000000000000001"_block),
-    Component("0120 FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"_block),
-    Component("0220 0000000000000000000000000000000000000000000000000000000000000000"_block),
-    Component("0220 0000000000000000000000000000000000000000000000000000000000000001"_block),
-    Component("0220 FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"_block),
-    Component(0x03),
-    Component("0301 44"_block),
-    Component("0301 46"_block),
-    Component("0302 4141"_block),
-    Component(),
-    Component("D"),
-    Component("F"),
-    Component("AA"),
-    Component(0x53B2),
-    Component("FD53B201 44"_block),
-    Component("FD53B201 46"_block),
-    Component("FD53B202 4141"_block),
-  };
+  const uint8_t arr[] = {1, 2, 3};
+  Component c1(arr);
+  BOOST_TEST(c1.wireEncode() == "0803010203"_block);
+  Component c2(128, arr);
+  BOOST_TEST(c2.wireEncode() == "8003010203"_block);
 
-  for (size_t i = 0; i < comps.size(); ++i) {
-    for (size_t j = 0; j < comps.size(); ++j) {
-      Component lhs = comps[i];
-      Component rhs = comps[j];
-      BOOST_CHECK_EQUAL(lhs == rhs, i == j);
-      BOOST_CHECK_EQUAL(lhs != rhs, i != j);
-      BOOST_CHECK_EQUAL(lhs <  rhs, i <  j);
-      BOOST_CHECK_EQUAL(lhs <= rhs, i <= j);
-      BOOST_CHECK_EQUAL(lhs >  rhs, i >  j);
-      BOOST_CHECK_EQUAL(lhs >= rhs, i >= j);
-    }
-  }
+  const std::vector<uint8_t> vec = {4, 5, 6};
+  Component c3(vec);
+  BOOST_TEST(c3.wireEncode() == "0803040506"_block);
+  Component c4(128, vec);
+  BOOST_TEST(c4.wireEncode() == "8003040506"_block);
+
+  Component c5(128, {7, 8});
+  BOOST_TEST(c5.wireEncode() == "80020708"_block);
+
+  const Block b("090109"_block);
+  Component c6(128, b);
+  BOOST_TEST(c6.wireEncode() == "8003090109"_block);
 }
 
-BOOST_AUTO_TEST_SUITE(CreateFromIterators) // Bug 2490
+BOOST_AUTO_TEST_SUITE(ConstructFromIterators) // Bug 2490
 
 using ContainerTypes = boost::mpl::vector<std::vector<uint8_t>,
                                           std::list<uint8_t>,
                                           std::vector<int8_t>,
                                           std::list<int8_t>>;
 
-BOOST_AUTO_TEST_CASE_TEMPLATE(ZeroOctet, T, ContainerTypes)
+BOOST_AUTO_TEST_CASE_TEMPLATE(ZeroOctets, T, ContainerTypes)
 {
   T bytes;
   Component c(bytes.begin(), bytes.end());
-  BOOST_CHECK_EQUAL(c.type(), tlv::GenericNameComponent);
-  BOOST_CHECK_EQUAL(c.value_size(), 0);
-  BOOST_CHECK_EQUAL(c.size(), 2);
+  BOOST_TEST(c.type() == tlv::GenericNameComponent);
+  BOOST_TEST(c.value_size() == 0);
+  BOOST_TEST(c.size() == 2);
 }
 
 BOOST_AUTO_TEST_CASE_TEMPLATE(OneOctet, T, ContainerTypes)
 {
   T bytes{1};
-  Component c(0x09, bytes.begin(), bytes.end());
-  BOOST_CHECK_EQUAL(c.type(), 0x09);
-  BOOST_CHECK_EQUAL(c.value_size(), 1);
-  BOOST_CHECK_EQUAL(c.size(), 3);
+  Component c(9, bytes.begin(), bytes.end());
+  BOOST_TEST(c.type() == 0x09);
+  BOOST_TEST(c.value_size() == 1);
+  BOOST_TEST(c.size() == 3);
 }
 
 BOOST_AUTO_TEST_CASE_TEMPLATE(FourOctets, T, ContainerTypes)
 {
   T bytes{1, 2, 3, 4};
   Component c(0xFCEC, bytes.begin(), bytes.end());
-  BOOST_CHECK_EQUAL(c.type(), 0xFCEC);
-  BOOST_CHECK_EQUAL(c.value_size(), 4);
-  BOOST_CHECK_EQUAL(c.size(), 8);
+  BOOST_TEST(c.type() == 0xFCEC);
+  BOOST_TEST(c.value_size() == 4);
+  BOOST_TEST(c.size() == 8);
 }
 
-BOOST_AUTO_TEST_SUITE_END() // CreateFromIterators
+BOOST_AUTO_TEST_SUITE_END() // ConstructFromIterators
 
 BOOST_AUTO_TEST_SUITE(NamingConvention)
 
@@ -585,6 +570,43 @@
 
 BOOST_AUTO_TEST_SUITE_END() // NamingConvention
 
+BOOST_AUTO_TEST_CASE(Compare)
+{
+  const std::vector<Component> comps = {
+    Component("0120 0000000000000000000000000000000000000000000000000000000000000000"_block),
+    Component("0120 0000000000000000000000000000000000000000000000000000000000000001"_block),
+    Component("0120 FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"_block),
+    Component("0220 0000000000000000000000000000000000000000000000000000000000000000"_block),
+    Component("0220 0000000000000000000000000000000000000000000000000000000000000001"_block),
+    Component("0220 FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"_block),
+    Component(0x03),
+    Component("0301 44"_block),
+    Component("0301 46"_block),
+    Component("0302 4141"_block),
+    Component(),
+    Component("D"),
+    Component("F"),
+    Component("AA"),
+    Component(0x53B2),
+    Component("FD53B201 44"_block),
+    Component("FD53B201 46"_block),
+    Component("FD53B202 4141"_block),
+  };
+
+  for (size_t i = 0; i < comps.size(); ++i) {
+    for (size_t j = 0; j < comps.size(); ++j) {
+      const auto& lhs = comps[i];
+      const auto& rhs = comps[j];
+      BOOST_CHECK_EQUAL(lhs == rhs, i == j);
+      BOOST_CHECK_EQUAL(lhs != rhs, i != j);
+      BOOST_CHECK_EQUAL(lhs <  rhs, i <  j);
+      BOOST_CHECK_EQUAL(lhs <= rhs, i <= j);
+      BOOST_CHECK_EQUAL(lhs >  rhs, i >  j);
+      BOOST_CHECK_EQUAL(lhs >= rhs, i >= j);
+    }
+  }
+}
+
 BOOST_AUTO_TEST_SUITE_END() // TestNameComponent
 
 } // namespace tests
diff --git a/tests/unit/name.t.cpp b/tests/unit/name.t.cpp
index 45149cb..bfddb4f 100644
--- a/tests/unit/name.t.cpp
+++ b/tests/unit/name.t.cpp
@@ -239,17 +239,18 @@
   name.append(25042, {'P', '3'});
   BOOST_CHECK_EQUAL(name.wireEncode(), "070C 0804456D6964 FD61D2025033"_block);
 
-  name.append(Component(make_span<uint8_t>({'.'})));
+  const uint8_t arr[] = {'.'};
+  name.append(arr);
   BOOST_CHECK_EQUAL(name.wireEncode(), "070F 0804456D6964 FD61D2025033 08012E"_block);
 
-  const std::vector<uint8_t> v1{0x28, 0xF0, 0xA3, 0x6B};
-  name.append(16, v1.begin(), v1.end());
+  const std::vector<uint8_t> vec{0x28, 0xF0, 0xA3, 0x6B};
+  name.append(16, vec.begin(), vec.end());
   BOOST_CHECK_EQUAL(name.wireEncode(), "0715 0804456D6964 FD61D2025033 08012E 100428F0A36B"_block);
 
   name.clear();
   BOOST_CHECK_EQUAL(name.wireEncode(), "0700"_block);
 
-  name.append(v1.begin(), v1.end());
+  name.append(vec.begin(), vec.end());
   BOOST_CHECK_EQUAL(name.wireEncode(), "0706 080428F0A36B"_block);
 
   name.append("xKh");