Boost logo

Boost Users :

Subject: [Boost-users] [program_options] Limited multitoken
From: Bradley Jensen (bradley.jensen_at_[hidden])
Date: 2012-01-20 08:23:45


Hello,

I'm working on a personal project. Everything works using my own options processing function, but I am having a hard time implementing one specific aspect of my option processing code using the Boost program_options library.

My program has a flag (-j) which takes in two doubles as arguments. Currently, I can invoke my program like so:
./foo -j 1.0 2.0 3
where 3 is treated like a positional.

Because the -j option must consume several tokens, it seemed natural that I should use multitoken, like so:
vector<double> v;
po::options_description desc("Allowed options");
desc.add_options()
   ("jingle,j", po::value<vector<double> >(&v)->multitoken(), "Test thing");

But this causes positional arguments to get eaten up and added to v when -j is the last flag option. So, in my example, v would contain 1.0, 2.0, and 3.0. I suppose I am looking for some way to indicate that the -j flag consumes exactly two tokens.

I've looked over the documentation on the Boost website, but I couldn't find anything about this. Any help would be greatly appreciated.

Thanks,
-Brad


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net