From cc522f037f128aaf1d1ab0a0ce08f12deab90aac Mon Sep 17 00:00:00 2001 From: Daniel Arndt Date: Sat, 10 Feb 2018 15:18:07 +0100 Subject: [PATCH] Use make_unique/shared in base --- include/deal.II/base/mg_level_object.h | 2 +- include/deal.II/base/parallel.h | 4 +- include/deal.II/base/parameter_handler.h | 8 ++-- include/deal.II/base/polynomial.h | 4 +- include/deal.II/base/thread_management.h | 6 +-- source/base/logstream.cc | 2 +- source/base/parameter_handler.cc | 4 +- source/base/patterns.cc | 58 ++++++++++++------------ source/base/polynomial.cc | 38 ++++++++-------- source/base/quadrature.cc | 4 +- 10 files changed, 65 insertions(+), 65 deletions(-) diff --git a/include/deal.II/base/mg_level_object.h b/include/deal.II/base/mg_level_object.h index 68799ba890..feb0f95b01 100644 --- a/include/deal.II/base/mg_level_object.h +++ b/include/deal.II/base/mg_level_object.h @@ -215,7 +215,7 @@ MGLevelObject::resize (const unsigned int new_minlevel, minlevel = new_minlevel; for (unsigned int i=0; i (new Object)); + objects.push_back(std::make_shared ()); } diff --git a/include/deal.II/base/parallel.h b/include/deal.II/base/parallel.h index 75102edd49..ad3e37e36c 100644 --- a/include/deal.II/base/parallel.h +++ b/include/deal.II/base/parallel.h @@ -706,7 +706,7 @@ namespace parallel TBBPartitioner() #ifdef DEAL_II_WITH_THREADS : - my_partitioner(new tbb::affinity_partitioner()), + my_partitioner(std::make_shared()), in_use(false) #endif {} @@ -734,7 +734,7 @@ namespace parallel { dealii::Threads::Mutex::ScopedLock lock(mutex); if (in_use) - return std::shared_ptr(new tbb::affinity_partitioner()); + return std::make_shared(); in_use = true; return my_partitioner; diff --git a/include/deal.II/base/parameter_handler.h b/include/deal.II/base/parameter_handler.h index 2bd9204fb4..e5bc57cb97 100644 --- a/include/deal.II/base/parameter_handler.h +++ b/include/deal.II/base/parameter_handler.h @@ -1468,7 +1468,7 @@ private: * object. Every nodes in the property tree corresponding to a parameter * stores an index into this array. */ - std::vector > patterns; + std::vector > 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 p; + * std::unique_ptr p; * }; * * @@ -1627,7 +1627,7 @@ private: * * void HelperClass::create_new (const unsigned int run_no) * { - * p.reset(new Problem()); + * p = std_cxx14::make_unique()); * } * * @@ -1991,7 +1991,7 @@ ParameterHandler::load (Archive &ar, const unsigned int) patterns.clear (); for (unsigned int j=0; j(Patterns::pattern_factory(descriptions[j]))); + patterns.push_back (Patterns::pattern_factory(descriptions[j])); } diff --git a/include/deal.II/base/polynomial.h b/include/deal.II/base/polynomial.h index 6b949900b2..c78532899f 100644 --- a/include/deal.II/base/polynomial.h +++ b/include/deal.II/base/polynomial.h @@ -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 > > recursive_coefficients; + static std::vector > > recursive_coefficients; }; diff --git a/include/deal.II/base/thread_management.h b/include/deal.II/base/thread_management.h index 2cc1fccbc5..006f89fdbb 100644 --- a/include/deal.II/base/thread_management.h +++ b/include/deal.II/base/thread_management.h @@ -863,7 +863,7 @@ namespace Threads void start (const std::function &function) { thread_is_active = true; - ret_val.reset(new return_value()); + ret_val = std::make_shared>(); thread = std::thread (thread_entry_point, function, ret_val); } @@ -943,7 +943,7 @@ namespace Threads */ void start (const std::function &function) { - ret_val.reset(new return_value()); + ret_val = std::make_shared>(); 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(function_object)); + task_descriptor = std::make_shared>(function_object); task_descriptor->queue_task (); } diff --git a/source/base/logstream.cc b/source/base/logstream.cc index 5040fde7e4..349b0461b1 100644 --- a/source/base/logstream.cc +++ b/source/base/logstream.cc @@ -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(); outstreams.get()->setf(std::ios::showpoint | std::ios::left); } diff --git a/source/base/parameter_handler.cc b/source/base/parameter_handler.cc index 71c42099d2..506bffeae1 100644 --- a/source/base/parameter_handler.cc +++ b/source/base/parameter_handler.cc @@ -458,7 +458,7 @@ namespace read_xml_recursively (const boost::property_tree::ptree &source, const std::string ¤t_path, const char path_separator, - const std::vector > & + const std::vector > & 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 (); } diff --git a/source/base/patterns.cc b/source/base/patterns.cc index 5dfe823970..e0241fef88 100644 --- a/source/base/patterns.cc +++ b/source/base/patterns.cc @@ -322,17 +322,17 @@ namespace Patterns is.ignore(strlen(description_init) + strlen(" range ")); if (!(is >> lower_bound)) - return std::unique_ptr(new Integer()); + return std_cxx14::make_unique(); is.ignore(strlen("...")); if (!(is >> upper_bound)) - return std::unique_ptr(new Integer()); + return std_cxx14::make_unique(); - return std::unique_ptr(new Integer(lower_bound, upper_bound)); + return std_cxx14::make_unique(lower_bound, upper_bound); } else - return std::unique_ptr(new Integer()); + return std_cxx14::make_unique(); } else return std::unique_ptr(); @@ -481,7 +481,7 @@ namespace Patterns std::string temp = description.substr(description_init_str.size()); if (temp == "]") - return std::unique_ptr(new Double(1.0, -1.0)); // return an invalid range + return std_cxx14::make_unique(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(new Double(lower_bound, upper_bound)); + return std_cxx14::make_unique(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(new Selection(sequence)); + return std_cxx14::make_unique(sequence); } else return std::unique_ptr(); @@ -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 base_pattern (pattern_factory(str)); + std::unique_ptr base_pattern (pattern_factory(str)); is.ignore(strlen(" of length ")); if (!(is >> min_elements)) - return std::unique_ptr(new List(*base_pattern)); + return std_cxx14::make_unique(*base_pattern); is.ignore(strlen("...")); if (!(is >> max_elements)) - return std::unique_ptr(new List(*base_pattern, min_elements)); + return std_cxx14::make_unique(*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(new List(*base_pattern, min_elements, max_elements, separator)); + return std_cxx14::make_unique(*base_pattern, min_elements, max_elements, separator); } else return std::unique_ptr(); @@ -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 key_pattern (pattern_factory(key)); - std::shared_ptr value_pattern (pattern_factory(value)); + std::unique_ptr key_pattern (pattern_factory(key)); + std::unique_ptr value_pattern (pattern_factory(value)); is.ignore(strlen(" of length ")); if (!(is >> min_elements)) - return std::unique_ptr(new Map(*key_pattern, *value_pattern)); + return std_cxx14::make_unique(*key_pattern, *value_pattern); is.ignore(strlen("...")); if (!(is >> max_elements)) - return std::unique_ptr(new Map(*key_pattern, *value_pattern, min_elements)); + return std_cxx14::make_unique(*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(new Map(*key_pattern, *value_pattern, - min_elements, max_elements, - separator, key_value_separator)); + return std_cxx14::make_unique(*key_pattern, *value_pattern, + min_elements, max_elements, + separator, key_value_separator); } else return std::unique_ptr(); @@ -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(new Tuple(patterns,separator)); + return std_cxx14::make_unique(patterns,separator); } else return std::unique_ptr(); @@ -1332,7 +1332,7 @@ namespace Patterns sequence.erase(0, std::strlen(description_init) + 1); sequence.erase(sequence.length()-2, 2); - return std::unique_ptr(new MultipleSelection(sequence)); + return std_cxx14::make_unique(sequence); } else return std::unique_ptr(); @@ -1388,7 +1388,7 @@ namespace Patterns std::unique_ptr Bool::create (const std::string &description) { if (description.compare(0, std::strlen(description_init), description_init) == 0) - return std::unique_ptr(new Bool()); + return std_cxx14::make_unique(); else return std::unique_ptr(); } @@ -1444,7 +1444,7 @@ namespace Patterns std::unique_ptr Anything::create (const std::string &description) { if (description.compare(0, std::strlen(description_init), description_init) == 0) - return std::unique_ptr(new Anything()); + return std_cxx14::make_unique(); else return std::unique_ptr(); } @@ -1526,7 +1526,7 @@ namespace Patterns else type = output; - return std::unique_ptr(new FileName(type)); + return std_cxx14::make_unique(type); } else return std::unique_ptr(); @@ -1582,7 +1582,7 @@ namespace Patterns std::unique_ptr DirectoryName::create (const std::string &description) { if (description.compare(0, std::strlen(description_init), description_init) == 0) - return std::unique_ptr(new DirectoryName()); + return std_cxx14::make_unique(); else return std::unique_ptr(); } diff --git a/source/base/polynomial.cc b/source/base/polynomial.cc index dfb805562f..c495c34d91 100644 --- a/source/base/polynomial.cc +++ b/source/base/polynomial.cc @@ -13,15 +13,15 @@ // // --------------------------------------------------------------------- -#include -#include #include -#include +#include +#include #include +#include +#include #include #include - #include #include #include @@ -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 > q_data; + std::unique_ptr > q_data; const Polynomial *q = nullptr; if (p.in_lagrange_product_form == true) { - q_data.reset (new Polynomial(p)); + q_data = std_cxx14::make_unique>(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 > q_data; + std::unique_ptr > q_data; const Polynomial *q = nullptr; if (p.in_lagrange_product_form == true) { - q_data.reset (new Polynomial(p)); + q_data = std_cxx14::make_unique>(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 > q_data; + std::unique_ptr > q_data; const Polynomial *q = nullptr; if (p.in_lagrange_product_form == true) { - q_data.reset (new Polynomial(p)); + q_data = std_cxx14::make_unique>(p); q_data->transform_into_standard_form(); q = q_data.get(); } @@ -600,11 +600,11 @@ namespace Polynomials if (degree() == 0) return Monomial(0, 0.); - std::shared_ptr > q_data; + std::unique_ptr > q_data; const Polynomial *q = nullptr; if (in_lagrange_product_form == true) { - q_data.reset (new Polynomial(*this)); + q_data = std_cxx14::make_unique>(*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 > q_data; + std::unique_ptr > q_data; const Polynomial *q = nullptr; if (in_lagrange_product_form == true) { - q_data.reset (new Polynomial(*this)); + q_data = std_cxx14::make_unique>(*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::vector > > Hierarchical::recursive_coefficients(20); @@ -1053,9 +1053,9 @@ namespace Polynomials // now make these arrays // const recursive_coefficients[0] = - std::shared_ptr >(c0); + std::unique_ptr >(c0); recursive_coefficients[1] = - std::shared_ptr >(c1); + std::unique_ptr >(c1); } else if (k==2) { @@ -1072,7 +1072,7 @@ namespace Polynomials (*c2)[2] = 4.*a; recursive_coefficients[2] = - std::shared_ptr >(c2); + std::unique_ptr >(c2); } else { @@ -1116,7 +1116,7 @@ namespace Polynomials // const pointer in the // coefficients array recursive_coefficients[k] = - std::shared_ptr >(ck); + std::unique_ptr >(ck); }; }; } diff --git a/source/base/quadrature.cc b/source/base/quadrature.cc index acef4b5dfe..475e946be9 100644 --- a/source/base/quadrature.cc +++ b/source/base/quadrature.cc @@ -164,7 +164,7 @@ Quadrature::Quadrature (const SubQuadrature &q1, if (is_tensor_product_flag) { - tensor_basis.reset(new std::array, dim>()); + tensor_basis = std_cxx14::make_unique, dim>> (); for (unsigned int i=0; i, dim>()); + tensor_basis = std_cxx14::make_unique, dim>> (); for (unsigned int i=0; i