From: Daniel Arndt Date: Tue, 9 Apr 2019 13:03:19 +0000 (+0200) Subject: Add overload for default constructors X-Git-Tag: v9.1.0-rc1~213^2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d31a04bb005a449944114a4ec23e1e4881737e16;p=dealii.git Add overload for default constructors --- 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"); } }