I would like to use boost::program_options to create an executable which can be called as follows:
./example --nmax=0,10 # nmax is chosen randomly between 0 and 10
./example --nmax=9 # nmax is set to 9
./example # nmax is set to the default value of 10
What is the best way to achieve this, in a type-safe way, with minimum code?
I am posting this code here, hoping it will prove useful to somebody. It is the “templatized” version of Sam Miller’s answer.
Used as follows: