Advertisement
Guest User

:(

a guest
Feb 10th, 2021
691
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.83 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm>
  4.  
  5. using namespace std;
  6.  
  7. struct Bar{
  8.     uint val;
  9.     uint some_other_val = 0;
  10.  
  11.     Bar(const uint & val){
  12.         this->val = val;
  13.     }
  14.  
  15.     void update(const uint & other_val){
  16.         this->some_other_val += other_val;
  17.     }
  18.  
  19.     bool operator=(const uint & other_val){
  20.         return this->val == other_val;
  21.     }
  22. };
  23.  
  24.  
  25. void do_some_stuff(const uint & val, const uint & update, vector<Bar> & foo){
  26.  
  27.     Bar bar;
  28.  
  29.     auto it = find(begin(foo), end(foo), val);
  30.     if (it == end(foo)){
  31.         bar = Bar(val);
  32.         foo.emplace_back(bar);
  33.     }
  34.     else
  35.         bar = *it;
  36.  
  37.     bar.update(update);
  38. }
  39.  
  40.  
  41. int main(){
  42.  
  43.     vector<Bar> foo = {Bar(3), Bar(4)};
  44.     do_some_stuff(4, 22, foo);
  45.     do_some_stuff(5, 22, foo);
  46.  
  47.     cout << ":(" << endl;
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement