#include <boost/fusion/include/adapt_struct.hpp>
#include <boost/spirit/include/qi.hpp>
#include <boost/spirit/include/phoenix.hpp>

#include <vector>
#include <string>
#include <iomanip>
#include <algorithm>

namespace qi    = boost::spirit::qi;
namespace ascii = boost::spirit::ascii;
namespace phx   = boost::phoenix;

struct my_record {
    std::vector<int>          m_ints;
    std::vector<std::string>  m_strs;
};

std::ostream& operator<<( std::ostream& os, const my_record& rec ) {
    for( const auto& x : rec.m_ints )
        os << x << ' ';
    os << '\n';

    for( const auto& x : rec.m_strs )
        os << x << ' ';
    return os;
}

BOOST_FUSION_ADAPT_STRUCT(
    ::my_record,
    (std::vector<int>,          m_ints)
    (std::vector<std::string>,  m_strs)
)

template<typename Iterator>
struct my_grammar
: qi::grammar<Iterator, my_record(), ascii::space_type> {

    my_grammar()
    : my_grammar::base_type(start) {

        quoted_string %= qi::lexeme['"' >> +(qi::char_ - '"') >> '"'];

        start = qi::lit("{")
                >>
                *( "INT:" >> qi::int_
                    [
                        phx::push_back(
                            phx::at_c<0>(
                                qi::_val
                            ),
                            qi::_1
                        )
                    ] % ","
                 | "STR:" >> quoted_string
                    [
                        phx::push_back(
                            phx::bind(
                                &my_record::m_strs,
                                qi::_val
                            ),
                            qi::_1
                        )
                    ] % ","
                 )
                >>
                "}"
                ;
    }
    qi::rule<Iterator, std::string(), ascii::space_type> quoted_string;
    qi::rule<Iterator, my_record(),   ascii::space_type> start;
};

int main () {
    std::string        input1 = "{ STR: \"Joe\" INT: 42, 24 STR: \"Smith\" ,\"John\" }";
    auto first=input1.begin(), last=input1.end();
    my_record mr;
    my_grammar<decltype(first)> g;
    bool r=qi::phrase_parse(
        first,
        last,
        g,
        ascii::space,
        mr
    );
    std::cout << std::boolalpha << "Parsed: " << r << '\n' << mr << '\n';
    return r;
}