Boost C++ Libraries Home Libraries People FAQ More

PrevUpHomeNext

build_parser

Synopsis

template <class P>
struct build_parser;

This is a template metafunction.

Table 8. Arguments

Name

Type

P

parser


Description

It generates a simple interface for parser. It returns a metafunction class that takes an input string, parses it with P and returns the result of parsing. It generates a compilation error when parsing fails.

Return value

It returns a template metafunction class:

struct
{
  template <class S>
  struct apply;
};

Table 9. Arguments

Name

Type

S

string


Header

#include <boost/metaparse/build_parser.hpp>

Expression semantics

For any p parser and s compile-time string

build_parser<p>::type::apply<s>

is equivalent to

get_result<p::apply<s>>

Example

#include <boost/metaparse/build_parser.hpp>
#include <boost/metaparse/int_.hpp>
#include <boost/metaparse/string.hpp>

using namespace boost::metaparse;

using string_to_int = build_parser<int_>::type;

static_assert(
  string_to_int::apply<BOOST_METAPARSE_STRING("1113")>::type::value == 1113,
  "string_to_int should be a metafunction turning a string into an int"
);

PrevUpHomeNext