]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Use make_unique/shared in base
authorDaniel Arndt <daniel.arndt@iwr.uni-heidelberg.de>
Sat, 10 Feb 2018 14:18:07 +0000 (15:18 +0100)
committerDaniel Arndt <daniel.arndt@iwr.uni-heidelberg.de>
Thu, 15 Feb 2018 21:00:31 +0000 (22:00 +0100)
include/deal.II/base/mg_level_object.h
include/deal.II/base/parallel.h
include/deal.II/base/parameter_handler.h
include/deal.II/base/polynomial.h
include/deal.II/base/thread_management.h
source/base/logstream.cc
source/base/parameter_handler.cc
source/base/patterns.cc
source/base/polynomial.cc
source/base/quadrature.cc

index 68799ba890a2c687338c3e12cae8eebd74e6a4cb..feb0f95b01b430d9026a405311db829c8bacefca 100644 (file)
@@ -215,7 +215,7 @@ MGLevelObject<Object>::resize (const unsigned int new_minlevel,
 
   minlevel = new_minlevel;
   for (unsigned int i=0; i<new_maxlevel-new_minlevel+1; ++i)
-    objects.push_back(std::shared_ptr<Object> (new Object));
+    objects.push_back(std::make_shared<Object> ());
 }
 
 
index 75102edd491374b3e88a828c079c744ee8119b92..ad3e37e36cf8f3836114968f06c6fa32c1560ee9 100644 (file)
@@ -706,7 +706,7 @@ namespace parallel
       TBBPartitioner()
 #ifdef DEAL_II_WITH_THREADS
         :
-        my_partitioner(new tbb::affinity_partitioner()),
+        my_partitioner(std::make_shared<tbb::affinity_partitioner>()),
         in_use(false)
 #endif
       {}
@@ -734,7 +734,7 @@ namespace parallel
       {
         dealii::Threads::Mutex::ScopedLock lock(mutex);
         if (in_use)
-          return std::shared_ptr<tbb::affinity_partitioner>(new tbb::affinity_partitioner());
+          return std::make_shared<tbb::affinity_partitioner>();
 
         in_use = true;
         return my_partitioner;
index 2bd9204fb411efa010621b00300f75e6daa79ffa..e5bc57cb978a8845a96285ff5f994e64865f9047 100644 (file)
@@ -1468,7 +1468,7 @@ private:
    * object. Every nodes in the property tree corresponding to a parameter
    * stores an index into this array.
    */
-  std::vector<std::shared_ptr<const Patterns::PatternBase> > patterns;
+  std::vector<std::unique_ptr<const Patterns::PatternBase> > patterns;
 
   /**
    * A list of actions that are associated with parameters. These
@@ -1618,7 +1618,7 @@ private:
  *
  *       static void declare_parameters (ParameterHandler &prm);
  *     private:
- *       std::shared_ptr<Problem> p;
+ *       std::unique_ptr<Problem> p;
  *     };
  *
  *
@@ -1627,7 +1627,7 @@ private:
  *
  *     void HelperClass::create_new (const unsigned int run_no)
  *     {
- *       p.reset(new Problem());
+ *       p = std_cxx14::make_unique<Problem>());
  *     }
  *
  *
@@ -1991,7 +1991,7 @@ ParameterHandler::load (Archive &ar, const unsigned int)
 
   patterns.clear ();
   for (unsigned int j=0; j<descriptions.size(); ++j)
-    patterns.push_back (std::shared_ptr<const Patterns::PatternBase>(Patterns::pattern_factory(descriptions[j])));
+    patterns.push_back (Patterns::pattern_factory(descriptions[j]));
 }
 
 
index 6b949900b2a8bf952e4b63e806b73f1a6bc658e9..c78532899f6b6e4e973e5e3365d62f4eb9749e36 100644 (file)
@@ -531,10 +531,10 @@ namespace Polynomials
      * polynomial, we keep one pointer to the list of coefficients; we do so
      * rather than keeping a vector of vectors in order to simplify
      * programming multithread-safe. In order to avoid memory leak, we use a
-     * shared_ptr in order to correctly free the memory of the vectors when
+     * unique_ptr in order to correctly free the memory of the vectors when
      * the global destructor is called.
      */
-    static std::vector<std::shared_ptr<const std::vector<double> > > recursive_coefficients;
+    static std::vector<std::unique_ptr<const std::vector<double> > > recursive_coefficients;
   };
 
 
