boost.lambda for_each and boost.array

Hi, these snipped doesn't compile, but why? ---8<--- #include <iostream> #include <boost/array.hpp> #include <boost/lambda/lambda.hpp> int main() { using namespace ::boost::lambda; boost::array<double, 10> values; for_each( values.begin(), values.end(), _1 = 2.0 ); for_each( values.begin(), values.end(), std::cout << _1 << '\n'); } --->8--- error: 'for_each' was not declared in this scope using std::list compiles and works. Did I miss something? Thanks, Olaf

On Mon, Apr 7, 2008 at 2:06 PM, Olaf Peter <ope-devel@gmx.de> wrote:
for_each( values.begin(), values.end(), std::cout << _1 << '\n');
error: 'for_each' was not declared in this scope
You never included <algorithm>, and it's std::for_each anyways.
using std::list compiles and works. Did I miss something?
That's a fluke. One of the headers (perhaps <list>) happens to include <algorithm>, and using std::list means that std::for_each gets found by ADL. Neither are good style, and the first is non-conforming if <algorithm> came indirectly from a standard header.

Thanks for all answers,
for_each( values.begin(), values.end(), std::cout << _1 << '\n');
error: 'for_each' was not declared in this scope
You never included <algorithm>, and it's std::for_each anyways.
using std::list compiles and works. Did I miss something?
That's a fluke. One of the headers (perhaps <list>) happens to include <algorithm>, and using std::list means that std::for_each gets found by ADL. Neither are good style, and the first is non-conforming if <algorithm> came indirectly from a standard header.
that's is what did confuse me. The boost.lambda header has a for_each struct/class calling std::for_each in boost/lambda/algorithm.hpp. Thanks, Olaf
participants (3)
-
Olaf Peter
-
Peter Dimov
-
Scott McMurray