Compare commits
1 Commits
master
...
fix_parse_
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
642bdfc05b |
@ -3,12 +3,6 @@
|
||||
This is the changelog for `cxxopts`, a C++11 library for parsing command line
|
||||
options. The project adheres to semantic versioning.
|
||||
|
||||
## 3.2.1
|
||||
|
||||
### Bug fixes
|
||||
|
||||
* Fix compilation with optional on C++20.
|
||||
|
||||
## 3.2
|
||||
|
||||
### Bug fixes
|
||||
|
||||
@ -94,7 +94,7 @@ THE SOFTWARE.
|
||||
|
||||
#define CXXOPTS__VERSION_MAJOR 3
|
||||
#define CXXOPTS__VERSION_MINOR 2
|
||||
#define CXXOPTS__VERSION_PATCH 1
|
||||
#define CXXOPTS__VERSION_PATCH 0
|
||||
|
||||
#if (__GNUC__ < 10 || (__GNUC__ == 10 && __GNUC_MINOR__ < 1)) && __GNUC__ >= 6
|
||||
#define CXXOPTS_NULL_DEREF_IGNORE
|
||||
@ -1538,15 +1538,6 @@ CXXOPTS_DIAGNOSTIC_POP
|
||||
return CXXOPTS_RTTI_CAST<const values::standard_value<T>&>(*m_value).get();
|
||||
}
|
||||
|
||||
#ifdef CXXOPTS_HAS_OPTIONAL
|
||||
template <typename T>
|
||||
std::optional<T>
|
||||
as_optional() const
|
||||
{
|
||||
return as<T>();
|
||||
}
|
||||
#endif
|
||||
|
||||
private:
|
||||
void
|
||||
ensure_value(const std::shared_ptr<const OptionDetails>& details)
|
||||
@ -1759,24 +1750,6 @@ CXXOPTS_DIAGNOSTIC_POP
|
||||
return viter->second;
|
||||
}
|
||||
|
||||
#ifdef CXXOPTS_HAS_OPTIONAL
|
||||
template <typename T>
|
||||
std::optional<T>
|
||||
as_optional(const std::string& option) const
|
||||
{
|
||||
auto iter = m_keys.find(option);
|
||||
if (iter != m_keys.end())
|
||||
{
|
||||
auto viter = m_values.find(iter->second);
|
||||
if (viter != m_values.end())
|
||||
{
|
||||
return viter->second.as_optional<T>();
|
||||
}
|
||||
}
|
||||
return std::nullopt;
|
||||
}
|
||||
#endif
|
||||
|
||||
const std::vector<KeyValue>&
|
||||
arguments() const
|
||||
{
|
||||
|
||||
@ -821,57 +821,6 @@ TEST_CASE("Options empty", "[options]") {
|
||||
CHECK_THROWS_AS(options.parse(argc, argv), cxxopts::exceptions::no_such_option);
|
||||
}
|
||||
|
||||
#ifdef CXXOPTS_HAS_OPTIONAL
|
||||
TEST_CASE("Optional value", "[optional]")
|
||||
{
|
||||
cxxopts::Options options("options", "query as std::optional");
|
||||
options.add_options()
|
||||
("int", "Integer", cxxopts::value<int>())
|
||||
("float", "Float", cxxopts::value<float>())
|
||||
("string", "String", cxxopts::value<std::string>())
|
||||
;
|
||||
|
||||
SECTION("Available") {
|
||||
Argv av({
|
||||
"--int",
|
||||
"42",
|
||||
"--float",
|
||||
"3.141",
|
||||
"--string",
|
||||
"Hello"
|
||||
});
|
||||
|
||||
auto** argv = av.argv();
|
||||
auto argc = av.argc();
|
||||
|
||||
auto result = options.parse(argc, argv);
|
||||
|
||||
CHECK(result.as_optional<int>("int"));
|
||||
CHECK(result.as_optional<float>("float"));
|
||||
CHECK(result.as_optional<string>("string"));
|
||||
|
||||
CHECK(*result.as_optional<int>("int") == 42);
|
||||
CHECK(*result.as_optional<float>("float") == 3.141);
|
||||
CHECK(*result.as_optional<string>("string") == "Hello");
|
||||
}
|
||||
|
||||
SECTION("Unavailable") {
|
||||
Argv av({
|
||||
});
|
||||
|
||||
auto** argv = av.argv();
|
||||
auto argc = av.argc();
|
||||
|
||||
auto result = options.parse(argc, argv);
|
||||
|
||||
CHECK(!result.as_optional<int>("int"));
|
||||
CHECK(!result.as_optional<float>("float"));
|
||||
CHECK(!result.as_optional<string>("string"));
|
||||
}
|
||||
|
||||
}
|
||||
#endif
|
||||
|
||||
TEST_CASE("Initializer list with group", "[options]") {
|
||||
cxxopts::Options options("Initializer list group", " - test initializer list with group");
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user