Closed nigels-com closed 6 months ago
Thanks for your PR. I will take a look properly when I get a chance in a couple of days.
No rush. We're having some interesting internal discussion. Want to check a few assumptions when I get a chance.
This looks good, I'm also thinking about whether there is a better name for the function. I wonder if there some convention from other projects like something with maybe
in the name.
What do you think about calling it maybe_as
, I think that fits the convention when a function can return an optional, and makes it clear that it is the same behaviour as as
.
I was thinking of make_optional
in the manner of std::make_shared.
It turns out that std::make_optional does already exist too. (News to me!)
I understand your reasoning with maybe but isn't that just a synonym for optional? Is clarity improved by assigning a "maybe" to an "optional"?
Or as_optional
might be even clearer. I'm just thinking that optional
by itself is not the clearest name as to what it does on that class.
Yes, as_optional
sounds good to me.
Updated as discussed.
We have some internal usage of
std::optional
that can integrate very tidily with cxxopts providing this query forstd::optional
value of given name and type.No need for an if-check of
count
or catching an exception.This change is