[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support std::optional<..> #36

Open
tversteeg opened this issue Sep 16, 2019 · 3 comments
Open

Support std::optional<..> #36

tversteeg opened this issue Sep 16, 2019 · 3 comments

Comments

@tversteeg
Copy link

I would like to be able to parse a struct containing std::optional<..> fields. For example:

struct arg_values {
     std::optional<int> pid;
} values;

auto cli = (
    clipp::option("--pid") & clipp::opt_integer("PID", values.parent_pid)
);
@muellan
Copy link
Owner
muellan commented Sep 18, 2019

Good idea. I should definitly add built-in support for std::optional.

@NikolausDemmel
Copy link

One thing this would provide is a straight forward way to check if an optional argument was passed or not.

Is there currently a canonical way to do that? I guess I could use .call(...) with some lambda that sets a bool to true, but that seems quite verbose. I was thinking something like:

option("--foo").set_true(foo_passed) & value(foo)

Or a way to get a handle the "option object" and query it after command line parsing, something like foo_option.was_passed().

@NikolausDemmel
Copy link

Is there currently a canonical way to do that?

To answer my own question, according to https://github.com/muellan/clipp#actions I guess you can do:

bool foo_passed = false;
int foo = 0;
option("--foo").set(foo_passed) & value("FOO", foo);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants