Last active
December 30, 2015 21:39
-
-
Save yutopp/7888832 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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