numeric_cast.hpp 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. // Boost.Geometry
  2. // Copyright (c) 2024 Barend Gehrels, Amsterdam, the Netherlands.
  3. // Use, modification and distribution is subject to the Boost Software License,
  4. // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  5. // http://www.boost.org/LICENSE_1_0.txt)
  6. #ifndef BOOST_GEOMETRY_UTIL_NUMERIC_CAST_HPP
  7. #define BOOST_GEOMETRY_UTIL_NUMERIC_CAST_HPP
  8. #include <boost/numeric/conversion/cast.hpp>
  9. namespace boost { namespace geometry { namespace util
  10. {
  11. #ifndef DOXYGEN_NO_DETAIL
  12. namespace detail
  13. {
  14. /// brief calls numeric cast
  15. template <typename Target, typename Source>
  16. struct numeric_caster
  17. {
  18. static inline Target apply(Source const& source)
  19. {
  20. return boost::numeric_cast<Target>(source);
  21. }
  22. };
  23. } // namespace detail
  24. #endif
  25. // Calls either boost::numeric_cast, or functionality specific for Boost.Geometry
  26. // (such as rational_cast for Boost.Rational)
  27. template <typename Target, typename Source>
  28. inline Target numeric_cast(Source const& source)
  29. {
  30. return detail::numeric_caster<Target, Source>::apply(source);
  31. }
  32. }}} // namespace boost::geometry::util
  33. #endif // BOOST_GEOMETRY_UTIL_NUMERIC_CAST_HPP