index 2cc1fccbc5fa133cd25e135291808f2b5bcd4e32..006f89fdbb2ef5cfa0e9bef4d01c085404116106 100644 (file)
@@ -863,7 +863,7 @@ namespace Threads
       void start (const std::function<RT ()> &function)
       {
         thread_is_active = true;
-        ret_val.reset(new return_value<RT>());
+        ret_val = std::make_shared<return_value<RT>>();
         thread = std::thread (thread_entry_point, function, ret_val);
       }
 
@@ -943,7 +943,7 @@ namespace Threads
        */
       void start (const std::function<RT ()> &function)
       {
-        ret_val.reset(new return_value<RT>());
+        ret_val = std::make_shared<return_value<RT>>();
         call (function, *ret_val);
       }
 
@@ -1629,7 +1629,7 @@ namespace Threads
     {
       // create a task descriptor and tell it to queue itself up with
       // the scheduling system
-      task_descriptor.reset (new internal::TaskDescriptor<RT>(function_object));
+      task_descriptor = std::make_shared<internal::TaskDescriptor<RT>>(function_object);
       task_descriptor->queue_task ();
     }
 
index 5040fde7e46782b23989925ca3cd703c9924bbca..349b0461b1d41901cae9fc15f96b5c1ce093a17a 100644 (file)
@@ -253,7 +253,7 @@ LogStream::get_stream()
   // there can only be one access at a time
   if (outstreams.get().get() == nullptr)
     {
-      outstreams.get().reset (new std::ostringstream);
+      outstreams.get() = std::make_shared<std::ostringstream>();
       outstreams.get()->setf(std::ios::showpoint | std::ios::left);
     }
 
index 71c42099d24b3bd02eec805943b941de0f081f15..506bffeae11ee8a91713dba6d429aaf28ad34ed0 100644 (file)
@@ -458,7 +458,7 @@ namespace
   read_xml_recursively (const boost::property_tree::ptree &source,
                         const std::string                 &current_path,
                         const char                         path_separator,
-                        const std::vector<std::shared_ptr<const Patterns::PatternBase> > &
+                        const std::vector<std::unique_ptr<const Patterns::PatternBase> > &
                         patterns,
                         boost::property_tree::ptree       &destination)
   {
@@ -586,7 +586,7 @@ void ParameterHandler::parse_input_from_xml (std::istream &in)
 
 void ParameterHandler::clear ()
 {
-  entries.reset (new boost::property_tree::ptree());
+  entries = std_cxx14::make_unique<boost::property_tree::ptree> ();
 }
 
 
index 5dfe8239709d277685174808406d5e9a7a24a1ba..e0241fef880bdd358d364a6b8b6f1e6fff6f673b 100644 (file)
@@ -322,17 +322,17 @@ namespace Patterns
             is.ignore(strlen(description_init) + strlen(" range "));
 
             if (!(is >> lower_bound))
-              return std::unique_ptr<Integer>(new Integer());
+              return std_cxx14::make_unique<Integer>();
 
             is.ignore(strlen("..."));
 
             if (!(is >> upper_bound))
-              return std::unique_ptr<Integer>(new Integer());
+              return std_cxx14::make_unique<Integer>();
 
-            return std::unique_ptr<Integer>(new Integer(lower_bound, upper_bound));
+            return std_cxx14::make_unique<Integer>(lower_bound, upper_bound);
           }
         else
-          return std::unique_ptr<Integer>(new Integer());
+          return std_cxx14::make_unique<Integer>();
       }
     else
       return std::unique_ptr<Integer>();
@@ -481,7 +481,7 @@ namespace Patterns
 
     std::string temp = description.substr(description_init_str.size());
     if (temp == "]")
-      return std::unique_ptr<Double>(new Double(1.0, -1.0)); // return an invalid range
+      return std_cxx14::make_unique<Double>(1.0, -1.0); // return an invalid range
 
     if (temp.find("...") != std::string::npos)
       temp.replace(temp.find("..."), 3, " ");
