summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNao Pross <naopross@thearcway.org>2019-10-10 01:29:36 +0200
committerNao Pross <naopross@thearcway.org>2019-10-10 01:29:36 +0200
commit56a88731ddb686822af7cdc425761a90fac618ff (patch)
tree7b480eb44fcc6f11641d6715100df6c7bf5c123c
parentUpdate access model for operator| (diff)
downloadlibmm-56a88731ddb686822af7cdc425761a90fac618ff.tar.gz
libmm-56a88731ddb686822af7cdc425761a90fac618ff.zip
Fix indentation
-rw-r--r--include/mm/view.hpp199
1 files changed, 99 insertions, 100 deletions
diff --git a/include/mm/view.hpp b/include/mm/view.hpp
index e701a78..fbbf365 100644
--- a/include/mm/view.hpp
+++ b/include/mm/view.hpp
@@ -9,104 +9,103 @@
namespace mm {
-
- namespace algorithm {
- // does nothing
- struct visit
- {
- visit() = default;
-
- template<typename Matrix>
- void operator()(Matrix& m) {}
- };
-
- struct transpose : public visit
- {
- /// does not work with non-square matrices
- template<typename Matrix>
- void operator()(Matrix& m) {
- static_assert(Matrix::rows == Matrix::cols);
- // naiive impl
- for (index r = 0; r < m.rows / 2; r++)
- for (index c = 0; c < m.cols; c++)
- if (c != r)
- std::swap(m.at(r, c), m.at(c, r));
- }
- };
-
- /// algorithm aliases
- using tr = transpose;
- }
-
- /// namespace alias
- namespace alg = algorithm;
-
- template<typename Matrix>
- struct clone
- {
- Matrix matrix;
-
- explicit clone(Matrix&& m) : matrix(m) {}
- explicit clone(const Matrix& m) : matrix(m) {}
-
- operator Matrix() {
- return std::move(matrix);
- }
- };
-
- template<typename Matrix, typename ...Algs>
- struct mutate
- {
- Matrix& matrix;
- std::tuple<Algs...> visitors;
-
- explicit mutate(Matrix& m) : matrix(m) {}
-
- template<typename ...OAlgs, typename Alg>
- explicit mutate(Matrix& m, std::tuple<OAlgs...>&& t, Alg&& v)
- : matrix(m)
- {
- /// append the new operator
- visitors = std::tuple_cat(t, std::make_tuple(v));
- }
-
- ~mutate() {
- visit();
- }
-
- void visit() {
- std::apply([this](auto&&... v) {
- (v(matrix),...);
- }, visitors);
- }
-
- operator Matrix() {
- return std::move(matrix);
- }
- };
-
- template<typename Matrix, typename Alg>
- clone<Matrix> operator|(clone<Matrix>&& cl, Alg&& v) {
- static_assert(std::is_convertible<Alg, alg::visit>::value);
- /// apply alg operator
- v(cl.matrix);
- /// forward to next alg
- return clone<Matrix>(std::move(cl));
- }
-
- template<typename Matrix, typename ...Algs, typename Alg>
- mutate<Matrix, Algs..., Alg> operator|(mutate<Matrix, Algs...>&& mut, Alg&& v) {
- static_assert(std::is_convertible<Alg, alg::visit>::value);
- /// append alg to the visitors tuple
- return mutate<Matrix, Algs..., Alg>(
- mut.matrix,
- std::move(mut.visitors),
- v
- );
- }
-
- template<typename Matrix, typename Alg>
- mutate<Matrix, Alg> operator|(Matrix& m, Alg&& v) {
- return mutate(m) | std::move(v);
- }
+ namespace algorithm {
+ // does nothing
+ struct visit
+ {
+ visit() = default;
+
+ template<typename Matrix>
+ void operator()(Matrix& m) {}
+ };
+
+ struct transpose : public visit
+ {
+ /// does not work with non-square matrices
+ template<typename Matrix>
+ void operator()(Matrix& m) {
+ static_assert(Matrix::rows == Matrix::cols);
+ // naiive impl
+ for (index r = 0; r < m.rows / 2; r++)
+ for (index c = 0; c < m.cols; c++)
+ if (c != r)
+ std::swap(m.at(r, c), m.at(c, r));
+ }
+ };
+
+ /// algorithm aliases
+ using tr = transpose;
+ }
+
+ /// namespace alias
+ namespace alg = algorithm;
+
+ template<typename Matrix>
+ struct clone
+ {
+ Matrix matrix;
+
+ explicit clone(Matrix&& m) : matrix(m) {}
+ explicit clone(const Matrix& m) : matrix(m) {}
+
+ operator Matrix() {
+ return std::move(matrix);
+ }
+ };
+
+ template<typename Matrix, typename ...Algs>
+ struct mutate
+ {
+ Matrix& matrix;
+ std::tuple<Algs...> visitors;
+
+ explicit mutate(Matrix& m) : matrix(m) {}
+
+ template<typename ...OAlgs, typename Alg>
+ explicit mutate(Matrix& m, std::tuple<OAlgs...>&& t, Alg&& v)
+ : matrix(m)
+ {
+ /// append the new operator
+ visitors = std::tuple_cat(t, std::make_tuple(v));
+ }
+
+ ~mutate() {
+ visit();
+ }
+
+ void visit() {
+ std::apply([this](auto&&... v) {
+ (v(matrix),...);
+ }, visitors);
+ }
+
+ operator Matrix() {
+ return std::move(matrix);
+ }
+ };
+
+ template<typename Matrix, typename Alg>
+ clone<Matrix> operator|(clone<Matrix>&& cl, Alg&& v) {
+ static_assert(std::is_convertible<Alg, alg::visit>::value);
+ /// apply alg operator
+ v(cl.matrix);
+ /// forward to next alg
+ return clone<Matrix>(std::move(cl));
+ }
+
+ template<typename Matrix, typename ...Algs, typename Alg>
+ mutate<Matrix, Algs..., Alg> operator|(mutate<Matrix, Algs...>&& mut, Alg&& v) {
+ static_assert(std::is_convertible<Alg, alg::visit>::value);
+ /// append alg to the visitors tuple
+ return mutate<Matrix, Algs..., Alg>(
+ mut.matrix,
+ std::move(mut.visitors),
+ v
+ );
+ }
+
+ template<typename Matrix, typename Alg>
+ mutate<Matrix, Alg> operator|(Matrix& m, Alg&& v) {
+ return mutate(m) | std::move(v);
+ }
}