Index arguments without storing their names twice

This commit is contained in:
Zhihao Yuan 2019-11-16 13:50:34 -06:00
parent 3f949fc3f1
commit 9007958c1f
No known key found for this signature in database
GPG Key ID: A2E474BDAA37E11C

View File

@ -39,6 +39,7 @@ SOFTWARE.
#include <sstream> #include <sstream>
#include <stdexcept> #include <stdexcept>
#include <string> #include <string>
#include <string_view>
#include <tuple> #include <tuple>
#include <type_traits> #include <type_traits>
#include <variant> #include <variant>
@ -581,13 +582,13 @@ private:
void index_argument(list_iterator argIt) { void index_argument(list_iterator argIt) {
for (auto &mName : std::as_const(argIt->mNames)) for (auto &mName : std::as_const(argIt->mNames))
mArgumentMap.insert_or_assign(mName, argIt); mArgumentMap.emplace(mName, argIt);
} }
std::string mProgramName; std::string mProgramName;
std::list<Argument> mPositionalArguments; std::list<Argument> mPositionalArguments;
std::list<Argument> mOptionalArguments; std::list<Argument> mOptionalArguments;
std::map<std::string, list_iterator, std::less<>> mArgumentMap; std::map<std::string_view, list_iterator, std::less<>> mArgumentMap;
}; };
} // namespace argparse } // namespace argparse