@@ -504,7 +504,7 @@ namespace Patterns
     if (is.fail())
       upper_bound = max_double_value;
 
-    return std::unique_ptr<Double>(new Double(lower_bound, upper_bound));
+    return std_cxx14::make_unique<Double>(lower_bound, upper_bound);
   }
 
 
@@ -613,7 +613,7 @@ namespace Patterns
         sequence.erase(0, std::strlen(description_init) + 1);
         sequence.erase(sequence.length()-2, 2);
 
-        return std::unique_ptr<Selection>(new Selection(sequence));
+        return std_cxx14::make_unique<Selection>(sequence);
       }
     else
       return std::unique_ptr<Selection>();
@@ -753,7 +753,7 @@ namespace Patterns
   {
     if (description.compare(0, std::strlen(description_init), description_init) == 0)
       {
-        int min_elements, max_elements;
+        unsigned int min_elements = 0, max_elements = 0;
 
         std::istringstream is(description);
         is.ignore(strlen(description_init) + strlen(" of <"));
@@ -761,24 +761,24 @@ namespace Patterns
         std::string str;
         std::getline(is, str, '>');
 
-        std::shared_ptr<PatternBase> base_pattern (pattern_factory(str));
+        std::unique_ptr<PatternBase> base_pattern (pattern_factory(str));
 
         is.ignore(strlen(" of length "));
         if (!(is >> min_elements))
-          return std::unique_ptr<List>(new List(*base_pattern));
+          return std_cxx14::make_unique<List>(*base_pattern);
 
         is.ignore(strlen("..."));
         if (!(is >> max_elements))
-          return std::unique_ptr<List>(new List(*base_pattern, min_elements));
+          return std_cxx14::make_unique<List>(*base_pattern, min_elements);
 
         is.ignore(strlen(" (inclusive) separated by <"));
         std::string separator;
-        if (is)
+        if (!is.eof())
           std::getline(is, separator, '>');
         else
           separator = ",";
 
-        return std::unique_ptr<List>(new List(*base_pattern, min_elements, max_elements, separator));
+        return std_cxx14::make_unique<List>(*base_pattern, min_elements, max_elements, separator);
       }
     else
       return std::unique_ptr<List>();
@@ -937,7 +937,7 @@ namespace Patterns
   {
     if (description.compare(0, std::strlen(description_init), description_init) == 0)
       {
-        int min_elements, max_elements;
+        unsigned int min_elements = 0, max_elements = 0;
 
         std::istringstream is(description);
         is.ignore(strlen(description_init) + strlen(" of <"));
@@ -952,27 +952,27 @@ namespace Patterns
         std::string value;
         std::getline(is, value, '>');
 
-        std::shared_ptr<PatternBase> key_pattern (pattern_factory(key));
-        std::shared_ptr<PatternBase> value_pattern (pattern_factory(value));
+        std::unique_ptr<PatternBase> key_pattern (pattern_factory(key));
+        std::unique_ptr<PatternBase> value_pattern (pattern_factory(value));
 
         is.ignore(strlen(" of length "));
         if (!(is >> min_elements))
-          return std::unique_ptr<Map>(new Map(*key_pattern, *value_pattern));
+          return std_cxx14::make_unique<Map>(*key_pattern, *value_pattern);
 
         is.ignore(strlen("..."));
         if (!(is >> max_elements))
-          return std::unique_ptr<Map>(new Map(*key_pattern, *value_pattern, min_elements));
+          return std_cxx14::make_unique<Map>(*key_pattern, *value_pattern, min_elements);
 
         is.ignore(strlen(" (inclusive) separated by <"));
         std::string separator;
-        if (is)
+        if (!is.eof())
           std::getline(is, separator, '>');
         else
           separator = ",";
 
-        return std::unique_ptr<Map>(new Map(*key_pattern, *value_pattern,
-                                            min_elements, max_elements,
-                                            separator, key_value_separator));
+        return std_cxx14::make_unique<Map>(*key_pattern, *value_pattern,
+                                           min_elements, max_elements,
+                                           separator, key_value_separator);
       }
     else
       return std::unique_ptr<Map>();
@@ -1166,12 +1166,12 @@ namespace Patterns
         is.ignore(strlen(" separated by <"));
 
         std::string separator;
-        if (is)
+        if (!is.eof())
           std::getline(is, separator, '>');
         else
           separator = ":";
 
-        return std::unique_ptr<Tuple>(new Tuple(patterns,separator));
+        return std_cxx14::make_unique<Tuple>(patterns,separator);
       }
     else
       return std::unique_ptr<Tuple>();
@@ -1332,7 +1332,7 @@ namespace Patterns
         sequence.erase(0, std::strlen(description_init) + 1);
         sequence.erase(sequence.length()-2, 2);
 
-        return std::unique_ptr<MultipleSelection>(new MultipleSelection(sequence));
+        return std_cxx14::make_unique<MultipleSelection>(sequence);
       }
     else
       return std::unique_ptr<MultipleSelection>();
