On Wed, Jul 7, 2010 at 3:30 AM, Max S. Kaznady
<max.kaznady@gmail.com> wrote:
Hi Robert,
Yep, the following works great. Not sure why the same code doesn't
work when I have it in my larger project, but I guess that's for me to
figure out.
There is still the problem with the std::for_each, see below:
#include <iostream>
#include <vector>
#include <algorithm>
#include <math.h>
#include "boost/bind.hpp"
#include <boost/numeric/ublas/vector.hpp>
#include <boost/numeric/ublas/io.hpp>
int main( )
{
boost::numeric::ublas::vector<double> v(10);
double exponent = 2.1;
std::fill(v.begin(), v.end(), 8.0);
// The following works just fine:
std::transform( v.begin(), v.end(), v.begin(), boost::bind( pow, _1,
exponent ) );
// But the for_each doesn't apply the power function, just leaves
the vector unaltered
std::for_each( v.begin(), v.end(), boost::bind( pow, _1, exponent ) );
// Print the result
std::cout<< v << std::endl;
return 0;
}
Compiled with: g++ -O2 -Wfatal-errors -Wall -g -ansi
-I/usr/local/boost/include -o main main.cpp