sign_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_SIGN_MIXTURE_FLC_12NOV2002_HPP
  10. #define BOOST_NUMERIC_CONVERSION_DETAIL_SIGN_MIXTURE_FLC_12NOV2002_HPP
  11. #include "boost/config.hpp"
  12. #include "boost/limits.hpp"
  13. #include "boost/numeric/conversion/sign_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 'SignMixture'
  19. typedef mpl::integral_c<sign_mixture_enum, unsigned_to_unsigned> unsig2unsig_c ;
  20. typedef mpl::integral_c<sign_mixture_enum, signed_to_signed> sig2sig_c ;
  21. typedef mpl::integral_c<sign_mixture_enum, signed_to_unsigned> sig2unsig_c ;
  22. typedef mpl::integral_c<sign_mixture_enum, unsigned_to_signed> unsig2sig_c ;
  23. // Metafunction:
  24. //
  25. // get_sign_mixture<T,S>::type
  26. //
  27. // Selects the appropriate SignMixture Integral Constant for the combination T,S.
  28. //
  29. template<class T,class S>
  30. struct get_sign_mixture
  31. {
  32. typedef mpl::bool_< ::std::numeric_limits<S>::is_signed > S_signed ;
  33. typedef mpl::bool_< ::std::numeric_limits<T>::is_signed > T_signed ;
  34. typedef typename
  35. for_both<S_signed, T_signed, sig2sig_c, sig2unsig_c, unsig2sig_c, unsig2unsig_c>::type
  36. type ;
  37. } ;
  38. // Metafunction:
  39. //
  40. // for_sign_mixture<SignMixture,Sig2Sig,Sig2Unsig,Unsig2Sig,Unsig2Unsig>::type
  41. //
  42. // {SignMixture} is one of the Integral Constants for SignMixture, declared above.
  43. // {Sig2Sig,Sig2Unsig,Unsig2Sig,Unsig2Unsig} are aribtrary types. (not metafunctions)
  44. //
  45. // According to the value of 'SignMixture', selects the corresponding type.
  46. //
  47. template<class SignMixture, class Sig2Sig, class Sig2Unsig, class Unsig2Sig, class Unsig2Unsig>
  48. struct for_sign_mixture
  49. {
  50. typedef typename
  51. ct_switch4<SignMixture
  52. , sig2sig_c, sig2unsig_c, unsig2sig_c // default
  53. , Sig2Sig , Sig2Unsig , Unsig2Sig , Unsig2Unsig
  54. >::type
  55. type ;
  56. } ;
  57. } } } // namespace boost::numeric::convdetail
  58. #endif
  59. //
  60. ///////////////////////////////////////////////////////////////////////////////////////////////