Not sure how to force a for_each with a lambda to invoke the random
function object successively. In the for_each version below get_long is
called just once. Not sure how to use var, std_function, bind or
something else to overcome this.
I'm sure the answer is straight forward... anyone?
Regards,
Matt.
#include <iostream>
#include
#include <vector>
#include
#include
typedef boost::mt19937 base_generator_type;
base_generator_type generator( 100123u );
boost::uniform_int
gen_long(generator,-100,100);
using namespace std;
using namespace boost::lambda;
int main(int argc, char *argv[])
{
vector<long> v(10);
for_each(v.begin(),v.end(), _1 = gen_long() );
for_each(v.begin(), v.end(), cout << _1 << ' ');
cout << "\n";
for( vector<>::iterator i = v.begin(); i != v.end(); ++i )
{
*i = gen_long();
}
for_each(v.begin(), v.end(), cout << _1 << ' ');
cout << "\n";
system("PAUSE");
return 0;
}