add clear and destructor

This commit is contained in:
ykiko 2024-02-18 22:52:00 +08:00
parent 415c1f6b38
commit 2368c361e3

View File

@ -362,6 +362,13 @@ namespace pkpy {
return *this; return *this;
} }
~small_vector() {
std::destroy_n(data(), m_size);
if (!is_small()) {
std::free(m_internal.begin);
}
}
template <typename... Args> void emplace_back(Args &&...args) noexcept { template <typename... Args> void emplace_back(Args &&...args) noexcept {
if (m_size == m_capacity) { if (m_size == m_capacity) {
auto new_capacity = m_capacity * 2; auto new_capacity = m_capacity * 2;
@ -396,5 +403,10 @@ namespace pkpy {
(data() + m_size)->~T(); (data() + m_size)->~T();
} }
} }
void clear() {
std::destroy_n(data(), m_size);
m_size = 0;
}
}; };
} // namespace pkpy } // namespace pkpy