Skip to content

Commit

Permalink
Merge pull request #1350.
Browse files Browse the repository at this point in the history
Removed usage of `auto_ptr` macros and the corresponding `configure` flag
  • Loading branch information
lballabio committed Apr 21, 2022
2 parents 1d161d7 + cc755cd commit aca86a2
Show file tree
Hide file tree
Showing 111 changed files with 135 additions and 552 deletions.
7 changes: 0 additions & 7 deletions .github/workflows/linux-full-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -140,13 +140,6 @@ jobs:
cc: gcc
cxx: g++
configureflags: --enable-std-classes
- name: "auto_ptr re-enabled"
shortname: autoptr
tag: rolling
cc: gcc
cxx: g++
cxxflags: "-Wno-deprecated-declarations"
configureflags: --disable-std-unique-ptr
- name: "Thread-safe observer enabled"
shortname: threadsafe
tag: rolling
Expand Down
8 changes: 0 additions & 8 deletions .github/workflows/linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -145,14 +145,6 @@ jobs:
cxx: g++
configureflags: --enable-std-classes
tests: true
- name: "auto_ptr re-enabled"
shortname: autoptr
tag: rolling
cc: gcc
cxx: g++
cxxflags: "-Wno-deprecated-declarations"
configureflags: --disable-std-unique-ptr
tests: true
- name: "Thread-safe observer enabled"
shortname: threadsafe
tag: rolling
Expand Down
2 changes: 0 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,12 @@ option(QL_USE_CLANG_TIDY "Use clang-tidy when building" OFF)
option(QL_USE_INDEXED_COUPON "Use indexed coupons instead of par coupons" OFF)
option(QL_USE_STD_CLASSES "Enable all QL_USE_STD_ options" OFF)
option(QL_USE_STD_SHARED_PTR "Use standard smart pointers instead of Boost ones" OFF)
option(QL_USE_STD_UNIQUE_PTR "Use std::unique_ptr instead of std::auto_ptr" ON)
option(QL_USE_STD_FUNCTION "Use std::function and std::bind instead of Boost ones" OFF)
option(QL_USE_STD_TUPLE "Use std::tuple instead of boost::tuple" OFF)

# Convenience option to activate all STD options
if (QL_USE_STD_CLASSES)
set(QL_USE_STD_SHARED_PTR ON)
set(QL_USE_STD_UNIQUE_PTR ON)
set(QL_USE_STD_FUNCTION ON)
set(QL_USE_STD_TUPLE ON)
endif()
Expand Down
6 changes: 0 additions & 6 deletions Docs/pages/config.docs
Original file line number Diff line number Diff line change
Expand Up @@ -113,12 +113,6 @@
default) the Boost facilities are used. Note that `std::shared_ptr`
does not check access and can cause segmentation faults.

\code
#define QL_USE_STD_UNIQUE_PTR
\endcode
If defined (the default), `std::unique_ptr` is
used instead of `std::auto_ptr`. If disabled, `std::auto_ptr` is used.

\code
#define QL_USE_STD_FUNCTION
\endcode
Expand Down
1 change: 1 addition & 0 deletions cmake/GenerateHeaders.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ function(generate_ql_header source_dir binary_dir)
"#endif\n\n")
file(GLOB children_hpp RELATIVE ${source_dir} "${source_dir}/ql/*.hpp")
list(FILTER children_hpp EXCLUDE REGEX "auto_link.hpp")
list(FILTER children_hpp EXCLUDE REGEX "auto_ptr.hpp")
list(FILTER children_hpp EXCLUDE REGEX "config.*.hpp")
list(FILTER children_hpp EXCLUDE REGEX "mathconstants.hpp")
list(FILTER children_hpp EXCLUDE REGEX "qldefines.hpp")
Expand Down
19 changes: 1 addition & 18 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -376,20 +376,6 @@ if test "$ql_use_std_pointers" = "yes" ; then
fi
AC_MSG_RESULT([$ql_use_std_pointers])

AC_MSG_CHECKING([whether to enable std::unique_ptr instead of std::auto_ptr])
AC_ARG_ENABLE([std-unique-ptr],
AS_HELP_STRING([--enable-std-unique-ptr],
[If enabled (the default), std::unique_ptr will
be used instead of the deprecated std::auto_ptr.
If disabled, std::auto_ptr will still be used.]),
[ql_use_unique_ptr=$enableval],
[ql_use_unique_ptr=yes])
if test "$ql_use_unique_ptr" = "yes" ; then
AC_DEFINE([QL_USE_STD_UNIQUE_PTR],[1],
[Define this if you want to replace std::auto_ptr with std::unique_ptr.])
fi
AC_MSG_RESULT([$ql_use_unique_ptr])

