max_size.h 722 B

123456789101112131415161718192021222324252627282930313233
  1. #ifndef IGL_MAX_SIZE_H
  2. #define IGL_MAX_SIZE_H
  3. #include <vector>
  4. namespace igl
  5. {
  6. // Determine max size of lists in a vector
  7. // Template:
  8. // T some list type object that implements .size()
  9. // Inputs:
  10. // V vector of list types T
  11. // Returns max .size() found in V, returns -1 if V is empty
  12. template <typename T>
  13. inline int max_size(const std::vector<T> & V);
  14. }
  15. // Implementation
  16. template <typename T>
  17. inline int igl::max_size(const std::vector<T> & V)
  18. {
  19. int max_size = -1;
  20. for(
  21. typename std::vector<T>::const_iterator iter = V.begin();
  22. iter != V.end();
  23. iter++)
  24. {
  25. int size = (int)iter->size();
  26. max_size = (max_size > size ? max_size : size);
  27. }
  28. return max_size;
  29. }
  30. #endif