Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to reference an optional submatch inside a semantic action with boost::xpressive static?
    text
    copied!<p>I have a boost xpressive sregex and semantic action that is equivalent to the following:</p> <pre><code>Rule = ('[' &gt;&gt; (s1=!(set=')',']','&gt;')))[some_op(as&lt;std::string&gt;(s1))]; </code></pre> <p>Previously I was using this on boost 1.43 without any problems. I have had to upgrade to a newer boost recently and now I run into the following issue. On boost 1.48 when the submatch does not match anything (as it is optional) a <code>bad_lexical_cast</code> exception is thrown by the semantic action when <code>as</code> executes on the empty <code>s1</code> object.</p> <p>How can I fix this problem, is it just a coincidence that it worked before and there is some better safer way I should be using to do this? Or is this just e.g. some change in the <code>lexical_cast</code> code that now breaks <code>xpressive</code>?</p> <h1>Additional information</h1> <p>I have managed to temporarily solve the actual problem by changing the following in regex_actions.hpp:</p> <pre><code>template&lt;typename T&gt; struct as { BOOST_PROTO_CALLABLE() typedef T result_type; template&lt;typename Value&gt; T operator()(Value const &amp;val) const { return lexical_cast&lt;T&gt;(val); } }; </code></pre> <p>Into:</p> <pre><code>template&lt;typename T&gt; struct as { BOOST_PROTO_CALLABLE() typedef T result_type; template&lt;typename Value&gt; T operator()(Value const &amp;val) const { if(val.first==val.second) { return T(); } else { return lexical_cast&lt;T&gt;(val); } } }; </code></pre> <p>This leads me to believe that perhaps this is something that needs to be fixed in <code>xpressive</code> itself. However I am not 100% convinced yet that it's not something I am doing wrong on my side, anyone with a bit more knowledge on <code>xpressive</code> have some insight into this?</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