AC_MSG_CHECKING([whether to enable std::function])
AC_ARG_ENABLE([std-function],
AS_HELP_STRING([--enable-std-function],
Expand Down Expand Up @@ -425,17 +411,14 @@ AC_MSG_CHECKING([whether to enable available std classes])
AC_ARG_ENABLE([std-classes],
AS_HELP_STRING([--enable-std-classes],
[This is a shortcut for --enable-std-pointers
--enable-std-unique-ptr --enable-std-function
--enable-std-tuple.
--enable-std-function --enable-std-tuple.
If enabled, this supersedes any --disable
option passed for the above.]),
[ql_use_std_classes=$enableval],
[ql_use_std_classes=no])
if test "$ql_use_std_classes" = "yes" ; then
AC_DEFINE([QL_USE_STD_SHARED_PTR],[1],
[Define this if you want to use standard smart pointers.])
AC_DEFINE([QL_USE_STD_UNIQUE_PTR],[1],
[Define this if you want to replace std::auto_ptr with std::unique_ptr.])
AC_DEFINE([QL_USE_STD_FUNCTION],[1],
[Define this if you want to use std::function and std::bind.])
AC_DEFINE([QL_USE_STD_TUPLE],[1],
Expand Down
1 change: 1 addition & 0 deletions ql/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ quantlib.hpp: Makefile.am
for i in $(this_include_HEADERS); do \
case $$i in \
auto_link.hpp) continue;; \
auto_ptr.hpp) continue;; \
config.hpp) continue;; \
mathconstants.hpp) continue;; \
qldefines.hpp) continue;; \
Expand Down
21 changes: 8 additions & 13 deletions ql/auto_ptr.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,19 @@
FOR A PARTICULAR PURPOSE. See the license for more details.
*/

/*! \file auto_ptr.hpp
\brief Facilities to switch from auto_ptr to unique_ptr
*/

#ifndef quantlib_auto_ptr_hpp
#define quantlib_auto_ptr_hpp

#include <ql/qldefines.hpp>

#if defined(QL_USE_STD_UNIQUE_PTR)
# define QL_UNIQUE_OR_AUTO_PTR std::unique_ptr
#else
# pragma message("Warning: using auto_ptr in QuantLib is now deprecated.")
# pragma message(" If you're using --disable-std-unique-ptr in your build")
# pragma message(" or if you undefined QL_USE_STD_UNIQUE_PTR in ql/userconfig.hpp,")
# pragma message(" please restore the default compilation options in the near future.")
# define QL_UNIQUE_OR_AUTO_PTR std::auto_ptr
#endif
#pragma message("Warning: the deprecated QL_UNIQUE_OR_AUTO_PTR macro is no longer used. Replace it with std::unique_ptr.")
#pragma message(" For the time being, the QL_USE_STD_UNIQUE_PTR macro is set to 1. However, do not check for it, since it will disappear in a future release.")
#pragma message(" This file will also disappear in a future release; do not include it.")

/*! \deprecated Use std::unique_ptr instead.
Deprecated in version 1.27
*/
#define QL_UNIQUE_OR_AUTO_PTR std::unique_ptr


#endif
Expand Down
1 change: 0 additions & 1 deletion ql/config.hpp.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
#cmakedefine QL_HIGH_RESOLUTION_DATE
#cmakedefine QL_USE_INDEXED_COUPON
#cmakedefine QL_USE_STD_SHARED_PTR
#cmakedefine QL_USE_STD_UNIQUE_PTR
#cmakedefine QL_USE_STD_FUNCTION
#cmakedefine QL_USE_STD_TUPLE

