diff --git a/application/argumentparser.cpp b/application/argumentparser.cpp index ae6b81a..64a5e5a 100644 --- a/application/argumentparser.cpp +++ b/application/argumentparser.cpp @@ -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. */ diff --git a/application/argumentparser.h b/application/argumentparser.h index ab38a19..f97e6a8 100644 --- a/application/argumentparser.h +++ b/application/argumentparser.h @@ -335,6 +335,7 @@ public: template std::vector> 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;