argparse icon indicating copy to clipboard operation
argparse copied to clipboard

default_value / implicit_value incompatible with store_into

Open noajshu opened this issue 6 months ago • 1 comments

Trying to make an inverted flag argument and use store_into. It does not seem to work as expected.

Minimum reproducing example:

#include <argparse/argparse.hpp>
int main(int argc, char* argv[]) {
  argparse::ArgumentParser program("cool binary");

  bool nicearg = false;
  program.add_argument("--deactivate")
      .help("Disable BFS-based detector ordering and use geometric orientation")
      .default_value(true)
      .implicit_value(false)
      .store_into(nicearg);

  try {
    program.parse_args(argc, argv);
  } catch (const std::exception& err) {
    std::cerr << err.what() << std::endl;
    std::cerr << program;
    return EXIT_FAILURE;
  }

  std::cout << "got nicearg = " << nicearg << std::endl;
}

Expected behavior: the nicearg should be true by default but false when the flag --deactivate is present. Actual behavior: nicearg is always true.

~/argparse-3.2$ clang++-19 -I include/  main.cc -o main
$ ./main
got nicearg = 1
$ ./main --deactivate
got nicearg = 1

noajshu avatar Aug 29 '25 03:08 noajshu

亲,来信已经收到!祝你快乐!

wanjiadenghuo111 avatar Aug 29 '25 03:08 wanjiadenghuo111