Boost C++ Libraries Home Libraries People FAQ More

PrevUpHomeNext

spaces

Synopsis

struct spaces;

This is a parser.

Description

spaces accepts any number of whitespace characters. It requires at least one to be present.

Header

#include <boost/metaparse/spaces.hpp>

Expression semantics

spaces

is equivalent to

repeated1<space>

Example

#include <boost/metaparse/spaces.hpp>
#include <boost/metaparse/start.hpp>
#include <boost/metaparse/string.hpp>
#include <boost/metaparse/is_error.hpp>
#include <boost/metaparse/get_remaining.hpp>

#include <type_traits>

using namespace boost::metaparse;

static_assert(
  std::is_same<
    BOOST_METAPARSE_STRING("foo"),
    get_remaining<spaces::apply<BOOST_METAPARSE_STRING("  foo"), start>>::type
  >::type::value,
  "it should consume all whitespaces at the beginning of the input"
);

static_assert(
  is_error<spaces::apply<BOOST_METAPARSE_STRING("x"), start>>::type::value,
  "it should return an error when the input does not begin with a whitespace"
);

PrevUpHomeNext