<div class="gmail_quote">On Wed, Jul 7, 2010 at 3:30 AM, Max S. Kaznady <span dir="ltr">&lt;<a href="mailto:max.kaznady@gmail.com">max.kaznady@gmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Hi Robert,<br>
<br>
Yep, the following works great. Not sure why the same code doesn&#39;t<br>
work when I have it in my larger project, but I guess that&#39;s for me to<br>
figure out.<br>
<br>
There is still the problem with the std::for_each, see below:<br>
<br>
#include &lt;iostream&gt;<br>
<div class="im">#include &lt;vector&gt;<br>
#include &lt;algorithm&gt;<br>
#include &lt;math.h&gt;<br>
#include &quot;boost/bind.hpp&quot;<br>
</div>#include &lt;boost/numeric/ublas/vector.hpp&gt;<br>
#include &lt;boost/numeric/ublas/io.hpp&gt;<br>
<br>
int main( )<br>
{<br>
  boost::numeric::ublas::vector&lt;double&gt; v(10);<br>
  double exponent = 2.1;<br>
  std::fill(v.begin(), v.end(), 8.0);<br>
  // The following works just fine:<br>
<div class="im">  std::transform( v.begin(), v.end(), v.begin(), boost::bind( pow, _1,<br>
exponent ) );<br>
</div>  // But the for_each doesn&#39;t apply the power function, just leaves<br>
the vector unaltered<br>
  std::for_each( v.begin(), v.end(), boost::bind( pow, _1, exponent ) );<br>
  // Print the result<br>
  std::cout&lt;&lt; v &lt;&lt; std::endl;<br>
<br>
  return 0;<br>
}<br>
<br>
Compiled with: g++ -O2 -Wfatal-errors -Wall -g -ansi<br>
-I/usr/local/boost/include -o main main.cpp<br>
<br></blockquote><div><br>Hi Max<br><br>I haven&#39;t taken the time to try this, but does this do the trick?<br><br>std::for_each(v.begin(), v.end(), boost::bind(pow, boost::ref(_1), exponent));<br><br>Cheers<br><br>- Rob.<br>
 <br></div></div>