@@ -1388,7 +1388,7 @@ namespace Patterns
   std::unique_ptr<Bool> Bool::create (const std::string &description)
   {
     if (description.compare(0, std::strlen(description_init), description_init) == 0)
-      return std::unique_ptr<Bool>(new Bool());
+      return std_cxx14::make_unique<Bool>();
     else
       return std::unique_ptr<Bool>();
   }
@@ -1444,7 +1444,7 @@ namespace Patterns
   std::unique_ptr<Anything> Anything::create (const std::string &description)
   {
     if (description.compare(0, std::strlen(description_init), description_init) == 0)
-      return std::unique_ptr<Anything>(new Anything());
+      return std_cxx14::make_unique<Anything>();
     else
       return std::unique_ptr<Anything>();
   }
@@ -1526,7 +1526,7 @@ namespace Patterns
         else
           type = output;
 
-        return std::unique_ptr<FileName>(new FileName(type));
+        return std_cxx14::make_unique<FileName>(type);
       }
     else
       return std::unique_ptr<FileName>();
@@ -1582,7 +1582,7 @@ namespace Patterns
   std::unique_ptr<DirectoryName> DirectoryName::create (const std::string &description)
   {
     if (description.compare(0, std::strlen(description_init), description_init) == 0)
-      return std::unique_ptr<DirectoryName>(new DirectoryName());
+      return std_cxx14::make_unique<DirectoryName>();
     else
       return std::unique_ptr<DirectoryName>();
   }
index dfb805562f9bab5c67f88a4a4d9b9c96a360ea08..c495c34d9102a3617f7e08ed18ac97a624549526 100644 (file)
 //
 // ---------------------------------------------------------------------
 
-#include <deal.II/base/polynomial.h>
-#include <deal.II/base/point.h>
 #include <deal.II/base/exceptions.h>
-#include <deal.II/base/thread_management.h>
+#include <deal.II/base/point.h>
+#include <deal.II/base/polynomial.h>
 #include <deal.II/base/quadrature_lib.h>
+#include <deal.II/base/std_cxx14/memory.h>
+#include <deal.II/base/thread_management.h>
 #include <deal.II/lac/full_matrix.h>
 #include <deal.II/lac/lapack_full_matrix.h>
 
-
 #include <cmath>
 #include <algorithm>
 #include <limits>
@@ -373,11 +373,11 @@ namespace Polynomials
     // need to transform p into standard form as
     // well if necessary. copy the polynomial to
     // do this
-    std::shared_ptr<Polynomial<number> > q_data;
+    std::unique_ptr<Polynomial<number> > q_data;
     const Polynomial<number> *q = nullptr;
     if (p.in_lagrange_product_form == true)
       {
-        q_data.reset (new Polynomial<number>(p));
+        q_data = std_cxx14::make_unique<Polynomial<number>>(p);
         q_data->transform_into_standard_form();
         q = q_data.get();
       }
@@ -417,11 +417,11 @@ namespace Polynomials
     // need to transform p into standard form as
     // well if necessary. copy the polynomial to
     // do this
-    std::shared_ptr<Polynomial<number> > q_data;
+    std::unique_ptr<Polynomial<number> > q_data;
     const Polynomial<number> *q = nullptr;
     if (p.in_lagrange_product_form == true)
       {
-        q_data.reset (new Polynomial<number>(p));
+        q_data = std_cxx14::make_unique<Polynomial<number>>(p);
         q_data->transform_into_standard_form();
         q = q_data.get();
       }
