name: allow negative argument for 'get' method to get component from the back
Change-Id: I7e76fc16dfc5ce8ed2a18cfb461f884b82e1b274
diff --git a/include/ndn-cpp/name.hpp b/include/ndn-cpp/name.hpp
index 132def5..633593c 100644
--- a/include/ndn-cpp/name.hpp
+++ b/include/ndn-cpp/name.hpp
@@ -582,7 +582,13 @@
* @return The name component at the index.
*/
const Component&
- get(size_t i) const { return components_[i]; }
+ get(ssize_t i) const
+ {
+ if (i >= 0)
+ return components_[i];
+ else
+ return components_[size() + i];
+ }
const Component&