#include <stdio.h>
#include <vector>
#include <algorithm>
using namespace std;
int negative(int n) { return -n; }
class plus_e
{
public:
int operator() (int a, int b)
{
return a + b;
}
};
int main()
{
// 初期設定
vector<int> v1 {0, 1, 2, 3, 4};
printf("v1 :");
for (auto x : v1)
printf(" %d", x);
printf("\n");
vector<int> v2 {10, 20, 30, 40, 50};
printf("v2 :");
for (auto x : v2)
printf(" %d", x);
printf("\n");
// v1 の各要素を負にする
printf("v1 の各要素を負にする\n");
transform(v1.begin(), v1.end(), v1.begin(), negative); // 関数
printf(" v1 :");
for (auto x : v1)
printf(" %d", x);
printf("\n");
// v1 と v2 を加え,v1 に保存する
printf("v1 と v2 を加え,v1 に保存する\n");
transform(v1.begin(), v1.end(), v2.begin(), v1.begin(), plus_e()); // 二項関数オブジェクト
// transform(v1.begin(), v1.end(), v2.begin(), v1.begin(), plus<int>()); // 関数オブジェクト plus
// transform(v1.begin(), v1.end(), v2.begin(), v1.begin(), [](int x, int y){ return x+y; }); // ラムダ式
printf(" v1 :");
for (auto x : v1)
printf(" %d", x);
printf("\n");
return 0;
}