Steven Mackenzie wrote:
Ian McCulloch wrote:
Bryan Green wrote: [snip]
While I'm on the subject, you sometimes see something like the following:
./prog -vvv or ./prog -v -v -v
This would *increment* the verbosity level three times. I can't see how to replicate this in program_options.
This is something I have asked about before on this list, but at the time there was no response. I would be very interested in knowing how to do this using boost::program_options!
One complete solution has already been posted, but just for diversity, setting a notifier function on the variable involves less typing. Something like
int verbosityLevel; ... verbosityLevel = 0; ... void VerbosityWatcher( bool val ) { ++verbosityLevel; } ... desc.add_options() ("verbose,v", po::bool_switch() ->notifier( &VerbosityWatcher ), "print extra information") ;
Does this actually work? I think the plan is for notifier functions to be called only when you call 'notify' on variables_map. So, notifier will be called only once. Of course, I might have forgotten how the library actually works, or there might be a bug. - Volodya