Skip to content

Commit

Permalink
Merge branch 'master' into c++17
Browse files Browse the repository at this point in the history
  • Loading branch information
lballabio committed Jul 24, 2024
2 parents 5c1d4ca + 5551e96 commit ba9ffb9
Show file tree
Hide file tree
Showing 118 changed files with 459 additions and 520 deletions.
11 changes: 0 additions & 11 deletions .ci/userconfig2019.alt.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,17 +113,6 @@
# define QL_USE_STD_SHARED_PTR
#endif

/* Undefine this to use boost::function and boost::bind instead of
std::function and std::bind. */
#ifndef QL_USE_STD_FUNCTION
//# define QL_USE_STD_FUNCTION
#endif

/* Undefine this to use boost::tuple instead of std::tuple. */
#ifndef QL_USE_STD_TUPLE
//# define QL_USE_STD_TUPLE
#endif

/* Define this to enable the implementation of Null as template functions. */
#ifndef QL_NULL_AS_FUNCTIONS
# define QL_NULL_AS_FUNCTIONS
Expand Down
11 changes: 0 additions & 11 deletions .ci/userconfig2022.alt.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,17 +113,6 @@
# define QL_USE_STD_SHARED_PTR
#endif

/* Undefine this to use boost::function and boost::bind instead of
std::function and std::bind. */
#ifndef QL_USE_STD_FUNCTION
//# define QL_USE_STD_FUNCTION
#endif

/* Undefine this to use boost::tuple instead of std::tuple. */
#ifndef QL_USE_STD_TUPLE
//# define QL_USE_STD_TUPLE
#endif

