Skip to content

Instantly share code, notes, and snippets.

@jefftrull
Created April 18, 2016 03:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jefftrull/2fbbd52a0dec25c1e14d1e69af3361ac to your computer and use it in GitHub Desktop.
Save jefftrull/2fbbd52a0dec25c1e14d1e69af3361ac to your computer and use it in GitHub Desktop.
Spirit sequence-of-sequences: struct vs. string
// To see if a rule whose attribute is sequence-of-sequence can make appends happen somehow
#include <string>
#include <vector>
#include <boost/spirit/include/qi.hpp>
#include <boost/fusion/include/adapt_struct.hpp>
struct tiny {
std::string thing;
int i;
};
BOOST_FUSION_ADAPT_STRUCT(
tiny,
(std::string, thing)
(int, i)
)
using string_it_t = std::string::const_iterator;
int main() {
using namespace boost::spirit;
using namespace boost::spirit::qi;
// STRING CASE
/*
rule<string_it_t, std::vector<std::string>()> l1, l2;
l1 = +qi::string("foo") ;
*/
// STRUCT CASE
rule<string_it_t, std::vector<tiny>()> l1, l2;
l1 = +(qi::string("foo") >> qi::int_);
// in both
l2 = *l1 ; // fails to compile with tiny, succeeds with std::string
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment