Boost C++ Libraries 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.
And Predicate (&a)

The and predicate generator is used to test, whether the embedded generator succeeds without generating any output. It succeeds if the embedded generator succeeds.

// forwards to <boost/spirit/home/karma/operator/and_predicate.hpp>
#include <boost/spirit/include/karma_and_predicate.hpp>

Also, see Include Structure.

Model of


Expression Semantics

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




The generator a is executed for the sole purpose of testing whether it succeeds. The and predicate generator succeeds if its embedded generator succeeds (unless the underlying output stream reports an error). The and predicate never produces any output.

The and generator is implemented by redirecting all output produced by its embedded generator into a discarding device.


See Compound Attribute Notation.



&a (and predicate, unary &)

a: A --> &a: A

[Note] Note

The attribute of the and predicate is not always unused_type, which is different from Qi's and predicate. This is necessary as the generator the and predicate is attached to most of the time needs an attribute.


The overall complexity of the and predicate generator is defined by the complexity of its embedded generator. The complexity of the and predicate generator itself is O(1).

[Note] Note

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

Some includes:

#include <boost/spirit/include/karma.hpp>
#include <boost/spirit/include/phoenix_core.hpp>
#include <boost/spirit/include/phoenix_operator.hpp>
#include <boost/fusion/include/std_pair.hpp>
#include <iostream>
#include <string>

Some using declarations:

using boost::spirit::karma::double_;
using boost::spirit::karma::ascii::char_;
using boost::spirit::karma::ascii::string;
using boost::phoenix::ref;

Basic usage of an and predicate generator:

test_generator_attr("b", &char_('a') << 'b' | 'c', 'a');
test_generator_attr("c", &char_('a') << 'b' | 'c', 'x');

test_generator_attr("abc", &string("123") << "abc" | "def", "123");
test_generator_attr("def", &string("123") << "abc" | "def", "456");