Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between default_value and implicit_value in boost::program_options?

That's the question. Why would I use implicit_value over default_value and vice versa?

Thanks!

like image 706
shaz Avatar asked May 13 '10 19:05

shaz


Video Answer


1 Answers

default_value() is the value that will be put in the variables_map if the user didn't specify another value:

./a.out             # implies width=75 if that's the default_value for width ./a.out --width=80  # default_value not used 

implicit_value() is the value that will be used if the user specifies the option but without an adjacent value.

./a.out --width     # implies width=75 if that's the implicit_value for width ./a.out --width=80  # implicit value not used 

If you use implicit_value then in commandline options's short options the user must specify the value immediately after the option:

./a.out -w80   # implicit_value not used ./a.out -w 80  # wrong: 80 parsed as extra arg if implicit_value is defined 
like image 185
wilhelmtell Avatar answered Oct 20 '22 07:10

wilhelmtell