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.
Not-Predicate Generator (!a)

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

// forwards to <boost/spirit/home/karma/operator/not_predicate.hpp>
#include <boost/spirit/include/karma_not_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 not-predicate generator succeeds if its embedded generator fails (unless the underlying output stream reports an error). The not-predicate never produces any output.

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


See Compound Attribute Notation.



!a (not-predicate, unary !)

a: A --> !a: A

[Note] Note

The attribute of the not-predicate is not always unused_type, which is different from Qi's not-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 not-predicate generator is defined by the complexity of its embedded generator. The complexity of the not-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/support_utree.hpp>
#include <boost/phoenix/core.hpp>
#include <boost/phoenix/operator.hpp>
#include <boost/fusion/include/std_pair.hpp>
#include <boost/proto/deep_copy.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 a not predicate generator:

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

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