p-ranav / argparse

Argument Parser for Modern C++
MIT License
2.72k stars 250 forks source link

store_into overload for bools assumes turning into a flag, which isn't correct for certain use cases #379

Open Xottab-DUTY opened 2 months ago

Xottab-DUTY commented 2 months ago

Reproduction code:

struct options
{
    bool my_opt{ true }
};

program.add_argument("-opt")
    .store_into(options.my_opt);

Here, store_into calls flag function, and then store_into sets the options.my_opt value to false, making initial value lost.

The use case is that I want to provide the recommended defaults for all the application options with the ability to override them. That means, some bool variables can be true by default instead of false and can be overridden with -opt=false syntax. This isn't possible with flags, and store_into for bools assumes exactly flags. This assumption is quite not for everyone.