scalar_traits.hpp 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. #ifndef BOOST_QVM_SCALAR_TRAITS_HPP_INCLUDED
  2. #define BOOST_QVM_SCALAR_TRAITS_HPP_INCLUDED
  3. // Copyright 2008-2022 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/quat_traits.hpp>
  7. #include <boost/qvm/vec_traits.hpp>
  8. #include <boost/qvm/mat_traits.hpp>
  9. #include <boost/qvm/config.hpp>
  10. namespace boost { namespace qvm {
  11. template <class Scalar>
  12. struct
  13. scalar_traits
  14. {
  15. static
  16. BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_CRITICAL
  17. Scalar
  18. value( int v )
  19. {
  20. return Scalar(v);
  21. }
  22. };
  23. namespace
  24. qvm_detail
  25. {
  26. template <class A,
  27. bool IsQ=is_quat<A>::value,
  28. bool IsV=is_vec<A>::value,
  29. bool IsM=is_mat<A>::value,
  30. bool IsS=is_scalar<A>::value>
  31. struct
  32. scalar_impl
  33. {
  34. typedef void type;
  35. };
  36. template <class A>
  37. struct
  38. scalar_impl<A,false,false,false,true>
  39. {
  40. typedef A type;
  41. };
  42. template <class A>
  43. struct
  44. scalar_impl<A,false,false,true,false>
  45. {
  46. typedef typename mat_traits<A>::scalar_type type;
  47. };
  48. template <class A>
  49. struct
  50. scalar_impl<A,false,true,false,false>
  51. {
  52. typedef typename vec_traits<A>::scalar_type type;
  53. };
  54. template <class A>
  55. struct
  56. scalar_impl<A,true,false,false,false>
  57. {
  58. typedef typename quat_traits<A>::scalar_type type;
  59. };
  60. }
  61. template <class A>
  62. struct
  63. scalar
  64. {
  65. typedef typename qvm_detail::scalar_impl<A>::type type;
  66. };
  67. } }
  68. #endif