]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Prefer v.get() to &v[0] with smart pointers.
authorDavid Wells <wellsd2@rpi.edu>
Sun, 8 Oct 2017 19:16:15 +0000 (15:16 -0400)
committerDavid Wells <wellsd2@rpi.edu>
Thu, 12 Oct 2017 19:57:47 +0000 (15:57 -0400)
include/deal.II/lac/chunk_sparse_matrix.templates.h
source/lac/sparsity_pattern.cc

index 18c83e1754eff4830febe24c0ba765be9ac1f86d..26d5e20a3363546a7d57b47057b4789a6618930b 100644 (file)
@@ -1580,9 +1580,9 @@ ChunkSparseMatrix<number>::block_write (std::ostream &out) const
   // first the simple objects, bracketed in [...]
   out << '[' << max_len << "][";
   // then write out real data
-  out.write (reinterpret_cast<const char *>(&val[0]),
-             reinterpret_cast<const char *>(&val[max_len])
-             - reinterpret_cast<const char *>(&val[0]));
+  out.write (reinterpret_cast<const char *>(val.get()),
+             reinterpret_cast<const char *>(val.get() + max_len)
+             - reinterpret_cast<const char *>(val.get()));
   out << ']';
 
   AssertThrow (out, ExcIO());
@@ -1612,9 +1612,9 @@ ChunkSparseMatrix<number>::block_read (std::istream &in)
   val.reset (new number[max_len]);
 
   // then read data
-  in.read (reinterpret_cast<char *>(&val[0]),
-           reinterpret_cast<char *>(&val[max_len])
-           - reinterpret_cast<char *>(&val[0]));
+  in.read (reinterpret_cast<char *>(val.get()),
+           reinterpret_cast<char *>(val.get() + max_len)
+           - reinterpret_cast<char *>(val.get()));
   in >> c;
   AssertThrow (c == ']', ExcIO());
 }
index 6609d8337d43341b65b4660bf25c06b12cb90f61..078c7f781541e03703c0f3e1895f5ac8cbee6574 100644 (file)
@@ -339,7 +339,7 @@ SparsityPattern::reinit (const size_type m,
           ExcInternalError());
 
   // preset the column numbers by a value indicating it is not in use
-  std::fill_n (&colnums[0], vec_len, invalid_entry);
+  std::fill_n (colnums.get(), vec_len, invalid_entry);
 
   // if diagonal elements are special: let the first entry in each row be the
   // diagonal value
@@ -654,7 +654,7 @@ SparsityPattern::operator () (const size_type i,
                                                  &colnums[rowstart[i+1]],
                                                  j);
   if ((p != &colnums[rowstart[i+1]])  &&  (*p == j))
-    return (p - &colnums[0]);
+    return (p - colnums.get());
   else
     return invalid_entry;
 }
@@ -783,8 +783,8 @@ SparsityPattern::matrix_position (const std::size_t global_index) const
   // it is sorted, and since there is an element for the one-past-last row, we
   // can simply use a bisection search on it
   const size_type row
-    = (std::upper_bound (&rowstart[0], &rowstart[rows], global_index)
-       - &rowstart[0] - 1);
+    = (std::upper_bound (rowstart.get(), rowstart.get() + rows, global_index)
+       - rowstart.get() - 1);
 
   // now, the column index is simple since that is what the colnums array
   // stores:
@@ -936,13 +936,13 @@ SparsityPattern::block_write (std::ostream &out) const
       << compressed << ' '
       << store_diagonal_first_in_row << "][";
   // then write out real data
-  out.write (reinterpret_cast<const char *>(&rowstart[0]),
-             reinterpret_cast<const char *>(&rowstart[max_dim+1])
-             - reinterpret_cast<const char *>(&rowstart[0]));
+  out.write (reinterpret_cast<const char *>(rowstart.get()),
+             reinterpret_cast<const char *>(rowstart.get() + max_dim + 1)
+             - reinterpret_cast<const char *>(rowstart.get()));
   out << "][";
-  out.write (reinterpret_cast<const char *>(&colnums[0]),
-             reinterpret_cast<const char *>(&colnums[max_vec_len])
-             - reinterpret_cast<const char *>(&colnums[0]));
+  out.write (reinterpret_cast<const char *>(colnums.get()),
+             reinterpret_cast<const char *>(colnums.get() + max_vec_len)
+             - reinterpret_cast<const char *>(colnums.get()));
   out << ']';
 
   AssertThrow (out, ExcIO());
@@ -978,16 +978,16 @@ SparsityPattern::block_read (std::istream &in)
   colnums.reset (new size_type[max_vec_len]);
 
   // then read data
-  in.read (reinterpret_cast<char *>(&rowstart[0]),
-           reinterpret_cast<char *>(&rowstart[max_dim+1])
-           - reinterpret_cast<char *>(&rowstart[0]));
+  in.read (reinterpret_cast<char *>(rowstart.get()),
+           reinterpret_cast<char *>(rowstart.get() + max_dim + 1)
+           - reinterpret_cast<char *>(rowstart.get()));
   in >> c;
   AssertThrow (c == ']', ExcIO());
   in >> c;
   AssertThrow (c == '[', ExcIO());
-  in.read (reinterpret_cast<char *>(&colnums[0]),
-           reinterpret_cast<char *>(&colnums[max_vec_len])
-           - reinterpret_cast<char *>(&colnums[0]));
+  in.read (reinterpret_cast<char *>(colnums.get()),
+           reinterpret_cast<char *>(colnums.get() + max_vec_len)
+           - reinterpret_cast<char *>(colnums.get()));
   in >> c;
   AssertThrow (c == ']', ExcIO());
 }

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.