Boost C++ Libraries

...one of the most highly regarded and expertly designed C++ library projects in the world. Herb Sutter and Andrei Alexandrescu, C++ Coding Standards

This is the documentation for an old version of Boost. Click here to view this page for the latest version.
PrevUpHomeNext
List (a % b)
Description

The list operator, a % b, is a binary operator that matches a list of one or more repetitions of a separated by occurrences of b. This is equivalent to a >> *(b >> a).

Header
// forwards to <boost/spirit/home/qi/operator/list.hpp>
#include <boost/spirit/include/qi_list.hpp>

Also, see Include Structure.

Model of

BinaryParser

Notation

a, b

A Parser

Expression Semantics

Semantics of an expression is defined only where it differs from, or is not defined in BinaryParser.

Expression

Semantics

a % b

Match a list of one or more repetitions of a separated by occurrences of b. This is equivalent to a >> *(b >> a).

Attributes

See Compound Attribute Notation.

Expression

Attribute

a % b

a: A, b: B --> (a % b): vector<A>
a: Unused, b: B --> (a % b): Unused

Complexity

The overall complexity of the List is defined by the complexity of its subject, a, multiplied by the number of repetitions. The complexity of the List itself is O(N), where N is the number successful repetitions.

Example
[Note] Note

The test harness for the example(s) below is presented in the Basics Examples section.

Some using declarations:

using boost::spirit::qi::int_;

Parse a comma separated list of numbers and put them in a vector:

std::vector<int> attr;
test_phrase_parser_attr(
    "111, 222, 333, 444, 555", int_ % ',', attr);
std::cout 
    << attr[0] << ',' << attr[1] << ',' << attr[2] << ',' 
    << attr[3] << ',' << attr[4] 
    << std::endl;


PrevUpHomeNext