title: c++ functional programming ( boost::phoenix && boost::spirit) testing for null-ptrs in pointer placeholders
body: <p>So, I have the following spirit karma rule body:</p>
  
  <pre><code>base_rule = 
      eps(_r1 != 0) [ // _r1 is a pointer_typed placeholder
          eps
      ]
  ;
  </code></pre>
  
  <p>which leads to a rather long error message from g++ which (helpfully) ends with : </p>
  
  <pre><code>/opt/dev_64_swat/Boost/include/boost/spirit/home/phoenix/operator/comparison.hpp
  :37:5: error: ISO C++ forbids comparison between pointer and integer 
  [-fpermissive]
  </code></pre>
  
  <p>This is valid c++:</p>
  
  <pre><code>struct zebra{};
  
  int main()
  {
    zebra * x;
    if( x == 0);  
  }
  </code></pre>
  
  <p>I thought to try <code>boost::phoenix::static_cast_&lt;_r1_type *&gt;(0)</code> as well as converting <code>_r1_type</code> to a integer (yes that is WRONG, it was just an experiment). </p>
  
  <p><strong>The question:</strong></p>
  
  <p>How can I use a spirit eps construct to perform a pointer test on a placeholder to prevent  rule body evaluation when the point is zero ? </p>
  
  <p>As with all "C++ functional programming library usage" questions I expect the answer to leave me feeling like a dimwit.</p>
  
  <p><strong>The Answer</strong></p>
  
  <p>Ildjam's point directly answers my question. There were two issues with my problem; there is a indirect problem above. And that is to do with conditionals in PEG. What I am trying to express should be written as such:</p>
  
  <pre><code>rule = ( eps(_r) &lt;&lt; ( /* grammar for when pointer is not null */ ) ) 
      | eps // otherwise dont do anything.
  ;
  </code></pre>
  
  <p>I was using the semantic action body ( specified in a  [] block), to express the conditional part of the grammar. Strangely though I have written conditional PEG grammars before, I just made a mistake, which led to the second class of problems. </p>
  
  <p>So, eps(_r1) does the trick, The second type of compilation issue is irrelevant to the question.</p>