Fix rule-of-3 for the Tensor module.

Adds copy constructors to Tensor ops, inherits assignment operators from
`TensorBase`.

Addresses #1863
This commit is contained in:
Antonio Sanchez
2020-11-12 15:59:29 -08:00
committed by Antonio Sánchez
parent 60218829b7
commit 3669498f5a
14 changed files with 110 additions and 263 deletions

View File

@@ -966,6 +966,7 @@ class TensorBase<Derived, ReadOnlyAccessors>
template<typename Derived, int AccessLevel = internal::accessors_level<Derived>::value>
class TensorBase : public TensorBase<Derived, ReadOnlyAccessors> {
public:
typedef TensorBase<Derived, ReadOnlyAccessors> Base;
typedef internal::traits<Derived> DerivedTraits;
typedef typename DerivedTraits::Scalar Scalar;
typedef typename DerivedTraits::Index Index;
@@ -1146,6 +1147,18 @@ class TensorBase : public TensorBase<Derived, ReadOnlyAccessors> {
}
protected:
EIGEN_DEFAULT_EMPTY_CONSTRUCTOR_AND_DESTRUCTOR(TensorBase)
EIGEN_DEFAULT_COPY_CONSTRUCTOR(TensorBase)
template<typename OtherDerived> EIGEN_DEVICE_FUNC
EIGEN_STRONG_INLINE Derived& operator=(const OtherDerived& other)
{
typedef TensorAssignOp<Derived, const OtherDerived> Assign;
Assign assign(derived(), other.derived());
internal::TensorExecutor<const Assign, DefaultDevice>::run(assign, DefaultDevice());
return derived();
}
EIGEN_DEVICE_FUNC
EIGEN_STRONG_INLINE Derived& derived() { return *static_cast<Derived*>(this); }
EIGEN_DEVICE_FUNC