Expand Down
18 changes: 7 additions & 11 deletions ql/experimental/variancegamma/fftengine.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,18 +46,14 @@ namespace QuantLib {

class FFTEngine :
public VanillaOption::engine {
public:
FFTEngine(ext::shared_ptr<StochasticProcess1D> process, Real logStrikeSpacing);
void calculate() const override;
void update() override;
public:
FFTEngine(ext::shared_ptr<StochasticProcess1D> process, Real logStrikeSpacing);
void calculate() const override;
void update() override;

void precalculate(const std::vector<ext::shared_ptr<Instrument> >& optionList);
#if defined(QL_USE_STD_UNIQUE_PTR)
void precalculate(const std::vector<ext::shared_ptr<Instrument> >& optionList);
virtual std::unique_ptr<FFTEngine> clone() const = 0;
#else
virtual std::auto_ptr<FFTEngine> clone() const = 0;
#endif
protected:
protected:
virtual void precalculateExpiry(Date d) = 0;
virtual std::complex<Real> complexFourierTransform(std::complex<Real> u) const = 0;
virtual Real discountFactor(Date d) const = 0;
Expand All @@ -68,7 +64,7 @@ namespace QuantLib {
ext::shared_ptr<StochasticProcess1D> process_;
Real lambda_; // Log strike spacing

private:
private:
typedef std::map<ext::shared_ptr<StrikedTypePayoff>, Real> PayoffResultMap;
typedef std::map<Date, PayoffResultMap> ResultMap;
ResultMap resultMap_;
Expand Down
6 changes: 2 additions & 4 deletions ql/experimental/variancegamma/fftvanillaengine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ FOR A PARTICULAR PURPOSE. See the license for more details.
#include <ql/experimental/variancegamma/fftvanillaengine.hpp>
#include <ql/exercise.hpp>
#include <ql/termstructures/volatility/equityfx/blackconstantvol.hpp>
#include <ql/auto_ptr.hpp>
#include <complex>

namespace QuantLib {
Expand All @@ -31,12 +30,11 @@ namespace QuantLib {
{
}

QL_UNIQUE_OR_AUTO_PTR<FFTEngine> FFTVanillaEngine::clone() const
std::unique_ptr<FFTEngine> FFTVanillaEngine::clone() const
{
ext::shared_ptr<GeneralizedBlackScholesProcess> process =
ext::dynamic_pointer_cast<GeneralizedBlackScholesProcess>(process_);
return QL_UNIQUE_OR_AUTO_PTR<FFTEngine>(
new FFTVanillaEngine(process, lambda_));
return std::unique_ptr<FFTEngine>(new FFTVanillaEngine(process, lambda_));
}

void FFTVanillaEngine::precalculateExpiry(Date d)
Expand Down
12 changes: 4 additions & 8 deletions ql/experimental/variancegamma/fftvanillaengine.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,12 @@ namespace QuantLib {
explicit FFTVanillaEngine(
const ext::shared_ptr<GeneralizedBlackScholesProcess>&process,
Real logStrikeSpacing = 0.001);
#if defined(QL_USE_STD_UNIQUE_PTR)
std::unique_ptr<FFTEngine> clone() const override;
#else
virtual std::auto_ptr<FFTEngine> clone() const;
#endif
protected:
void precalculateExpiry(Date d) override;
std::complex<Real> complexFourierTransform(std::complex<Real> u) const override;
Real discountFactor(Date d) const override;
Real dividendYield(Date d) const override;
void precalculateExpiry(Date d) override;
std::complex<Real> complexFourierTransform(std::complex<Real> u) const override;
Real discountFactor(Date d) const override;
Real dividendYield(Date d) const override;

private:
DiscountFactor dividendDiscount_;
Expand Down
6 changes: 2 additions & 4 deletions ql/experimental/variancegamma/fftvariancegammaengine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ FOR A PARTICULAR PURPOSE. See the license for more details.

#include <ql/experimental/variancegamma/fftvariancegammaengine.hpp>
#include <ql/exercise.hpp>
#include <ql/auto_ptr.hpp>
#include <complex>

namespace QuantLib {
Expand All @@ -30,12 +29,11 @@ namespace QuantLib {
{
}

QL_UNIQUE_OR_AUTO_PTR<FFTEngine> FFTVarianceGammaEngine::clone() const
std::unique_ptr<FFTEngine> FFTVarianceGammaEngine::clone() const
{
ext::shared_ptr<VarianceGammaProcess> process =
ext::dynamic_pointer_cast<VarianceGammaProcess>(process_);
return QL_UNIQUE_OR_AUTO_PTR<FFTEngine>(
new FFTVarianceGammaEngine(process, lambda_));
return std::unique_ptr<FFTEngine>(new FFTVarianceGammaEngine(process, lambda_));
}

void FFTVarianceGammaEngine::precalculateExpiry(Date d)
Expand Down
12 changes: 4 additions & 8 deletions ql/experimental/variancegamma/fftvariancegammaengine.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,12 @@ namespace QuantLib {
explicit FFTVarianceGammaEngine(
const ext::shared_ptr<VarianceGammaProcess>&process,
Real logStrikeSpacing = 0.001);
#if defined(QL_USE_STD_UNIQUE_PTR)
std::unique_ptr<FFTEngine> clone() const override;
#else
virtual std::auto_ptr<FFTEngine> clone() const;
#endif
protected:
void precalculateExpiry(Date d) override;
std::complex<Real> complexFourierTransform(std::complex<Real> u) const override;
Real discountFactor(Date d) const override;
Real dividendYield(Date d) const override;
void precalculateExpiry(Date d) override;
std::complex<Real> complexFourierTransform(std::complex<Real> u) const override;
Real discountFactor(Date d) const override;
Real dividendYield(Date d) const override;

private:
DiscountFactor dividendDiscount_;
Expand Down
12 changes: 0 additions & 12 deletions ql/methods/finitedifferences/operators/ninepointlinearop.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,6 @@

#include <ql/math/matrixutilities/sparsematrix.hpp>
#include <ql/methods/finitedifferences/operators/fdmlinearop.hpp>
#if !defined(QL_USE_STD_UNIQUE_PTR)
#include <boost/shared_array.hpp>
#endif
#include <memory>

namespace QuantLib {
Expand All @@ -57,21 +54,12 @@ namespace QuantLib {
NinePointLinearOp() = default;

Size d0_, d1_;
#if !defined(QL_USE_STD_UNIQUE_PTR)
boost::shared_array<Size> i00_, i10_, i20_;
boost::shared_array<Size> i01_, i21_;
boost::shared_array<Size> i02_, i12_, i22_;
boost::shared_array<Real> a00_, a10_, a20_;
boost::shared_array<Real> a01_, a11_, a21_;
boost::shared_array<Real> a02_, a12_, a22_;
#else
std::unique_ptr<Size[]> i00_, i10_, i20_;
std::unique_ptr<Size[]> i01_, i21_;
std::unique_ptr<Size[]> i02_, i12_, i22_;
std::unique_ptr<Real[]> a00_, a10_, a20_;
std::unique_ptr<Real[]> a01_, a11_, a21_;
std::unique_ptr<Real[]> a02_, a12_, a22_;
#endif

ext::shared_ptr<FdmMesher> mesher_;
};
Expand Down
9 changes: 0 additions & 9 deletions ql/methods/finitedifferences/operators/triplebandlinearop.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,6 @@
#define quantlib_triple_band_linear_op_hpp

#include <ql/methods/finitedifferences/operators/fdmlinearop.hpp>
#if !defined(QL_USE_STD_UNIQUE_PTR)
#include <boost/shared_array.hpp>
#endif
#include <memory>

namespace QuantLib {
Expand Down Expand Up @@ -69,15 +66,9 @@ namespace QuantLib {
TripleBandLinearOp() = default;

Size direction_;
#if !defined(QL_USE_STD_UNIQUE_PTR)
boost::shared_array<Size> i0_, i2_;
boost::shared_array<Size> reverseIndex_;
boost::shared_array<Real> lower_, diag_, upper_;
#else
std::unique_ptr<Size[]> i0_, i2_;
std::unique_ptr<Size[]> reverseIndex_;
std::unique_ptr<Real[]> lower_, diag_, upper_;
#endif

ext::shared_ptr<FdmMesher> mesher_;
};
Expand Down
4 changes: 0 additions & 4 deletions ql/methods/montecarlo/exercisestrategy.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,7 @@ namespace QuantLib {
virtual void reset() = 0;
virtual bool exercise(const State& currentState) const = 0;
virtual void nextStep(const State& currentState) = 0;
#if defined(QL_USE_STD_UNIQUE_PTR)
virtual std::unique_ptr<ExerciseStrategy<State> > clone() const = 0;
#else
virtual std::auto_ptr<ExerciseStrategy<State> > clone() const = 0;
#endif
};

}
Expand Down
8 changes: 0 additions & 8 deletions ql/methods/montecarlo/longstaffschwartzpathpricer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,6 @@
#include <ql/methods/montecarlo/earlyexercisepathpricer.hpp>
#include <ql/methods/montecarlo/pathpricer.hpp>
#include <ql/termstructures/yieldtermstructure.hpp>
#if !defined(QL_USE_STD_UNIQUE_PTR)
#include <boost/scoped_array.hpp>
#endif
#include <utility>
#include <memory>

Expand Down Expand Up @@ -78,13 +75,8 @@ namespace QuantLib {

mutable QuantLib::IncrementalStatistics exerciseProbability_;

#if defined(QL_USE_STD_UNIQUE_PTR)
std::unique_ptr<Array[]> coeff_;
std::unique_ptr<DiscountFactor[]> dF_;
#else
boost::scoped_array<Array> coeff_;
boost::scoped_array<DiscountFactor> dF_;
#endif

mutable std::vector<PathType> paths_;
const std::vector<ext::function<Real(StateType)> > v_;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
FOR A PARTICULAR PURPOSE. See the license for more details.
*/

#include <ql/auto_ptr.hpp>
#include <ql/models/marketmodels/callability/bermudanswaptionexercisevalue.hpp>
#include <ql/models/marketmodels/curvestate.hpp>
#include <ql/models/marketmodels/utilities.hpp>
Expand Down Expand Up @@ -79,10 +78,9 @@ namespace QuantLib {
return cf_;
}

QL_UNIQUE_OR_AUTO_PTR<MarketModelExerciseValue>
std::unique_ptr<MarketModelExerciseValue>
BermudanSwaptionExerciseValue::clone() const {
return QL_UNIQUE_OR_AUTO_PTR<MarketModelExerciseValue>(
new BermudanSwaptionExerciseValue(*this));
return std::unique_ptr<MarketModelExerciseValue>(new BermudanSwaptionExerciseValue(*this));
}

}

0 comments on commit aca86a2

Please sign in to comment.