Skip to content

Commit 36c3ff7

Browse files
pcaspersjenkins
authored andcommitted
QPR-11984 replace memcpy with copy
1 parent bbb1833 commit 36c3ff7

1 file changed

Lines changed: 12 additions & 6 deletions

File tree

QuantExt/qle/math/randomvariable.cpp

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ Filter::Filter(const Filter& r) {
3737
constantData_ = r.constantData_;
3838
if (r.data_) {
3939
data_ = new bool[n_];
40-
std::memcpy(data_, r.data_, n_ * sizeof(bool));
40+
// std::memcpy(data_, r.data_, n_ * sizeof(bool));
41+
std::copy(r.data_, r.data_ + n_, data_);
4142
} else {
4243
data_ = nullptr;
4344
}
@@ -67,7 +68,8 @@ Filter& Filter::operator=(const Filter& r) {
6768
delete[] data_;
6869
data_ = new bool[r.n_];
6970
}
70-
std::memcpy(data_, r.data_, r.n_ * sizeof(bool));
71+
// std::memcpy(data_, r.data_, r.n_ * sizeof(bool));
72+
std::copy(r.data_, r.data_ + r.n_, data_);
7173
} else {
7274
if (data_) {
7375
delete[] data_;
@@ -253,7 +255,8 @@ RandomVariable::RandomVariable(const RandomVariable& r) {
253255
constantData_ = r.constantData_;
254256
if (r.data_) {
255257
data_ = new double[n_];
256-
std::memcpy(data_, r.data_, n_ * sizeof(double));
258+
// std::memcpy(data_, r.data_, n_ * sizeof(double));
259+
std::copy(r.data_, r.data_ + n_, data_);
257260
} else {
258261
data_ = nullptr;
259262
}
@@ -285,7 +288,8 @@ RandomVariable& RandomVariable::operator=(const RandomVariable& r) {
285288
delete[] data_;
286289
data_ = new double[r.n_];
287290
}
288-
std::memcpy(data_, r.data_, r.n_ * sizeof(double));
291+
// std::memcpy(data_, r.data_, r.n_ * sizeof(double));
292+
std::copy(r.data_, r.data_ + r.n_, data_);
289293
} else {
290294
if (data_) {
291295
delete[] data_;
@@ -341,7 +345,8 @@ RandomVariable::RandomVariable(const QuantLib::Array& array, const Real time) {
341345
time_ = time;
342346
if (n_ != 0) {
343347
data_ = new double[n_];
344-
std::memcpy(data_, array.begin(), n_ * sizeof(double));
348+
// std::memcpy(data_, array.begin(), n_ * sizeof(double));
349+
std::copy(array.begin(),array.end(), data_);
345350
} else {
346351
data_ = nullptr;
347352
}
@@ -360,7 +365,8 @@ void RandomVariable::copyToArray(QuantLib::Array& array) const {
360365
if (deterministic_)
361366
std::fill(array.begin(), array.end(), constantData_);
362367
else if (n_ != 0) {
363-
std::memcpy(array.begin(), data_, n_ * sizeof(double));
368+
// std::memcpy(array.begin(), data_, n_ * sizeof(double));
369+
std::copy(array.begin(),array.end(), data_);
364370
}
365371
}
366372

0 commit comments

Comments
 (0)