Ticket #12732: karma-char-seq.cpp

File karma-char-seq.cpp, 629 bytes (added by Braden McDaniel <braden@…>, 6 years ago)

Example

Line 
1#include <boost/phoenix.hpp>
2#include <boost/spirit/include/karma.hpp>
3#include <boost/fusion/include/adapt_struct.hpp>
4
5struct foo {
6 std::string a, b;
7};
8
9BOOST_FUSION_ADAPT_STRUCT(
10 foo,
11 (std::string, a)
12 (std::string, b)
13)
14
15int main()
16{
17 using namespace boost::spirit::karma;
18 using boost::phoenix::at_c;
19
20 typedef rule<std::back_insert_iterator<std::string>, foo(), space_type>
21 rule_t;
22
23 rule_t r
24 = +char_ << '(' << string << ')'
25 | skip[string] << string
26 ;
27
28 foo f = {"a", "b"};
29 std::string s;
30 generate_delimited(std::back_inserter(s), r, space, f);
31}