deduce_vec.hpp 2.4 KB

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