Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <algorithm>
- using namespace std;
- struct Bar{
- uint val;
- uint some_other_val = 0;
- Bar(const uint & val){
- this->val = val;
- }
- void update(const uint & other_val){
- this->some_other_val += other_val;
- }
- bool operator=(const uint & other_val){
- return this->val == other_val;
- }
- };
- void do_some_stuff(const uint & val, const uint & update, vector<Bar> & foo){
- Bar bar;
- auto it = find(begin(foo), end(foo), val);
- if (it == end(foo)){
- bar = Bar(val);
- foo.emplace_back(bar);
- }
- else
- bar = *it;
- bar.update(update);
- }
- int main(){
- vector<Bar> foo = {Bar(3), Bar(4)};
- do_some_stuff(4, 22, foo);
- do_some_stuff(5, 22, foo);
- cout << ":(" << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement