boost-program-options

Boost Program Options Add Options Syntax

徘徊边缘 提交于 2019-11-28 02:31:32
问题 I am writing a program that uses Boost's Program Options library and I noticed the following syntax that has haunted me since I saw it: desc.add_options() ("help","produce help message") ( /* other flag, value, description pairs here */) ; I see that in the header, operator() is overridden, but I'm not sure how that allows this to be syntactically correct. Secondly, is there any advantage to this syntax, compared with just calling add_options() multiple times (besides showing off the fact

boost-program-options: notifier for options with no value

和自甴很熟 提交于 2019-11-28 00:39:19
One can use notifier for parsed options only if they have value_semantic. What is the best way for no-value options to be automatically handled by the given notifier? The simple approach is to make a dummy value_semantic with implicit assignment, so a user can pass the option without a value. This leads to a possibility of explicitly provided values. One can add a run-time check if the value was provided and throw an error. Update: BUT, this doesn't work in presence of positional options, because a positional option's value can follow no-value option raising an exception as s given value to it

Boost program options allowed set of input values

六月ゝ 毕业季﹏ 提交于 2019-11-27 21:40:54
问题 Is there a way to set an allowed set of input variables for parameters? For example parameter "arg" can have only string values like "cat" and "dog". 回答1: You can use the custom validator feature. Define a distinct type for your option, and then overload the validate function on that type. struct catdog { catdog(std::string const& val): value(val) { } std::string value; }; void validate(boost::any& v, std::vector<std::string> const& values, catdog* /* target_type */, int) { using namespace

Required and Optional Arguments Using Boost Library Program Options

拈花ヽ惹草 提交于 2019-11-27 09:34:31
问题 I'm using Boost Program Options Library to parse the command line arguments. I have the following requirements: Once "help" is provided, all the other options are optional; Once "help" is not provided, all the other options are required. How I can deal with this? Here is the my code handling this, and I found it's very redundant, and I think there must be an easy to do, right? #include <boost/program_options.hpp> #include <iostream> #include <sstream> namespace po = boost::program_options;

C++: Boost program_options: Multiple lists of arguments

a 夏天 提交于 2019-11-27 07:21:13
问题 I'm currently working with boost::program_options . My program is supposed to take as arguments (amongst other things...) an arbitrary number of 'lists' of arbitrary length. For example, the user should be able to call ./myprogram -list item1 item2 item3 -list item1 item2 -list item1 item2 Obviously, I don't want to get one list/vector with all the items one after the other as a result, but (in this case) three lists/vectors (or, for example, one vector of vectors containing the elements)

Handle complex options with Boost's program_options

半腔热情 提交于 2019-11-27 03:19:53
问题 I have a program that generates graphs using different multi-level models. Each multi-level model consists of a generation of a smaller seed graph (say, 50 nodes) which can be created from several models (for example - for each possible edge, choose to include it with probability p). After the seed graph generation, the graph is expanded into a larger one (say 1000 nodes), using one of another set of models. In each of the two stages, each model require a different number of parameters. I