mirror of
https://github.com/p-ranav/argparse
synced 2026-06-08 16:35:45 +00:00
Add operator bool for ArgumentParser
This allows checking whether user input was processed into the parser or any attached subparsers. Closes #212 Signed-off-by: Sean Robinson <sean.robinson@scottsdalecc.edu>
This commit is contained in:
@@ -1104,6 +1104,21 @@ public:
|
||||
return *this;
|
||||
}
|
||||
|
||||
explicit operator bool() const {
|
||||
auto arg_used = std::any_of(m_argument_map.cbegin(),
|
||||
m_argument_map.cend(),
|
||||
[](auto &it) {
|
||||
return it.second->m_is_used;
|
||||
});
|
||||
auto subparser_used = std::any_of(m_subparser_used.cbegin(),
|
||||
m_subparser_used.cend(),
|
||||
[](auto &it) {
|
||||
return it.second;
|
||||
});
|
||||
|
||||
return m_is_parsed && (arg_used || subparser_used);
|
||||
}
|
||||
|
||||
// Parameter packing
|
||||
// Call add_argument with variadic number of string arguments
|
||||
template <typename... Targs> Argument &add_argument(Targs... f_args) {
|
||||
|
||||
Reference in New Issue
Block a user