From 7f654494923a81565f032d17d1924159fe5bd5a5 Mon Sep 17 00:00:00 2001 From: Simon Praetorius Date: Thu, 10 Oct 2019 20:55:19 +0200 Subject: [PATCH 1/2] cleanup wrap_or_share --- src/amdis/ProblemStat.inc.hpp | 4 ++-- src/amdis/common/SharedPtr.hpp | 20 +++++--------------- 2 files changed, 7 insertions(+), 17 deletions(-) diff --git a/src/amdis/ProblemStat.inc.hpp b/src/amdis/ProblemStat.inc.hpp index b12361d2..163d9413 100644 --- a/src/amdis/ProblemStat.inc.hpp +++ b/src/amdis/ProblemStat.inc.hpp @@ -138,9 +138,9 @@ restore(Flag initFlag) // restore grid from file if (Dune::Capabilities::hasBackupRestoreFacilities::v) - adoptGrid(Grid::instance(Dune::BackupRestoreFacility::restore(grid_filename))); + adoptGrid(Grid::instance(std::unique_ptr(Dune::BackupRestoreFacility::restore(grid_filename)))); else - adoptGrid(Grid::instance(BackupRestoreByGridFactory::restore(grid_filename))); + adoptGrid(Grid::instance(std::unique_ptr(BackupRestoreByGridFactory::restore(grid_filename)))); // create fespace if (initFlag.isSet(INIT_FE_SPACE) || initFlag.isSet(INIT_SYSTEM)) diff --git a/src/amdis/common/SharedPtr.hpp b/src/amdis/common/SharedPtr.hpp index 3cb9bffd..561fe5e4 100644 --- a/src/amdis/common/SharedPtr.hpp +++ b/src/amdis/common/SharedPtr.hpp @@ -1,6 +1,7 @@ #pragma once #include +#include #include #include @@ -30,15 +31,10 @@ namespace AMDiS } template - std::shared_ptr wrap_or_share(T*& t) + std::shared_ptr wrap_or_share(T* t) { - return std::shared_ptr(t, Dune::null_deleter()); - } - - template - std::shared_ptr wrap_or_share(T*&& t) - { - return std::shared_ptr(t); + static_assert(not std::is_pointer::value, + "Raw pointers must be wrapped into smart pointers or references to clarify ownership"); } template @@ -48,13 +44,7 @@ namespace AMDiS } template - std::shared_ptr wrap_or_share(std::unique_ptr& t) - { - return std::shared_ptr(t.get(), Dune::null_deleter()); - } - - template - std::shared_ptr wrap_or_share(std::unique_ptr&& t) + std::shared_ptr wrap_or_share(std::unique_ptr t) { return std::shared_ptr(std::move(t)); } -- GitLab From fa4aea1eeb06ef7e099bf99779b44932083f52bf Mon Sep 17 00:00:00 2001 From: Simon Praetorius Date: Thu, 10 Oct 2019 21:45:33 +0200 Subject: [PATCH 2/2] change yaspgrid construction --- test/ISTLCommTest.cpp | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/test/ISTLCommTest.cpp b/test/ISTLCommTest.cpp index 1ef3d0e1..c2cdcb85 100644 --- a/test/ISTLCommTest.cpp +++ b/test/ISTLCommTest.cpp @@ -75,8 +75,7 @@ int main(int argc, char** argv) int ovlp = 1; { - auto hostGrid = std::make_unique(lower2d, upper2d, nElements2d, std::bitset<2>(), - ovlp); + YaspGrid2d hostGrid(lower2d, upper2d, nElements2d, std::bitset<2>(), ovlp); auto grid = AdaptiveGrid::instance(hostGrid); auto l1 = LagrangeBasis::create(grid->leafGridView()); @@ -86,8 +85,7 @@ int main(int argc, char** argv) AMDIS_TEST(test(th, "Yasp2d_TH_Ovlp")); } { - auto hostGrid = std::make_unique(lower3d, upper3d, nElements3d, std::bitset<3>(), - ovlp); + YaspGrid3d hostGrid(lower3d, upper3d, nElements3d, std::bitset<3>(), ovlp); auto grid = AdaptiveGrid::instance(hostGrid); auto l1 = LagrangeBasis::create(grid->leafGridView()); -- GitLab