#include <iostream>
#include <vector>
#include <algorithm>
struct absInt {
int operator()( int iv ){
return (iv > 0) ? iv : -iv;
}
};
int main(){
std::vector<int> ia = {-1, 3, -31, 6};
std::transform( ia.begin(), ia.end(), ia.begin(), absInt() );
for ( const int& e : ia ){
std::cout << e << "\n";
}
}
operator() must be declared as a member function.transform() is a temporary object of class absInt created by invoking the default constructor of absInt.