Quite often (right now actually), I have to do this...
I would like to use for_each for snippets like this, but can't figure out the syntax. Something like this?Code:std::container::const_iterator ci; for (ci = my_container.begin(); ci != my_container.end(); ++ci) { std::cout << *ci; }
Code:std::for_each( my_container.begin(); my_container.end(); std::cout.operator<<() );



LinkBack URL
About LinkBacks



No, you have to write a function or a functor that does the output and give it to for_each. The lesson here is that for_each is dumb and you're better off just ignoring it if you don't already have a function that fits the third argument.