Boost logo

Boost Users :

Subject: [Boost-users] apply std::pow to vector or matrix
From: Max S. Kaznady (max.kaznady_at_[hidden])
Date: 2010-07-05 16:18:22


I followed the UBLAS extensions here:
http://www.crystalclearsoftware.com/cgi-bin/boost_wiki/wiki.pl?Examples_-_How_To_Extend_UBLAS
and I figured out how to extend functions like "exp" and "log" to act
on a vector.

But, those are functions of one argument. What I want is to be able to
apply a function with one fixed argument, like std::pow, to a vector
for some exponent exp, so I would like the code to look like:
vector<double> v( 100 );
double exponent = 2.1; // some exponent value
// ... fill v ...
std::cout << apply_to_all( v, functor::my_pow<double>(exponent) ) << std::endl;
std::cout << apply_to_all<functor::my_pow<double>(exponent) >( v ) << std::endl;
OR
std::cout << apply_to_all( v, functor::my_pow<double>() , exponent) <<
std::endl;

How can I do this? I tried overloading apply_to_all and writing
constructor code, but it didn't work because the return type of the
apply function is static.

P.S. I tried posting this to ublas lists, but got a message saying
that my e-mail address is not registered. I guess that list is only
for developers.

Thanks,
Max


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net