Re: string_view and c.insert(c.end(), std::move(val)) compile error

Olaf Peter <[email protected]>
Newsgroups gmane.comp.parsers.spirit.general
Message-ID <[email protected]>
> for my x3 parser I replaced string with string_view, but failed in this
> concrete case. For some reasons it want to insert into a container which
> must fail in this case. I separated the raw rule, but no luck. Setting
> x3::raw outside works, but the double quotes are embedded which isn't
> intended. What do I overlook here? '"' is handled as literal, isn't it?
> Explicit use of x3::lit('"') doesn't change it. How to fix the rule?
> Note, I'm using an older compiler not fully C++17 aware :(

I reduced the example to:

---8<---
#include <iostream>
#include <vector>

#include <string_view>

namespace boost { namespace spirit { namespace x3 { namespace traits {

template <typename It>
void move_to(It b, It e, std::string_view& v)
{
     // Note requires storage to be contiguous
     v = std::string_view(&*b, e - b);
}

} } } }

//#define BOOST_SPIRIT_X3_DEBUG
#include <boost/spirit/home/x3.hpp>

#if 1
// XXX basic_string_view<char>« has no member named »insert« XXX
typedef std::string_view  attribute_type;
#else
typedef std::string                     attribute_type;
#endif

int main()
{
     namespace x3 = boost::spirit::x3;

     auto const string_literal = x3::rule<struct _, attribute_type> {} =
     x3::lexeme[
            '"'
         >> x3::raw[ *(x3::char_ - '"') ]
         >> '"'
     ];

     std::vector<std::string> const test_cases {
         R"("FooBar")",
         };

     /* expected output:
      * parse '"FooBar"': succeeded: 'FooBar'
      */

     typedef std::string::const_iterator iterator_type;

     for(auto str: test_cases) {
         iterator_type iter = str.begin();
         iterator_type const end = str.end();

         attribute_type attr;

         std::cout << "parse '" << str << "': ";

         bool r = phrase_parse(iter, end, string_literal, x3::space, attr);

         if (r && iter == end) {
             std::cout << "succeeded: '" << attr << "'\n";
         } else {
             std::cout << "*** failed ***\n";
         }
     }

     return 0;
}
--->8---

Is it a bug? Something more to specialize as move_to?

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Spirit-general mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/spirit-general
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.