From a43d1b3158c3704c1eb304b55a1aae641757898d Mon Sep 17 00:00:00 2001 From: Guilherme Amadio Date: Tue, 20 Jun 2017 15:02:12 +0200 Subject: [PATCH] [Math] Replace std::auto_ptr with std::unique_ptr --- math/mathcore/CMakeLists.txt | 6 ---- math/mathcore/inc/Math/Functor.h | 32 +++---------------- .../inc/Math/MinimTransformFunction.h | 2 +- .../inc/Math/MinimTransformVariable.h | 4 +-- math/mathcore/inc/Math/ParamFunctor.h | 6 ++-- math/mathcore/inc/Math/WrappedParamFunction.h | 6 ++-- math/mathcore/src/Fitter.cxx | 4 +-- math/mathmore/src/ChebyshevApprox.cxx | 24 ++++++-------- math/unuran/src/TUnuran.cxx | 8 ++--- 9 files changed, 29 insertions(+), 63 deletions(-) diff --git a/math/mathcore/CMakeLists.txt b/math/mathcore/CMakeLists.txt index 9afa23c6ed6e8..34b59f3fb0098 100644 --- a/math/mathcore/CMakeLists.txt +++ b/math/mathcore/CMakeLists.txt @@ -2,8 +2,6 @@ # CMakeLists.txt file for building ROOT io/io package ############################################################################ -ROOT_ADD_CXX_FLAG(CMAKE_CXX_FLAGS -Wno-deprecated-declarations) # auto_ptr... - set(MATHCORE_HEADERS TRandom.h TRandom1.h TRandom2.h TRandom3.h TKDTree.h TKDTreeBinning.h TStatistic.h Math/Error.h Math/IParamFunction.h Math/IFunction.h Math/ParamFunctor.h Math/Functor.h @@ -46,7 +44,3 @@ endif() ROOT_INSTALL_HEADERS() ROOT_ADD_TEST_SUBDIRECTORY(test) - - - - diff --git a/math/mathcore/inc/Math/Functor.h b/math/mathcore/inc/Math/Functor.h index 6cda5baf2eb72..da7ce63204440 100644 --- a/math/mathcore/inc/Math/Functor.h +++ b/math/mathcore/inc/Math/Functor.h @@ -435,7 +435,7 @@ class Functor : public IBaseFunctionMultiDim { ImplBase() { if (rhs.fImpl) - fImpl = std::unique_ptr( (rhs.fImpl)->Copy() ); + fImpl = std::unique_ptr((rhs.fImpl)->Copy()); } // need a specialization in order to call base classes and use clone @@ -445,12 +445,7 @@ class Functor : public IBaseFunctionMultiDim { */ Functor & operator = (const Functor & rhs) { Functor copy(rhs); - // swap the poiter - fImpl.swap( copy.fImpl); - // // swap unique_ptr by hand - // Impl * p = fImpl.release(); - // fImpl.reset(copy.fImpl.release()); - // copy.fImpl.reset(p); + fImpl.swap(copy.fImpl); return *this; } @@ -508,7 +503,7 @@ class Functor1D : public IBaseFunctionOneDim { */ template Functor1D(const Func & f) : - fImpl(new FunctorHandler(f) ) + fImpl(new FunctorHandler(f)) {} @@ -544,29 +539,20 @@ class Functor1D : public IBaseFunctionOneDim { */ Functor1D & operator = (const Functor1D & rhs) { Functor1D copy(rhs); - fImpl.swap( copy.fImpl); - // swap auto_ptr by hand - // Impl * p = fImpl.release(); - // fImpl.reset(copy.fImpl.release()); - // copy.fImpl.reset(p); + fImpl.swap(copy.fImpl); return *this; } - // clone of the function handler (use copy-ctor) ImplBase * Clone() const { return new Functor1D(*this); } - private : inline double DoEval (double x) const { return (*fImpl)(x); } - std::unique_ptr fImpl; // pointer to base functor handler - - }; /** @@ -644,7 +630,7 @@ class GradFunctor : public IGradientFunctionMultiDim { ImplBase() { if (rhs.fImpl) - fImpl = std::unique_ptr( rhs.fImpl->Copy() ); + fImpl = std::unique_ptr(rhs.fImpl->Copy()); } /** @@ -653,10 +639,6 @@ class GradFunctor : public IGradientFunctionMultiDim { GradFunctor & operator = (const GradFunctor & rhs) { GradFunctor copy(rhs); fImpl.swap(copy.fImpl); - // swap auto_ptr by hand - // Impl * p = fImpl.release(); - // fImpl.reset(copy.fImpl.release()); - // copy.fImpl.reset(p); return *this; } @@ -773,10 +755,6 @@ class GradFunctor1D : public IGradientFunctionOneDim { GradFunctor1D & operator = (const GradFunctor1D & rhs) { GradFunctor1D copy(rhs); fImpl.swap(copy.fImpl); - // swap auto_ptr by hand - // Impl * p = fImpl.release(); - // fImpl.reset(copy.fImpl.release()); - // copy.fImpl.reset(p); return *this; } diff --git a/math/mathcore/inc/Math/MinimTransformFunction.h b/math/mathcore/inc/Math/MinimTransformFunction.h index 2d640df3722b3..94d1877778326 100644 --- a/math/mathcore/inc/Math/MinimTransformFunction.h +++ b/math/mathcore/inc/Math/MinimTransformFunction.h @@ -68,7 +68,7 @@ class MinimTransformFunction : public IMultiGradFunction { unsigned int NTot() const { return fFunc->NDim(); } - /// clone: not supported (since auto_ptr used in the fVariables) + /// clone: not supported (since unique_ptr used in the fVariables) IMultiGenFunction * Clone() const { return 0; } diff --git a/math/mathcore/inc/Math/MinimTransformVariable.h b/math/mathcore/inc/Math/MinimTransformVariable.h index 5e4b45f31e617..084b4f2c6cf66 100644 --- a/math/mathcore/inc/Math/MinimTransformVariable.h +++ b/math/mathcore/inc/Math/MinimTransformVariable.h @@ -87,7 +87,7 @@ class MinimTransformVariable { fFix(rhs.fFix), fLowBound(rhs.fLowBound), fUpBound(rhs.fUpBound), fBounds(rhs.fBounds), fLower(rhs.fLower), fUpper(rhs.fUpper) { - // swap auto_ptr + // swap unique_ptr fTransform.swap( const_cast( rhs).fTransform) ; } @@ -100,7 +100,7 @@ class MinimTransformVariable { fBounds = rhs.fBounds; fLower = rhs.fLower; fUpper = rhs.fUpper; - // swap auto_ptr + // swap unique_ptr fTransform.swap( const_cast( rhs).fTransform) ; return *this; } diff --git a/math/mathcore/inc/Math/ParamFunctor.h b/math/mathcore/inc/Math/ParamFunctor.h index 8b98303307798..2d1e0c633f77d 100644 --- a/math/mathcore/inc/Math/ParamFunctor.h +++ b/math/mathcore/inc/Math/ParamFunctor.h @@ -328,7 +328,7 @@ class ParamFunctorTempl { fImpl(0) { // if (rhs.fImpl.get() != 0) -// fImpl = std::auto_ptr( (rhs.fImpl)->Clone() ); +// fImpl = std::unique_ptr( (rhs.fImpl)->Clone() ); if (rhs.fImpl != 0) fImpl = rhs.fImpl->Clone(); } @@ -337,7 +337,7 @@ class ParamFunctorTempl { */ ParamFunctorTempl & operator = (const ParamFunctorTempl & rhs) { // ParamFunctor copy(rhs); - // swap auto_ptr by hand + // swap unique_ptr by hand // Impl * p = fImpl.release(); // fImpl.reset(copy.fImpl.release()); // copy.fImpl.reset(p); @@ -373,7 +373,7 @@ class ParamFunctorTempl { private : - //std::auto_ptr fImpl; + //std::unique_ptr fImpl; Impl * fImpl; diff --git a/math/mathcore/inc/Math/WrappedParamFunction.h b/math/mathcore/inc/Math/WrappedParamFunction.h index a4d5b6ac2f3bb..38b9af7639fb8 100644 --- a/math/mathcore/inc/Math/WrappedParamFunction.h +++ b/math/mathcore/inc/Math/WrappedParamFunction.h @@ -57,7 +57,7 @@ class WrappedParamFunction : public IParamMultiFunction { // /** // Constructor a wrapped function from a non-const pointer to a callable object, the function dimension and number of parameters // which are set to zero by default -// This constructor is needed in the case FuncPtr is a std::auto_ptr which has a copy ctor taking non const objects +// This constructor is needed in the case FuncPtr is a std::unique_ptr which has a copy ctor taking non const objects // */ // WrappedParamFunction (FuncPtr & func, unsigned int dim = 1, unsigned int npar = 0, double * par = 0) : // fFunc(func), @@ -80,7 +80,7 @@ class WrappedParamFunction : public IParamMultiFunction { // /** // Constructor a wrapped function from a non - const pointer to a callable object, the function dimension and an iterator specifying begin and end of parameters. -// This constructor is needed in the case FuncPtr is a std::auto_ptr which has a copy ctor taking non const objects +// This constructor is needed in the case FuncPtr is a std::unique_ptr which has a copy ctor taking non const objects // */ // template // WrappedParamFunction (FuncPtr func, unsigned int dim, Iterator begin, Iterator end) : @@ -158,7 +158,7 @@ class WrappedParamFunctionGen : public IParamMultiFunction { /** Constructor as before but taking now a non - const pointer to a callable object. - This constructor is needed in the case FuncPtr is a std::auto_ptr which has a copy ctor taking non const objects + This constructor is needed in the case FuncPtr is a std::unique_ptr which has a copy ctor taking non const objects */ WrappedParamFunctionGen (FuncPtr & func, unsigned int dim, unsigned int npar, const double * par, const unsigned int * idx) : fFunc(func), diff --git a/math/mathcore/src/Fitter.cxx b/math/mathcore/src/Fitter.cxx index 1d2bd47611f33..907ffd77fd016 100644 --- a/math/mathcore/src/Fitter.cxx +++ b/math/mathcore/src/Fitter.cxx @@ -91,7 +91,7 @@ Fitter & Fitter::operator = (const Fitter &rhs) // fBinFit = rhs.fBinFit; // fResult = rhs.fResult; // fConfig = rhs.fConfig; -// // function is copied and managed by FitResult (maybe should use an auto_ptr) +// // function is copied and managed by FitResult (maybe should use an unique_ptr) // fFunc = fResult.ModelFunction(); // if (rhs.fFunc != 0 && fResult.ModelFunction() == 0) { // case no fit has been done yet - then clone // if (fFunc) delete fFunc; @@ -827,7 +827,7 @@ bool Fitter::ApplyWeightCorrection(const ROOT::Math::IMultiGenFunction & loglw2, return false; } // need to re-init the minimizer and set w2 - fObjFunction = std::auto_ptr ( loglw2.Clone() ); + fObjFunction = std::unique_ptr ( loglw2.Clone() ); // need to re-initialize the minimizer for the changes applied in the // objective functions if (!DoInitMinimizer()) return false; diff --git a/math/mathmore/src/ChebyshevApprox.cxx b/math/mathmore/src/ChebyshevApprox.cxx index e014d0257a9d9..5dfdb533d5e7b 100644 --- a/math/mathmore/src/ChebyshevApprox.cxx +++ b/math/mathmore/src/ChebyshevApprox.cxx @@ -130,30 +130,24 @@ std::pair ChebyshevApprox::EvalErr( double x, size_t n) const { return std::make_pair( result, error); } - - -ChebyshevApprox * ChebyshevApprox::Deriv() { - // calculate derivative. Returna pointer to a new series - // used auto_ptr (supprseed since not good support on some compilers) - ChebyshevApprox * deriv = new ChebyshevApprox(fOrder); +ChebyshevApprox *ChebyshevApprox::Deriv() +{ + // calculate derivative. Returns pointer to a new series + ChebyshevApprox *deriv = new ChebyshevApprox(fOrder); // check for errors ? - gsl_cheb_calc_deriv( (deriv->fSeries)->get(), fSeries->get() ); + gsl_cheb_calc_deriv((deriv->fSeries)->get(), fSeries->get()); return deriv; - // diable auto_ptr to fix AIX compilation - // std::auto_ptr pDeriv(deriv); - // return pDeriv; } -ChebyshevApprox * ChebyshevApprox::Integral() { +ChebyshevApprox *ChebyshevApprox::Integral() +{ // integral (return pointer) - ChebyshevApprox * integ = new ChebyshevApprox(fOrder); + ChebyshevApprox *integ = new ChebyshevApprox(fOrder); // check for errors ? - gsl_cheb_calc_integ( (integ->fSeries)->get(), fSeries->get() ); + gsl_cheb_calc_integ((integ->fSeries)->get(), fSeries->get()); return integ; - // std::auto_ptr pInteg(integ); - // return pInteg; } } // namespace Math diff --git a/math/unuran/src/TUnuran.cxx b/math/unuran/src/TUnuran.cxx index 1e9f8b81b0c5c..91d8f2f135dc9 100644 --- a/math/unuran/src/TUnuran.cxx +++ b/math/unuran/src/TUnuran.cxx @@ -94,7 +94,7 @@ bool TUnuran::Init(const TUnuranContDist & distr, const std::string & method) { // initialization with a distribution and and generator // the distribution object is copied in and managed by this class - // use auto_ptr to manage previously existing distribution objects + // use std::unique_ptr to manage previously existing distribution objects TUnuranContDist * distNew = distr.Clone(); fDist.reset(distNew); @@ -110,7 +110,7 @@ bool TUnuran::Init(const TUnuranMultiContDist & distr, const std::string & meth { // initialization with a distribution and method // the distribution object is copied in and managed by this class - // use auto_ptr to manage previously existing distribution objects + // use std::unique_ptr to manage previously existing distribution objects TUnuranMultiContDist * distNew = distr.Clone(); fDist.reset(distNew); @@ -125,7 +125,7 @@ bool TUnuran::Init(const TUnuranMultiContDist & distr, const std::string & meth bool TUnuran::Init(const TUnuranDiscrDist & distr, const std::string & method ) { // initialization with a distribution and and generator // the distribution object is copied in and managed by this class - // use auto_ptr to manage previously existing distribution objects + // use std::unique_ptr to manage previously existing distribution objects TUnuranDiscrDist * distNew = distr.Clone(); fDist.reset(distNew); @@ -139,7 +139,7 @@ bool TUnuran::Init(const TUnuranDiscrDist & distr, const std::string & method ) bool TUnuran::Init(const TUnuranEmpDist & distr, const std::string & method ) { // initialization with a distribution and and generator // the distribution object is copied in and managed by this class - // use auto_ptr to manage previously existing distribution objects + // use std::unique_ptr to manage previously existing distribution objects TUnuranEmpDist * distNew = distr.Clone(); fDist.reset(distNew);