#6948 closed Bugs (invalid)
Boost::spirit::karma generator bug
Reported by: | 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)
Change History (5)
by , 10 years ago
comment:1 by , 10 years ago
Owner: | changed from | to
---|
follow-up: 3 comment:2 by , 10 years ago
Resolution: | → invalid |
---|---|
Status: | new → closed |
comment:3 by , 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;
}
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.