title: Splitting string using boost spirit
body: <p>Is it a good idea? For a reason I thought it should be faster than boost's tokenizer or split. however most of the time I'm stuck in the boost::spirit::compile</p>
  <pre><code>template &lt;typename Iterator&gt;
  struct ValueList : bsq::grammar&lt;Iterator, std::vector&lt;std::string&gt;()&gt;
  {
      ValueList(const std::string&amp; sep, bool isCaseSensitive) : ValueList::base_type(query)
      {
          if(isCaseSensitive)
          {
              query = value &gt;&gt; *(sep &gt;&gt; value);
              value = *(bsq::char_ - sep);
          }
          else
          {
              auto separator = bsq::no_case[sep];
              query = value &gt;&gt; *(separator &gt;&gt; value);
              value = *(bsq::char_ - separator);
          }
      }
      bsq::rule&lt;Iterator, std::vector&lt;std::string&gt;()&gt; query;
      bsq::rule&lt;Iterator, std::string()&gt; value;
  };
  
  inline bool Split(std::vector&lt;std::string&gt;&amp; result, const std::string&amp; buffer, const std::string&amp; separator,
                    bool isCaseSensitive)
  {
      result.clear();
      ValueList&lt;std::string::const_iterator&gt; parser(separator, isCaseSensitive);
      auto itBeg = buffer.begin();
      auto itEnd = buffer.end();
      if(!(bsq::parse(itBeg, itEnd, parser, result) &amp;&amp; (itBeg == itEnd)))
          result.push_back(buffer);
      return true;
  }
  </code></pre>
  <p>I've implemented it as shown above. What is wrong with my code? or just because the separator is defined in runtime the recompilation is inevitable?</p>
  <p>EDIT001:
  Example and comparison with possible implementation with boost::split and original imp with tokenizer on <a href="http://coliru.stacked-crooked.com/a/e9af60ee8bb7ead5" rel="nofollow noreferrer">CoLiRu</a>
  Looks like coliru is down now. In any case these are result for 1M runs on string &quot;2lkhj309|ioperwkl|20sdf39i|rjjdsf|klsdjf230o|kx23904iep2|xp39f4p2|xlmq2i3219&quot; with separator &quot;|&quot;<br></p>
  <blockquote>
  <p>8000000 splits in 1081ms.<br>8000000 splits in 1169ms.<br>8000000
  splits in 2663ms.<br></p>
  </blockquote>
  <p>first is for tokenizer, second is for boost::split and the third is for boost::spirit</p>