Compare commits
2 Commits
3b4b750cbf
...
da805eec83
Author | SHA1 | Date | |
---|---|---|---|
da805eec83 | |||
eb35abfa52 |
@ -7,6 +7,7 @@
|
|||||||
#define STRINGIZE_VALUE_OF(x) STRINGIZE(x)
|
#define STRINGIZE_VALUE_OF(x) STRINGIZE(x)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
// Like check(), but with a custom error message.
|
||||||
#define expect(expr, message) \
|
#define expect(expr, message) \
|
||||||
do { \
|
do { \
|
||||||
if (!(expr)) [[unlikely]] \
|
if (!(expr)) [[unlikely]] \
|
||||||
@ -15,6 +16,7 @@
|
|||||||
} \
|
} \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
|
// Like assert(), but always enabled.
|
||||||
#define check(expr) \
|
#define check(expr) \
|
||||||
do { \
|
do { \
|
||||||
if (!(expr)) [[unlikely]] \
|
if (!(expr)) [[unlikely]] \
|
||||||
|
@ -14,6 +14,60 @@ template <typename T> class Vector
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Vector(const Vector<T>& other)
|
||||||
|
{
|
||||||
|
reserve(other.capacity());
|
||||||
|
memcpy(m_data, other.data(), other.size());
|
||||||
|
m_size = other.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
Vector(Vector<T>&& other)
|
||||||
|
{
|
||||||
|
m_data = other.data();
|
||||||
|
m_capacity = other.capacity();
|
||||||
|
m_size = other.size();
|
||||||
|
|
||||||
|
other.m_capacity = other.m_size = 0;
|
||||||
|
other.m_data = nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
Vector<T>& operator=(const Vector<T>& other)
|
||||||
|
{
|
||||||
|
if (&other == this) return *this;
|
||||||
|
|
||||||
|
if (m_data) free_impl(m_data);
|
||||||
|
|
||||||
|
m_data = nullptr;
|
||||||
|
m_capacity = m_size = 0;
|
||||||
|
|
||||||
|
reserve(other.capacity());
|
||||||
|
memcpy(m_data, other.data(), other.size());
|
||||||
|
m_size = other.size();
|
||||||
|
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
Vector<T>& operator=(Vector<T>&& other)
|
||||||
|
{
|
||||||
|
if (&other == this) return *this;
|
||||||
|
|
||||||
|
if (m_data) free_impl(m_data);
|
||||||
|
|
||||||
|
m_data = other.data();
|
||||||
|
m_capacity = other.capacity();
|
||||||
|
m_size = other.size();
|
||||||
|
|
||||||
|
other.m_capacity = other.m_size = 0;
|
||||||
|
other.m_data = nullptr;
|
||||||
|
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
~Vector()
|
||||||
|
{
|
||||||
|
if (m_data) free_impl(m_data);
|
||||||
|
}
|
||||||
|
|
||||||
Result<void> try_reserve(usize capacity)
|
Result<void> try_reserve(usize capacity)
|
||||||
{
|
{
|
||||||
return resize(capacity);
|
return resize(capacity);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user