Skip to content

Commit 82feac3

Browse files
Владимир СеверовВладимир Северов
authored andcommitted
17.04.23 21:13 - std::copy instead of memcpy
1 parent 4a245b8 commit 82feac3

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

M2-LW-7/M2-LW-7/Vector.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#ifndef __TVECTOR_INCLUDED__
22
#define __TVECTOR_INCLUDED__
33

4+
#pragma warning(disable:4996)
5+
46
#include <memory>
57
#include <exception>
68

@@ -88,7 +90,7 @@ class Vector
8890

8991
internalCapacity_ = _count;
9092
value_type * newPtr = new value_type[internalCapacity_];
91-
memcpy(newPtr, ptr_, sizeof(value_type) * size_);
93+
std::copy(ptr_, ptr_ + size_, newPtr);
9294
delete[] ptr_;
9395
ptr_ = newPtr;
9496
}
@@ -98,7 +100,7 @@ class Vector
98100
, size_(_rhs.size_)
99101
{
100102
ptr_ = new value_type[internalCapacity_];
101-
memcpy(ptr_, _rhs.ptr_, sizeof(value_type) * internalCapacity_);
103+
std::copy(_rhs.ptr_, _rhs.ptr_ + size_, ptr_);
102104
}
103105

104106
Vector& operator=(const Vector& _rhs)
@@ -112,7 +114,7 @@ class Vector
112114
ptr_ = new value_type[internalCapacity_];
113115
}
114116
size_ = _rhs.size_;
115-
memcpy(ptr_, _rhs.ptr_, sizeof(value_type) * internalCapacity_);
117+
std::copy(_rhs.ptr_, _rhs.ptr_ + internalCapacity_, ptr_);
116118
return *this;
117119
}
118120

0 commit comments

Comments
 (0)