Created
April 18, 2016 03:21
-
-
Save jefftrull/2fbbd52a0dec25c1e14d1e69af3361ac to your computer and use it in GitHub Desktop.
Spirit sequence-of-sequences: struct vs. string
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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