...one of the most highly
regarded and expertly designed C++ library projects in the
world.
— Herb Sutter and Andrei
Alexandrescu, C++
Coding Standards
#include <boost/phoenix/statement/switch.hpp>
The syntax is:
switch_(integral_expression) [ case_<integral_value>(sequenced_statements), ... default_<integral_value>(sequenced_statements) ]
A comma separated list of cases, and an optional default can be provided. Note unlike a normal switch statement, cases do not fall through.
Example: This code prints out "one"
,
"two"
or "other value"
depending on the
element's actual value:
std::for_each(c.begin(), c.end(), switch_(arg1) [ case_<1>(std::cout << val("one") << '\n'), case_<2>(std::cout << val("two") << '\n'), default_(std::cout << val("other value") << '\n') ] );