ps-lite icon indicating copy to clipboard operation
ps-lite copied to clipboard

more standard implementation of SArray::operator=

Open microwish opened this issue 8 years ago • 0 comments

It might be better to implement SArray::operator= in a more standard way.

1 template <typename W>
2 SArray<V>& operator=(const SArray<W>& arr)
3 {
4 if (this == &arr) return *this;
5 size_ = arr.size() * sizeof(W) / sizeof(V);
6 CHECK_EQ(size_ * sizeof(V), arr.size() * sizeof(W)); 7 capacity_ = arr.capacity() * sizeof(W) / sizeof(V);
8 ptr_ = std::shared_ptr<V>(arr.ptr(), reinterpret_cast<V *>(arr.data())); 9 }

microwish avatar Mar 28 '17 01:03 microwish