]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Simplify code that uses variadic templates.
authorWolfgang Bangerth <bangerth@colostate.edu>
Mon, 21 Aug 2017 23:05:11 +0000 (17:05 -0600)
committerWolfgang Bangerth <bangerth@colostate.edu>
Mon, 21 Aug 2017 23:12:05 +0000 (17:12 -0600)
It turns out that we can do '&args...' to get the addresses of the objects, and then
'{ &args... }' to get a std::initializer_list that we can iterate over. This makes the
code significantly easier to read.

include/deal.II/hp/fe_collection.h

index 6ed435e74d7207e8f825b8e29dc098744a0451e1..060c8da695332706ba9f74bb23e8964de826dffe 100644 (file)
@@ -457,16 +457,13 @@ namespace hp
     static_assert(is_base_of_all<FiniteElement<dim, spacedim>, FETypes...>::value,
                   "Not all of the input parameters are derived from FiniteElement<dim, spacedim>!");
 
-    // We want to call 'push_back' for each of the arguments. To do so parameter
-    // pack expansion comes in handy. Unfortunately, we can't just write
-    //   push_back(fes)...;
-    // but have to treat this as arguments to some function which doesn't need
-    // to do anything with it. Now,
-    //   [](...) {}(push_back(fes)...);
-    // doesn't work as well because the ellipsis cannot deal with no parameters
-    // at all. Hence, we extend the return value of each of the return values
-    // by zero using the comma operator.
-    [](...) {}((push_back(fes),0)...);
+    // loop over all of the given arguments and add the finite
+    // elements to this collection
+    for (auto p :
+         {
+           &fes...
+         })
+      push_back (*p);
   }
 
 

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.