diff --git a/include/cxxopts.hpp b/include/cxxopts.hpp index 94b81ef..69656e6 100644 --- a/include/cxxopts.hpp +++ b/include/cxxopts.hpp @@ -1044,6 +1044,12 @@ namespace cxxopts return m_count; } + bool + has_value() const + { + return m_value != nullptr; + } + template const T& as() const @@ -1147,6 +1153,10 @@ namespace cxxopts } auto riter = m_results.find(iter->second); + if (!riter->second.has_value()) + { + throw option_required_exception(option); + } return riter->second; }