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
What if actions want to return std::vector? #69
Comments
Actions were designed to be similar to the visitor pattern in ANTLR - visit each argument/fragment, make changes given some context and save it. The parameter to .action() is a $./program --foo 1 4 3 6 Here, action receives How does this change in your proposal? What is the argument to .action(). Is it now a vector of strings if nargs > 1? |
I know this part, but what if users want to do this: program.action([](std::string const& s) {
return std::vector<int>(std::stoi(s)); // let's say it's a vector of N random numbers
}); Then the user cannot use |
Understood. Just need some clarifications: What is the argument Then is .. Or is Just need to clarify the semantics here. |
|
Ah I see now. Okay, makes sense. |
Parsing a list of values is now supported with |
If an option wants to parse a list of values
--foo 1,4,2,6
, then it cannot returnstd::vector<int>
because this type is considered a container. We probably will never want to parse a list like that (because there are so many good parsing libraries for structural data), so we cannot return the existing containers functionality to "makeget<std::vector<T>>()
work" for this demand.We should consider changing the multivalue argument support. Some observations:
std::vector<std::string>
is verbose to spellstd::array
is not supported (and is tricky to support, because it's not a container that can grow)std::list
is probably never used for lots of reasonsInventing a new set of API is an option, but the
present
API (#66) will double the number of names. I think the situation can be improved by blessing a type that is both impossible to be stored instd::any
, and is terse to write -- array type.Here is how the new
get
may look like:get<T[]>
: returnsstd::vector<T>
get<T[N]>
: returnsstd::array<T, N>
ifN
== nargs, throws otherwiseget<T>
: returnsT
The old spelling
get<std::vector<std::string>>
becomesget<std::string[]>
after the change. To not to break everything immediately, we can make the old spelling[[deprecated]]
.FAQ
T[]
andT[N]
return entirely different types? I hope users can interpret[]
as "returning a type withoperator[]
."std::span
(of static extent or dynamic extent)? Technical issue, we only have storage forstd::vector<std::any>
rather thanstd::vector<T>
.The text was updated successfully, but these errors were encountered: