fork download
  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm>
  4.  
  5. struct Item
  6. {
  7. int attribute;
  8. };
  9.  
  10. void fun(const Item &i)
  11. {
  12. std::cout << "Item with attr: " << i.attribute << std::endl;
  13. }
  14.  
  15. int main() {
  16. std::vector<Item> items = {
  17. Item {1}, Item {4}, Item{8}
  18. };
  19.  
  20. fun(*std::find_if(items.begin(), items.end(), [](const Item &i) {return i.attribute == 4; }));
  21.  
  22. return 0;
  23. }
Success #stdin #stdout 0s 3272KB
stdin
Standard input is empty
stdout
Item with attr: 4