-
Notifications
You must be signed in to change notification settings - Fork 363
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
Options that take an index + value argument. #296
Comments
I was playing around a bit with support for a pair(possibly generalized to a tuple) but will start with pair, i think that would allow your use case. Then for the first case at least it would look like std::pair<size_t, int> index;
app.add_option("--entry",index," pair option"); just like any other single variable. Might also be able to support complex directly without the extra function for that currently. |
After pr #310 the first part of the issue can be handled with
though as I read through this some more, #310 only makes a few steps toward what you need. and probably what is needed is vector of tuples/pairs and way to validate appropriately only parts of tuples. |
This looks useful. However, as I currently understand it, the option now takes an index but I can only specify one index, value pair, e.g. in your example above I could do Not sure how this can be worked around. What I want is to use the std::pair to insert these values in. a std::vector. Like (not a working code).
I think the validation/transform part is sufficient as it is. The first thing is always an index (the check can probably be deduced from the vector (here: somevalues) and the 2nd argument is always a value. That is of course ignoring the part with the index + vector I would also need. So, I think apart from the insertion in a vector this is what I need to fix my first half. Thanks! |
You are right this only addresses part of your issue. I thought about different ways of making the index periodic, but none were clean or intuitive with the way type_sizes are handled internally currently. So reworking that a little is the next step. What I want to get to eventually is support for std::vector<std::pair<X,Y>> then the index would apply to each subcomponent of the vector. That might be a few steps down the road yet. A little more tinkering with the type size and expected values is required before that step can be taken in a reasonable fashion. I have a few ideas on how eventually we might get to support std::vector<std::vector> as well and things like std::pair<int, std::vector. We will see how soon we get to them. |
@mathiaswagner I think #325 actually gets at what you wanted. and in the second case the validators are indexed on the element of the vector, so index 0 would apply the first of the std::pair and the index 1 applies to the second element of the pair or inner vector. |
@mathiaswagner I think is is working completely now in master so I am going to close the issue, but if you try it and doesn't work yet let me know. |
While I think it is possible to hack things with the function passed to add_options I was wondering whether there is a cleaner solution to handle options that take a pair of values.
There is #128 but what I need are options like
--something 1 "double" --something 2 "single" --other 1 16.0 --other 3 0.0
.Basically you can think of the
--something
option being a vector but instead of specifying--something "double" "single"
the 1 and 2 as the first argument to the option specify the index in that vector. For the 2nd argument I still want to be able to use the transform / check options.The most fancy use case is when you have a vector of vectors, like:
--vectorsomething 1 12 8 6 4 --vectorsomething 2 4 4 4 4
Here the first number again gives the position in a vector but the components are itself a vector (here:
12 8 6 4
and2 2 2 2
).The vector of vector thing is optional, but I am still looking for clean way to achieve the first thing.
Current hack looks like:
but that is not very portable and errors also are not handled properly. If you have some pointer to where I could find useful components I am happy to work on that.
The text was updated successfully, but these errors were encountered: