2
0
mirror of https://github.com/boostorg/hana.git synced 2026-01-23 17:42:37 +00:00
Files
hana/example/cppcon_2014/ring.cpp
Louis Dionne f373b421f9 [Headers] Minimize the #includes in headers
- Allow specializing models_impl with a forward declaration only
- Modularize remaining concept headers
- Include <boost/hana.hpp> in unit tests to ease the transition
- Add the core/dispatch.hpp header to reduce the number of boilerplate includes
2015-08-26 11:27:28 -04:00

99 lines
2.3 KiB
C++

/*
@copyright Louis Dionne 2015
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
{
auto a = matrix(
row(1, 2, 3),
row(4, 5, 6)
);
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)
)
));
}
}