Eigen  3.2.10
 
Loading...
Searching...
No Matches
NoAlias.h
1// This file is part of Eigen, a lightweight C++ template library
2// for linear algebra.
3//
4// Copyright (C) 2009 Gael Guennebaud <gael.guennebaud@inria.fr>
5//
6// This Source Code Form is subject to the terms of the Mozilla
7// Public License v. 2.0. If a copy of the MPL was not distributed
8// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
9
10#ifndef EIGEN_NOALIAS_H
11#define EIGEN_NOALIAS_H
12
13namespace Eigen {
14
30template<typename ExpressionType, template <typename> class StorageBase>
31class NoAlias
32{
33 typedef typename ExpressionType::Scalar Scalar;
34 public:
35 NoAlias(ExpressionType& expression) : m_expression(expression) {}
36
39 template<typename OtherDerived>
40 EIGEN_STRONG_INLINE ExpressionType& operator=(const StorageBase<OtherDerived>& other)
41 { return internal::assign_selector<ExpressionType,OtherDerived,false>::run(m_expression,other.derived()); }
42
44 template<typename OtherDerived>
45 EIGEN_STRONG_INLINE ExpressionType& operator+=(const StorageBase<OtherDerived>& other)
46 {
47 typedef SelfCwiseBinaryOp<internal::scalar_sum_op<Scalar>, ExpressionType, OtherDerived> SelfAdder;
48 SelfAdder tmp(m_expression);
49 typedef typename internal::nested<OtherDerived>::type OtherDerivedNested;
50 typedef typename internal::remove_all<OtherDerivedNested>::type _OtherDerivedNested;
51 internal::assign_selector<SelfAdder,_OtherDerivedNested,false>::run(tmp,OtherDerivedNested(other.derived()));
52 return m_expression;
53 }
54
56 template<typename OtherDerived>
57 EIGEN_STRONG_INLINE ExpressionType& operator-=(const StorageBase<OtherDerived>& other)
58 {
59 typedef SelfCwiseBinaryOp<internal::scalar_difference_op<Scalar>, ExpressionType, OtherDerived> SelfAdder;
60 SelfAdder tmp(m_expression);
61 typedef typename internal::nested<OtherDerived>::type OtherDerivedNested;
62 typedef typename internal::remove_all<OtherDerivedNested>::type _OtherDerivedNested;
63 internal::assign_selector<SelfAdder,_OtherDerivedNested,false>::run(tmp,OtherDerivedNested(other.derived()));
64 return m_expression;
65 }
66
67#ifndef EIGEN_PARSED_BY_DOXYGEN
68 template<typename ProductDerived, typename Lhs, typename Rhs>
69 EIGEN_STRONG_INLINE ExpressionType& operator+=(const ProductBase<ProductDerived, Lhs,Rhs>& other)
70 { other.derived().addTo(m_expression); return m_expression; }
71
72 template<typename ProductDerived, typename Lhs, typename Rhs>
73 EIGEN_STRONG_INLINE ExpressionType& operator-=(const ProductBase<ProductDerived, Lhs,Rhs>& other)
74 { other.derived().subTo(m_expression); return m_expression; }
75
76 template<typename Lhs, typename Rhs, int NestingFlags>
77 EIGEN_STRONG_INLINE ExpressionType& operator+=(const CoeffBasedProduct<Lhs,Rhs,NestingFlags>& other)
78 { return m_expression.derived() += CoeffBasedProduct<Lhs,Rhs,NestByRefBit>(other.lhs(), other.rhs()); }
79
80 template<typename Lhs, typename Rhs, int NestingFlags>
81 EIGEN_STRONG_INLINE ExpressionType& operator-=(const CoeffBasedProduct<Lhs,Rhs,NestingFlags>& other)
82 { return m_expression.derived() -= CoeffBasedProduct<Lhs,Rhs,NestByRefBit>(other.lhs(), other.rhs()); }
83
84 template<typename OtherDerived>
85 ExpressionType& operator=(const ReturnByValue<OtherDerived>& func)
86 { return m_expression = func; }
87#endif
88
89 ExpressionType& expression() const
90 {
91 return m_expression;
92 }
93
94 protected:
95 ExpressionType& m_expression;
96};
97
126template<typename Derived>
131
132} // end namespace Eigen
133
134#endif // EIGEN_NOALIAS_H
NoAlias< Derived, Eigen::MatrixBase > noalias()
Definition NoAlias.h:127
Pseudo expression providing an operator = assuming no aliasing.
Definition NoAlias.h:32
ExpressionType & operator=(const StorageBase< OtherDerived > &other)
Definition NoAlias.h:40
ExpressionType & operator-=(const StorageBase< OtherDerived > &other)
Definition NoAlias.h:57
ExpressionType & operator+=(const StorageBase< OtherDerived > &other)
Definition NoAlias.h:45