Dear team
We tried to use Tclap to enter a type “ std::pair ( int, double)” in our command line as described in the tclap documentation section “how to use different type.”
In our implementation
The tclap parameter is named p.
We inserted the ArgTraits typedef as described in the doc for std::pair<t,u>
We did the surcharge of the operator >> for a std::pair ( int n, double x)” with
std::istream& operator>>(std::istream &f, std::pair<int,double> &mrate ) {
f>>mrate.first;
f>>mrate.second;
return f;
};
We entered in the terminal the pair eg –p 210 0.005
No build error
However it seem that Tclap is only extracted the first value ( eg 210 in our example)</int,double></t,u>
Could you please advice if Tclap is able to extract several value with ValueLike ? ( or if it is only possible with StringLike)
If yes ( possible with ValueLike) could you give us somemore info on how to make it work ? should we change the >> surcharge ? or should the entry in the terminal be different ? both ? else ?
Thanks
Christophe
You can use either string or value semantics, but if you want the latter you need to have operator>> and operator<< defined in global scope for your new type. However, I think the problem you are facing is different.
In your example you have
–p 210 0.005
which will be split into three separate arguments in argv (because of the spaces). There is no way for TCLAP to know that you want both the "210" and "0.005" to belong to the-p
flag. Each flag expects exactly one argument following it, so you would need to specify your pair in a different way, for example210,0.005
(note no space around the comma), or escape it'210 0.005'
. This also mean you would need to tweak your operator>> to be able to deal with that.I think the documentation is not really clear here and we should probably provide a full example.
Last edit: Daniel Aarno 2020-12-14
Updated documentation and provided examples: http://tclap.sourceforge.net/manual.html#USING_ARGTRAITS