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 5 #ifndef BOOST_HANA_EXAMPLE_CPPCON_2014_MATRIX_MONOID_HPP 6 #define BOOST_HANA_EXAMPLE_CPPCON_2014_MATRIX_MONOID_HPP 7 8 #include "matrix.hpp" 9 10 #include <boost/hana/integral_constant.hpp> 11 #include <boost/hana/concept/sequence.hpp> 12 #include <boost/hana/concept/monoid.hpp> 13 #include <boost/hana/range.hpp> 14 15 16 namespace boost { namespace hana { 17 template <unsigned R, unsigned C> 18 struct plus_impl<cppcon::Matrix<R, C>, cppcon::Matrix<R, C>> { 19 template <typename M1, typename M2> applyboost::hana::plus_impl20 static constexpr decltype(auto) apply(M1&& m1, M2&& m2) { 21 return element_wise(plus)( 22 std::forward<M1>(m1), 23 std::forward<M2>(m2) 24 ); 25 } 26 }; 27 28 template <unsigned R, unsigned C> 29 struct zero_impl<cppcon::Matrix<R, C>> { applyboost::hana::zero_impl30 static constexpr decltype(auto) apply() { 31 auto zeros = replicate(int_<0>, int_<C>); 32 return unpack(replicate(zeros, int_<R>), cppcon::matrix); 33 } 34 }; 35 }} 36 37 #endif // !BOOST_HANA_EXAMPLE_CPPCON_2014_MATRIX_MONOID_HPP 38