On Wed, Aug 26, 2009 at 3:44 PM, Steven Watanabe
AMDG
Robert Jones wrote:
I've asked a similar question before, but I can't seem to locate the mail or recall the answer! In the code below, how can I eliminate f()?
#include "boost/iterator/counting_iterator.hpp" #include "boost/bind.hpp" #include <iostream>
using namespace std; using namespace boost;
ostream & f( ostream & s, int i ) { return s << i; }
int main( ) { for_each( make_counting_iterator( 0 ), make_counting_iterator( 10 ), bind( & f, ref( cout ), _1 ) ); }
If I write something like
bind( static_cast< ostream & ( * )( ostream &, int ) >( operator << ), ref( cout ), _1 )
the compiler can't locate operator<<()
Any thoughts, solutions even?
operator<< for int a member function.
template
basic_ostream & std::basic_ostream ::operator<<(int n);
Look at Phoenix's bind instead of the root bind. Phoenix's bind
combines the root bind and lambda's bind all in one. something like
this I think would work:
// these are all phoenix's version, do not include boost bind, you do
not even need bind...
int main( )
{
for_each(
make_counting_iterator( 0 ),
make_counting_iterator( 10 ),
cout<