fork(21) download
  1. #include <iostream>
  2. #include <vector>
  3. #include <tuple>
  4. #include <algorithm>
  5.  
  6. struct Size {
  7. int width, height;
  8. };
  9.  
  10. int main()
  11. {
  12. std::vector<Size> sizes = { {4, 1}, {2, 3}, {1, 2} };
  13.  
  14. decltype(sizes)::iterator minEl, maxEl;
  15. std::tie(minEl, maxEl) = std::minmax_element(begin(sizes), end(sizes),
  16. [] (Size const& s1, Size const& s2)
  17. {
  18. return s1.width < s2.width;
  19. });
  20.  
  21. std::cout << "Minimum (based on width): "
  22. << minEl->width << "," << minEl->height << std::endl;
  23.  
  24. std::cout << "Maximum (based on width): "
  25. << maxEl->width << "," << maxEl->height << std::endl;
  26. }
  27.  
Success #stdin #stdout 0s 2984KB
stdin
Standard input is empty
stdout
Minimum (based on width): 1,2
Maximum (based on width): 4,1