From db0c4abe10a7e8ea9824e9c2df38ad5cbe5aba40 Mon Sep 17 00:00:00 2001 From: Sergii Bogomolov Date: Thu, 7 Mar 2019 11:29:44 -0600 Subject: [PATCH] Throw option_required_exception if option value is not present --- include/cxxopts.hpp | 10 ++++++++++ 1 file changed, 10 insertions(+) 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; }