Sort names on argument construction

This commit is contained in:
Stephan van Veen 2019-05-25 09:44:06 +02:00
parent 7c5ee10205
commit 34d259d892

View File

@ -84,7 +84,11 @@ public:
explicit Argument(Args... args)
: mNames({std::move(args)...})
, mIsOptional((is_optional(args) || ...))
{}
{
std::sort(mNames.begin(), mNames.end(), [](const auto& lhs, const auto& rhs) {
return lhs.size() == rhs.size() ? lhs < rhs : lhs.size() < rhs.size();
});
}
Argument& help(std::string aHelp) {
mHelp = std::move(aHelp);
@ -401,10 +405,6 @@ class ArgumentParser {
for (const auto & mOptionalArgument : mOptionalArguments) {
size_t tCurrentLength = 0;
auto tNames = mOptionalArgument->mNames;
std::sort(tNames.begin(), tNames.end(),
[](const std::string& lhs, const std::string& rhs) {
return lhs.size() == rhs.size() ? lhs < rhs : lhs.size() < rhs.size();
});
for (size_t j = 0; j < tNames.size() - 1; j++) {
auto tCurrentName = tNames[j];
stream << tCurrentName;