cxxomfort  rel.20211024
Simple backports for C++ - https://ryan.gulix.cl/fossil.cgi/cxxomfort/
Macros
impl/foreach.hpp File Reference

Macros

#define CXXO_FOREACH(itemdecl, collection)   for (implementation_specific_arguments;;)
 Foreach loop construct that iterates over collection . More...
 

Macro Definition Documentation

◆ CXXO_FOREACH

#define CXXO_FOREACH (   itemdecl,
  collection 
)    for (implementation_specific_arguments;;)

Foreach loop construct that iterates over collection .

See also
http://www.artima.com/cppsource/foreach.html

See also "<iterator> support" .

A foreach macro declares iteration over collection , which can be any STL-compatible sequence, using itemdecl as the iterating item.

Usage is as follows:

list<int> L = {2, 3, 5, 7, 11};
CXXO_FOREACH (int x, L) {
cout<< x<< ' ';
}

When using C++11 onwards, this evaluates to the native range-for syntax, for zero overhead.

Note
FOREACH support varies according to compiler capabilities. In particular, for compilers that do not fully support at least C++98/C++03, the macro works only with lvalues.