[program_options] positional options starting with a '-' sign
Hi, I have an app using program_options, which has various optional arguments, followed by any number of floating point numbers, which are read as positional options. A user just pointed out that it fails with an 'unknown option -0' error if any of those positional options are negative, because it tries to interpret a number like "-0.34" as an option. Is there a way to treat unregistered options as positional arguments? allow_unregistered() doesn't quite do it - it doesn't give an error anymore but neither does it treat "-0.34" as a positional option (even if it is not the first positional argument). Regards, Ian McCulloch
Ian McCulloch wrote:
Hi,
I have an app using program_options, which has various optional arguments, followed by any number of floating point numbers, which are read as positional options.
A user just pointed out that it fails with an 'unknown option -0' error if any of those positional options are negative, because it tries to interpret a number like "-0.34" as an option.
Is there a way to treat unregistered options as positional arguments? allow_unregistered() doesn't quite do it - it doesn't give an error anymore but neither does it treat "-0.34" as a positional option (even if it is not the first positional argument).
This is not presently possible -- and would make for a bad error reporting. It's possible to use -- to terminate the list of options. Everything thereafter will be taken as positional option. - Volodya
Vladimir Prus wrote:
Ian McCulloch wrote:
Hi,
I have an app using program_options, which has various optional arguments, followed by any number of floating point numbers, which are read as positional options.
A user just pointed out that it fails with an 'unknown option -0' error if any of those positional options are negative, because it tries to interpret a number like "-0.34" as an option.
Is there a way to treat unregistered options as positional arguments? allow_unregistered() doesn't quite do it - it doesn't give an error anymore but neither does it treat "-0.34" as a positional option (even if it is not the first positional argument).
This is not presently possible -- and would make for a bad error reporting. It's possible to use -- to terminate the list of options. Everything thereafter will be taken as positional option.
Ok, I'll just add a note in the documentation to use -- before the positional arguments. Thanks! Cheers, Ian
participants (2)
-
Ian McCulloch
-
Vladimir Prus