Skip to content

Commit

Permalink
Merge pull request #1019.
Browse files Browse the repository at this point in the history
C++11 modernization — use `nullptr` keyword
  • Loading branch information
lballabio committed Feb 7, 2021
2 parents b30099f + d961780 commit 8a70608
Show file tree
Hide file tree
Showing 210 changed files with 504 additions and 547 deletions.
2 changes: 1 addition & 1 deletion .clang-tidy
@@ -1,5 +1,5 @@
---
Checks: '-*,readability-*,bugprone-*,misc-*,performance-*,modernize-redundant-void-arg,modernize-deprecated-headers,modernize-use-override,modernize-use-auto,-readability-else-after-return,-readability-named-parameter,-readability-braces-around-statements,-readability-inconsistent-declaration-parameter-name,-readability-isolate-declaration,-readability-magic-numbers,-readability-convert-member-functions-to-static,-bugprone-macro-parentheses,-bugprone-narrowing-conversions,-bugprone-branch-clone,-misc-non-private-member-variables-in-classes,-misc-unused-parameters'
Checks: '-*,readability-*,bugprone-*,misc-*,performance-*,modernize-redundant-void-arg,modernize-deprecated-headers,modernize-use-override,modernize-use-auto,modernize-use-nullptr,-readability-else-after-return,-readability-named-parameter,-readability-braces-around-statements,-readability-inconsistent-declaration-parameter-name,-readability-isolate-declaration,-readability-magic-numbers,-readability-convert-member-functions-to-static,-bugprone-macro-parentheses,-bugprone-narrowing-conversions,-bugprone-branch-clone,-misc-non-private-member-variables-in-classes,-misc-unused-parameters'
WarningsAsErrors: ''
HeaderFilterRegex: '.*'
AnalyzeTemporaryDtors: false
Expand Down
3 changes: 2 additions & 1 deletion Examples/GlobalOptimizer/GlobalOptimizer.cpp
Expand Up @@ -144,7 +144,8 @@ class TestFunction : public CostFunction {
typedef ext::function<Real(const Array&)> RealFunc;
typedef ext::function<Disposable<Array>(const Array&)> ArrayFunc;
explicit TestFunction(const RealFunc & f, const ArrayFunc & fs = ArrayFunc()) : f_(f), fs_(fs) {}
explicit TestFunction(Real(*f)(const Array&), Disposable<Array>(*fs)(const Array&) = NULL) : f_(f), fs_(fs) {}
explicit TestFunction(Real (*f)(const Array&), Disposable<Array> (*fs)(const Array&) = nullptr)
: f_(f), fs_(fs) {}
~TestFunction() override {}
Real value(const Array& x) const override { return f_(x); }
Disposable<Array> values(const Array& x) const override {
Expand Down
2 changes: 1 addition & 1 deletion ql/cashflow.cpp
Expand Up @@ -62,7 +62,7 @@ namespace QuantLib {

void CashFlow::accept(AcyclicVisitor& v) {
auto* v1 = dynamic_cast<Visitor<CashFlow>*>(&v);
if (v1 != 0)
if (v1 != nullptr)
v1->visit(*this);
else
Event::accept(v);
Expand Down
2 changes: 1 addition & 1 deletion ql/cashflows/averagebmacoupon.cpp
Expand Up @@ -153,7 +153,7 @@ namespace QuantLib {

void AverageBMACoupon::accept(AcyclicVisitor& v) {
auto* v1 = dynamic_cast<Visitor<AverageBMACoupon>*>(&v);
if (v1 != 0) {
if (v1 != nullptr) {
v1->visit(*this);
} else {
FloatingRateCoupon::accept(v);
Expand Down
2 changes: 1 addition & 1 deletion ql/cashflows/capflooredcoupon.cpp
Expand Up @@ -131,7 +131,7 @@ namespace QuantLib {
void CappedFlooredCoupon::accept(AcyclicVisitor& v) {
typedef FloatingRateCoupon super;
auto* v1 = dynamic_cast<Visitor<CappedFlooredCoupon>*>(&v);
if (v1 != 0)
if (v1 != nullptr)
v1->visit(*this);
else
super::accept(v);
Expand Down
4 changes: 2 additions & 2 deletions ql/cashflows/capflooredcoupon.hpp
Expand Up @@ -121,7 +121,7 @@ namespace QuantLib {

void accept(AcyclicVisitor& v) override {
auto* v1 = dynamic_cast<Visitor<CappedFlooredIborCoupon>*>(&v);
if (v1 != 0)
if (v1 != nullptr)
v1->visit(*this);
else
CappedFlooredCoupon::accept(v);
Expand Down Expand Up @@ -153,7 +153,7 @@ namespace QuantLib {

void accept(AcyclicVisitor& v) override {
auto* v1 = dynamic_cast<Visitor<CappedFlooredCmsCoupon>*>(&v);
if (v1 != 0)
if (v1 != nullptr)
v1->visit(*this);
else
CappedFlooredCoupon::accept(v);
Expand Down
16 changes: 9 additions & 7 deletions ql/cashflows/capflooredinflationcoupon.cpp
Expand Up @@ -80,16 +80,17 @@ namespace QuantLib {
const ext::shared_ptr<YoYInflationCouponPricer>& pricer) {

YoYInflationCoupon::setPricer(pricer);
if (underlying_ != 0)
if (underlying_ != nullptr)
underlying_->setPricer(pricer);
}


Rate CappedFlooredYoYInflationCoupon::rate() const {
Rate swapletRate = underlying_ != 0 ? underlying_->rate() : YoYInflationCoupon::rate();
Rate swapletRate =
underlying_ != nullptr ? underlying_->rate() : YoYInflationCoupon::rate();

if(isFloored_ || isCapped_) {
if (underlying_ != 0) {
if (underlying_ != nullptr) {
QL_REQUIRE(underlying_->pricer(), "pricer not set");
} else {
QL_REQUIRE(pricer_, "pricer not set");
Expand All @@ -98,14 +99,15 @@ namespace QuantLib {

Rate floorletRate = 0.;
if(isFloored_) {
floorletRate = underlying_ != 0 ?
floorletRate = underlying_ != nullptr ?
underlying_->pricer()->floorletRate(effectiveFloor()) :
pricer()->floorletRate(effectiveFloor());
}
Rate capletRate = 0.;
if(isCapped_) {
capletRate = underlying_ != 0 ? underlying_->pricer()->capletRate(effectiveCap()) :
pricer()->capletRate(effectiveCap());
capletRate = underlying_ != nullptr ?
underlying_->pricer()->capletRate(effectiveCap()) :
pricer()->capletRate(effectiveCap());
}

return swapletRate + floorletRate - capletRate;
Expand Down Expand Up @@ -149,7 +151,7 @@ namespace QuantLib {
typedef YoYInflationCoupon super;
auto* v1 = dynamic_cast<Visitor<CappedFlooredYoYInflationCoupon>*>(&v);

if (v1 != 0)
if (v1 != nullptr)
v1->visit(*this);
else
super::accept(v);
Expand Down
33 changes: 16 additions & 17 deletions ql/cashflows/cashflows.cpp
Expand Up @@ -40,7 +40,7 @@ namespace QuantLib {
Date d = Date::maxDate();
for (Size i=0; i<leg.size(); ++i) {
ext::shared_ptr<Coupon> c = ext::dynamic_pointer_cast<Coupon>(leg[i]);
if (c != 0)
if (c != nullptr)
d = std::min(d, c->accrualStartDate());
else
d = std::min(d, leg[i]->date());
Expand All @@ -54,7 +54,7 @@ namespace QuantLib {
Date d = Date::minDate();
for (Size i=0; i<leg.size(); ++i) {
ext::shared_ptr<Coupon> c = ext::dynamic_pointer_cast<Coupon>(leg[i]);
if (c != 0)
if (c != nullptr)
d = std::max(d, c->accrualEndDate());
else
d = std::max(d, leg[i]->date());
Expand Down Expand Up @@ -237,7 +237,7 @@ namespace QuantLib {
Date paymentDate = (*cf)->date();
for (; cf<leg.end() && (*cf)->date()==paymentDate; ++cf) {
ext::shared_ptr<Coupon> cp = ext::dynamic_pointer_cast<Coupon>(*cf);
if (cp != 0)
if (cp != nullptr)
return cp->nominal();
}
return 0.0;
Expand All @@ -252,7 +252,7 @@ namespace QuantLib {
Date paymentDate = (*cf)->date();
for (; cf<leg.end() && (*cf)->date()==paymentDate; ++cf) {
ext::shared_ptr<Coupon> cp = ext::dynamic_pointer_cast<Coupon>(*cf);
if (cp != 0)
if (cp != nullptr)
return cp->accrualStartDate();
}
return Date();
Expand All @@ -267,7 +267,7 @@ namespace QuantLib {
Date paymentDate = (*cf)->date();
for (; cf<leg.end() && (*cf)->date()==paymentDate; ++cf) {
ext::shared_ptr<Coupon> cp = ext::dynamic_pointer_cast<Coupon>(*cf);
if (cp != 0)
if (cp != nullptr)
return cp->accrualEndDate();
}
return Date();
Expand All @@ -282,7 +282,7 @@ namespace QuantLib {
Date paymentDate = (*cf)->date();
for (; cf<leg.end() && (*cf)->date()==paymentDate; ++cf) {
ext::shared_ptr<Coupon> cp = ext::dynamic_pointer_cast<Coupon>(*cf);
if (cp != 0)
if (cp != nullptr)
return cp->referencePeriodStart();
}
return Date();
Expand All @@ -297,7 +297,7 @@ namespace QuantLib {
Date paymentDate = (*cf)->date();
for (; cf<leg.end() && (*cf)->date()==paymentDate; ++cf) {
ext::shared_ptr<Coupon> cp = ext::dynamic_pointer_cast<Coupon>(*cf);
if (cp != 0)
if (cp != nullptr)
return cp->referencePeriodEnd();
}
return Date();
Expand All @@ -312,7 +312,7 @@ namespace QuantLib {
Date paymentDate = (*cf)->date();
for (; cf<leg.end() && (*cf)->date()==paymentDate; ++cf) {
ext::shared_ptr<Coupon> cp = ext::dynamic_pointer_cast<Coupon>(*cf);
if (cp != 0)
if (cp != nullptr)
return cp->accrualPeriod();
}
return 0;
Expand All @@ -327,7 +327,7 @@ namespace QuantLib {
Date paymentDate = (*cf)->date();
for (; cf<leg.end() && (*cf)->date()==paymentDate; ++cf) {
ext::shared_ptr<Coupon> cp = ext::dynamic_pointer_cast<Coupon>(*cf);
if (cp != 0)
if (cp != nullptr)
return cp->accrualDays();
}
return 0;
Expand All @@ -345,7 +345,7 @@ namespace QuantLib {
Date paymentDate = (*cf)->date();
for (; cf<leg.end() && (*cf)->date()==paymentDate; ++cf) {
ext::shared_ptr<Coupon> cp = ext::dynamic_pointer_cast<Coupon>(*cf);
if (cp != 0)
if (cp != nullptr)
return cp->accruedPeriod(settlementDate);
}
return 0;
Expand All @@ -363,7 +363,7 @@ namespace QuantLib {
Date paymentDate = (*cf)->date();
for (; cf<leg.end() && (*cf)->date()==paymentDate; ++cf) {
ext::shared_ptr<Coupon> cp = ext::dynamic_pointer_cast<Coupon>(*cf);
if (cp != 0)
if (cp != nullptr)
return cp->accruedDays(settlementDate);
}
return 0;
Expand All @@ -382,7 +382,7 @@ namespace QuantLib {
Real result = 0.0;
for (; cf<leg.end() && (*cf)->date()==paymentDate; ++cf) {
ext::shared_ptr<Coupon> cp = ext::dynamic_pointer_cast<Coupon>(*cf);
if (cp != 0)
if (cp != nullptr)
result += cp->accruedAmount(settlementDate);
}
return result;
Expand Down Expand Up @@ -491,7 +491,7 @@ namespace QuantLib {
ext::dynamic_pointer_cast<Coupon>(leg[i]);
Real df = discountCurve.discount(cf.date());
npv += cf.amount() * df;
if(cp != NULL)
if (cp != nullptr)
bps += cp->nominal() * cp->accrualPeriod() * df;
}
}
Expand Down Expand Up @@ -567,7 +567,7 @@ namespace QuantLib {
Date refStartDate, refEndDate;
ext::shared_ptr<Coupon> coupon =
ext::dynamic_pointer_cast<Coupon>(cashFlow);
if (coupon != 0) {
if (coupon != nullptr) {
refStartDate = coupon->referencePeriodStart();
refEndDate = coupon->referencePeriodEnd();
} else {
Expand All @@ -581,14 +581,13 @@ namespace QuantLib {
refEndDate = cashFlowDate;
}

if ((coupon != 0) && lastDate != coupon->accrualStartDate()) {
if ((coupon != nullptr) && lastDate != coupon->accrualStartDate()) {
Time couponPeriod = dc.yearFraction(coupon->accrualStartDate(),
cashFlowDate, refStartDate, refEndDate);
Time accruedPeriod = dc.yearFraction(coupon->accrualStartDate(),
lastDate, refStartDate, refEndDate);
return couponPeriod - accruedPeriod;
}
else {
} else {
return dc.yearFraction(lastDate, cashFlowDate,
refStartDate, refEndDate);
}
Expand Down
2 changes: 1 addition & 1 deletion ql/cashflows/cmscoupon.cpp
Expand Up @@ -46,7 +46,7 @@ namespace QuantLib {

void CmsCoupon::accept(AcyclicVisitor& v) {
auto* v1 = dynamic_cast<Visitor<CmsCoupon>*>(&v);
if (v1 != 0)
if (v1 != nullptr)
v1->visit(*this);
else
FloatingRateCoupon::accept(v);
Expand Down
2 changes: 1 addition & 1 deletion ql/cashflows/coupon.cpp
Expand Up @@ -76,7 +76,7 @@ namespace QuantLib {

void Coupon::accept(AcyclicVisitor& v) {
auto* v1 = dynamic_cast<Visitor<Coupon>*>(&v);
if (v1 != 0)
if (v1 != nullptr)
v1->visit(*this);
else
CashFlow::accept(v);
Expand Down
6 changes: 3 additions & 3 deletions ql/cashflows/couponpricer.cpp
Expand Up @@ -225,13 +225,13 @@ namespace QuantLib {
// we might end up here because a CappedFlooredCoupon
// was directly constructed; we should then check
// the underlying for consistency with the pricer
if (ext::dynamic_pointer_cast<IborCoupon>(c.underlying()) != 0) {
if (ext::dynamic_pointer_cast<IborCoupon>(c.underlying()) != nullptr) {
QL_REQUIRE(ext::dynamic_pointer_cast<IborCouponPricer>(pricer_),
"pricer not compatible with Ibor Coupon");
} else if (ext::dynamic_pointer_cast<CmsCoupon>(c.underlying()) != 0) {
} else if (ext::dynamic_pointer_cast<CmsCoupon>(c.underlying()) != nullptr) {
QL_REQUIRE(ext::dynamic_pointer_cast<CmsCouponPricer>(pricer_),
"pricer not compatible with CMS Coupon");
} else if (ext::dynamic_pointer_cast<CmsSpreadCoupon>(c.underlying()) != 0) {
} else if (ext::dynamic_pointer_cast<CmsSpreadCoupon>(c.underlying()) != nullptr) {
QL_REQUIRE(ext::dynamic_pointer_cast<CmsSpreadCouponPricer>(pricer_),
"pricer not compatible with CMS spread Coupon");
}
Expand Down
2 changes: 1 addition & 1 deletion ql/cashflows/cpicoupon.cpp
Expand Up @@ -59,7 +59,7 @@ namespace QuantLib {

void CPICoupon::accept(AcyclicVisitor& v) {
auto* v1 = dynamic_cast<Visitor<CPICoupon>*>(&v);
if (v1 != 0)
if (v1 != nullptr)
v1->visit(*this);
else
InflationCoupon::accept(v);
Expand Down
2 changes: 1 addition & 1 deletion ql/cashflows/digitalcmscoupon.cpp
Expand Up @@ -43,7 +43,7 @@ namespace QuantLib {
void DigitalCmsCoupon::accept(AcyclicVisitor& v) {
typedef DigitalCoupon super;
auto* v1 = dynamic_cast<Visitor<DigitalCmsCoupon>*>(&v);
if (v1 != 0)
if (v1 != nullptr)
v1->visit(*this);
else
super::accept(v);
Expand Down
2 changes: 1 addition & 1 deletion ql/cashflows/digitalcoupon.cpp
Expand Up @@ -282,7 +282,7 @@ namespace QuantLib {
void DigitalCoupon::accept(AcyclicVisitor& v) {
typedef FloatingRateCoupon super;
auto* v1 = dynamic_cast<Visitor<DigitalCoupon>*>(&v);
if (v1 != 0)
if (v1 != nullptr)
v1->visit(*this);
else
super::accept(v);
Expand Down
4 changes: 2 additions & 2 deletions ql/cashflows/digitalcoupon.hpp
Expand Up @@ -131,10 +131,10 @@ namespace QuantLib {
void accept(AcyclicVisitor&) override;

void setPricer(const ext::shared_ptr<FloatingRateCouponPricer>& pricer) override {
if (pricer_ != 0)
if (pricer_ != nullptr)
unregisterWith(pricer_);
pricer_ = pricer;
if (pricer_ != 0)
if (pricer_ != nullptr)
registerWith(pricer_);
update();
underlying_->setPricer(pricer);
Expand Down
2 changes: 1 addition & 1 deletion ql/cashflows/digitaliborcoupon.cpp
Expand Up @@ -43,7 +43,7 @@ namespace QuantLib {
void DigitalIborCoupon::accept(AcyclicVisitor& v) {
typedef DigitalCoupon super;
auto* v1 = dynamic_cast<Visitor<DigitalIborCoupon>*>(&v);
if (v1 != 0)
if (v1 != nullptr)
v1->visit(*this);
else
super::accept(v);
Expand Down
2 changes: 1 addition & 1 deletion ql/cashflows/dividend.cpp
Expand Up @@ -25,7 +25,7 @@ namespace QuantLib {

void Dividend::accept(AcyclicVisitor& v) {
auto* v1 = dynamic_cast<Visitor<Dividend>*>(&v);
if (v1 != 0)
if (v1 != nullptr)
v1->visit(*this);
else
CashFlow::accept(v);
Expand Down
2 changes: 1 addition & 1 deletion ql/cashflows/fixedratecoupon.hpp
Expand Up @@ -123,7 +123,7 @@ namespace QuantLib {

inline void FixedRateCoupon::accept(AcyclicVisitor& v) {
auto* v1 = dynamic_cast<Visitor<FixedRateCoupon>*>(&v);
if (v1 != 0)
if (v1 != nullptr)
v1->visit(*this);
else
Coupon::accept(v);
Expand Down
4 changes: 2 additions & 2 deletions ql/cashflows/floatingratecoupon.cpp
Expand Up @@ -60,10 +60,10 @@ namespace QuantLib {

void FloatingRateCoupon::setPricer(
const ext::shared_ptr<FloatingRateCouponPricer>& pricer) {
if (pricer_ != 0)
if (pricer_ != nullptr)
unregisterWith(pricer_);
pricer_ = pricer;
if (pricer_ != 0)
if (pricer_ != nullptr)
registerWith(pricer_);
update();
}
Expand Down
2 changes: 1 addition & 1 deletion ql/cashflows/floatingratecoupon.hpp
Expand Up @@ -144,7 +144,7 @@ namespace QuantLib {

inline void FloatingRateCoupon::accept(AcyclicVisitor& v) {
auto* v1 = dynamic_cast<Visitor<FloatingRateCoupon>*>(&v);
if (v1 != 0)
if (v1 != nullptr)
v1->visit(*this);
else
Coupon::accept(v);
Expand Down
2 changes: 1 addition & 1 deletion ql/cashflows/iborcoupon.cpp
Expand Up @@ -143,7 +143,7 @@ namespace QuantLib {

void IborCoupon::accept(AcyclicVisitor& v) {
auto* v1 = dynamic_cast<Visitor<IborCoupon>*>(&v);
if (v1 != 0)
if (v1 != nullptr)
v1->visit(*this);
else
FloatingRateCoupon::accept(v);
Expand Down
2 changes: 1 addition & 1 deletion ql/cashflows/indexedcashflow.hpp
Expand Up @@ -88,7 +88,7 @@ namespace QuantLib {

inline void IndexedCashFlow::accept(AcyclicVisitor& v) {
auto* v1 = dynamic_cast<Visitor<IndexedCashFlow>*>(&v);
if (v1 != 0)
if (v1 != nullptr)
v1->visit(*this);
else
CashFlow::accept(v);
Expand Down

0 comments on commit 8a70608

Please sign in to comment.