#include<iostream>
#include<string>
#include<vector>
#include<boost/spirit/include/phoenix.hpp>
#include<boost/spirit/include/karma.hpp>
struct test_spirit
{
void read_function(std::string &result, std::string const &val) const
{
if(result != "memo_zero") result += val;
}
};
void spirit_01b()
{
std::vector<std::string> data;
data.push_back("memo_zero"); data.push_back("memo_two");
data.push_back("memo_three");
std::string temp;
test_spirit ts;
karma::generate
(
std::back_inserter(temp),
(
karma::string[phoenix::bind(&test_spirit::read_function, &ts, karma::_1,
karma::_val)] << ", "
),
data, data
);
std::cout<<temp<<std::endl;
std::cin.get();
}
The desired output is
"memo_two, memo_three, "(I don't know how to get rid of the last ", ")
The type pass into the function is "std::vector<std::string>"
but what I need is std::string
How could I pass in std::string?
After some experiment, I think semantic action can't do what I want
since result is a temporarily value but now the result I want
(the one wrapped by std::back_inserter)