CompareTo.hpp 793 B

1234567891011121314151617181920212223242526272829303132333435
  1. ///
  2. /// \file Util/CompareTo.hpp
  3. ///
  4. /// Utility functions for comparing objects.
  5. ///
  6. /// \copyright
  7. /// Copyright (c) 2014 Josh Blum
  8. /// SPDX-License-Identifier: BSL-1.0
  9. ///
  10. #pragma once
  11. #include <Pothos/Config.hpp>
  12. #include <typeinfo>
  13. #include <string>
  14. namespace Pothos {
  15. namespace Util {
  16. /*!
  17. * Compare two objects and return a integer result.
  18. * The objects being compared require operator==() and operator<().
  19. * \param v0 value on the left hand side of the comparison
  20. * \param v1 value on the right hand side of the comparison
  21. * \return 0 for equal, -1 if v0 < v1, +1 if v0 > v1
  22. */
  23. template <typename T0, typename T1>
  24. int compareTo(const T0 &v0, const T1 &v1)
  25. {
  26. if (v0 == v1) return 0;
  27. if (v0 < v1) return -1;
  28. else return +1;
  29. }
  30. } //namespace Util
  31. } //namespace Pothos