Boost C++ Libraries Home Libraries People FAQ More

PrevUpHomeNext

3.3. Accepting optional whitespaces at the end of the input

[Note] Note

Note that you can find everything that has been included and defined so far here.

Our parser became a bit too restrictive now. It doesn't allow anything after the number, not even whitespaces:

> exp_parser2::apply<BOOST_METAPARSE_STRING("11 ")>::type
<< compilation error >>

Let's allow whitespaces after the number:

> #include <boost/metaparse/token.hpp>

This makes the token template class available. It takes a parser as its argument and allows optional whitespaces after that. Let's create a third parser allowing whitespaces after the number:

> using exp_parser3 = build_parser<entire_input<token<int_>>>;

We expect token<int_> to be the entire input in this case. We allow optional whitespaces after int_ but nothing else:

> exp_parser3::apply<BOOST_METAPARSE_STRING("11 ")>::type
mpl_::integral_c<int, 11>

PrevUpHomeNext