Skip to content

Commit a15c257

Browse files
committed
use move
1 parent 06d739e commit a15c257

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed

quantlib/cashflows/_overnight_indexed_coupon.pxd

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ from quantlib.time.businessdayconvention cimport BusinessDayConvention
1212
from quantlib.indexes._ibor_index cimport OvernightIndex
1313
from ._floating_rate_coupon cimport FloatingRateCoupon
1414
from .rateaveraging cimport RateAveraging
15+
from .._cashflow cimport Leg
1516

1617
cdef extern from 'ql/cashflows/overnightindexedcoupon.hpp' namespace 'QuantLib' nogil:
1718
cdef cppclass OvernightIndexedCoupon(FloatingRateCoupon):
@@ -50,3 +51,11 @@ cdef extern from 'ql/cashflows/overnightindexedcoupon.hpp' namespace 'QuantLib'
5051
OvernightLeg& withObservationShift(bool)
5152
OvernightLeg& withLookbackDays(Natural)
5253
OvernightLeg& withLockoutDays(Natural)
54+
Leg operator() const
55+
56+
cdef extern from 'ql/cashflows/overnightindexedcoupon.hpp':
57+
# this allows to declare the cast operator as raising exceptions
58+
"""
59+
#define to_leg(x) static_cast<QuantLib::Leg>(x)
60+
"""
61+
cdef Leg to_leg(OvernightLeg) except +

quantlib/cashflows/fixed_rate_coupon.pyx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from quantlib.types cimport Rate, Real
22
from cython.operator cimport dereference as deref, preincrement as preinc
33
from libcpp.vector cimport vector
4+
from libcpp.utility cimport move
45
from quantlib.compounding cimport Compounding
56
from quantlib.handle cimport shared_ptr
67
from quantlib.time.businessdayconvention cimport BusinessDayConvention
@@ -11,6 +12,7 @@ from quantlib.time.daycounter cimport DayCounter
1112
from quantlib.time.schedule cimport Schedule
1213
cimport quantlib._cashflow as _cf
1314
from quantlib.interest_rate cimport InterestRate
15+
from .._cashflow cimport Leg as QlLeg
1416
cimport quantlib._interest_rate as _ir
1517

1618
cdef class FixedRateCoupon(Coupon):
@@ -60,7 +62,7 @@ cdef class FixedRateLeg(Leg):
6062
return self
6163

6264
def __call__(self):
63-
self._thisptr = _frc.to_leg(deref(self.frl))
65+
self._thisptr = move[QlLeg](_frc.to_leg(deref(self.frl)))
6466
return self
6567

6668
def __iter__(self):

quantlib/cashflows/overnight_indexed_coupon.pyx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ from quantlib.types cimport Integer, Natural, Real, Spread
22

33
from libcpp cimport bool
44
from libcpp.vector cimport vector
5+
from libcpp.utility cimport move
56
from cython.operator cimport dereference as deref, preincrement as preinc
67
from quantlib.handle cimport make_shared, shared_ptr, static_pointer_cast
78
from quantlib.time.businessdayconvention cimport BusinessDayConvention
@@ -140,5 +141,5 @@ cdef class OvernightLeg(Leg):
140141
return self
141142

142143
def __call__(self):
143-
self._thisptr = <QlLeg>deref(self.leg)
144+
self._thisptr = move[QlLeg](_oic.to_leg(deref(self.leg)))
144145
return self

0 commit comments

Comments
 (0)