[#sequence]
[section sequence]

[h1 Synopsis]

  template <class... Ps>
  struct sequence;

This is a [link parser_combinator parser combinator].

[table Arguments
  [[Name] [Type]]
  [[`Ps`] [[link parser parser]s]]
]

[h1 Description]

`sequence` applies the `Ps...` parsers in sequence on the input. It accepts an
input when all of these parsers accept it. The result of parsing is a sequence
of the results of the parsers.

On compilers, which are not C++11-compliant, the maximum number of parsers
`sequence` accepts can be specified with the
`BOOST_METAPARSE_LIMIT_SEQUENCE_SIZE` macro. Its default value is `5`.

[h1 Header]

  #include <boost/metaparse/sequence.hpp>

[h1 Expression semantics]

For any `n > 0`, `p0`, ..., `pn` parsers the result of `sequence<p0, ..., p1>`
is a compile-time sequence of the results of the parsers, applied after each
other in order on the input string when none of them returns an error.
The remaining string is the remaining string the last parser returns.

When one of the parsers returns an error, the combinator returns that error.

[h1 Example]

  #include <boost/metaparse/sequence.hpp>
  #include <boost/metaparse/token.hpp>
  #include <boost/metaparse/int_.hpp>
  #include <boost/metaparse/lit_c.hpp>
  #include <boost/metaparse/start.hpp>
  #include <boost/metaparse/string.hpp>
  #include <boost/metaparse/is_error.hpp>
  #include <boost/metaparse/get_result.hpp>
  
  #include <boost/mpl/at.hpp>
  
  using namespace boost::metaparse;
  
  using int_token = token<int_>;
  using plus_token = token<lit_c<'+'>>;
  
  using a_plus_b = sequence<int_token, plus_token, int_token>;
  
  static_assert(
    boost::mpl::at_c<
      get_result<a_plus_b::apply<BOOST_METAPARSE_STRING("1 + 2"), start>>::type,
      0
    >::type::value == 1,
    "the first element of the sequence should be the first number"
  );
  
  static_assert(
    boost::mpl::at_c<
      get_result<a_plus_b::apply<BOOST_METAPARSE_STRING("1 + 2"), start>>::type,
      1
    >::type::value == '+',
    "the second element of the sequence should be the plus"
  );
  
  static_assert(
    boost::mpl::at_c<
      get_result<a_plus_b::apply<BOOST_METAPARSE_STRING("1 + 2"), start>>::type,
      2
    >::type::value == 2,
    "the third element of the sequence should be the second number"
  );
  
  static_assert(
    is_error<a_plus_b::apply<BOOST_METAPARSE_STRING("1 +"), start>>::type::value,
    "when not all of the parsers accept the input, sequence should fail"
  );

[endsect]

