VCCC  2024.05
VisualCamp Common C++ library
matrix_assigner.hpp
Go to the documentation of this file.
1 # /*
2 # * Created by YongGyu Lee on 2020/03/16.
3 # */
4 #
5 # ifndef VCCC_MATH_MATRIX_MATRIXASSIGNER_H
6 # define VCCC_MATH_MATRIX_MATRIXASSIGNER_H
7 #
10 # include <type_traits>
11 # include <string>
12 
13 namespace vccc {
14 
16  public:
17  using alias_safe_t = std::true_type;
18  using alias_unsafe_t = std::false_type;
19 
20  template<typename ExpressionType>
21  static auto create(ExpressionType&& expr) {
22  using traits = internal::math::traits<ExpressionType>;
23  return Matrix<typename traits::value_type, traits::rows, traits::cols>(std::forward<ExpressionType>(expr));
24  }
25 
26  template<typename ExprType, typename DstType>
27  static inline void assign(const MatrixBase<ExprType>& expr, MatrixBase<DstType>& dst) {
28  assignImpl(internal::math::is_alias_safe_t<ExprType>{}, expr, dst.derived());
29  }
30 
31  template<typename ExprType, typename DstType>
32  static inline void assignNocopy(const MatrixBase<ExprType>& expr, MatrixBase<DstType>& dst) {
33  assignImpl(alias_safe_t{}, expr, dst.derived());
34  }
35 
36  private:
37  template<typename ExprType, typename DstType>
38  static void assignImpl(alias_safe_t, const MatrixBase<ExprType>& expr, DstType& dst) {
40  dst(i) = expr(i);
41  }
42 
43  template<typename ExprType, typename DstType>
44  static void assignImpl(alias_unsafe_t, const MatrixBase<ExprType>& expr, DstType& dst) {
45  DstType copy;
47  copy(i) = expr(i);
49  dst(i) = std::move(copy(i));
50  }
51 };
52 
53 } // namespace vccc
54 
55 #endif // VCCC_MATH_MATRIX_MATRIXASSIGNER_H
Definition: matrix_assigner.hpp:15
static void assign(const MatrixBase< ExprType > &expr, MatrixBase< DstType > &dst)
Definition: matrix_assigner.hpp:27
static auto create(ExpressionType &&expr)
Definition: matrix_assigner.hpp:21
std::true_type alias_safe_t
Definition: matrix_assigner.hpp:17
static void assignNocopy(const MatrixBase< ExprType > &expr, MatrixBase< DstType > &dst)
Definition: matrix_assigner.hpp:32
std::false_type alias_unsafe_t
Definition: matrix_assigner.hpp:18
Definition: matrix_base.hpp:20
constexpr const derived_type & derived() const
Definition: matrix_base.hpp:46
A class that represents 2D matrix.
Definition: matrix.hpp:57
constexpr VCCC_INLINE_OR_STATIC detail::copy_niebloid copy
Definition: copy.hpp:69
constexpr VCCC_INLINE_OR_STATIC detail::size_niebloid size
returns the size of a container or array
Definition: size.hpp:145
Definition: directory.h:12