Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>If a library extension was easily implementable there would have been no need for a language extension. See <a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2004/n1607.pdf" rel="nofollow noreferrer">N1607</a> for details on the auto proposal.</p> <p>However, the <a href="http://www.artima.com/cppsource/foreach.html" rel="nofollow noreferrer">article</a> on the <a href="http://www.boost.org/doc/libs/1_35_0/doc/html/foreach.html" rel="nofollow noreferrer">Boost.Foreach</a> (which sort of does what you want) macro may help understand the issues related to such an implementation.</p> <blockquote> <p><strong>What is BOOST_FOREACH?</strong></p> <p>In C++, writing a loop that iterates over a sequence is tedious. We can either use iterators, which requires a considerable amount of boiler-plate, or we can use the std::for_each() algorithm and move our loop body into a predicate, which requires no less boiler-plate and forces us to move our logic far from where it will be used. In contrast, some other languages, like Perl, provide a dedicated "foreach" construct that automates this process. BOOST_FOREACH is just such a construct for C++. It iterates over sequences for us, freeing us from having to deal directly with iterators or write predicates.</p> <p>BOOST_FOREACH is designed for ease-of-use and efficiency. It does no dynamic allocations, makes no virtual function calls or calls through function pointers, and makes no calls that are not transparent to the compiler's optimizer. This results in near-optimal code generation; the performance of BOOST_FOREACH is usually within a few percent of the equivalent hand-coded loop. And although BOOST_FOREACH is a macro, it is a remarkably well-behaved one. It evaluates its arguments exactly once, leading to no nasty surprises.</p> </blockquote>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload