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.


Block Statement
if_ Statement
if_else_ Statement
switch_ Statement
while_ Statement
do_while_ Statement
for_ Statement
try_ catch_ Statement

Lazy statements...

The expressions presented so far are sufficiently powerful to construct quite elaborate structures. We have presented lazy-functions and lazy-operators. How about lazy-statements? First, an appetizer:

Print all odd-numbered contents of an STL container using std::for_each (all_odds.cpp):

std::for_each(c.begin(), c.end(),
    if_(arg1 % 2 == 1)
        cout << arg1 << ' '

Huh? Is that valid C++? Read on...

Yes, it is valid C++. The sample code above is as close as you can get to the syntax of C++. This stylized C++ syntax differs from actual C++ code. First, the if has a trailing underscore. Second, the block uses square brackets instead of the familiar curly braces {}.

[Note] Note

C++ in C++?

In as much as Spirit attempts to mimic EBNF in C++, Phoenix attempts to mimic C++ in C++!!!

[Note] Note

Unlike lazy functions and lazy operators, lazy statements always return void.

Here are more examples with annotations. The code almost speaks for itself.