From: Mathias Anselmann Date: Tue, 18 May 2021 18:40:54 +0000 (+0200) Subject: added copy and move constructors / assignment operators to fix compilation issues... X-Git-Tag: v9.3.0-rc1~8^2~3 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6353b518b2b0918940c8776037f2c0610466d669;p=dealii.git added copy and move constructors / assignment operators to fix compilation issues with gcc 11.1 --- diff --git a/include/deal.II/base/tensor.h b/include/deal.II/base/tensor.h index 2c8f8940f5..d0ab1225be 100644 --- a/include/deal.II/base/tensor.h +++ b/include/deal.II/base/tensor.h @@ -166,6 +166,30 @@ public: constexpr DEAL_II_CUDA_HOST_DEV Tensor(const OtherNumber &initializer); + /** + * Copy constructor + */ + constexpr DEAL_II_CUDA_HOST_DEV + Tensor(const Tensor<0, dim, Number> &other); + + /** + * Copy assignment operator + */ + constexpr DEAL_II_CUDA_HOST_DEV Tensor<0, dim, Number> & + operator=(const Tensor<0, dim, Number> &other); + + /** + * Move constructor + */ + constexpr DEAL_II_CUDA_HOST_DEV + Tensor(Tensor<0, dim, Number> &&other) noexcept; + + /** + * Move assignment operator + */ + constexpr DEAL_II_CUDA_HOST_DEV Tensor<0, dim, Number> & + operator=(Tensor<0, dim, Number> &&other) noexcept; + /** * Return a pointer to the first element of the underlying storage. */ @@ -223,19 +247,6 @@ public: constexpr DEAL_II_CUDA_HOST_DEV Tensor & operator=(const Tensor<0, dim, OtherNumber> &rhs); -#ifdef __INTEL_COMPILER - /** - * Assignment from tensors with same underlying scalar type. - * This is needed for ICC15 because it can't generate a suitable - * copy constructor for Sacado::Rad::ADvar types automatically. - * See https://github.com/dealii/dealii/pull/5865. - * - * @note This function can also be used in CUDA device code. - */ - constexpr DEAL_II_CUDA_HOST_DEV Tensor & - operator=(const Tensor<0, dim, Number> &rhs); -#endif - /** * This operator assigns a scalar to a tensor. This obviously requires * that the @p OtherNumber type is convertible to @p Number. @@ -547,6 +558,28 @@ public: constexpr operator Tensor<1, dim, Tensor>() const; + /** + * Copy constructor + */ + constexpr Tensor(const Tensor &); + + /** + * Copy assignment operator + */ + constexpr Tensor & + operator=(const Tensor &); + + /** + * Move constructor + */ + constexpr Tensor(Tensor &&) noexcept; + + /** + * Move assignment operator + */ + constexpr Tensor & + operator=(Tensor &&) noexcept; + /** * Read-Write access operator. * @@ -886,6 +919,42 @@ constexpr DEAL_II_ALWAYS_INLINE DEAL_II_CUDA_HOST_DEV +template +constexpr DEAL_II_ALWAYS_INLINE DEAL_II_CUDA_HOST_DEV + Tensor<0, dim, Number>::Tensor(const Tensor<0, dim, Number> &other) + : value{other.value} +{} + + + +template +constexpr DEAL_II_ALWAYS_INLINE DEAL_II_CUDA_HOST_DEV Tensor<0, dim, Number> & +Tensor<0, dim, Number>::operator=(const Tensor<0, dim, Number> &other) +{ + value = other.value; + return *this; +} + + + +template +constexpr DEAL_II_ALWAYS_INLINE DEAL_II_CUDA_HOST_DEV + Tensor<0, dim, Number>::Tensor(Tensor<0, dim, Number> &&other) noexcept + : value{std::move(other.value)} +{} + + + +template +constexpr DEAL_II_ALWAYS_INLINE DEAL_II_CUDA_HOST_DEV Tensor<0, dim, Number> & + Tensor<0, dim, Number>::operator=(Tensor<0, dim, Number> &&other) noexcept +{ + value = std::move(other.value); + return *this; +} + + + template inline Number * Tensor<0, dim, Number>::begin_raw() @@ -959,18 +1028,6 @@ constexpr inline DEAL_II_ALWAYS_INLINE } -# ifdef __INTEL_COMPILER -template -constexpr inline DEAL_II_ALWAYS_INLINE - DEAL_II_CUDA_HOST_DEV Tensor<0, dim, Number> & - Tensor<0, dim, Number>::operator=(const Tensor<0, dim, Number> &p) -{ - value = p.value; - return *this; -} -# endif - - template template constexpr inline DEAL_II_ALWAYS_INLINE @@ -1219,6 +1276,44 @@ constexpr DEAL_II_ALWAYS_INLINE Tensor:: } +template +constexpr DEAL_II_ALWAYS_INLINE +Tensor::Tensor(const Tensor &other) +{ + for (unsigned int i = 0; i < dim; ++i) + values[i] = other.values[i]; +} + + +template +constexpr DEAL_II_ALWAYS_INLINE Tensor & +Tensor::operator=(const Tensor &other) +{ + for (unsigned int i = 0; i < dim; ++i) + values[i] = other.values[i]; + return *this; +} + + +template +constexpr DEAL_II_ALWAYS_INLINE +Tensor::Tensor(Tensor &&other) noexcept +{ + for (unsigned int i = 0; i < dim; ++i) + values[i] = other.values[i]; +} + + +template +constexpr DEAL_II_ALWAYS_INLINE Tensor & + Tensor:: + operator=(Tensor &&other) noexcept +{ + for (unsigned int i = 0; i < dim; ++i) + values[i] = other.values[i]; + return *this; +} + namespace internal {