Skip to content

Instantly share code, notes, and snippets.

@yutopp
Last active December 30, 2015 21:39
Show Gist options
  • Save yutopp/7888832 to your computer and use it in GitHub Desktop.
Save yutopp/7888832 to your computer and use it in GitHub Desktop.
#include <iostream>
#include <vector>
#ifndef BOOST_SPIRIT_USE_PHOENIX_V3
# define BOOST_SPIRIT_USE_PHOENIX_V3
#endif
#include <boost/spirit/include/qi.hpp>
#include <boost/fusion/include/adapt_struct.hpp>
struct wrapper
{
std::vector<int> v;
};
BOOST_FUSION_ADAPT_STRUCT(
wrapper,
(std::vector<int>, v)
)
int main()
{
namespace qi = boost::spirit::qi;
std::string const test_input = "1, 2, 3, 4, 5";
auto it = test_input.cbegin();
auto const last = test_input.cend();
wrapper result;
auto const r = qi::int_ % qi::lit( ',' );
auto const s = qi::phrase_parse( it, last, r, qi::ascii::space, result );
assert( s );
assert( it == last );
for( auto const& i : result.v )
std::cout << i << " ";
std::cout << std::endl;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment