boost.png (6897 bytes)

PrevUpHomeNext

Portability

BOOST_FOREACH uses some fairly sophisticated techniques that not all compilers support. Depending on how compliant your compiler is, you may not be able to use BOOST_FOREACH in some scenarios. Since BOOST_FOREACH uses Boost.Range, it inherits Boost.Range's portability issues. You can read about those issues in that library's Portability section.

In addition to the demands placed on the compiler by Boost.Range, BOOST_FOREACH places additional demands in order to handle r-value sequences properly. (Recall that an r-value is an unnamed object, so an example of an r-value sequence would be a function that returns a std::vector<> by value.) Compilers vary in their handling of r-values and l-values. To cope with the situation BOOST_FOREACH defines three levels of compliance, described below:

BOOST_FOREACH Compliance Levels

Level 0
Highest level of compliance
BOOST_FOREACH works with l-values, r-values and const-qualified r-values.
Level 1
Moderate level of compliance
BOOST_FOREACH works with l-values and plain r-values, but not const-qualified r-values.
BOOST_FOREACH_NO_CONST_RVALUE_DETECTION is defined in this case.
Level 2
Lowest level of compliance
BOOST_FOREACH works with l-values only, not r-values.
BOOST_FOREACH_NO_RVALUE_DETECTION is defined in this case.

Below are the compilers BOOST_FOREACH has been tested with, and the compliance level you can expect from each.

Compiler Compliance Level

Compiler Compliance Level
Visual C++ 7.1 Level 1
Visual C++ Whidbey Beta Level 1
Visual C++ 7.0 Level 2
Visual C++ 6.0 Level 2
gcc 3.3.3 Level 0
Intel for Windows 8.0 Level 1
Intel for Windows 7.0 Level 2
Comeau 4.3.3 Level 0

Also, if your compiler is one for which the Boost config system defines BOOST_NO_FUNCTION_TEMPLATE_ORDERING, then the compliance level for the BOOST_FOREACH macro is Level 2, the lowest.

Copyright © 2004 Eric Niebler

PrevUpHomeNext