You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It proposes creating a temporary ArgumentParser instance and passing it to add_subparser. This can't work as add_subparser takes ArgumentParser &parser reference and adds it to m_subparsers which is a referencewrapper to the original object. std::list<std::reference_wrapper<ArgumentParser>> m_subparsers;
As such in my application the compiler complains with:
error: cannot bind non-const lvalue reference of type ‘argparse::ArgumentParser&’ to an rvalue of type ‘argparse::ArgumentParser’
6 | program.add_subparser(argparse::ArgumentParser{"walk"});
I would agree that the intended behaviour is wanted. I see two 'easy' options, either by changing m_subparsers to be a copy of the passed subparser or keeping a separate copy when calling a copy-by-value variant of the add_subparser function.
The text was updated successfully, but these errors were encountered:
The following snippets can't work. It is given in the section Getting Argument and Subparser Instances
It proposes creating a temporary
ArgumentParser
instance and passing it toadd_subparser
. This can't work asadd_subparser
takesArgumentParser &parser
reference and adds it tom_subparsers
which is a referencewrapper to the original object.std::list<std::reference_wrapper<ArgumentParser>> m_subparsers;
As such in my application the compiler complains with:
I would agree that the intended behaviour is wanted. I see two 'easy' options, either by changing
m_subparsers
to be a copy of the passed subparser or keeping a separate copy when calling a copy-by-value variant of theadd_subparser
function.The text was updated successfully, but these errors were encountered: