Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>For the first part, this should work</p> <pre><code>namespace po = boost::program_options; po::option_descriptions desc(""); desc.add_options() ("opt", po::value&lt;std::vector&lt;int&gt; &gt;()-&gt;multitoken(), "description"); </code></pre> <p>The second part, requires a bit more work. The function <a href="http://www.boost.org/doc/libs/1_48_0/doc/html/program_options/reference.html#header.boost.program_options.value_semantic_hpp"><code>po::value</code></a> returns a <code>po::typed_value&lt; T, charT &gt;</code> on which you'll have to override the behavior of several functions, as follows</p> <pre><code>template&lt; typename T, typename charT = char &gt; class fixed_tokens_typed_value : public po::typed_value&lt; T, charT &gt; { unsigned _min, _max; typedef po::typed_value&lt; T, charT &gt; base; public: fixed_tokens_typed_value( T * t, unsigned min, unsigned max ) : _min(min), _max(max), base( t ) { base::multitoken(); } virtual multi_typed_value* min_tokens( unsigned min ) { _min = min; return *this; } unsigned min_tokens() const {return _min;} virtual multi_typed_value* max_tokens( unsigned max ) { _max = max; return *this; } unsigned max_tokens() const {return _max;} base* zero_tokens() { _min = _max = 0; base::zero_tokens(); return *this; } } </code></pre> <p>which needs to be accompanied by </p> <pre><code>template&lt; typename T &gt; fixed_tokens_typed_value&lt; T &gt; fixed_tokens_value(unsigned min, unsigned max) { return fixed_tokens_typed_value&lt; T &gt;(0, min, max ); } template&lt; typename T &gt; fixed_tokens_typed_value&lt; T &gt; fixed_tokens_value(T * t, unsigned min, unsigned max) { fixed_tokens_typed_value&lt; T &gt;* r = new fixed_tokens_typed_value&lt; T &gt;(t, min, max); return r; } </code></pre> <p>Then </p> <pre><code>desc.add_options() ("opt", po::fixed_tokens_value&lt;std::vector&lt;int&gt; &gt;(2,2), "description"); </code></pre> <p>should work. I have not yet had a chance to test it, so it likely contains a few bugs. But, at a minimum, should give you an idea of what you need.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload