int_float_mixture.hpp 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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_INT_FLOAT_MIXTURE_FLC_12NOV2002_HPP
  10. #define BOOST_NUMERIC_CONVERSION_DETAIL_INT_FLOAT_MIXTURE_FLC_12NOV2002_HPP
  11. #include "boost/config.hpp"
  12. #include "boost/limits.hpp"
  13. #include "boost/numeric/conversion/int_float_mixture_enum.hpp"
  14. #include "boost/numeric/conversion/detail/meta.hpp"
  15. #include "boost/mpl/integral_c.hpp"
  16. namespace boost { namespace numeric { namespace convdetail
  17. {
  18. // Integral Constants for 'IntFloatMixture'
  19. typedef mpl::integral_c<int_float_mixture_enum, integral_to_integral> int2int_c ;
  20. typedef mpl::integral_c<int_float_mixture_enum, integral_to_float> int2float_c ;
  21. typedef mpl::integral_c<int_float_mixture_enum, float_to_integral> float2int_c ;
  22. typedef mpl::integral_c<int_float_mixture_enum, float_to_float> float2float_c ;
  23. // Metafunction:
  24. //
  25. // get_int_float_mixture<T,S>::type
  26. //
  27. // Selects the appropriate Int-Float Mixture Integral Constant for the combination T,S.
  28. //
  29. template<class T,class S>
  30. struct get_int_float_mixture
  31. {
  32. typedef mpl::bool_< ::std::numeric_limits<S>::is_integer > S_int ;
  33. typedef mpl::bool_< ::std::numeric_limits<T>::is_integer > T_int ;
  34. typedef typename
  35. for_both<S_int, T_int, int2int_c, int2float_c, float2int_c, float2float_c>::type
  36. type ;
  37. } ;
  38. // Metafunction:
  39. //
  40. // for_int_float_mixture<Mixture,int_int,int_float,float_int,float_float>::type
  41. //
  42. // {Mixture} is one of the Integral Constants for Mixture, declared above.
  43. // {int_int,int_float,float_int,float_float} are aribtrary types. (not metafunctions)
  44. //
  45. // According to the value of 'IntFloatMixture', selects the corresponding type.
  46. //
  47. template<class IntFloatMixture, class Int2Int, class Int2Float, class Float2Int, class Float2Float>
  48. struct for_int_float_mixture
  49. {
  50. typedef typename
  51. ct_switch4<IntFloatMixture
  52. ,int2int_c, int2float_c, float2int_c // default
  53. ,Int2Int , Int2Float , Float2Int , Float2Float
  54. >::type
  55. type ;
  56. } ;
  57. } } } // namespace boost::numeric::convdetail
  58. #endif
  59. //
  60. ///////////////////////////////////////////////////////////////////////////////////////////////