returntype_deduction.hpp 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. /*
  2. * Copyright (c) 2001-2003 Joel de Guzman
  3. *
  4. * Use, modification and distribution is subject to the Boost Software
  5. * License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  6. * http://www.boost.org/LICENSE_1_0.txt)
  7. */
  8. #ifndef _BOOST_UBLAS_NUMERICTYPE_DEDUCTION_
  9. #define _BOOST_UBLAS_NUMERICTYPE_DEDUCTION_
  10. // See original in boost-sandbox/boost/utility/type_deduction.hpp for comments
  11. #include <boost/mpl/vector/vector20.hpp>
  12. #include <boost/mpl/at.hpp>
  13. #include <boost/mpl/or.hpp>
  14. #include <boost/mpl/identity.hpp>
  15. #include <boost/type_traits/remove_cv.hpp>
  16. #include <boost/type_traits/is_same.hpp>
  17. #include <boost/utility/enable_if.hpp>
  18. namespace boost { namespace numeric { namespace ublas {
  19. struct error_cant_deduce_type {};
  20. namespace type_deduction_detail
  21. {
  22. typedef char(&bool_value_type)[1];
  23. typedef char(&float_value_type)[2];
  24. typedef char(&double_value_type)[3];
  25. typedef char(&long_double_value_type)[4];
  26. typedef char(&char_value_type)[5];
  27. typedef char(&schar_value_type)[6];
  28. typedef char(&uchar_value_type)[7];
  29. typedef char(&short_value_type)[8];
  30. typedef char(&ushort_value_type)[9];
  31. typedef char(&int_value_type)[10];
  32. typedef char(&uint_value_type)[11];
  33. typedef char(&long_value_type)[12];
  34. typedef char(&ulong_value_type)[13];
  35. typedef char(&x_value_type)[14];
  36. typedef char(&y_value_type)[15];
  37. typedef char(&cant_deduce_type)[16];
  38. template <typename T, typename PlainT = typename remove_cv<T>::type>
  39. struct is_basic
  40. : mpl::or_<
  41. typename mpl::or_<
  42. is_same<PlainT, bool>
  43. , is_same<PlainT, float>
  44. , is_same<PlainT, double>
  45. , is_same<PlainT, long double>
  46. > ::type,
  47. typename mpl::or_<
  48. is_same<PlainT, char>
  49. , is_same<PlainT, signed char>
  50. , is_same<PlainT, unsigned char>
  51. , is_same<PlainT, short>
  52. , is_same<PlainT, unsigned short>
  53. > ::type,
  54. typename mpl::or_<
  55. is_same<PlainT, int>
  56. , is_same<PlainT, unsigned int>
  57. , is_same<PlainT, long>
  58. , is_same<PlainT, unsigned long>
  59. > ::type
  60. > {};
  61. struct asymmetric;
  62. template <typename X, typename Y>
  63. cant_deduce_type
  64. test(...); // The black hole !!!
  65. template <typename X, typename Y>
  66. bool_value_type
  67. test(bool const&);
  68. template <typename X, typename Y>
  69. float_value_type
  70. test(float const&);
  71. template <typename X, typename Y>
  72. double_value_type
  73. test(double const&);
  74. template <typename X, typename Y>
  75. long_double_value_type
  76. test(long double const&);
  77. template <typename X, typename Y>
  78. char_value_type
  79. test(char const&);
  80. template <typename X, typename Y>
  81. schar_value_type
  82. test(signed char const&);
  83. template <typename X, typename Y>
  84. uchar_value_type
  85. test(unsigned char const&);
  86. template <typename X, typename Y>
  87. short_value_type
  88. test(short const&);
  89. template <typename X, typename Y>
  90. ushort_value_type
  91. test(unsigned short const&);
  92. template <typename X, typename Y>
  93. int_value_type
  94. test(int const&);
  95. template <typename X, typename Y>
  96. uint_value_type
  97. test(unsigned int const&);
  98. template <typename X, typename Y>
  99. long_value_type
  100. test(long const&);
  101. template <typename X, typename Y>
  102. ulong_value_type
  103. test(unsigned long const&);
  104. template <typename X, typename Y>
  105. typename boost::disable_if<
  106. is_basic<X>, x_value_type
  107. >::type
  108. test(X const&);
  109. template <typename X, typename Y>
  110. typename boost::disable_if<
  111. mpl::or_<
  112. is_basic<Y>
  113. , is_same<Y, asymmetric>
  114. , is_same<const X, const Y>
  115. >
  116. , y_value_type
  117. >::type
  118. test(Y const&);
  119. template <typename X, typename Y>
  120. struct base_result_of
  121. {
  122. typedef typename remove_cv<X>::type x_type;
  123. typedef typename remove_cv<Y>::type y_type;
  124. typedef mpl::vector16<
  125. mpl::identity<bool>
  126. , mpl::identity<float>
  127. , mpl::identity<double>
  128. , mpl::identity<long double>
  129. , mpl::identity<char>
  130. , mpl::identity<signed char>
  131. , mpl::identity<unsigned char>
  132. , mpl::identity<short>
  133. , mpl::identity<unsigned short>
  134. , mpl::identity<int>
  135. , mpl::identity<unsigned int>
  136. , mpl::identity<long>
  137. , mpl::identity<unsigned long>
  138. , mpl::identity<x_type>
  139. , mpl::identity<y_type>
  140. , mpl::identity<error_cant_deduce_type>
  141. >
  142. types;
  143. };
  144. }}} } // namespace boost::numeric::ublas ::type_deduction_detail
  145. #endif