Add Argument::firstValueOr() for conveniently accessing the first value with a fallback
This commit is contained in:
parent
8a9d72bee9
commit
f109d36ad2
|
@ -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.
|
* \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;
|
template <typename... TargetType> std::vector<std::tuple<TargetType...>> allValuesAs() const;
|
||||||
|
|
||||||
const char *firstValue() const;
|
const char *firstValue() const;
|
||||||
|
const char *firstValueOr(const char *fallback) const;
|
||||||
bool allRequiredValuesPresent(std::size_t occurrence = 0) const;
|
bool allRequiredValuesPresent(std::size_t occurrence = 0) const;
|
||||||
bool isPresent() const;
|
bool isPresent() const;
|
||||||
std::size_t occurrences() const;
|
std::size_t occurrences() const;
|
||||||
|
|
Loading…
Reference in New Issue