summaryrefslogtreecommitdiffstats
path: root/src/boost/libs/hana/example/cppcon_2014/ring.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/boost/libs/hana/example/cppcon_2014/ring.cpp')
-rw-r--r--src/boost/libs/hana/example/cppcon_2014/ring.cpp96
1 files changed, 96 insertions, 0 deletions
diff --git a/src/boost/libs/hana/example/cppcon_2014/ring.cpp b/src/boost/libs/hana/example/cppcon_2014/ring.cpp
new file mode 100644
index 000000000..9d06400de
--- /dev/null
+++ b/src/boost/libs/hana/example/cppcon_2014/ring.cpp
@@ -0,0 +1,96 @@
+// Copyright Louis Dionne 2013-2017
+// Distributed under the Boost Software License, Version 1.0.
+// (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)
+
+#include <boost/hana/assert.hpp>
+#include <boost/hana/equal.hpp>
+#include <boost/hana/mult.hpp>
+#include <boost/hana/one.hpp>
+
+#include "matrix/comparable.hpp"
+#include "matrix/ring.hpp"
+namespace hana = boost::hana;
+using namespace cppcon;
+
+
+int main() {
+ // mult
+ {
+ BOOST_HANA_CONSTEXPR_LAMBDA auto a = matrix(
+ row(1, 2, 3),
+ row(4, 5, 6)
+ );
+
+ BOOST_HANA_CONSTEXPR_LAMBDA auto b = matrix(
+ row(1, 2),
+ row(3, 4),
+ row(5, 6)
+ );
+
+ BOOST_HANA_CONSTEXPR_CHECK(hana::equal(
+ hana::mult(a, b),
+ matrix(
+ row(1*1 + 2*3 + 5*3, 1*2 + 2*4 + 3*6),
+ row(4*1 + 3*5 + 5*6, 4*2 + 5*4 + 6*6)
+ )
+ ));
+ }
+
+ // one
+ {
+ BOOST_HANA_CONSTEXPR_CHECK(hana::equal(
+ hana::one<Matrix<1, 1>>(),
+ matrix(
+ row(1)
+ )
+ ));
+
+ BOOST_HANA_CONSTEXPR_CHECK(hana::equal(
+ hana::one<Matrix<2, 2>>(),
+ matrix(
+ row(1, 0),
+ row(0, 1)
+ )
+ ));
+
+ BOOST_HANA_CONSTEXPR_CHECK(hana::equal(
+ hana::one<Matrix<3, 3>>(),
+ matrix(
+ row(1, 0, 0),
+ row(0, 1, 0),
+ row(0, 0, 1)
+ )
+ ));
+
+ BOOST_HANA_CONSTEXPR_CHECK(hana::equal(
+ hana::one<Matrix<4, 4>>(),
+ matrix(
+ row(1, 0, 0, 0),
+ row(0, 1, 0, 0),
+ row(0, 0, 1, 0),
+ row(0, 0, 0, 1)
+ )
+ ));
+
+ BOOST_HANA_CONSTEXPR_CHECK(hana::equal(
+ hana::one<Matrix<4, 5>>(),
+ matrix(
+ row(1, 0, 0, 0, 0),
+ row(0, 1, 0, 0, 0),
+ row(0, 0, 1, 0, 0),
+ row(0, 0, 0, 1, 0)
+ )
+ ));
+
+ BOOST_HANA_CONSTEXPR_CHECK(hana::equal(
+ hana::one<Matrix<5, 4>>(),
+ matrix(
+ row(1, 0, 0, 0),
+ row(0, 1, 0, 0),
+ row(0, 0, 1, 0),
+ row(0, 0, 0, 1),
+ row(0, 0, 0, 0)
+ )
+ ));
+ }
+}