deduce_vec.hpp 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. //Copyright (c) 2008-2016 Emil Dotchevski and Reverge Studios, Inc.
  2. //Distributed under the Boost Software License, Version 1.0. (See accompanying
  3. //file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  4. #ifndef UUID_7E7AB138196311E0907B246CDFD72085
  5. #define UUID_7E7AB138196311E0907B246CDFD72085
  6. #include <boost/qvm/deduce_scalar.hpp>
  7. #include <boost/qvm/vec_traits.hpp>
  8. #include <boost/qvm/static_assert.hpp>
  9. namespace
  10. boost
  11. {
  12. namespace
  13. qvm
  14. {
  15. template <class T,int D>
  16. struct vec;
  17. namespace
  18. qvm_detail
  19. {
  20. template <class V,int D,
  21. int VD=vec_traits<V>::dim>
  22. struct
  23. deduce_vec_default
  24. {
  25. typedef vec<typename vec_traits<V>::scalar_type,D> type;
  26. };
  27. template <class V,int D>
  28. struct
  29. deduce_vec_default<V,D,D>
  30. {
  31. typedef V type;
  32. };
  33. }
  34. template <class V,int Dim=vec_traits<V>::dim>
  35. struct
  36. deduce_vec
  37. {
  38. BOOST_QVM_STATIC_ASSERT(is_vec<V>::value);
  39. typedef typename qvm_detail::deduce_vec_default<V,Dim>::type type;
  40. };
  41. namespace
  42. qvm_detail
  43. {
  44. template <class A,class B,int D,
  45. bool VA=is_vec<A>::value,
  46. bool VB=is_vec<B>::value,
  47. int AD=vec_traits<A>::dim,
  48. int BD=vec_traits<B>::dim>
  49. struct
  50. deduce_v2_default
  51. {
  52. typedef vec<
  53. typename deduce_scalar<
  54. typename scalar<A>::type,
  55. typename scalar<B>::type>::type,
  56. D> type;
  57. };
  58. template <class V,int D>
  59. struct
  60. deduce_v2_default<V,V,D,true,true,D,D>
  61. {
  62. typedef V type;
  63. };
  64. }
  65. template <class A,class B,int D>
  66. struct
  67. deduce_vec2
  68. {
  69. BOOST_QVM_STATIC_ASSERT(is_vec<A>::value || is_vec<B>::value);
  70. typedef typename qvm_detail::deduce_v2_default<A,B,D>::type type;
  71. };
  72. }
  73. }
  74. #endif