Boost logo

Boost :

From: Eric Niebler (eric_at_[hidden])
Date: 2005-05-02 13:56:50


Stefan Strasser wrote:
> Dave Harris schrieb:
>
>> For example, from looking at the implementation it seems that the
>> macro caches the end() value in a variable called _foreach_end.
>
> it is cached, but why?
> end is end and stays end, unless it is invalidated.
>

Performance. Even when writing loops by hand, it's a good idea to save
the result of .end() in a local to avoid repeated function calls that
are not necessary. It's called "hoisting". It's one of the side-benefits
of using FOREACH and std:: algorithms.

-- 
Eric Niebler
Boost Consulting
www.boost-consulting.com

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk