iconv.hpp 1003 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. // Copyright (c) 2009 John Maddock
  2. // Use, modification and distribution are subject to the
  3. // Boost Software License, Version 1.0. (See accompanying file
  4. // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  5. #ifndef BOOST_MATH_ICONV_HPP
  6. #define BOOST_MATH_ICONV_HPP
  7. #ifdef _MSC_VER
  8. #pragma once
  9. #endif
  10. #include <boost/math/special_functions/round.hpp>
  11. #include <boost/type_traits/is_convertible.hpp>
  12. namespace boost { namespace math { namespace detail{
  13. template <class T, class Policy>
  14. inline int iconv_imp(T v, Policy const&, std::true_type const&)
  15. {
  16. return static_cast<int>(v);
  17. }
  18. template <class T, class Policy>
  19. inline int iconv_imp(T v, Policy const& pol, std::false_type const&)
  20. {
  21. BOOST_MATH_STD_USING
  22. return iround(v, pol);
  23. }
  24. template <class T, class Policy>
  25. inline int iconv(T v, Policy const& pol)
  26. {
  27. typedef typename std::is_convertible<T, int>::type tag_type;
  28. return iconv_imp(v, pol, tag_type());
  29. }
  30. }}} // namespaces
  31. #endif // BOOST_MATH_ICONV_HPP