@@ -83,7 +83,8 @@ namespace plg {
8383 noexcept (std::is_nothrow_copy_constructible_v<T>)
8484 {
8585 if constexpr (std::is_trivially_copy_constructible_v<T>) {
86- std::memmove ((void *)this , (const void *)std::addressof (rhs), sizeof (ipvbase));
86+ std::memcpy (data_, rhs.data_ , rhs.size_ * sizeof (T));
87+ size_ = rhs.size_ ;
8788 } else {
8889 std::uninitialized_copy_n (rhs.data_ , rhs.size_ , data_);
8990 size_ = rhs.size_ ;
@@ -97,7 +98,8 @@ namespace plg {
9798 )
9899 {
99100 if constexpr (std::is_trivially_move_constructible_v<T>) {
100- std::memmove ((void *)this , (const void *)std::addressof (rhs), sizeof (ipvbase));
101+ std::memcpy (data_, rhs.data_ , rhs.size_ * sizeof (T));
102+ size_ = rhs.size_ ;
101103#if defined(__cpp_lib_trivially_relocatable)
102104 } else if constexpr (std::is_trivially_relocatable_v<T>) {
103105 std::uninitialized_relocate_n (rhs.data_ , rhs.size_ , data_);
@@ -112,10 +114,11 @@ namespace plg {
112114 void operator =(const ipvbase& rhs)
113115 noexcept (std::is_nothrow_copy_constructible_v<T> && std::is_nothrow_copy_assignable_v<T>)
114116 {
117+ if (this == std::addressof (rhs)) return ;
118+
115119 if constexpr (std::is_trivially_copy_constructible_v<T> && std::is_trivially_copy_assignable_v<T> && std::is_trivially_destructible_v<T>) {
116- std::memmove ((void *)this , (const void *)std::addressof (rhs), sizeof (ipvbase));
117- } else if (this == std::addressof (rhs)) {
118- // do nothing
120+ std::memcpy (data_, rhs.data_ , rhs.size_ * sizeof (T));
121+ size_ = rhs.size_ ;
119122 } else if (rhs.size_ <= size_) {
120123 std::copy (rhs.data_ , rhs.data_ + rhs.size_ , data_);
121124 std::destroy (data_ + rhs.size_ , data_ + size_);
@@ -129,10 +132,11 @@ namespace plg {
129132 void operator =(ipvbase&& rhs)
130133 noexcept (std::is_nothrow_move_constructible_v<T> && std::is_nothrow_move_assignable_v<T>)
131134 {
135+ if (this == std::addressof (rhs)) return ;
136+
132137 if constexpr (std::is_trivially_move_constructible_v<T> && std::is_trivially_move_assignable_v<T> && std::is_trivially_destructible_v<T>) {
133- std::memmove ((void *)this , (const void *)std::addressof (rhs), sizeof (ipvbase));
134- } else if (this == std::addressof (rhs)) {
135- // do nothing
138+ std::memcpy (data_, rhs.data_ , rhs.size_ * sizeof (T));
139+ size_ = rhs.size_ ;
136140 } else if (rhs.size_ <= size_) {
137141 std::move (rhs.data_ , rhs.data_ + rhs.size_ , data_);
138142 std::destroy (data_ + rhs.size_ , data_ + size_);
0 commit comments