#include
#include
#include
#include
using namespace std;
// A function object that computes a reciprocal.
class reciprocal : unary_function {
public:
result_type sum;
result_type operator()(argument_type val) {
if(val == 0.0) return 0.0;
return 1.0 / val; // return reciprocal
}
};
int main(){
int i;
vector v;
for(i=1; i < 10; ++i) v.push_back((double)i);
vector v2(10);
transform(v.begin(), v.end(), v2.begin(), reciprocal());
return 0;
}