IndexComparison.h 688 B

123456789101112131415161718192021222324252627282930
  1. #ifndef IGL_INDEXCOMPARISON_H
  2. #define IGL_INDEXCOMPARISON_H
  3. // Comparison struct used by sort
  4. // http://bytes.com/topic/c/answers/132045-sort-get-index
  5. namespace igl{
  6. // For use with functions like std::sort
  7. template<class T> struct IndexLessThan
  8. {
  9. IndexLessThan(const T arr) : arr(arr) {}
  10. bool operator()(const size_t a, const size_t b) const
  11. {
  12. return arr[a] < arr[b];
  13. }
  14. const T arr;
  15. };
  16. // For use with functions like std::unique
  17. template<class T> struct IndexEquals
  18. {
  19. IndexEquals(const T arr) : arr(arr) {}
  20. bool operator()(const size_t a, const size_t b) const
  21. {
  22. return arr[a] == arr[b];
  23. }
  24. const T arr;
  25. };
  26. }
  27. #endif