I need to set a parameters to be a date :
test -d "2013/05/16"
What is the best way to do it ?
PS : I put format in "%Y/%m/%d" but this could also be changed.
So I think to add a parameter -f "%Y/%m/%d"
Using a ValueArg<String> for either -d or -f should work fine. You'll just need to cast the string to a date type. If you're looking for something like ValueArg<Date>, then that would be more work. In that case you'd need to make sure Date supported operator<< and had a proper ArgTrait. I'd almost certainly recommend just using ValueArg<String>.
As usual "best" can be many things :) You basically have two options. For something simple you do what mes5k suggested, simply read in the value as a string and parse the string into some representation that you use in your program. The alternative is to use a Date type to represent your date, in which case the responsibility for parsing the date argument can be delegated to the Date class (or a helper function). For the second approach you can check out http://tclap.sourceforge.net/manual.html#USING_ARGTRAITS and the vector examples provided in test11 and test12.
Sign up for the SourceForge newsletter:
You seem to have CSS turned off.
Please don't fill out this field.