diff --git a/include/cxxopts.hpp b/include/cxxopts.hpp index a2e71fa..2819f50 100644 --- a/include/cxxopts.hpp +++ b/include/cxxopts.hpp @@ -1743,6 +1743,12 @@ CXXOPTS_DIAGNOSTIC_POP return viter->second.count(); } + bool + contains(const std::string& o) const + { + return static_cast(count(o)); + } + const OptionValue& operator[](const std::string& option) const { diff --git a/test/options.cpp b/test/options.cpp index 647934c..60d2f05 100644 --- a/test/options.cpp +++ b/test/options.cpp @@ -89,6 +89,7 @@ TEST_CASE("Basic options", "[options]") auto result = options.parse(argc, actual_argv); CHECK(result.count("long") == 1); + CHECK(result.contains("long")); CHECK(result.count("s") == 1); CHECK(result.count("value") == 1); CHECK(result.count("a") == 1); @@ -112,6 +113,8 @@ TEST_CASE("Basic options", "[options]") CHECK(arguments[2].key() == "value"); CHECK(arguments[3].key() == "av"); + CHECK(result.count("nothing") == 0); + CHECK_FALSE(result.contains("nothing")); CHECK_THROWS_AS(result["nothing"].as(), cxxopts::exceptions::option_has_no_value); CHECK(options.program() == "tester");