VCCC  2024.05
VisualCamp Common C++ library
matrix_minus.hpp
Go to the documentation of this file.
1 # /*
2 # * Created by YongGyu Lee on 2020/02/04.
3 # */
4 #
5 # ifndef VCCC_MATH_MATRIX_MATRIX_MINUS_HPP
6 # define VCCC_MATH_MATRIX_MATRIX_MINUS_HPP
7 #
10 
11 namespace vccc {
12 
13 namespace internal {
14 namespace math {
15 
16 template<typename E>
17 struct traits<MatrixMinus<E>> {
18  enum : int {
19  rows = traits<E>::rows,
20  cols = traits<E>::cols,
21  size = rows * cols,
22  };
23 
24  enum : int {
25  option = traits<E>::option | Flag::kReferenceUnsafe
26  };
27  using value_type = typename E::value_type;
28 };
29 
30 } // namespace math
31 } // namespace internal
32 
35 
36 template<typename E>
37 class MatrixMinus : public MatrixBase<MatrixMinus<E>> {
38  const E& e;
39 
40  public:
41  using lhs_type = internal::math::hold_type_selector_t<E>;
42  using value_type = typename E::value_type;
43 
44  constexpr explicit MatrixMinus(const E& e) : e(e) {}
45 
46  constexpr value_type operator() (std::size_t i) const { return -e(i); }
47  constexpr value_type operator() (std::size_t i, std::size_t j) const { return -e(i, j); }
48  constexpr value_type operator[] (std::size_t i) const { return -e[i]; }
49 };
50 
51 template<typename E>
52 constexpr inline MatrixMinus<E> operator-(const MatrixBase<E>& lhs) {
53  return MatrixMinus<E>(*static_cast<const E*>(&lhs));
54 }
55 
57 
58 } // namespace vccc
59 
60 # endif // VCCC_MATH_MATRIX_MATRIX_MINUS_HPP
Definition: matrix_base.hpp:20
Definition: matrix_minus.hpp:37
constexpr MatrixMinus(const E &e)
Definition: matrix_minus.hpp:44
constexpr value_type operator[](std::size_t i) const
Definition: matrix_minus.hpp:48
internal::math::hold_type_selector_t< E > lhs_type
Definition: matrix_minus.hpp:41
typename E::value_type value_type
Definition: matrix_minus.hpp:42
constexpr value_type operator()(std::size_t i) const
Definition: matrix_minus.hpp:46
constexpr MatrixMinus< E > operator-(const MatrixBase< E > &lhs)
Definition: matrix_minus.hpp:52
Definition: directory.h:12
constexpr auto size(const C &c) -> decltype(c.size())
Definition: size.hpp:16