Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>This is <code>workaround</code> for my initial problem:</p> <pre><code>#define BOOST_RESULT_OF_USE_DECLTYPE #define BOOST_SPIRIT_USE_PHOENIX_V3 #include &lt;boost/function.hpp&gt; #include &lt;boost/spirit/include/phoenix.hpp&gt; #include &lt;boost/spirit/include/qi.hpp&gt; #include &lt;iostream&gt; #include &lt;algorithm&gt; #include &lt;iterator&gt; #include &lt;string&gt; #include &lt;climits&gt; namespace qi = boost::spirit::qi; namespace ph = boost::phoenix; namespace ascii = boost::spirit::ascii; template&lt;typename T,typename R&gt; void testParser( R rule ) { for ( const auto &amp;input : std::vector&lt; std::string &gt;{ "5 1.0 2.0 3.0 4.0 5.0" } ) { bool rc=false; T maxValue, minValue; auto iter( input.begin() ), last( input.end() ); std::vector&lt; T &gt; data; qi::rule&lt; decltype(iter),std::vector&lt;T&gt;( T&amp;, T&amp; ),qi::space_type &gt; mrule; mrule %= qi::eps[ qi::_r1=std::numeric_limits&lt;T&gt;::max(), qi::_r2=std::numeric_limits&lt;T&gt;::min() ] &gt;&gt; -( qi::omit[ qi::int_[ ph::reserve( qi::_val,qi::_1 ) ] ] &gt;&gt; *rule[ ph::if_(qi::_r1&gt;qi::_1)[ qi::_r1=qi::_1 ], ph::if_(qi::_r2&lt;qi::_1)[ qi::_r2=qi::_1 ] ] ); rc = qi::phrase_parse( iter, last, mrule( ph::ref(minValue), ph::ref(maxValue) ), qi::space, data ) &amp;&amp; iter==last; std::cout &lt;&lt; ( rc ? "ok :`" : "err:`" ) &lt;&lt; input &lt;&lt; "` -&gt; "; if( rc ) { std::cout &lt;&lt; "min=" &lt;&lt; minValue &lt;&lt; " max=" &lt;&lt; maxValue &lt;&lt; "\t"; std::copy( data.begin(), data.end(), std::ostream_iterator&lt;T&gt;( std::cout," " )); } else std::cout &lt;&lt; *iter; std::cout &lt;&lt; std::endl; } } int main( int argc, char**argv ) { testParser&lt;double&gt;( qi::double_ ); return 0; } </code></pre>
 

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