mirror of
https://github.com/KeqingMoe/argparse.git
synced 2025-07-04 15:14:39 +00:00
Use string_view in getter interface
This commit is contained in:
parent
f7fe9cf439
commit
56c041707a
@ -454,19 +454,15 @@ public:
|
|||||||
* @throws std::logic_error in case of an invalid argument name
|
* @throws std::logic_error in case of an invalid argument name
|
||||||
* @throws std::logic_error in case of incompatible types
|
* @throws std::logic_error in case of incompatible types
|
||||||
*/
|
*/
|
||||||
template <typename T = std::string> T get(const std::string &aArgumentName) {
|
template <typename T = std::string> T get(std::string_view aArgumentName) {
|
||||||
auto tIterator = mArgumentMap.find(aArgumentName);
|
return (*this)[aArgumentName].get<T>();
|
||||||
if (tIterator != mArgumentMap.end()) {
|
|
||||||
return tIterator->second->get<T>();
|
|
||||||
}
|
|
||||||
throw std::logic_error("No such argument");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Indexing operator. Return a reference to an Argument object
|
/* Indexing operator. Return a reference to an Argument object
|
||||||
* Used in conjuction with Argument.operator== e.g., parser["foo"] == true
|
* Used in conjuction with Argument.operator== e.g., parser["foo"] == true
|
||||||
* @throws std::logic_error in case of an invalid argument name
|
* @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);
|
auto tIterator = mArgumentMap.find(aArgumentName);
|
||||||
if (tIterator != mArgumentMap.end()) {
|
if (tIterator != mArgumentMap.end()) {
|
||||||
return *(tIterator->second);
|
return *(tIterator->second);
|
||||||
|
Loading…
Reference in New Issue
Block a user