From 56c041707a698f7d47118c0ee8fde44595b1fc52 Mon Sep 17 00:00:00 2001 From: Zhihao Yuan Date: Sat, 16 Nov 2019 21:58:49 -0600 Subject: [PATCH] Use string_view in getter interface --- include/argparse.hpp | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/include/argparse.hpp b/include/argparse.hpp index dd937b7..253cea9 100644 --- a/include/argparse.hpp +++ b/include/argparse.hpp @@ -454,19 +454,15 @@ public: * @throws std::logic_error in case of an invalid argument name * @throws std::logic_error in case of incompatible types */ - template T get(const std::string &aArgumentName) { - auto tIterator = mArgumentMap.find(aArgumentName); - if (tIterator != mArgumentMap.end()) { - return tIterator->second->get(); - } - throw std::logic_error("No such argument"); + template T get(std::string_view aArgumentName) { + return (*this)[aArgumentName].get(); } /* Indexing operator. Return a reference to an Argument object * Used in conjuction with Argument.operator== e.g., parser["foo"] == true * @throws std::logic_error in case of an invalid argument name */ - Argument &operator[](const std::string &aArgumentName) { + Argument &operator[](std::string_view aArgumentName) { auto tIterator = mArgumentMap.find(aArgumentName); if (tIterator != mArgumentMap.end()) { return *(tIterator->second);