deduce_mat.hpp 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. #ifndef BOOST_QVM_DEDUCE_MAT_HPP_INCLUDED
  2. #define BOOST_QVM_DEDUCE_MAT_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/deduce_scalar.hpp>
  7. #include <boost/qvm/mat_traits.hpp>
  8. #include <boost/qvm/static_assert.hpp>
  9. namespace boost { namespace qvm {
  10. template <class T,int Rows,int Cols>
  11. struct mat;
  12. namespace
  13. qvm_detail
  14. {
  15. template <class M,int R,int C,class S,
  16. int MR=mat_traits<M>::rows,
  17. int MC=mat_traits<M>::cols,
  18. class MS=typename mat_traits<M>::scalar_type>
  19. struct
  20. deduce_m_default
  21. {
  22. BOOST_QVM_STATIC_ASSERT(is_mat<M>::value);
  23. typedef mat<typename mat_traits<M>::scalar_type,R,C> type;
  24. };
  25. template <class M,int R,int C,class S>
  26. struct
  27. deduce_m_default<M,R,C,S,R,C,S>
  28. {
  29. BOOST_QVM_STATIC_ASSERT(is_mat<M>::value);
  30. typedef M type;
  31. };
  32. }
  33. template <class M,int R=mat_traits<M>::rows,int C=mat_traits<M>::cols,class S=typename mat_traits<M>::scalar_type>
  34. struct
  35. deduce_mat
  36. {
  37. BOOST_QVM_STATIC_ASSERT(is_mat<M>::value);
  38. typedef typename qvm_detail::deduce_m_default<M,R,C,S>::type type;
  39. };
  40. namespace
  41. qvm_detail
  42. {
  43. template <class A,class B,int R,int C,class S,
  44. bool IsScalarA=is_scalar<A>::value,
  45. bool IsScalarB=is_scalar<B>::value>
  46. struct
  47. deduce_m2_default
  48. {
  49. typedef mat<S,R,C> type;
  50. };
  51. template <class M,int R,int C,class S>
  52. struct
  53. deduce_m2_default<M,M,R,C,S,false,false>
  54. {
  55. BOOST_QVM_STATIC_ASSERT(is_mat<M>::value);
  56. typedef M type;
  57. };
  58. template <class A,class B,int R,int C,class S>
  59. struct
  60. deduce_m2_default<A,B,R,C,S,false,true>
  61. {
  62. BOOST_QVM_STATIC_ASSERT(is_mat<A>::value);
  63. typedef typename deduce_mat<A,R,C,S>::type type;
  64. };
  65. template <class A,class B,int R,int C,class S>
  66. struct
  67. deduce_m2_default<A,B,R,C,S,true,false>
  68. {
  69. BOOST_QVM_STATIC_ASSERT(is_mat<B>::value);
  70. typedef typename deduce_mat<B,R,C,S>::type type;
  71. };
  72. }
  73. template <class A,class B,int R,int C,class S=typename deduce_scalar_detail::deduce_scalar_impl<typename scalar<A>::type,typename scalar<B>::type>::type>
  74. struct
  75. deduce_mat2
  76. {
  77. BOOST_QVM_STATIC_ASSERT(is_mat<A>::value || is_mat<B>::value);
  78. typedef typename qvm_detail::deduce_m2_default<A,B,R,C,S>::type type;
  79. };
  80. } }
  81. #endif