p-ranav / argparse

Argument Parser for Modern C++

Repository from Github https://github.comp-ranav/argparseRepository from Github https://github.comp-ranav/argparse

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

Xottab-DUTY opened this issue · comments

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.