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
Attribute Parser (attr)
Description

The Attribute parser does not consume any input, for this reason it always matches an empty string and always succeeds. It's purpose is to expose its specified parameter as an attribute.

Header
// forwards to <boost/spirit/home/qi/auxiliary/attr.hpp>
#include <boost/spirit/include/qi_attr.hpp>

Also, see Include Structure.

Namespace

Name

boost::spirit::attr // alias: boost::spirit::qi::attr

Model of

PrimitiveParser

Notation

a

A arbitrary typed constant value, e.g. 0.0, "Hello", or a variable of arbitrary type or a Lazy Argument that evaluates to an arbitrary type.

A

The type of a or if it is a Lazy Argument, its return type.

Expression Semantics

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

Expression

Semantics

attr(a)

Create a pseudo parser exposing the current value of a as its attribute without consuming any input at parse time.

Attributes

Expression

Attribute

attr(a)

A

Complexity

O(1)

The complexity is constant as no input is consumed and no matching is done.

Example
[Note] Note

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

Some using declarations:

namespace phx = boost::phoenix;
using boost::spirit::qi::attr;

Using attr with literals:

std::string str;
test_parser_attr("", attr("boost"), str);
std::cout << str << std::endl;            // will print 'boost'

double d;
test_parser_attr("", attr(1.0), d);
std::cout << d << std::endl;              // will print '1.0'

Using attr with Phoenix function objects:

d = 0.0;
double d1 = 1.2;
test_parser_attr("", attr(phx::ref(d1)), d);
std::cout << d << std::endl;              // will print '1.2'


PrevUpHomeNext