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

Feature request: value pairs or tuples #394

Open
maickrau opened this issue Mar 6, 2023 · 1 comment
Open

Feature request: value pairs or tuples #394

maickrau opened this issue Mar 6, 2023 · 1 comment

Comments

@maickrau
Copy link

maickrau commented Mar 6, 2023

Hi, I'd like an option to input two values for a parameter and take them as an input. This would differ from std::vector values in that the number of values given is constant. The use case I was trying to solve is optionally inputting a file with data and an another file with metadata describing the previous file, where the user can either include both or leave both out but including one without the other is invalid. Here's an example of what it would look like:

options.add_options()("file", "File and metadata", cxxopts::value<std::pair<std::string, std::string>>())
./main --file file1 metadata1

Ideally this could also be used with std::vector

options.add_options()("file", "File and metadata", cxxopts::value<std::vector<std::pair<std::string, std::string>>>())
./main --file file1 metadata1 --file file2 metadata2

and similarly with std::tuple for more than 2 values.

@jarro2783
Copy link
Owner

The main difficulty would be parsing these together. It seems reasonable that you could split the values with a comma. Then I could support a pair or tuple and expect exactly the number of arguments in the type.
For example

cxxopts::value<std::tuple<int, int, int>>

would accept
--option 1,2,3

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