title: Spirit.X3 using string_view and member named 'insert' compiler error
body: <p>At Stackoverflow there are several Questions &amp; Answers which are related to use <code>{boost, std}::string_view</code>, e.g.:</p>
  
  <ul>
  <li><p><a href="https://stackoverflow.com/questions/39225502/parsing-from-stdstring-into-a-booststring-view-using-boostspiritx3?answertab=active#tab-top">parsing from std::string into a boost::string_view using boost::spirit::x3</a> with overloading x3's <code>move_to</code></p>
  
  <pre><code>namespace boost { namespace spirit { namespace x3 { namespace traits {
  
  template &lt;typename It&gt;
  void move_to(It b, It e, boost::string_view&amp; v)
  {
      v = boost::string_view(&amp;*b, e-b);
  }
  
  } } } }
  </code></pre></li>
  <li><p><a href="https://stackoverflow.com/questions/39230186/parse-into-vectorbooststring-view-using-boostspiritx3?answertab=active#tab-top">parse into vector using boost::spirit::x3</a> where further the information about the compatibility of the attributes is given</p>
  
  <pre><code>namespace boost { namespace spirit { namespace x3 { namespace traits { 
      template &lt;&gt;
      struct is_substitute&lt;raw_attribute_type,boost::string_view&gt; : boost::mpl::true_
      {};
  } } } }
  </code></pre></li>
  </ul>
  
  <p>llonesmiz wrote an example at <a href="https://wandbox.org/permlink/9vUBT2WZ895sZvqv" rel="nofollow noreferrer">wandbox</a> which compiles with <a href="https://wandbox.org/permlink/SLkvZGUr4OxTVMGw" rel="nofollow noreferrer">boost 1.64</a>, but failed with <a href="https://wandbox.org/permlink/CeWFqOfFq2Okbnio" rel="nofollow noreferrer">boost 1.67</a> now with</p>
  
  <pre><code>    opt/wandbox/boost-1.67.0/gcc-7.3.0/include/boost/spirit/home/x3/support/traits/container_traits.hpp:177:15: error: 'class boost::basic_string_view&lt;char, std::char_traits&lt;char&gt; &gt;' has no member named 'insert'
                   c.insert(c.end(), first, last);
                   ~~^~~~~~
  </code></pre>
  
  <p>the same error I faced in my project. </p>
  
  <p>The problem raises also by use of <code>std::string</code>
  even with the explicite use of <a href="https://stackoverflow.com/questions/33816662/understanding-the-list-operator-in-boost-spirit?answertab=active#tab-top">Sehe's as&lt;> "directive"</a>, see also at <a href="https://wandbox.org/permlink/dJxe2cCS1qg6ekyn" rel="nofollow noreferrer">wandbox</a>:</p>
  
  <pre><code>    #include &lt;iostream&gt;
      #include &lt;string&gt;
      #include &lt;string_view&gt;
  
      namespace boost { namespace spirit { namespace x3 { namespace traits {
  
      template &lt;typename It&gt;
      void move_to(It b, It e, std::string_view&amp; v)
      {
          v = std::string_view(&amp;*b, e-b);
      }
  
      } } } } // namespace boost
  
  
      #include &lt;boost/spirit/home/x3.hpp&gt;
  
  
      namespace boost { namespace spirit { namespace x3 { namespace traits {
  
      template &lt;&gt;
      struct is_substitute&lt;raw_attribute_type, std::string_view&gt; : boost::mpl::true_
      {};
  
      } } } } // namespace boost
  
  
      namespace parser
      {
          namespace x3 = boost::spirit::x3;
          using x3::char_;
          using x3::raw;
  
          template&lt;typename T&gt;
          auto as = [](auto p) { return x3::rule&lt;struct _, T&gt;{ "as" } = x3::as_parser(p); };
  
          const auto str = as&lt;std::string_view&gt;(raw[ +~char_('_')] &gt;&gt; '_');
          const auto str_vec  = *str;
      }
  
      int main()
      {
          std::string input = "hello_world_";
  
          std::vector&lt;std::string_view&gt; strVec; 
          boost::spirit::x3::parse(input.data(), input.data()+input.size(), parser::str_vec, strVec);
  
          for(auto&amp; x : strVec) { std::cout &lt;&lt; x &lt;&lt; std::endl; }
      }
  </code></pre>
  
  <p>As far I've seen, the problem starts with boost 1.65. What has been changed and how to fix it?</p>
  
  <p>Finaly, I've a question about the requirement of contiguous storage mentioned by <a href="https://stackoverflow.com/questions/39225502/parsing-from-stdstring-into-a-booststring-view-using-boostspiritx3?answertab=active#tab-top">sehe</a>: I understand the requirements of this, but does the parser can violate this? - In my opinion the parser has to fail even on backtracking, so this can't happen by spirit. By use of the error_handler,  the memory storage address which refers the string_view is at last on parse level valid. I conclude it's save to use string_view as far the references are in the scope under this condition, isn't it?</p>