From 54d929162c83bd27857311f34888ff08309ea6bf Mon Sep 17 00:00:00 2001 From: Stefan Girke <stefan.girke@wwu.de> Date: Mon, 8 Feb 2016 17:20:18 +0100 Subject: [PATCH] make it compile with 2.4 release. --- dune/fem-dg/algorithm/sub/advection.hh | 6 +- .../algorithm/sub/advectiondiffusion.hh | 10 ++- dune/fem-dg/misc/memory.hh | 88 +++++++++++++++++++ 3 files changed, 98 insertions(+), 6 deletions(-) create mode 100644 dune/fem-dg/misc/memory.hh diff --git a/dune/fem-dg/algorithm/sub/advection.hh b/dune/fem-dg/algorithm/sub/advection.hh index f8ed3124..822e467e 100644 --- a/dune/fem-dg/algorithm/sub/advection.hh +++ b/dune/fem-dg/algorithm/sub/advection.hh @@ -1,6 +1,8 @@ #ifndef DUNE_FEMDG_ALGORITHM_ADVECTION_STEPPER_HH #define DUNE_FEMDG_ALGORITHM_ADVECTION_STEPPER_HH +#include <dune/fem-dg/misc/memory.hh> + // dune-fem-dg includes #include <dune/fem-dg/operator/adaptation/estimator.hh> #include <dune/fem-dg/solver/rungekuttasolver.hh> @@ -81,8 +83,8 @@ namespace Fem ExtraParameterTupleType tuple = ExtraParameterTupleType() ) : BaseType( grid, container ), tuple_( ), - advectionOperator_( std::make_unique< FullOperatorType >( gridPart_, problem(), tuple_, name() ) ), - adaptIndicator_( std::make_unique< AdaptIndicatorOptional<AdaptIndicatorType> >( solution(), problem(), tuple_, name() ) ) + advectionOperator_( Std::make_unique< FullOperatorType >( gridPart_, problem(), tuple_, name() ) ), + adaptIndicator_( Std::make_unique< AdaptIndicatorOptional<AdaptIndicatorType> >( solution(), problem(), tuple_, name() ) ) {} virtual AdaptIndicatorType* adaptIndicator () diff --git a/dune/fem-dg/algorithm/sub/advectiondiffusion.hh b/dune/fem-dg/algorithm/sub/advectiondiffusion.hh index 524669a8..6c7c9b07 100644 --- a/dune/fem-dg/algorithm/sub/advectiondiffusion.hh +++ b/dune/fem-dg/algorithm/sub/advectiondiffusion.hh @@ -1,6 +1,8 @@ #ifndef DUNE_FEMDG_ALGORITHM_ADVECTIONDIFFUSION_STEPPER_HH #define DUNE_FEMDG_ALGORITHM_ADVECTIONDIFFUSION_STEPPER_HH +#include <dune/fem-dg/misc/memory.hh> + // dune-fem-dg includes #include <dune/fem-dg/operator/adaptation/estimator.hh> #include <dune/fem-dg/solver/rungekuttasolver.hh> @@ -87,10 +89,10 @@ namespace Fem //velo_( "velocity", vSpace_ ), //tuple_( &velo_ ), tuple_( ), - operator_( std::make_unique< OperatorType >( gridPart_, problem(), typename OperatorType::ExtraParameterTupleType(), name() ) ), - advectionOperator_( std::make_unique< ExplicitOperatorType >( gridPart_, problem(), typename ExplicitOperatorType::ExtraParameterTupleType(), name() ) ), - diffusionOperator_( std::make_unique< ImplicitOperatorType >( gridPart_, problem(), typename ImplicitOperatorType::ExtraParameterTupleType(), name() ) ), - adaptIndicator_( std::make_unique< AdaptIndicatorOptional<AdaptIndicatorType> >( solution(), problem(), typename AdaptIndicatorType::ExtraParameterTupleType(), name() ) ) + operator_( Std::make_unique< OperatorType >( gridPart_, problem(), typename OperatorType::ExtraParameterTupleType(), name() ) ), + advectionOperator_( Std::make_unique< ExplicitOperatorType >( gridPart_, problem(), typename ExplicitOperatorType::ExtraParameterTupleType(), name() ) ), + diffusionOperator_( Std::make_unique< ImplicitOperatorType >( gridPart_, problem(), typename ImplicitOperatorType::ExtraParameterTupleType(), name() ) ), + adaptIndicator_( Std::make_unique< AdaptIndicatorOptional<AdaptIndicatorType> >( solution(), problem(), typename AdaptIndicatorType::ExtraParameterTupleType(), name() ) ) {} virtual AdaptIndicatorType* adaptIndicator () diff --git a/dune/fem-dg/misc/memory.hh b/dune/fem-dg/misc/memory.hh new file mode 100644 index 00000000..16a3df71 --- /dev/null +++ b/dune/fem-dg/misc/memory.hh @@ -0,0 +1,88 @@ +// -*- tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- +// vi: set ts=8 sw=2 et sts=2: +#ifndef DUNE_COMMON_STD_MEMORY_HH +#define DUNE_COMMON_STD_MEMORY_HH + +#include <memory> +#include <utility> + +namespace Dune +{ + + namespace Std + { + + // Helper struct to distinguish non-array, unknown bound + // array, and known bound array types using SFINAE + // following proposal N3656 by Stephan T. Lavavej. + + template<class T> + struct MakeUniqueHelper + { + typedef std::unique_ptr<T> NonArrayUniquePtr; + }; + + template<class T> + struct MakeUniqueHelper<T[]> + { + typedef std::unique_ptr<T[]> UnknownBoundArrayUniquePtr; + typedef T RawType; + }; + + template<class T, size_t N> + struct MakeUniqueHelper<T[N]> + { + typedef void KnownBoundArrayUniquePtr; + }; + + + /** \brief Implementation of std::make_unique to be introduced in C++14 + * + * \tparam T Nonarray type of object to be constructed + * \tparam ...Args Parameter types for constructor of T + * + * \param args Arguments to be passed to constructor of T + * + * This fallback implementation using perfect forwarding + * as proposed by Herb Sutter in http://herbsutter.com/gotw/_102/ + */ + template<typename T, typename... Args> + typename MakeUniqueHelper<T>::NonArrayUniquePtr + make_unique(Args&&... args) + { + return std::unique_ptr<T>(new T(std::forward<Args>(args)...)); + } + + /** \brief Implementation of std::make_unique to be introduced in C++14 + * + * \tparam T Array type of unknown bound + * + * \param n Size of array to allocate + */ + template<typename T> + typename MakeUniqueHelper<T>::UnknownBoundArrayUniquePtr + make_unique(size_t n) + { + return std::unique_ptr<T>(new typename MakeUniqueHelper<T>::RawType[n]()); + } + + /** \brief Implementation of std::make_unique to be introduced in C++14 + * + * \tparam T Array type of known bound + * \tparam Args Dummy arguments + * + * This is deleted, since, according to the standard this should not + * participate in overload resolution + * + * \param args Dummy arguments + */ + template<typename T, typename ...Args> + typename MakeUniqueHelper<T>::KnownBoundArrayUniquePtr + make_unique(Args&&... args) = delete; + + + } // namespace Std + +} // namespace Dune + +#endif // #ifndef DUNE_COMMON_STD_MEMORY_HH -- GitLab