opynsim
Unofficial C++ Documentation
Loading...
Searching...
No Matches
matrix.h
Go to the documentation of this file.
1#pragma once
2
3#include <cstddef>
4#include <ostream>
5#include <sstream>
6#include <string>
7#include <string_view>
8#include <tuple>
9#include <utility>
10
11namespace osc
12{
13 // a column-major matrix containing `C` columns and `R` rows of type-`T` values
14 template<typename T, size_t C, size_t R>
15 struct Matrix;
16
17 template<typename T, size_t C, size_t R>
18 std::ostream& operator<<(std::ostream& o, const Matrix<T, C, R>& m)
19 {
20 for (size_t row = 0; row < R; ++row) {
21 std::string_view delimiter;
22 for (size_t column = 0; column < C; ++column) {
23 o << delimiter << m[column][row];
24 delimiter = " ";
25 }
26 o << '\n';
27 }
28 return o;
29 }
30
31 template<typename T, size_t C, size_t R>
32 std::string to_string(const Matrix<T, C, R>& m)
33 {
34 std::stringstream ss;
35 ss << m;
36 return std::move(ss).str();
37 }
38
39 // when handled as a tuple-like object, a `Matrix` decomposes into its column `Vector`s
40
41 template<size_t I, typename T, size_t C, size_t R>
42 constexpr const typename Matrix<T, C, R>::value_type& get(const Matrix<T, C, R>& m) { return m[I]; }
43
44 template<size_t I, typename T, size_t C, size_t R>
45 constexpr typename Matrix<T, C, R>::value_type& get(Matrix<T, C, R>& m) { return m[I]; }
46
47 template<size_t I, typename T, size_t C, size_t R>
48 constexpr typename Matrix<T, C, R>::value_type&& get(Matrix<T, C, R>&& m) { return std::move(m[I]); }
49
50 template<size_t I, typename T, size_t C, size_t R>
51 constexpr const typename Matrix<T, C, R>::value_type&& get(const Matrix<T, C, R>&& m) { return std::move(m[I]); }
52}
53
54template<typename T, size_t C, size_t R>
55struct std::tuple_size<osc::Matrix<T, C, R>> {
56 static constexpr size_t value = C;
57};
58
59template<size_t I, typename T, size_t C, size_t R>
60struct std::tuple_element<I, osc::Matrix<T, C, R>> {
62};
Definition custom_decoration_generator.h:5
std::ostream & operator<<(std::ostream &, const Object &)
constexpr const T & get(const Rgb< T > &v)
Definition rgb.h:88
std::string to_string(const Matrix< T, C, R > &m)
Definition matrix.h:32
constexpr U to(T &&value)
Definition conversion.h:56
Definition matrix.h:15
typename osc::Matrix< T, C, R >::value_type type
Definition matrix.h:61