I am trying to set a multitoken value from a ini file.
commonOptions.add_options()("ccf.multiPort", po::value<std::vector<int>>()->multitoken(), "multi port");
parsing multitoken value from the command line works well
./main --ccf.multiPort 123 423 421
however I was not able to set the same values in an ini file
[ccf]
multiPort = 1234 2356 7745
produces the following error
terminate called after throwing an instance of 'boost::wrapexcept<boost::program_options::invalid_option_value>'
what(): the argument ('1234 2356 7745') for option 'ccf.multiPort' is invalid
I have also tried
[ccf]
multiPort = 1234,2356,7745
Boost::program_options versino 1.75 OS linux Compiler gcc version 9.4.0 (Ubuntu 9.4.0-1ubuntu1~20.04.1)
Does anybody know the right format ?
Please help me to avoid digging into the source code 😉
2
Answers
well ... this one works
but is somehow ugly. Can I use something like
One way is using a custom notifier:
Which you configure as:
Now it works with both config file and command line args:
Demo
Live On Coliru
With input.txt:
And command line:
Prints
Simplify
I’d simplify: Coliru
With
Prints
Of course, substitute
std::set
with almost no further changes: