diff_abs.hpp 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. // Boost.Geometry Index
  2. //
  3. // Abs of difference
  4. //
  5. // Copyright (c) 2011-2013 Adam Wulkiewicz, Lodz, Poland.
  6. //
  7. // Use, modification and distribution is subject to the Boost Software License,
  8. // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  9. // http://www.boost.org/LICENSE_1_0.txt)
  10. #ifndef BOOST_GEOMETRY_INDEX_DETAIL_ALGORITHMS_DIFF_ABS_HPP
  11. #define BOOST_GEOMETRY_INDEX_DETAIL_ALGORITHMS_DIFF_ABS_HPP
  12. namespace boost { namespace geometry { namespace index { namespace detail {
  13. template <typename T>
  14. inline T diff_abs_dispatch(T const& v1, T const& v2, boost::mpl::bool_<true> const& /*is_integral*/)
  15. {
  16. return v1 < v2 ? v2 - v1 : v1 - v2;
  17. }
  18. template <typename T>
  19. inline T diff_abs_dispatch(T const& v1, T const& v2, boost::mpl::bool_<false> const& /*is_integral*/)
  20. {
  21. return ::fabs(v1 - v2);
  22. }
  23. template <typename T>
  24. inline T diff_abs(T const& v1, T const& v2)
  25. {
  26. typedef boost::mpl::bool_<
  27. boost::is_integral<T>::value
  28. > is_integral;
  29. return diff_abs_dispatch(v1, v2, is_integral());
  30. }
  31. }}}} // namespace boost::geometry::index::detail
  32. #endif // BOOST_GEOMETRY_INDEX_DETAIL_ALGORITHMS_DIFF_ABS_HPP