Boost C++ Libraries Home Libraries People FAQ More

PrevUpHomeNext

next_line

Synopsis

template <class SourcePosition, class Ch>
struct next_line;

This is a lazy template metafunction.

Table 61. Arguments

Name

Type

SourcePosition

source position

Ch

boxed character value. The character SourcePosition points to in the input.


Description

Returns a new source position, pointing to the beginning of the next line.

Header

#include <boost/metaparse/next_line.hpp>

Expression semantics

For any s source position and c wrapped character the following are equivalent

get_col<next_line<s, c>>::type

boost::mpl::int_<1>

get_line<next_line<s, c>>

boost::mpl::plus<get_line<s>::type, boost::mpl::int_<1>>

get_prev_char<next_line<s, c>>::type

c

Example

#include <boost/metaparse/next_line.hpp>
#include <boost/metaparse/source_position.hpp>
#include <boost/metaparse/get_col.hpp>
#include <boost/metaparse/get_line.hpp>
#include <boost/metaparse/get_prev_char.hpp>

#include <type_traits>

using namespace boost::metaparse;

struct returns_source_position
{
  using type =
    source_position<
      std::integral_constant<int, 11>,
      std::integral_constant<int, 13>,
      std::integral_constant<char, 'a'>
    >;
};

struct returns_char
{
  using type = std::integral_constant<char, '\n'>;
};

static_assert(
  get_col<
    next_line<
      source_position<
        std::integral_constant<int, 11>,
        std::integral_constant<int, 13>,
        std::integral_constant<char, 'a'>
      >,
      std::integral_constant<char, '\n'>
    >
  >::type::value == 1,
  "it should set the column to 1"
);

static_assert(
  get_line<
    next_line<
      source_position<
        std::integral_constant<int, 11>,
        std::integral_constant<int, 13>,
        std::integral_constant<char, 'a'>
      >,
      std::integral_constant<char, '\n'>
    >
  >::type::value == 12,
  "it should increase the line component of the source position"
);

static_assert(
  get_prev_char<
    next_line<
      source_position<
        std::integral_constant<int, 11>,
        std::integral_constant<int, 13>,
        std::integral_constant<char, 'a'>
      >,
      std::integral_constant<char, '\n'>
    >
  >::type::value == '\n',
  "it should update the prev char component of the source position"
);

static_assert(
  get_col<next_line<returns_source_position, returns_char>>::type::value == 1,
  "it should support lazy evaluation"
);

PrevUpHomeNext