Boost C++ Libraries Home Libraries People FAQ More

PrevUpHomeNext

fail

Synopsis

template <class Msg>
struct fail;

This is a parser.

Table 18. Arguments

Name

Type

Msg

parsing error message


Description

Parser rejecting every input.

Header

#include <boost/metaparse/fail.hpp>

Expression semantics

For any msg parsing error message, s compile-time string and pos source position

fail<msg>::apply<s, pos>::type

returns an error with msg as the error message.

Example

#include <boost/metaparse/fail.hpp>
#include <boost/metaparse/string.hpp>
#include <boost/metaparse/start.hpp>
#include <boost/metaparse/is_error.hpp>
#include <boost/metaparse/get_message.hpp>
#include <boost/metaparse/define_error.hpp>

using namespace boost::metaparse;

BOOST_METAPARSE_DEFINE_ERROR(sample_error, "This is an example parsing error");

using fail_p = fail<sample_error>;

static_assert(
  is_error<fail_p::apply<BOOST_METAPARSE_STRING("foo"), start>>::type::value,
  "it should reject every input"
);

static_assert(
  std::is_same<
    get_message<fail_p::apply<BOOST_METAPARSE_STRING("foo"), start>>::type,
    sample_error
  >::type::value,
  "the error message should be the type specified"
);

PrevUpHomeNext