NoAlias.h
Go to the documentation of this file.
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 
13 #include "./InternalHeaderCheck.h"
14 
15 namespace Eigen {
16 
32 template<typename ExpressionType, template <typename> class StorageBase>
33 class NoAlias
34 {
35  public:
36  typedef typename ExpressionType::Scalar Scalar;
37 
39  explicit NoAlias(ExpressionType& expression) : m_expression(expression) {}
40 
41  template<typename OtherDerived>
43  EIGEN_STRONG_INLINE ExpressionType& operator=(const StorageBase<OtherDerived>& other)
44  {
45  call_assignment_no_alias(m_expression, other.derived(), internal::assign_op<Scalar,typename OtherDerived::Scalar>());
46  return m_expression;
47  }
48 
49  template<typename OtherDerived>
51  EIGEN_STRONG_INLINE ExpressionType& operator+=(const StorageBase<OtherDerived>& other)
52  {
53  call_assignment_no_alias(m_expression, other.derived(), internal::add_assign_op<Scalar,typename OtherDerived::Scalar>());
54  return m_expression;
55  }
56 
57  template<typename OtherDerived>
59  EIGEN_STRONG_INLINE ExpressionType& operator-=(const StorageBase<OtherDerived>& other)
60  {
61  call_assignment_no_alias(m_expression, other.derived(), internal::sub_assign_op<Scalar,typename OtherDerived::Scalar>());
62  return m_expression;
63  }
64 
66  ExpressionType& expression() const
67  {
68  return m_expression;
69  }
70 
71  protected:
72  ExpressionType& m_expression;
73 };
74 
103 template<typename Derived>
105 {
106  return NoAlias<Derived, Eigen::MatrixBase >(derived());
107 }
108 
109 } // end namespace Eigen
110 
111 #endif // EIGEN_NOALIAS_H
#define EIGEN_DEVICE_FUNC
Definition: Macros.h:883
NoAlias< Derived, Eigen::MatrixBase > noalias()
Definition: NoAlias.h:104
Pseudo expression providing an operator = assuming no aliasing.
Definition: NoAlias.h:34
ExpressionType & operator+=(const StorageBase< OtherDerived > &other)
Definition: NoAlias.h:51
ExpressionType & operator=(const StorageBase< OtherDerived > &other)
Definition: NoAlias.h:43
ExpressionType::Scalar Scalar
Definition: NoAlias.h:36
NoAlias(ExpressionType &expression)
Definition: NoAlias.h:39
ExpressionType & operator-=(const StorageBase< OtherDerived > &other)
Definition: NoAlias.h:59
ExpressionType & m_expression
Definition: NoAlias.h:72
ExpressionType & expression() const
Definition: NoAlias.h:66
EIGEN_CONSTEXPR void call_assignment_no_alias(Dst &dst, const Src &src, const Func &func)
: InteropHeaders
Definition: Core:139