conversion_traits.hpp 3.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. // (c) Copyright Fernando Luis Cacciola Carballal 2000-2004
  2. // Use, modification, and distribution is subject to the Boost Software
  3. // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  4. // http://www.boost.org/LICENSE_1_0.txt)
  5. // See library home page at http://www.boost.org/libs/numeric/conversion
  6. //
  7. // Contact the author at: fernando_cacciola@hotmail.com
  8. //
  9. #ifndef BOOST_NUMERIC_CONVERSION_DETAIL_CONVERSION_TRAITS_FLC_12NOV2002_HPP
  10. #define BOOST_NUMERIC_CONVERSION_DETAIL_CONVERSION_TRAITS_FLC_12NOV2002_HPP
  11. #include "boost/type_traits/is_arithmetic.hpp"
  12. #include "boost/type_traits/is_same.hpp"
  13. #include "boost/type_traits/remove_cv.hpp"
  14. #include "boost/numeric/conversion/detail/meta.hpp"
  15. #include "boost/numeric/conversion/detail/int_float_mixture.hpp"
  16. #include "boost/numeric/conversion/detail/sign_mixture.hpp"
  17. #include "boost/numeric/conversion/detail/udt_builtin_mixture.hpp"
  18. #include "boost/numeric/conversion/detail/is_subranged.hpp"
  19. namespace boost { namespace numeric { namespace convdetail
  20. {
  21. //-------------------------------------------------------------------
  22. // Implementation of the Conversion Traits for T != S
  23. //
  24. // This is a VISIBLE base class of the user-level conversion_traits<> class.
  25. //-------------------------------------------------------------------
  26. template<class T,class S>
  27. struct non_trivial_traits_impl
  28. {
  29. typedef typename get_int_float_mixture <T,S>::type int_float_mixture ;
  30. typedef typename get_sign_mixture <T,S>::type sign_mixture ;
  31. typedef typename get_udt_builtin_mixture <T,S>::type udt_builtin_mixture ;
  32. typedef typename get_is_subranged<T,S>::type subranged ;
  33. typedef mpl::false_ trivial ;
  34. typedef T target_type ;
  35. typedef S source_type ;
  36. typedef T result_type ;
  37. typedef typename mpl::if_< is_arithmetic<S>, S, S const&>::type argument_type ;
  38. typedef typename mpl::if_<subranged,S,T>::type supertype ;
  39. typedef typename mpl::if_<subranged,T,S>::type subtype ;
  40. } ;
  41. //-------------------------------------------------------------------
  42. // Implementation of the Conversion Traits for T == S
  43. //
  44. // This is a VISIBLE base class of the user-level conversion_traits<> class.
  45. //-------------------------------------------------------------------
  46. template<class N>
  47. struct trivial_traits_impl
  48. {
  49. typedef typename get_int_float_mixture <N,N>::type int_float_mixture ;
  50. typedef typename get_sign_mixture <N,N>::type sign_mixture ;
  51. typedef typename get_udt_builtin_mixture<N,N>::type udt_builtin_mixture ;
  52. typedef mpl::false_ subranged ;
  53. typedef mpl::true_ trivial ;
  54. typedef N target_type ;
  55. typedef N source_type ;
  56. typedef N const& result_type ;
  57. typedef N const& argument_type ;
  58. typedef N supertype ;
  59. typedef N subtype ;
  60. } ;
  61. //-------------------------------------------------------------------
  62. // Top level implementation selector.
  63. //-------------------------------------------------------------------
  64. template<class T, class S>
  65. struct get_conversion_traits
  66. {
  67. typedef typename remove_cv<T>::type target_type ;
  68. typedef typename remove_cv<S>::type source_type ;
  69. typedef typename is_same<target_type,source_type>::type is_trivial ;
  70. typedef trivial_traits_impl <target_type> trivial_imp ;
  71. typedef non_trivial_traits_impl<target_type,source_type> non_trivial_imp ;
  72. typedef typename mpl::if_<is_trivial,trivial_imp,non_trivial_imp>::type type ;
  73. } ;
  74. } } } // namespace boost::numeric::convdetail
  75. #endif