Replies: 4 comments 3 replies
-
Hi @feldroop, If you have an option that has no sensible default, it might be enough to suppress the |
Beta Was this translation helpful? Give feedback.
-
First of all, from a programming style standpoint I would like to have the ability to model cases like this with a std::optional. I can hide the invalid default from users, but why should I be forced to have it flying around in my code when patterns like the Secondly, as far as I know (and I might have missed something), sharg does not tell me whether a certain flag was set by the user. It might happen that every possible value of my The latter is not the case in my app at the moment. I could suppress the default print to the help menu (which I didn't know was possible before) and set the default to something like the maximum int. But I still feel like a |
Beta Was this translation helpful? Give feedback.
-
You can use After #226, it will work with long or short IDs, for now you would have to check for both long and short (see PR). |
Beta Was this translation helpful? Give feedback.
-
You can make namespace std
{
// Make external::bar satisfy sharg::ostreamable
template <typename optional_type>
requires sharg::ostreamable<optional_type>
ostream & operator<<(ostream & output, std::optional<optional_type> const & opt)
{
if (opt.has_value())
output << opt.value(); // Adapt this for your type
else
output << "optional not set";
return output;
}
// Make std::optional<optional_type> satisfy sharg::istreamable
template <typename optional_type>
requires sharg::istreamable<optional_type>
istream & operator>>(istream & input, std::optional<optional_type> & opt)
{
optional_type val;
input >> val; // Adapt this for your type
opt = val;
return input;
}
} // namespace std Add the above and then you can use std::optional for |
Beta Was this translation helpful? Give feedback.
-
As far as I know, this is not possible right now. It would be useful for when you want to have an non-required option and it is not sensible to provide a default (default then would be std::nullopt).
Beta Was this translation helpful? Give feedback.
All reactions