/* Define this to enable the implementation of Null as template functions. */
#ifndef QL_NULL_AS_FUNCTIONS
# define QL_NULL_AS_FUNCTIONS
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/linux-full-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ jobs:
tag: rolling
cc: gcc
cxx: g++
configureflags: --disable-std-function --disable-std-tuple --enable-std-pointers --enable-std-any --enable-std-optional
configureflags: --enable-std-pointers --enable-std-any --enable-std-optional
- name: "Thread-safe observer enabled"
shortname: threadsafe
tag: rolling
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/linux-nondefault.yml
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ jobs:
tag: rolling
cc: gcc
cxx: g++
configureflags: --disable-std-function --disable-std-tuple --enable-std-pointers --enable-std-any --enable-std-optional
configureflags: --enable-std-pointers --enable-std-any --enable-std-optional
- name: "OpenMP enabled"
shortname: openmp
tag: rolling
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ jobs:
tag: rolling
cc: gcc
cxx: g++
configureflags: --disable-std-function --disable-std-tuple --enable-std-pointers --enable-std-any --enable-std-optional
configureflags: --enable-std-pointers --enable-std-any --enable-std-optional
tests: true
- name: "Thread-safe observer enabled"
shortname: threadsafe
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/macos-nondefault.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
classes: [boost, std]
include:
- classes: std
configureflags: --disable-std-function --disable-std-tuple --enable-std-pointers --enable-std-optional --enable-std-any
configureflags: --enable-std-pointers --enable-std-optional --enable-std-any
steps:
- uses: actions/checkout@v4
- name: Setup
Expand Down
30 changes: 30 additions & 0 deletions .github/workflows/namespaces.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: Fix deprecated uses of ext namespace
on:
push:
branches:
- '**'
jobs:
namespaces:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Check
run: |
shopt -s globstar
sed -i -e 's/ext::function\b/std::function/g' **/*.[hc]pp
sed -i -e 's/ext::bind\b/std::bind/g' **/*.[hc]pp
sed -i -e 's/ext::ref\b/std::ref/g' **/*.[hc]pp
sed -i -e 's/ext::cref\b/std::cref/g' **/*.[hc]pp
sed -i -e 's/ext::placeholders\b/std::placeholders/g' **/*.[hc]pp
sed -i -e 's/ext::tuple\b/std::tuple/g' **/*.[hc]pp
sed -i -e 's/ext::make_tuple\b/std::make_tuple/g' **/*.[hc]pp
sed -i -e 's/ext::get\b/std::get/g' **/*.[hc]pp
sed -i -e 's/ext::tie\b/std::tie/g' **/*.[hc]pp
- uses: peter-evans/create-pull-request@v6
with:
token: ${{ secrets.GITHUB_TOKEN }}
branch: fix-ext-namespace-${{ github.ref_name }}
delete-branch: true
commit-message: 'Fix deprecated uses of ext namespace'
title: 'Fix deprecated uses of ext namespace'
author: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
4 changes: 0 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,8 @@ 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_ANY "Use std::any instead of boost::any" OFF)
option(QL_USE_STD_CLASSES "Enable all QL_USE_STD_ options" OFF)
option(QL_USE_STD_FUNCTION "Use std::function and std::bind instead of Boost ones" ON)
option(QL_USE_STD_OPTIONAL "Use std::optional instead of boost::optional" OFF)
option(QL_USE_STD_SHARED_PTR "Use standard smart pointers instead of Boost ones" OFF)
option(QL_USE_STD_TUPLE "Use std::tuple instead of boost::tuple" ON)
set(QL_EXTERNAL_SUBDIRECTORIES "" CACHE STRING "Optional list of external source directories to be added to the build (semicolon-separated)")
# set -lpapi here
set(QL_EXTRA_LINK_LIBRARIES "" CACHE STRING "Optional extra link libraries to add to QuantLib")
Expand All @@ -92,9 +90,7 @@ if (QL_USE_STD_CLASSES)
set(QL_USE_STD_ANY ON)
set(QL_USE_STD_OPTIONAL ON)
endif()
set(QL_USE_STD_FUNCTION ON)
set(QL_USE_STD_SHARED_PTR ON)
set(QL_USE_STD_TUPLE ON)
endif()

if (CMAKE_CXX_STANDARD LESS 17)
Expand Down
4 changes: 0 additions & 4 deletions CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -305,8 +305,6 @@
"QL_USE_STD_SHARED_PTR": "ON",
"QL_USE_STD_ANY": "ON",
"QL_USE_STD_OPTIONAL": "ON",
"QL_USE_STD_FUNCTION": "OFF",
"QL_USE_STD_TUPLE": "OFF",
"QL_COMPILE_WARNING_AS_ERROR": "ON"
}
},
Expand All @@ -328,8 +326,6 @@
"QL_USE_STD_SHARED_PTR": "ON",
"QL_USE_STD_ANY": "ON",
"QL_USE_STD_OPTIONAL": "ON",
"QL_USE_STD_FUNCTION": "OFF",
"QL_USE_STD_TUPLE": "OFF",
"QL_COMPILE_WARNING_AS_ERROR": "ON",
"CMAKE_CXX_COMPILER_LAUNCHER": "sccache"
}
Expand Down
14 changes: 0 additions & 14 deletions Docs/pages/config.docs
Original file line number Diff line number Diff line change
Expand Up @@ -127,20 +127,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_FUNCTION
\endcode
If defined (the default), `std::function`, `std::bind` and related
classes and functions are used. If disabled, the corresponding
Boost facilities are used instead.

\code
#define QL_USE_STD_TUPLE
\endcode
If defined (the default), `std::tuple` and related classes and
functions are used. If disabled, the corresponding Boost
facilities are used instead..

\code
#define QL_USE_STD_ANY
\endcode
Expand Down
4 changes: 2 additions & 2 deletions Examples/GlobalOptimizer/GlobalOptimizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,8 @@ Real printFunction(Problem& p, const Array& x) {

class TestFunction : public CostFunction {
public:
typedef ext::function<Real(const Array&)> RealFunc;
typedef ext::function<Array(const Array&)> ArrayFunc;
typedef std::function<Real(const Array&)> RealFunc;
typedef std::function<Array(const Array&)> ArrayFunc;
explicit TestFunction(RealFunc f, ArrayFunc fs = ArrayFunc())
: f_(std::move(f)), fs_(std::move(fs)) {}
explicit TestFunction(Real (*f)(const Array&), Array (*fs)(const Array&) = nullptr)
Expand Down
2 changes: 1 addition & 1 deletion Examples/MultidimIntegral/MultidimIntegral.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ int main() {
Real exactSol = std::pow(std::exp(-.25) *
std::sqrt(M_PI), static_cast<Real>(dimension));

ext::function<Real(const std::vector<Real>& arg)> f = integrand();
std::function<Real(const std::vector<Real>& arg)> f = integrand();

#ifndef QL_PATCH_SOLARIS
GaussianQuadMultidimIntegrator intg(dimension, 15);
Expand Down
34 changes: 0 additions & 34 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -432,36 +432,6 @@ if test "$ql_use_std_pointers" = "yes" ; then
fi
AC_MSG_RESULT([$ql_use_std_pointers])

AC_MSG_CHECKING([whether to enable std::function])
AC_ARG_ENABLE([std-function],
AS_HELP_STRING([--enable-std-function],
[If enabled (the default), std::function
and std::bind will be used. If
disabled, the corresponding Boost
classes will be used instead.]),
[ql_use_std_function=$enableval],
[ql_use_std_function=yes])
if test "$ql_use_std_function" = "yes" ; then
AC_DEFINE([QL_USE_STD_FUNCTION],[1],
[Define this if you want to use std::function and std::bind.])
fi
AC_MSG_RESULT([$ql_use_std_function])

AC_MSG_CHECKING([whether to enable std::tuple])
AC_ARG_ENABLE([std-tuple],
AS_HELP_STRING([--enable-std-tuple],
[If enabled (the default), std::tuple and
related functions will be used. If
disabled, the corresponding Boost
facilities will be used instead.]),
[ql_use_std_tuple=$enableval],
[ql_use_std_tuple=yes])
if test "$ql_use_std_tuple" = "yes" ; then
AC_DEFINE([QL_USE_STD_TUPLE],[1],
[Define this if you want to use std::tuple.])
fi
AC_MSG_RESULT([$ql_use_std_tuple])

AC_MSG_CHECKING([whether to enable available std classes])
AC_ARG_ENABLE([std-classes],
AS_HELP_STRING([--enable-std-classes],
Expand All @@ -474,10 +444,6 @@ AC_ARG_ENABLE([std-classes],
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_FUNCTION],[1],
[Define this if you want to use std::function and std::bind.])
AC_DEFINE([QL_USE_STD_TUPLE],[1],
[Define this if you want to use std::tuple.])
fi
AC_MSG_RESULT([$ql_use_std_classes])

Expand Down
14 changes: 7 additions & 7 deletions ql/cashflows/conundrumpricer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ namespace QuantLib {

class VariableChange {
public:
VariableChange(ext::function<Real (Real)>& f,
VariableChange(std::function<Real (Real)>& f,
Real a, Real b, Size k)
: a_(a), width_(b-a), f_(f), k_(k) {}
Real value(Real x) const {
Expand All @@ -246,21 +246,21 @@ namespace QuantLib {
}
private:
Real a_, width_;
ext::function<Real (Real)> f_;
std::function<Real (Real)> f_;
Size k_;
};

class Spy {
public:
explicit Spy(ext::function<Real(Real)> f) : f_(std::move(f)) {}
explicit Spy(std::function<Real(Real)> f) : f_(std::move(f)) {}
Real value(Real x){
abscissas.push_back(x);
Real value = f_(x);
functionValues.push_back(value);
return value;
}
private:
ext::function<Real (Real)> f_;
std::function<Real (Real)> f_;
std::vector<Real> abscissas;
std::vector<Real> functionValues;
};
Expand Down Expand Up @@ -298,21 +298,21 @@ namespace QuantLib {
if (b > a)
upperBoundary = std::min(upperBoundary, b);

ext::function<Real(Real)> f;
std::function<Real(Real)> f;
GaussKronrodNonAdaptive
gaussKronrodNonAdaptive(precision_, 1000000, 1.0);
// if the integration intervall is wide enough we use the
// following change variable x -> a + (b-a)*(t/(a-b))^3
upperBoundary = std::max(a, std::min(upperBoundary, hardUpperLimit_));
if (upperBoundary > 2 * a) {
Size k = 3;
ext::function<Real(Real)> temp = ext::cref(integrand);
std::function<Real(Real)> temp = std::cref(integrand);
VariableChange variableChange(temp, a, upperBoundary, k);
f = [&](Real _x) { return variableChange.value(_x); };
result = gaussKronrodNonAdaptive(f, .0, 1.0);
}
else {
f = ext::cref(integrand);
f = std::cref(integrand);
result = gaussKronrodNonAdaptive(f, a, upperBoundary);
}

Expand Down
2 changes: 0 additions & 2 deletions ql/config.hpp.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@
#cmakedefine QL_USE_STD_ANY 1
#cmakedefine QL_USE_STD_OPTIONAL 1
#cmakedefine QL_USE_STD_SHARED_PTR 1
#cmakedefine QL_USE_STD_FUNCTION 1
#cmakedefine QL_USE_STD_TUPLE 1
#cmakedefine QL_NULL_AS_FUNCTIONS 1

#endif
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,11 @@ namespace QuantLib {
Real taumax,
int iord,
int igm,
const ext::function<Real(Real, Real)>& integr,
const ext::function<Real(Real, Real)>& integalpha,
const ext::function<Real(Real, Real)>& integs,
const ext::function<Real(Real)>& alpha,
const ext::function<Real(Real)>& sigmaq) {
const std::function<Real(Real, Real)>& integr,
const std::function<Real(Real, Real)>& integalpha,
const std::function<Real(Real, Real)>& integs,
const std::function<Real(Real)>& alpha,
const std::function<Real(Real)>& sigmaq) {
Real v0=0.0, v1=0.0, v1p=0.0, v2p=0.0, v2pp=0.0, gm=0.0;
int i=0,j=0;
Real tmp=0.0, e1=0.0, e2=0.0, e3=0.0, e4=0.0;
Expand Down
8 changes: 4 additions & 4 deletions ql/experimental/callablebonds/callablebond.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ namespace QuantLib {

class OASHelper {
public:
OASHelper(const ext::function<Real(Real)>& npvhelper,
OASHelper(const std::function<Real(Real)>& npvhelper,
Real targetValue):
npvhelper_(npvhelper),
targetValue_(targetValue)
Expand All @@ -169,7 +169,7 @@ namespace QuantLib {
return targetValue_ - npvhelper_(x);
}
private:
const ext::function<Real(Real)>& npvhelper_;
const std::function<Real(Real)>& npvhelper_;
Real targetValue_;
};

Expand Down Expand Up @@ -292,7 +292,7 @@ namespace QuantLib {
Real dirtyPrice = cleanPrice + accruedAmount(settlement);
dirtyPrice /= 100.0 / notional(settlement);

ext::function<Real(Real)> f = NPVSpreadHelper(*this);
std::function<Real(Real)> f = NPVSpreadHelper(*this);
OASHelper obj(f, dirtyPrice);

Brent solver;
Expand Down Expand Up @@ -328,7 +328,7 @@ namespace QuantLib {
compounding,
frequency);

ext::function<Real(Real)> f = NPVSpreadHelper(*this);
std::function<Real(Real)> f = NPVSpreadHelper(*this);

Real P = f(oas) * 100.0 / notional(settlement) - accruedAmount(settlement);

Expand Down
8 changes: 4 additions & 4 deletions ql/experimental/credit/randomdefaultlatentmodel.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ namespace QuantLib {
Real percentile(const Date& d, Real percentile) const override;
/*! Returns the VaR value for a given percentile and the 95 confidence
interval of that value. */
virtual ext::tuple<Real, Real, Real> percentileAndInterval(
virtual std::tuple<Real, Real, Real> percentileAndInterval(
const Date& d, Real percentile) const;
/*! Distributes the total VaR amount along the portfolio counterparties.
The passed loss amount is in loss units.
Expand Down Expand Up @@ -524,7 +524,7 @@ namespace QuantLib {
template<template <class, class> class D, class C, class URNG>
Real RandomLM<D, C, URNG>::percentile(const Date& d, Real perc) const {
// need to specify return type in tuples' get is parametric
return ext::get<0>(percentileAndInterval(d, perc));
return std::get<0>(percentileAndInterval(d, perc));
}


Expand All @@ -535,7 +535,7 @@ namespace QuantLib {
of the stimator just computed. See the reference for a discussion.
*/
template<template <class, class> class D, class C, class URNG>
ext::tuple<Real, Real, Real> RandomLM<D, C, URNG>::percentileAndInterval(const Date& d,
std::tuple<Real, Real, Real> RandomLM<D, C, URNG>::percentileAndInterval(const Date& d,
Real percentile) const {

QL_REQUIRE(percentile >= 0. && percentile <= 1.,
Expand Down Expand Up @@ -613,7 +613,7 @@ namespace QuantLib {
lowerPercentile = rankLosses[r];
upperPercentile = rankLosses[s];

return ext::make_tuple(quantileValue, lowerPercentile, upperPercentile);
return std::make_tuple(quantileValue, lowerPercentile, upperPercentile);
}


Expand Down
Loading

0 comments on commit ba9ffb9

Please sign in to comment.