Ticket #8013: attr_compat.cpp

File attr_compat.cpp, 1.0 KB (added by K-ballo <kaballo86@…>, 10 years ago)

Small sample reproducing the issue

Line 
1
2#include <boost/fusion/adapted.hpp>
3#include <boost/fusion/container/vector.hpp>
4
5#include <boost/spirit/home/qi.hpp>
6
7#include <iostream>
8
9namespace qi = boost::spirit::qi;
10
11struct test
12{
13 int a;
14 char b;
15};
16
17BOOST_FUSION_ADAPT_STRUCT(
18 test
19 , (int, a)
20 (char, b)
21)
22
23template <typename P, typename T>
24void test_parser_attr(
25 char const* input, P const& p, T& attr, bool full_match = true)
26{
27 using boost::spirit::qi::parse;
28
29 char const* f(input);
30 char const* l(f + strlen(f));
31 if (parse(f, l, p, attr) && (!full_match || (f == l)))
32 std::cout << "ok" << std::endl;
33 else
34 std::cout << "fail" << std::endl;
35}
36
37int main( int argc, char** argv )
38{
39 boost::fusion::vector< int, char > ft;
40 test_parser_attr( "64c128.0", qi::int_ > qi::char_ > qi::float_, ft );
41
42 test st;
43 test_parser_attr( "64c128.0", qi::int_ > qi::char_ > qi::float_, st );
44 test_parser_attr( "64c128.0", qi::as< test >()[ qi::int_ > qi::char_ > qi::float_ ], st );
45
46 return 0;
47}