boost::spirit::karma::generate not working as expected

Hi,

I am taking a code sample from the documentation of Boost.Spirit (see https://www.boost.org/doc/libs/1_74_0/libs/spirit/doc/html/spirit/abstracts/attributes/primitive_attributes.html), the code is as simple as is possible, like so:


1
2
3
4
5
6
namespace karma = boost::spirit::karma;

int value = 145;
std::string str;
std::back_insert_iterator<std::string> out(str);
karma::generate(out, boost::spirit::qi::int_, value);          // str == "123" 


I get the error: error_invalid_expression with the template arguments as such:


OutputIterator=std::back_insert_iterator<boost::spirit::utf8_string>,
Expr=boost::spirit::int_type,
Attr=int



Other errors occur explaining this main error:


error C2039: 'properties': is not a member of 'boost::spirit::tag::int_'
error C2504: 'properties': base class undefined
error C2039: 'value': is not a member of 'boost::spirit::traits::properties_of<boost::spirit::tag::int_>'



I have no current access to the spirit mailing list so I cannot post the problem there yet... I was hoping somebody would find it in their good nature to help ...

Thank you
Juan
Perhaps you're missing a necessary include file. Here is the example code working properly on Compiler explorer:
https://godbolt.org/z/n3ThPc

Maybe there is a version mismatch between Boost and the Documentation?
Perhaps you're missing a necessary include file. Here is the example code working properly on Compiler explorer:
https://godbolt.org/z/n3ThPc


Generates 1 compile error
The example compiles with GCC as given. Perhaps I changed compilers without noticing. Sorry:
https://godbolt.org/z/YnW85T
:) :)
the error is using boost::spirit::qi::int_ instead of karma::_int: this is correct now:

1
2
3
4
int value = 145;
std::string str;
std::back_insert_iterator<std::string> out(str);
karma::generate(out, karma::int_, value);                // str == "123" 


for getting access to this int_, we need to include at least

#include <boost/spirit/include/karma_int.hpp>

or to be more complete:

#include <boost/spirit/include/karma_numeric.hpp>
#include <boost/spirit/include/karma.hpp>


although I think the karma.hpp includes karma_numeric.hpp and this last one includes karma_int.hpp...

Thanks for the help!


I have found that in Boost, usually not #including a header file causes many compilation errors


Regards all
Last edited on
Topic archived. No new replies allowed.