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

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

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)