diff --git a/src/amdis/ProblemStat.inc.hpp b/src/amdis/ProblemStat.inc.hpp index dda726e466bdf04fdb34d8082a2443cee6b00caf..d709b453fa8c653875ff00107f8df29e8c1fd27a 100644 --- a/src/amdis/ProblemStat.inc.hpp +++ b/src/amdis/ProblemStat.inc.hpp @@ -482,16 +482,26 @@ writeFiles(AdaptInfo& adaptInfo, bool force) } +template <class Grid, class GridView, + class = decltype(Dune::BackupRestoreFacility<Grid>::backup(std::declval<Grid>(), std::string("")))> +void backup_impl(Grid const& grid, GridView const& gv, std::string filename, std::true_type) +{ + Dune::BackupRestoreFacility<Grid>::backup(grid, filename); +} + +template <class Grid, class GridView, bool B, + class = decltype(BackupRestoreByGridFactory<Grid>::backup(std::declval<GridView>(), std::string("")))> +void backup_impl(Grid const& grid, GridView const& gv, std::string filename, bool_t<B>) +{ + warning("Falling back to backup of gridview."); + BackupRestoreByGridFactory<Grid>::backup(gv, filename); +} + template <class Traits> void ProblemStat<Traits>:: backup(std::string const& filename) const { - if (Dune::Capabilities::hasBackupRestoreFacilities<Grid>::v) - Dune::BackupRestoreFacility<Grid>::backup(*grid_, filename); - else { - warning("Falling back to backup of gridview."); - BackupRestoreByGridFactory<Grid>::backup(gridView(), filename); - } + backup_impl(*grid_, gridView(), filename, bool_t<Dune::Capabilities::hasBackupRestoreFacilities<Grid>::v>{}); } @@ -513,16 +523,26 @@ backup(AdaptInfo& adaptInfo) } +template <class Grid, + class = decltype(Dune::BackupRestoreFacility<Grid>::restore(std::string("")))> +auto restore_impl(std::string filename, std::true_type) +{ + return Dune::BackupRestoreFacility<Grid>::restore(filename); +} + +template <class Grid, bool B, + class = decltype(BackupRestoreByGridFactory<Grid>::restore(std::string("")))> +auto restore_impl(std::string filename, bool_t<B>) +{ + return BackupRestoreByGridFactory<Grid>::restore(filename); +} + template <class Traits> auto ProblemStat<Traits>:: restore(std::string const& filename) { // restore grid from file - std::unique_ptr<Grid> grid; - if (Dune::Capabilities::hasBackupRestoreFacilities<Grid>::v) - grid.reset(Dune::BackupRestoreFacility<Grid>::restore(filename)); - else - grid.reset(BackupRestoreByGridFactory<Grid>::restore(filename)); + std::unique_ptr<Grid> grid(restore_impl<Grid>(filename, bool_t<Dune::Capabilities::hasBackupRestoreFacilities<Grid>::v>{})); return std::move(grid); }