@@ -453,11 +453,11 @@ namespace Polynomials
     // need to transform p into standard form as
     // well if necessary. copy the polynomial to
     // do this
-    std::shared_ptr<Polynomial<number> > q_data;
+    std::unique_ptr<Polynomial<number> > q_data;
     const Polynomial<number> *q = nullptr;
     if (p.in_lagrange_product_form == true)
       {
-        q_data.reset (new Polynomial<number>(p));
+        q_data = std_cxx14::make_unique<Polynomial<number>>(p);
         q_data->transform_into_standard_form();
         q = q_data.get();
       }
@@ -600,11 +600,11 @@ namespace Polynomials
     if (degree() == 0)
       return Monomial<number>(0, 0.);
 
-    std::shared_ptr<Polynomial<number> > q_data;
+    std::unique_ptr<Polynomial<number> > q_data;
     const Polynomial<number> *q = nullptr;
     if (in_lagrange_product_form == true)
       {
-        q_data.reset (new Polynomial<number>(*this));
+        q_data = std_cxx14::make_unique<Polynomial<number>>(*this);
         q_data->transform_into_standard_form();
         q = q_data.get();
       }
@@ -626,11 +626,11 @@ namespace Polynomials
   {
     // no simple form possible for Lagrange
     // polynomial on product form
-    std::shared_ptr<Polynomial<number> > q_data;
+    std::unique_ptr<Polynomial<number> > q_data;
     const Polynomial<number> *q = nullptr;
     if (in_lagrange_product_form == true)
       {
-        q_data.reset (new Polynomial<number>(*this));
+        q_data = std_cxx14::make_unique<Polynomial<number>>(*this);
         q_data->transform_into_standard_form();
         q = q_data.get();
       }
@@ -976,7 +976,7 @@ namespace Polynomials
 
 // Reserve space for polynomials up to degree 19. Should be sufficient
 // for the start.
-  std::vector<std::shared_ptr<const std::vector<double> > >
+  std::vector<std::unique_ptr<const std::vector<double> > >
   Hierarchical::recursive_coefficients(20);
 
 
@@ -1053,9 +1053,9 @@ namespace Polynomials
             // now make these arrays
             // const
             recursive_coefficients[0] =
-              std::shared_ptr<const std::vector<double> >(c0);
+              std::unique_ptr<const std::vector<double> >(c0);
             recursive_coefficients[1] =
-              std::shared_ptr<const std::vector<double> >(c1);
+              std::unique_ptr<const std::vector<double> >(c1);
           }
         else if (k==2)
           {
@@ -1072,7 +1072,7 @@ namespace Polynomials
             (*c2)[2] =   4.*a;
 
             recursive_coefficients[2] =
-              std::shared_ptr<const std::vector<double> >(c2);
+              std::unique_ptr<const std::vector<double> >(c2);
           }
         else
           {
@@ -1116,7 +1116,7 @@ namespace Polynomials
             // const pointer in the
             // coefficients array
             recursive_coefficients[k] =
-              std::shared_ptr<const std::vector<double> >(ck);
+              std::unique_ptr<const std::vector<double> >(ck);
           };
       };
   }
index acef4b5dfe54cb9887eb699f88d19286fe93b0e2..475e946be97acb38a4bf8a5d744efc8c087ea614 100644 (file)
@@ -164,7 +164,7 @@ Quadrature<dim>::Quadrature (const SubQuadrature &q1,
 
   if (is_tensor_product_flag)
     {
-      tensor_basis.reset(new std::array<Quadrature<1>, dim>());
+      tensor_basis = std_cxx14::make_unique<std::array<Quadrature<1>, dim>> ();
       for (unsigned int i=0; i<dim-1; ++i)
         (*tensor_basis)[i] = q1.get_tensor_basis()[i];
       (*tensor_basis)[dim-1] = q2;
@@ -266,7 +266,7 @@ Subscriptor(),
           ++k;
         }
 
-  tensor_basis.reset (new std::array<Quadrature<1>, dim>());
+  tensor_basis = std_cxx14::make_unique<std::array<Quadrature<1>, dim>> ();
   for (unsigned int i=0; i<dim; ++i)
     (*tensor_basis)[i] = q;
 }

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.