mat_assign.hpp 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. #ifndef BOOST_QVM_DETAIL_MAT_ASSIGN_HPP_INCLUDED
  2. #define BOOST_QVM_DETAIL_MAT_ASSIGN_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/gen/mat_assign2.hpp>
  7. #include <boost/qvm/gen/mat_assign3.hpp>
  8. #include <boost/qvm/gen/mat_assign4.hpp>
  9. namespace boost { namespace qvm {
  10. namespace
  11. qvm_detail
  12. {
  13. template <int M,int N>
  14. struct
  15. assign_mm_defined
  16. {
  17. static bool const value=false;
  18. };
  19. template <int I,int N>
  20. struct
  21. copy_matrix_elements
  22. {
  23. template <class A,class B>
  24. static
  25. BOOST_QVM_INLINE_CRITICAL
  26. void
  27. f( A & a, B const & b )
  28. {
  29. mat_traits<A>::template write_element<I/mat_traits<A>::cols,I%mat_traits<A>::cols>(a) =
  30. mat_traits<B>::template read_element<I/mat_traits<B>::cols,I%mat_traits<B>::cols>(b);
  31. copy_matrix_elements<I+1,N>::f(a,b);
  32. }
  33. };
  34. template <int N>
  35. struct
  36. copy_matrix_elements<N,N>
  37. {
  38. template <class A,class B>
  39. static
  40. BOOST_QVM_INLINE_CRITICAL
  41. void
  42. f( A &, B const & )
  43. {
  44. }
  45. };
  46. }
  47. template <class A,class B>
  48. BOOST_QVM_INLINE_TRIVIAL
  49. typename enable_if_c<
  50. is_mat<A>::value && is_mat<B>::value &&
  51. mat_traits<A>::rows==mat_traits<B>::rows &&
  52. mat_traits<A>::cols==mat_traits<B>::cols &&
  53. !qvm_detail::assign_mm_defined<mat_traits<A>::rows,mat_traits<A>::cols>::value,
  54. A &>::type
  55. assign( A & a, B const & b )
  56. {
  57. qvm_detail::copy_matrix_elements<0,mat_traits<A>::rows*mat_traits<A>::cols>::f(a,b);
  58. return a;
  59. }
  60. } }
  61. #endif