summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2019-03-18 15:29:48 +0100
committerStanislaw Halik <sthalik@misaki.pl>2019-03-18 16:50:19 +0100
commit46300d64f240343aa02a4ea154817eae59945552 (patch)
tree14913a9a30d12ba61e0eae067a896208732a8a91
parentee2580a056368e2fe5c9e026b3691d2e919c6fe9 (diff)
compat/simple-mat: add tuple destructuring
-rw-r--r--compat/simple-mat.hpp20
1 files changed, 20 insertions, 0 deletions
diff --git a/compat/simple-mat.hpp b/compat/simple-mat.hpp
index d499ee36..01af1c99 100644
--- a/compat/simple-mat.hpp
+++ b/compat/simple-mat.hpp
@@ -8,6 +8,7 @@
#pragma once
+#include <cstddef>
#include <type_traits>
#include <utility>
#include <cmath>
@@ -286,6 +287,12 @@ public:
}
};
+template<unsigned k, typename num, int h, int w>
+constexpr num get(const Mat<num, h, w>& m) { return m(k); }
+
+template<unsigned k, typename num, int h, int w>
+constexpr num& get(Mat<num, h, w>& m) { return m(k); }
+
} // ns simple_mat
template<typename num, int h, int w>
@@ -306,3 +313,16 @@ constexpr Mat<num, H, W> operator*(const Mat<num, H, W>& self, num other)
ret(j, i) = self(j, i) * other;
return ret;
}
+
+namespace std {
+ template<typename num, int H, int W>
+ struct tuple_size<Mat<num, H, W>> :
+ std::integral_constant<std::size_t, H == 1 || W == 1 ? W * H : 0>
+ {};
+
+ template<std::size_t k, typename num, int h, int w>
+ struct tuple_element<k, Mat<num, h, w>>
+ {
+ using type = std::remove_const_t<std::remove_reference_t<num>>;
+ };
+} // ns std