fork download
  1. #include <iostream>
  2. #include <numeric>
  3.  
  4. struct GEOGRAPHIC_REGION
  5. {
  6. float fNorthMost;
  7. float fSouthMost;
  8. float fWestMost;
  9. float fEastMost;
  10. };
  11.  
  12. GEOGRAPHIC_REGION combine(const GEOGRAPHIC_REGION& accum, const GEOGRAPHIC_REGION& tocombine)
  13. {
  14. GEOGRAPHIC_REGION combined = {
  15. std::max(accum.fNorthMost, tocombine.fNorthMost),
  16. std::min(accum.fSouthMost, tocombine.fSouthMost),
  17. std::min(accum.fWestMost, tocombine.fWestMost),
  18. std::max(accum.fEastMost, tocombine.fEastMost)
  19. };
  20. return combined;
  21. }
  22.  
  23. int main()
  24. {
  25. const GEOGRAPHIC_REGION regions[] =
  26. {
  27. { 2,-1,-1,1 },
  28. { 1,-2,-1,1 },
  29. { 1,-1,-2,1 },
  30. { 1,-1,-1,2 },
  31. };
  32.  
  33. GEOGRAPHIC_REGION super = std::accumulate(regions, regions+4, regions[0], combine);
  34.  
  35. std::cout << "{ " << super.fNorthMost << ", "
  36. << super.fSouthMost << ", "
  37. << super.fWestMost << ", "
  38. << super.fEastMost << " }" << std::endl;
  39. }
  40.  
Success #stdin #stdout 0s 2724KB
stdin
Standard input is empty
stdout
{ 2, -2, -2, 2 }