From d31a04bb005a449944114a4ec23e1e4881737e16 Mon Sep 17 00:00:00 2001 From: Daniel Arndt Date: Tue, 9 Apr 2019 15:03:19 +0200 Subject: [PATCH] Add overload for default constructors --- .../deal.II/algorithms/general_data_storage.h | 18 ++++++++++++++++++ tests/algorithms/general_data_storage_01.cc | 6 ++++++ 2 files changed, 24 insertions(+) diff --git a/include/deal.II/algorithms/general_data_storage.h b/include/deal.II/algorithms/general_data_storage.h index 07d9075e60..2517b41149 100644 --- a/include/deal.II/algorithms/general_data_storage.h +++ b/include/deal.II/algorithms/general_data_storage.h @@ -266,6 +266,13 @@ public: Arg && argument, Args &&... arguments); + /** + * Same as above for default constructors. + */ + template + Type & + get_or_add_object_with_name(const std::string &name); + /** * Return a reference to the object with given name. * @@ -475,6 +482,17 @@ GeneralDataStorage::get_or_add_object_with_name(const std::string &name, } +template +Type & +GeneralDataStorage::get_or_add_object_with_name(const std::string &name) +{ + if (!stores_object_with_name(name)) + add_unique_copy(name, Type()); + + return get_object_with_name(name); +} + + #endif // DOXYGEN diff --git a/tests/algorithms/general_data_storage_01.cc b/tests/algorithms/general_data_storage_01.cc index 5721492f80..483149a9b8 100644 --- a/tests/algorithms/general_data_storage_01.cc +++ b/tests/algorithms/general_data_storage_01.cc @@ -145,6 +145,8 @@ main() const double val_1 = 1.0; const double &val_2 = data.get_or_add_object_with_name("value", val_1); + const std::string &str = + data.get_or_add_object_with_name("empty string"); } // Pass Arguments by rvalue reference @@ -152,12 +154,16 @@ main() double val_1 = 1.0; const double &val_2 = data.get_or_add_object_with_name("value", std::move(val_1)); + const std::string &str = + data.get_or_add_object_with_name("empty string"); } // Pass Arguments ambiguously { const double &val_2 = data.get_or_add_object_with_name("value", 1.0); + const std::string &str = + data.get_or_add_object_with_name("empty string"); } } -- 2.39.5