]> https://gitweb.dealii.org/ - dealii.git/commitdiff
added copy and move constructors / assignment operators to fix compilation issues...
authorMathias Anselmann <mathias.anselmann@posteo.de>
Tue, 18 May 2021 18:40:54 +0000 (20:40 +0200)
committerMathias Anselmann <mathias.anselmann@posteo.de>
Thu, 20 May 2021 21:05:45 +0000 (23:05 +0200)
include/deal.II/base/tensor.h

index 2c8f8940f5be5ebe36bfce0f84d9dae856ad94f9..d0ab1225be00dc3f13e791b8c7b5dd4e478bb968 100644 (file)
@@ -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<rank_ - 1, dim, OtherNumber>>() const;
 
+  /**
+   * Copy constructor
+   */
+  constexpr Tensor(const Tensor<rank_, dim, Number> &);
+
+  /**
+   * Copy assignment operator
+   */
+  constexpr Tensor<rank_, dim, Number> &
+  operator=(const Tensor<rank_, dim, Number> &);
+
+  /**
+   * Move constructor
+   */
+  constexpr Tensor(Tensor<rank_, dim, Number> &&) noexcept;
+
+  /**
+   * Move assignment operator
+   */
+  constexpr Tensor<rank_, dim, Number> &
+  operator=(Tensor<rank_, dim, Number> &&) noexcept;
+
   /**
    * Read-Write access operator.
    *
@@ -886,6 +919,42 @@ constexpr DEAL_II_ALWAYS_INLINE DEAL_II_CUDA_HOST_DEV
 
 
 
+template <int dim, typename Number>
+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 <int dim, typename Number>
+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 <int dim, typename Number>
+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 <int dim, typename Number>
+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 <int dim, typename Number>
 inline Number *
 Tensor<0, dim, Number>::begin_raw()
@@ -959,18 +1028,6 @@ constexpr inline DEAL_II_ALWAYS_INLINE
 }
 
 
-#  ifdef __INTEL_COMPILER
-template <int dim, typename Number>
-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 <int dim, typename Number>
 template <typename OtherNumber>
 constexpr inline DEAL_II_ALWAYS_INLINE
@@ -1219,6 +1276,44 @@ constexpr DEAL_II_ALWAYS_INLINE Tensor<rank_, dim, Number>::
 }
 
 
+template <int rank_, int dim, typename Number>
+constexpr DEAL_II_ALWAYS_INLINE
+Tensor<rank_, dim, Number>::Tensor(const Tensor<rank_, dim, Number> &other)
+{
+  for (unsigned int i = 0; i < dim; ++i)
+    values[i] = other.values[i];
+}
+
+
+template <int rank_, int dim, typename Number>
+constexpr DEAL_II_ALWAYS_INLINE Tensor<rank_, dim, Number> &
+Tensor<rank_, dim, Number>::operator=(const Tensor<rank_, dim, Number> &other)
+{
+  for (unsigned int i = 0; i < dim; ++i)
+    values[i] = other.values[i];
+  return *this;
+}
+
+
+template <int rank_, int dim, typename Number>
+constexpr DEAL_II_ALWAYS_INLINE
+Tensor<rank_, dim, Number>::Tensor(Tensor<rank_, dim, Number> &&other) noexcept
+{
+  for (unsigned int i = 0; i < dim; ++i)
+    values[i] = other.values[i];
+}
+
+
+template <int rank_, int dim, typename Number>
+constexpr DEAL_II_ALWAYS_INLINE Tensor<rank_, dim, Number> &
+                                Tensor<rank_, dim, Number>::
+                                operator=(Tensor<rank_, dim, Number> &&other) noexcept
+{
+  for (unsigned int i = 0; i < dim; ++i)
+    values[i] = other.values[i];
+  return *this;
+}
+
 
 namespace internal
 {

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.