deduce_quat.hpp 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. #ifndef BOOST_QVM_DEDUCE_QUAT_HPP_INCLUDED
  2. #define BOOST_QVM_DEDUCE_QUAT_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/quat_traits.hpp>
  8. #include <boost/qvm/static_assert.hpp>
  9. namespace boost { namespace qvm {
  10. template <class T>
  11. struct quat;
  12. namespace
  13. qvm_detail
  14. {
  15. template <class Q,class S,
  16. class QS=typename quat_traits<Q>::scalar_type>
  17. struct
  18. deduce_q_default
  19. {
  20. BOOST_QVM_STATIC_ASSERT(is_quat<Q>::value);
  21. typedef quat<typename quat_traits<Q>::scalar_type> type;
  22. };
  23. template <class Q,class S>
  24. struct
  25. deduce_q_default<Q,S,S>
  26. {
  27. BOOST_QVM_STATIC_ASSERT(is_quat<Q>::value);
  28. typedef Q type;
  29. };
  30. }
  31. template <class Q,class S=typename quat_traits<Q>::scalar_type>
  32. struct
  33. deduce_quat
  34. {
  35. BOOST_QVM_STATIC_ASSERT(is_quat<Q>::value);
  36. typedef typename qvm_detail::deduce_q_default<Q,S>::type type;
  37. };
  38. namespace
  39. qvm_detail
  40. {
  41. template <class A,class B,class S,
  42. bool IsScalarA=is_scalar<A>::value,
  43. bool IsScalarB=is_scalar<B>::value>
  44. struct
  45. deduce_q2_default
  46. {
  47. typedef quat<S> type;
  48. };
  49. template <class Q,class S>
  50. struct
  51. deduce_q2_default<Q,Q,S,false,false>
  52. {
  53. BOOST_QVM_STATIC_ASSERT(is_quat<Q>::value);
  54. typedef Q type;
  55. };
  56. template <class A,class B,class S>
  57. struct
  58. deduce_q2_default<A,B,S,false,true>
  59. {
  60. BOOST_QVM_STATIC_ASSERT(is_quat<A>::value);
  61. typedef typename deduce_quat<A,S>::type type;
  62. };
  63. template <class A,class B,class S>
  64. struct
  65. deduce_q2_default<A,B,S,true,false>
  66. {
  67. BOOST_QVM_STATIC_ASSERT(is_quat<B>::value);
  68. typedef typename deduce_quat<B,S>::type type;
  69. };
  70. }
  71. template <class A,class B,class S=typename deduce_scalar_detail::deduce_scalar_impl<typename scalar<A>::type,typename scalar<B>::type>::type>
  72. struct
  73. deduce_quat2
  74. {
  75. BOOST_QVM_STATIC_ASSERT(is_quat<A>::value || is_quat<B>::value);
  76. typedef typename qvm_detail::deduce_q2_default<A,B,S>::type type;
  77. };
  78. } }
  79. #endif