Open eyalroz opened 1 year ago
That sounds pretty reasonable.
@jarro2783 : An alternative, or an addition, to this, which would be "breaking", is changing as<T>
so that it always returns an optional<T>
, and never throws.
A non-breaking change would be adding get<T>()
that returns an optional<T>
. Combine this with operator[]
and you could have some very compact syntax:
opts.get<std::string>("key"); // returns std::optional<std::string>
Suppose I define a non-boolean option of type T, without a default value, using cxxopts.
I can't obtain this option using just
cxxopts::ParseResults::as<T>()
- because that might throw. Instead, I have to first usecount()
, like in the README example code:This is somewhat redundant. Why do I have to say "bar" twice? ... instead, I should be able to write:
and get an optional which is nullopt if bar wasn't specified, and a boxed actual string if it was.
Bonus points if you support
std::experimental::optional
when C++14 is used.