Add Argument::firstValueOr() for conveniently accessing the first value with a fallback

charconv
Martchus 2 years ago
parent 8a9d72bee9
commit f109d36ad2
  1. 12
      application/argumentparser.cpp
  2. 1
      application/argumentparser.h

@ -499,6 +499,18 @@ const char *Argument::firstValue() const
}
}
/*!
* \brief Returns the first value like Argument::firstValue() but returns \a fallback instead of nullptr if there's no value.
*/
const char *Argument::firstValueOr(const char *fallback) const
{
if (const auto *const v = firstValue()) {
return v;
} else {
return fallback;
}
}
/*!
* \brief Writes the name, the abbreviation and other information about the Argument to the give ostream.
*/

@ -335,6 +335,7 @@ public:
template <typename... TargetType> std::vector<std::tuple<TargetType...>> allValuesAs() const;
const char *firstValue() const;
const char *firstValueOr(const char *fallback) const;
bool allRequiredValuesPresent(std::size_t occurrence = 0) const;
bool isPresent() const;
std::size_t occurrences() const;

Loading…
Cancel
Save