-
Notifications
You must be signed in to change notification settings - Fork 0
/
7.1.6.1 Simple binding
48 lines (43 loc) · 1008 Bytes
/
7.1.6.1 Simple binding
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#include "stdafx.h"
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
using namespace std;
struct Country
{
string name;
int area;
Country operator*(int value)
{
this->area *= value;
return *this;
}
};
Country multiply(Country c, int x)
{
return c * x;
}
void print(Country country)
{
cout << country.name<< " " << country.area << endl;
}
//your code
int main()
{
vector <Country> countries = {
{ "India", 3287 },{ "Argentina", 2780 },
{ "Brazil", 8515 },{ "Australia", 7692 },
{ "China", 9572 },{ "United States of America", 9525 },
{ "Russia", 17098 },{ "Canada", 9984 },
{ "Kazakhstan", 2724 },{ "Algeria", 2381 }
};
vector <Country> c(countries.size());
//for_each(countries.begin(), countries.end(), print);
transform(countries.begin(), countries.end(), c.begin(), bind2nd(ptr_fun(multiply), 1000));
//for_each(countries.begin(), countries.end(), print);
for_each(c.begin(), c.end(), print);
system("pause");
return 0;
}