monoid.hpp 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. // Copyright Louis Dionne 2013-2017
  2. // Distributed under the Boost Software License, Version 1.0.
  3. // (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)
  4. #ifndef BOOST_HANA_EXAMPLE_CPPCON_2014_MATRIX_MONOID_HPP
  5. #define BOOST_HANA_EXAMPLE_CPPCON_2014_MATRIX_MONOID_HPP
  6. #include "matrix.hpp"
  7. #include <boost/hana/integral_constant.hpp>
  8. #include <boost/hana/concept/sequence.hpp>
  9. #include <boost/hana/concept/monoid.hpp>
  10. #include <boost/hana/range.hpp>
  11. namespace boost { namespace hana {
  12. template <unsigned R, unsigned C>
  13. struct plus_impl<cppcon::Matrix<R, C>, cppcon::Matrix<R, C>> {
  14. template <typename M1, typename M2>
  15. static constexpr decltype(auto) apply(M1&& m1, M2&& m2) {
  16. return element_wise(plus)(
  17. std::forward<M1>(m1),
  18. std::forward<M2>(m2)
  19. );
  20. }
  21. };
  22. template <unsigned R, unsigned C>
  23. struct zero_impl<cppcon::Matrix<R, C>> {
  24. static constexpr decltype(auto) apply() {
  25. auto zeros = replicate(int_<0>, int_<C>);
  26. return unpack(replicate(zeros, int_<R>), cppcon::matrix);
  27. }
  28. };
  29. }}
  30. #endif // !BOOST_HANA_EXAMPLE_CPPCON_2014_MATRIX_MONOID_HPP