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

Custom parser supported? #443

Open
Ecordonnier opened this issue Nov 19, 2024 · 1 comment
Open

Custom parser supported? #443

Ecordonnier opened this issue Nov 19, 2024 · 1 comment

Comments

@Ecordonnier
Copy link

Ecordonnier commented Nov 19, 2024

Hi, is there support for adding a custom parser by manually specializing a template function?
E.g.;

struct Foobar {
...
};

template <>
const std::vector<Foobar> &cxxopts::OptionValue::as<std::vector<Foobar>>() const
{
...
}

foobar = parsed["foobar"].as<std::vector<Foobar>>();

I tried to specialize template <> T&cxxopts::OptionValue::as<T>() const in order to implement the custom parser, however it returns a reference so I guess it's not the proper way to do this?

@jarro2783
Copy link
Owner

My intention was that you could override parse_value with a parser for your type. But I'm not sure that I've done it correctly, and currently it will use the default parser which uses an overload for operator>> with your type.

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

No branches or pull requests

2 participants