Disallow vector copying, allow moves.

This commit is contained in:
Bartosz Taudul 2017-09-23 01:10:48 +02:00
parent 34aecee1f9
commit b62dc57a92

View File

@ -24,12 +24,32 @@ public:
{ {
} }
Vector( const Vector& ) = delete;
Vector( Vector&& src )
: m_ptr( src.m_ptr )
, m_size( src.m_size )
, m_capacity( src.m_capacity )
{
src.m_ptr = nullptr;
}
~Vector() ~Vector()
{ {
memUsage.fetch_sub( m_capacity * sizeof( T ), std::memory_order_relaxed ); memUsage.fetch_sub( m_capacity * sizeof( T ), std::memory_order_relaxed );
delete[] m_ptr; delete[] m_ptr;
} }
Vector& operator=( const Vector& ) = delete;
Vector& operator=( Vector&& src )
{
delete[] m_ptr;
m_ptr = src.m_ptr;
m_size = src.m_size;
m_capacity = src.m_capacity;
src.m_ptr = nullptr;
return *this;
}
bool empty() const { return m_size == 0; } bool empty() const { return m_size == 0; }
size_t size() const { return m_size; } size_t size() const { return m_size; }