Boost C++ Libraries Home Libraries People FAQ More

PrevUpHomeNext

get_position

Synopsis

template <class D>
struct get_position;

This is a lazy template metafunction.

Table 34. Arguments

Name

Type

D

accept or reject value


Description

Returns the source position information of a parsing result.

Header

#include <boost/metaparse/get_position.hpp>

Example

#include <boost/metaparse/get_position.hpp>
#include <boost/metaparse/start.hpp>
#include <boost/metaparse/accept.hpp>
#include <boost/metaparse/reject.hpp>
#include <boost/metaparse/string.hpp>
#include <boost/metaparse/define_error.hpp>

#include <type_traits>

using namespace boost::metaparse;

BOOST_METAPARSE_DEFINE_ERROR(sample_error, "Sample error message");

struct returns_reject
{
  using type = reject<sample_error, start>;
};

static_assert(
  std::is_same<
    start,
    get_position<reject<sample_error, start>>::type
  >::type::value,
  "It should return the position of a reject"
);

static_assert(
  std::is_same<
    start,
    get_position<
      accept<sample_error, BOOST_METAPARSE_STRING("foo"), start>
    >::type
  >::type::value,
  "It should return the position of an accept"
);

static_assert(
  std::is_same<start, get_position<returns_reject>::type>::type::value,
  "It should support lazy evaluation"
);

PrevUpHomeNext