Opened 10 years ago

Closed 10 years ago

Last modified 10 years ago

#6948 closed Bugs (invalid)

Boost::spirit::karma generator bug

Reported by: yaoyuan1216@… Owned by: Hartmut Kaiser
Milestone: To Be Determined Component: spirit
Version: Boost 1.49.0 Severity: Problem
Keywords: Cc:

Description

I wanna save a generator so that I can call it anytime without writing duplicate codes. Here is my code:

#include<boost/spirit/include/karma.hpp> #include<boost/spirit/include/karma_format_attr.hpp> #include<list> #include<iostream>

auto par = '{' << -(boost::spirit::karma::int_ % ',') << '}';This would lead error! int main(){

using namespace std; namespace karma = boost::spirit::karma; list<int> l{1, 2, 4}; auto par = '{' << -(boost::spirit::karma::int_ % ',') << '}';This would not! cout<<karma::format(par, l)<<endl; return 0;

}

When I define par out of a functint would leads to runtime error. Does I used it generator in a wrong way or it is a bug? GCC version 4.6.3

Attachments (2)

2.cpp (445 bytes ) - added by yaoyuan1216@… 10 years ago.
2_new.cpp (477 bytes ) - added by anonymous 10 years ago.

Download all attachments as: .zip

Change History (5)

by yaoyuan1216@…, 10 years ago

Attachment: 2.cpp added

comment:1 by Joel de Guzman, 10 years ago

Owner: changed from Joel de Guzman to Hartmut Kaiser

comment:2 by Hartmut Kaiser, 10 years ago

Resolution: invalid
Status: newclosed

Use BOOST_AUTO instead (see here: http://boost-spirit.com/home/articles/qi-example/zero-to-60-mph-in-2-seconds/). The article explains the rationale as well.

in reply to:  2 comment:3 by anonymous, 10 years ago

Replying to hkaiser:

Use BOOST_AUTO instead (see here: http://boost-spirit.com/home/articles/qi-example/zero-to-60-mph-in-2-seconds/). The article explains the rationale as well.

Excuse me! I've changed 'auto' to 'BOOST_AUTO', but it doesn't work! I got the same error as before. In addition, I used gcc4.6.3 which supports 'auto' keyword. Would you have any idea?

Code: #include<boost/spirit/include/karma.hpp> #include<boost/spirit/include/karma_format_attr.hpp> #include<list> #include<iostream>

BOOST_AUTO(par, '{' << -(boost::spirit::karma::int_ % ',') << '}');Define par here would lead to error! int main(){

using namespace std; namespace karma = boost::spirit::karma; list<int> l{1, 2, 4}; BOOST_AUTO(par, '{' << -(boost::spirit::karma::int_ % ',') << '}');Whils this would not! cout<<karma::format(par, l)<<endl; return 0;

}

by anonymous, 10 years ago

Attachment: 2_new.cpp added
Note: See TracTickets for help on using tickets.