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 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
|
#include <fstream>
#include <istream>
#include <string>
#include <iostream>
#include <vector>
#include <future>
using namespace std;
class foo{
private:
int n;
string s;
public:
foo(){}
foo(string sp, int np):s(sp), n(np){}
int getN(){ return this->n; }
string getS(){ return this->s; }
void setN(int np){ this->n = np; }
static void display(vector<foo> p)
{
for(auto & i : p)
{
cout << i.getS() << i.getN() << endl;
}
cout << endl;
}
bool equalFoo(foo p)
{
if(this->n == p.getN() && this->s == p.getS())
return true;
else
return false;
}
static void add(vector<foo> & p, foo l, int val){
for (vector<foo>::size_type it = 0; it != p.size(); it++)
{
if(p[it].equalFoo(l))
{
p[it].setN(val);
cout << "value changed !" << endl;
}
}
}
};
int main()
{
cout << "Hello World!" << endl;
vector<foo> vectFoos =
{
{"S",1}, {"A",1}, {"A",2}, {"A",3}, {"A",4}, {"A",5}, {"A",6},
{"S",2}, {"S",3}, {"B",1}, {"B",2}, {"B",3}, {"B",4}, {"B",5},
{"B",6}, {"S",4}, {"S",5}, {"S",6}, {"C",1}, {"C",2}, {"C",3},
{"C",4}, {"C",5}, {"C",6}, {"S",7}, {"S",8}, {"S",9}, {"S",10}
};
foo::display(vectFoos);
auto outputRslt1 = std::async(foo::add, vectFoos, foo("B",2), 10);
auto outputRslt2 = std::async(foo::add, vectFoos, foo("A",5), 10);
auto outputRslt3 = std::async(foo::add, vectFoos, foo("C",1), 10);
outputRslt1.get();
outputRslt2.get();
outputRslt3.get();
foo::display(vectFoos);
return 0;
}
|