| Home | Libraries | People | FAQ | More

##### And-Predicate Generator (`&a`)

###### Description

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

###### Header

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

Also, see Include Structure.

###### Model of

> `UnaryGenerator`

###### Expression Semantics

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

Expression | Semantics
--- | ---
`&a` | 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.

###### Attributes

See Compound Attribute Notation.

Expression | Attribute
--- | ---
`&a` (and-predicate, unary `&`) | `a: A --> &a: A`

| 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.

###### Complexity

> 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).

###### Example

| 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/support_utree.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");