Boost logo

Boost :

Subject: Re: [boost] program_options negative numbers
From: Mateusz Loskot (mateusz_at_[hidden])
Date: 2011-02-04 04:39:31


On 03/02/11 13:31, Andrzej Zielinski wrote:
> I am using boost::program_options and found a problem with passing a series
> of positive/negative numbers.
> i.e
> myProgram.out --system 0 -2 2 -3
>
> Similar problem like in:
> http://stackoverflow.com/questions/4107087/accepting-negative-doubles-with-boostprogram-options
> I do not want to disable short options. I want to make quotes working.
>
> So when I call
>
>myProgram.out --system '0 -2'
> error: in option 'system': invalid option value

A couple of months ago, I discussed it quickly with Volodya on the
#boost IRC channel and here is a short recipe of how it could be solved:

####################################################################
Nov 10 17:04:17 <mloskot> volodya: I think it's feasible to refactor
the loops in the cmdline parser to handle multitoken options with
negative numbers as values. I have an idea to add ::multitoken(int
exact_tokens_num) and make parser consuming as much values as the exact
number of tokens specified, regardless how the options look like

Nov 10 17:04:26 <mloskot> volodya: what you think about this idea?

Nov 10 17:05:30 <volodya> mloskot: well, I think that if that
translates into min and max number of tokesn of the option being equal
to that value, it seems sane

Nov 10 17:05:53 <mloskot> volodya: yes, basically that would be the thing

Nov 10 17:05:55 <volodya> and of course, when min=max, there's no
need to guessing.

Nov 10 17:05:59 <volodya> ok, sounds good.
####################################################################

It's not a big problem, just lack of man power to solve.
I suppose program_options would welcome relevant patches.

Best regards,

-- 
Mateusz Loskot, http://mateusz.loskot.net
Charter Member of OSGeo, http://osgeo.org
Member of ACCU, http://accu.org

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk