]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Add overload for default constructors 7880/head
authorDaniel Arndt <daniel.arndt@iwr.uni-heidelberg.de>
Tue, 9 Apr 2019 13:03:19 +0000 (15:03 +0200)
committerDaniel Arndt <daniel.arndt@iwr.uni-heidelberg.de>
Tue, 9 Apr 2019 13:04:32 +0000 (15:04 +0200)
include/deal.II/algorithms/general_data_storage.h
tests/algorithms/general_data_storage_01.cc

index 07d9075e60afd019c08bf06290743730b9f04cbe..2517b411497a0858e1e959ffb1aef9077688e501 100644 (file)
@@ -266,6 +266,13 @@ public:
                               Arg &&             argument,
                               Args &&... arguments);
 
+  /**
+   * Same as above for default constructors.
+   */
+  template <typename Type>
+  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 <typename Type>
+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<Type>(name);
+}
+
+
 #endif // DOXYGEN
 
 
index 5721492f80b3fb15adfab0bd6cb69cbb075738bb..483149a9b8a34d3ff430ca3283d216cbc193c98c 100644 (file)
@@ -145,6 +145,8 @@ main()
       const double  val_1 = 1.0;
       const double &val_2 =
         data.get_or_add_object_with_name<double>("value", val_1);
+      const std::string &str =
+        data.get_or_add_object_with_name<std::string>("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<double>("value", std::move(val_1));
+      const std::string &str =
+        data.get_or_add_object_with_name<std::string>("empty string");
     }
 
     // Pass Arguments ambiguously
     {
       const double &val_2 =
         data.get_or_add_object_with_name<double>("value", 1.0);
+      const std::string &str =
+        data.get_or_add_object_with_name<std::string>("empty string");
     }
   }
 

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.