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
Directive Testing if Parser Succeeded (matches[])
Description

The matches[] directive executes the embedded parser and returns whether it succeeded matching.

Header
// forwards to <boost/spirit/home/qi/directive/matches.hpp>
#include <boost/spirit/include/qi_matches.hpp>

Also, see Include Structure.

Namespace

Name

boost::spirit::matches // alias: boost::spirit::qi::matches

Model of

UnaryParser

Notation

a

A Parser.

Expression Semantics

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

Expression

Semantics

matches[a]

Execute the subject parser a, and return as its attribute whether it succeeded. The directive itself does always succeed.

Attributes

Expression

Attribute

matches[a]

bool

Complexity

The complexity is defined by the complexity of the subject parser, a

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::matches;
using boost::spirit::qi::int_;

This parser tries to match an int and returns true a its attribute as it succeeded matching:

bool result = false;
test_parser_attr("345", matches[int_], result);
std::cout << std::boolalpha << result << std::endl; // should print: true

This parser tries to match an int as well and returns false as its attribute as it fails matching:

result = true;
test_parser_attr("abc", matches[int_], result);
std::cout << std::boolalpha << result << std::endl; // should print: false


PrevUpHomeNext