]> https://gitweb.dealii.org/ - dealii.git/commitdiff
AlignedVector: use is_trivially_copyable.
authorDavid Wells <drwells@email.unc.edu>
Sat, 7 Dec 2024 22:07:48 +0000 (17:07 -0500)
committerDavid Wells <drwells@email.unc.edu>
Sat, 7 Dec 2024 23:59:57 +0000 (18:59 -0500)
This is much more precise than std::is_trivial_v<T>.

include/deal.II/base/aligned_vector.h

index 96507769405d6cba7ec4b6c9372dc6f6a44c5ef4..4d031a8e1e5ac6c2334f41d4522fcf4927d53723 100644 (file)
@@ -820,8 +820,8 @@ namespace internal
       if (end == begin)
         return;
 
-      // for classes trivial assignment can use memcpy.
-      if constexpr (std::is_trivial_v<T> == true &&
+      // We can use memcpy() with trivially copyable objects.
+      if constexpr (std::is_trivially_copyable_v<T> == true &&
                     (std::is_same_v<T *, RandomAccessIterator> ||
                      std::is_same_v<const T *, RandomAccessIterator>) == true)
         std::memcpy(destination_ + begin,
@@ -888,8 +888,8 @@ namespace internal
       if (end == begin)
         return;
 
-      // Classes with trivial assignment can use memcpy.
-      if constexpr (std::is_trivial_v<T> == true &&
+      // We can use memcpy() with trivially copyable objects.
+      if constexpr (std::is_trivially_copyable_v<T> == true &&
                     (std::is_same_v<T *, RandomAccessIterator> ||
                      std::is_same_v<const T *, RandomAccessIterator>) == true)
         std::memcpy(destination_ + begin,
@@ -1790,11 +1790,11 @@ AlignedVector<T>::replicate_across_communicator(const MPI_Comm     communicator,
   // has all of the data.
   if (is_shmem_root)
     {
-      if (std::is_trivial_v<T>)
+      if (std::is_trivially_copyable_v<T> == true)
         {
-          // The data is "trivial", i.e., we can copy things directly without
-          // having to go through the serialization/deserialization machinery of
-          // Utilities::MPI::broadcast.
+          // The data is trivially copyable, i.e., we can copy things directly
+          // without having to go through the serialization/deserialization
+          // machinery of Utilities::MPI::broadcast.
           //
           // In that case, first tell all of the other shmem roots how many
           // elements we will have to deal with, and let them resize their
@@ -1983,7 +1983,7 @@ AlignedVector<T>::replicate_across_communicator(const MPI_Comm     communicator,
   // shared memory space.
   if (is_shmem_root)
     {
-      if (std::is_trivial_v<T> == true)
+      if (std::is_trivially_copyable_v<T> == true)
         std::memcpy(aligned_shmem_pointer, elements.get(), sizeof(T) * size());
       else
         for (std::size_t i = 0; i < size(); ++i)

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.