* for level objects.
* @param[in] maxlevel The highest level for which to provision memory
* for level objects.
+ * @param[in] args Optional arguments passed to the constructor of the
+ * underlying object.
*
* @pre minlevel <= maxlevel
*/
+ template <class... Args>
MGLevelObject(const unsigned int minlevel = 0,
- const unsigned int maxlevel = 0);
+ const unsigned int maxlevel = 0,
+ Args &&... args);
/**
* Access object on level @p level.
* for level objects.
* @param[in] new_maxlevel The highest level for which to provision memory
* for level objects.
+ * @param[in] args Optional arguments passed to the constructor of the
+ * underlying object.
*
* @pre minlevel <= maxlevel
*/
+ template <class... Args>
void
- resize(const unsigned int new_minlevel, const unsigned int new_maxlevel);
+ resize(const unsigned int new_minlevel,
+ const unsigned int new_maxlevel,
+ Args &&... args);
/**
* Call <tt>operator = (s)</tt> on all objects stored by this object.
template <class Object>
+template <class... Args>
MGLevelObject<Object>::MGLevelObject(const unsigned int min,
- const unsigned int max)
+ const unsigned int max,
+ Args &&... args)
: minlevel(0)
{
- resize(min, max);
+ resize(min, max, std::forward<Args>(args)...);
}
template <class Object>
+template <class... Args>
void
MGLevelObject<Object>::resize(const unsigned int new_minlevel,
- const unsigned int new_maxlevel)
+ const unsigned int new_maxlevel,
+ Args &&... args)
{
Assert(new_minlevel <= new_maxlevel, ExcInternalError());
// note that on clear(), the
minlevel = new_minlevel;
for (unsigned int i = 0; i < new_maxlevel - new_minlevel + 1; ++i)
- objects.push_back(std::make_shared<Object>());
+ objects.push_back(std::make_shared<Object>(std::forward<Args>(args)...));
}
--- /dev/null
+// ---------------------------------------------------------------------
+//
+// Copyright (C) 2019 - 2020 by the deal.II authors
+//
+// This file is part of the deal.II library.
+//
+// The deal.II library is free software; you can use it, redistribute
+// it, and/or modify it under the terms of the GNU Lesser General
+// Public License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+// The full text of the license can be found in the file LICENSE.md at
+// the top level directory of deal.II.
+//
+// ---------------------------------------------------------------------
+
+
+// Test optional arguments of MGLevelObject.
+
+#include <deal.II/base/mg_level_object.h>
+
+#include <deal.II/dofs/dof_handler.h>
+
+#include <deal.II/grid/tria.h>
+
+#include "../tests.h"
+
+using namespace dealii;
+
+int
+main()
+{
+ initlog();
+
+ Triangulation<2> tria;
+
+ MGLevelObject<DoFHandler<2>> dof_handlers(0, 3, tria, true);
+
+ dof_handlers.resize(0, 5, tria, true);
+
+ deallog << "OK!" << std::endl;
+}