deduce_scalar.hpp 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. #ifndef BOOST_QVM_DEDUCE_SCALAR_HPP_INCLUDED
  2. #define BOOST_QVM_DEDUCE_SCALAR_HPP_INCLUDED
  3. /// Copyright (c) 2008-2021 Emil Dotchevski and Reverge Studios, Inc.
  4. /// Distributed under the Boost Software License, Version 1.0. (See accompanying
  5. /// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  6. #include <boost/qvm/scalar_traits.hpp>
  7. #include <boost/qvm/static_assert.hpp>
  8. namespace boost { namespace qvm {
  9. namespace
  10. deduce_scalar_detail
  11. {
  12. template <class A,class B>
  13. struct
  14. deduce_scalar_impl
  15. {
  16. typedef void type;
  17. };
  18. template <class T>
  19. struct
  20. deduce_scalar_impl<T,T>
  21. {
  22. typedef T type;
  23. };
  24. template <> struct deduce_scalar_impl<signed char,unsigned char> { typedef unsigned char type; };
  25. template <> struct deduce_scalar_impl<signed char,unsigned short> { typedef unsigned short type; };
  26. template <> struct deduce_scalar_impl<signed char,unsigned int> { typedef unsigned int type; };
  27. template <> struct deduce_scalar_impl<signed char,unsigned long> { typedef unsigned long type; };
  28. template <> struct deduce_scalar_impl<signed char,signed short> { typedef signed short type; };
  29. template <> struct deduce_scalar_impl<signed char,signed int> { typedef signed int type; };
  30. template <> struct deduce_scalar_impl<signed char,signed long> { typedef signed long type; };
  31. template <> struct deduce_scalar_impl<signed char,float> { typedef float type; };
  32. template <> struct deduce_scalar_impl<signed char,double> { typedef double type; };
  33. template <> struct deduce_scalar_impl<unsigned char,unsigned short> { typedef unsigned short type; };
  34. template <> struct deduce_scalar_impl<unsigned char,unsigned int> { typedef unsigned int type; };
  35. template <> struct deduce_scalar_impl<unsigned char,unsigned long> { typedef unsigned long type; };
  36. template <> struct deduce_scalar_impl<unsigned char,signed short> { typedef signed short type; };
  37. template <> struct deduce_scalar_impl<unsigned char,signed int> { typedef signed int type; };
  38. template <> struct deduce_scalar_impl<unsigned char,signed long> { typedef signed long type; };
  39. template <> struct deduce_scalar_impl<unsigned char,float> { typedef float type; };
  40. template <> struct deduce_scalar_impl<unsigned char,double> { typedef double type; };
  41. template <> struct deduce_scalar_impl<signed short,unsigned short> { typedef unsigned short type; };
  42. template <> struct deduce_scalar_impl<signed short,unsigned int> { typedef unsigned int type; };
  43. template <> struct deduce_scalar_impl<signed short,unsigned long> { typedef unsigned long type; };
  44. template <> struct deduce_scalar_impl<signed short,signed int> { typedef signed int type; };
  45. template <> struct deduce_scalar_impl<signed short,signed long> { typedef signed long type; };
  46. template <> struct deduce_scalar_impl<signed short,float> { typedef float type; };
  47. template <> struct deduce_scalar_impl<signed short,double> { typedef double type; };
  48. template <> struct deduce_scalar_impl<unsigned short,unsigned int> { typedef unsigned int type; };
  49. template <> struct deduce_scalar_impl<unsigned short,unsigned long> { typedef unsigned long type; };
  50. template <> struct deduce_scalar_impl<unsigned short,signed int> { typedef signed int type; };
  51. template <> struct deduce_scalar_impl<unsigned short,signed long> { typedef signed long type; };
  52. template <> struct deduce_scalar_impl<unsigned short,float> { typedef float type; };
  53. template <> struct deduce_scalar_impl<unsigned short,double> { typedef double type; };
  54. template <> struct deduce_scalar_impl<signed int,unsigned int> { typedef unsigned int type; };
  55. template <> struct deduce_scalar_impl<signed int,unsigned long> { typedef unsigned long type; };
  56. template <> struct deduce_scalar_impl<signed int,signed long> { typedef signed long type; };
  57. template <> struct deduce_scalar_impl<signed int,float> { typedef float type; };
  58. template <> struct deduce_scalar_impl<signed int,double> { typedef double type; };
  59. template <> struct deduce_scalar_impl<unsigned int,unsigned long> { typedef unsigned long type; };
  60. template <> struct deduce_scalar_impl<unsigned int,signed long> { typedef signed long type; };
  61. template <> struct deduce_scalar_impl<unsigned int,float> { typedef float type; };
  62. template <> struct deduce_scalar_impl<unsigned int,double> { typedef double type; };
  63. template <> struct deduce_scalar_impl<signed long,unsigned long> { typedef unsigned long type; };
  64. template <> struct deduce_scalar_impl<signed long,float> { typedef float type; };
  65. template <> struct deduce_scalar_impl<signed long,double> { typedef double type; };
  66. template <> struct deduce_scalar_impl<unsigned long,float> { typedef float type; };
  67. template <> struct deduce_scalar_impl<unsigned long,double> { typedef double type; };
  68. template <> struct deduce_scalar_impl<float,double> { typedef double type; };
  69. template <> struct deduce_scalar_impl<unsigned char,signed char> { typedef unsigned char type; };
  70. template <> struct deduce_scalar_impl<unsigned short,signed char> { typedef unsigned short type; };
  71. template <> struct deduce_scalar_impl<unsigned int,signed char> { typedef unsigned int type; };
  72. template <> struct deduce_scalar_impl<unsigned long,signed char> { typedef unsigned long type; };
  73. template <> struct deduce_scalar_impl<signed short,signed char> { typedef signed short type; };
  74. template <> struct deduce_scalar_impl<signed int,signed char> { typedef signed int type; };
  75. template <> struct deduce_scalar_impl<signed long,signed char> { typedef signed long type; };
  76. template <> struct deduce_scalar_impl<float,signed char> { typedef float type; };
  77. template <> struct deduce_scalar_impl<double,signed char> { typedef double type; };
  78. template <> struct deduce_scalar_impl<unsigned short,unsigned char> { typedef unsigned short type; };
  79. template <> struct deduce_scalar_impl<unsigned int,unsigned char> { typedef unsigned int type; };
  80. template <> struct deduce_scalar_impl<unsigned long,unsigned char> { typedef unsigned long type; };
  81. template <> struct deduce_scalar_impl<signed short,unsigned char> { typedef signed short type; };
  82. template <> struct deduce_scalar_impl<signed int,unsigned char> { typedef signed int type; };
  83. template <> struct deduce_scalar_impl<signed long,unsigned char> { typedef signed long type; };
  84. template <> struct deduce_scalar_impl<float,unsigned char> { typedef float type; };
  85. template <> struct deduce_scalar_impl<double,unsigned char> { typedef double type; };
  86. template <> struct deduce_scalar_impl<unsigned short,signed short> { typedef unsigned short type; };
  87. template <> struct deduce_scalar_impl<unsigned int,signed short> { typedef unsigned int type; };
  88. template <> struct deduce_scalar_impl<unsigned long,signed short> { typedef unsigned long type; };
  89. template <> struct deduce_scalar_impl<signed int,signed short> { typedef signed int type; };
  90. template <> struct deduce_scalar_impl<signed long,signed short> { typedef signed long type; };
  91. template <> struct deduce_scalar_impl<float,signed short> { typedef float type; };
  92. template <> struct deduce_scalar_impl<double,signed short> { typedef double type; };
  93. template <> struct deduce_scalar_impl<unsigned int,unsigned short> { typedef unsigned int type; };
  94. template <> struct deduce_scalar_impl<unsigned long,unsigned short> { typedef unsigned long type; };
  95. template <> struct deduce_scalar_impl<signed int,unsigned short> { typedef signed int type; };
  96. template <> struct deduce_scalar_impl<signed long,unsigned short> { typedef signed long type; };
  97. template <> struct deduce_scalar_impl<float,unsigned short> { typedef float type; };
  98. template <> struct deduce_scalar_impl<double,unsigned short> { typedef double type; };
  99. template <> struct deduce_scalar_impl<unsigned int,signed int> { typedef unsigned int type; };
  100. template <> struct deduce_scalar_impl<unsigned long,signed int> { typedef unsigned long type; };
  101. template <> struct deduce_scalar_impl<signed long,signed int> { typedef signed long type; };
  102. template <> struct deduce_scalar_impl<float,signed int> { typedef float type; };
  103. template <> struct deduce_scalar_impl<double,signed int> { typedef double type; };
  104. template <> struct deduce_scalar_impl<unsigned long,unsigned int> { typedef unsigned long type; };
  105. template <> struct deduce_scalar_impl<signed long,unsigned int> { typedef signed long type; };
  106. template <> struct deduce_scalar_impl<float,unsigned int> { typedef float type; };
  107. template <> struct deduce_scalar_impl<double,unsigned int> { typedef double type; };
  108. template <> struct deduce_scalar_impl<unsigned long,signed long> { typedef unsigned long type; };
  109. template <> struct deduce_scalar_impl<float,signed long> { typedef float type; };
  110. template <> struct deduce_scalar_impl<double,signed long> { typedef double type; };
  111. template <> struct deduce_scalar_impl<float,unsigned long> { typedef float type; };
  112. template <> struct deduce_scalar_impl<double,unsigned long> { typedef double type; };
  113. template <> struct deduce_scalar_impl<double,float> { typedef double type; };
  114. }
  115. template <class A,class B>
  116. struct
  117. deduce_scalar
  118. {
  119. BOOST_QVM_STATIC_ASSERT(is_scalar<A>::value);
  120. BOOST_QVM_STATIC_ASSERT(is_scalar<B>::value);
  121. typedef typename deduce_scalar_detail::deduce_scalar_impl<A,B>::type type;
  122. };
  123. } }
  124. #endif