udt_builtin_mixture.hpp 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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_UDT_BUILTIN_MIXTURE_FLC_12NOV2002_HPP
  10. #define BOOST_NUMERIC_CONVERSION_DETAIL_UDT_BUILTIN_MIXTURE_FLC_12NOV2002_HPP
  11. #include "boost/type_traits/is_arithmetic.hpp"
  12. #include "boost/numeric/conversion/udt_builtin_mixture_enum.hpp"
  13. #include "boost/numeric/conversion/detail/meta.hpp"
  14. #include "boost/mpl/integral_c.hpp"
  15. namespace boost { namespace numeric { namespace convdetail
  16. {
  17. // Integral Constants for 'UdtMixture'
  18. typedef mpl::integral_c<udt_builtin_mixture_enum, builtin_to_builtin> builtin2builtin_c ;
  19. typedef mpl::integral_c<udt_builtin_mixture_enum, builtin_to_udt> builtin2udt_c ;
  20. typedef mpl::integral_c<udt_builtin_mixture_enum, udt_to_builtin> udt2builtin_c ;
  21. typedef mpl::integral_c<udt_builtin_mixture_enum, udt_to_udt> udt2udt_c ;
  22. // Metafunction:
  23. //
  24. // for_udt_mixture<UdtMixture,BuiltIn2BuiltIn,BuiltIn2Udt,Udt2BuiltIn,Udt2Udt>::type
  25. //
  26. // {UdtMixture} is one of the Integral Constants for UdMixture, declared above.
  27. // {BuiltIn2BuiltIn,BuiltIn2Udt,Udt2BuiltIn,Udt2Udt} are aribtrary types. (not metafunctions)
  28. //
  29. // According to the value of 'UdtMixture', selects the corresponding type.
  30. //
  31. template<class UdtMixture, class BuiltIn2BuiltIn, class BuiltIn2Udt, class Udt2BuiltIn, class Udt2Udt>
  32. struct for_udt_builtin_mixture
  33. {
  34. typedef typename
  35. ct_switch4<UdtMixture
  36. , builtin2builtin_c, builtin2udt_c, udt2builtin_c // default
  37. , BuiltIn2BuiltIn , BuiltIn2Udt , Udt2BuiltIn , Udt2Udt
  38. >::type
  39. type ;
  40. } ;
  41. // Metafunction:
  42. //
  43. // get_udt_mixture<T,S>::type
  44. //
  45. // Selects the appropriate UdtMixture Integral Constant for the combination T,S.
  46. //
  47. template<class T,class S>
  48. struct get_udt_builtin_mixture
  49. {
  50. typedef is_arithmetic<S> S_builtin ;
  51. typedef is_arithmetic<T> T_builtin ;
  52. typedef typename
  53. for_both<S_builtin, T_builtin, builtin2builtin_c, builtin2udt_c, udt2builtin_c, udt2udt_c>::type
  54. type ;
  55. } ;
  56. } } } // namespace boost::numeric::convdetail
  57. #endif