diff options
author | Ali Mohammad Pur <ali.mpfard@gmail.com> | 2022-03-26 21:29:33 +0430 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2022-03-28 23:11:48 +0200 |
commit | e21fa158dd6e06d53fe7a4c3ba25fc392515ca69 (patch) | |
tree | 7947587158aa087d6dad304a315e5954dd115c17 /AK/Vector.h | |
parent | bd6927ecaba40485a77b8efc655aa26b4c7f0530 (diff) | |
download | serenity-e21fa158dd6e06d53fe7a4c3ba25fc392515ca69.zip |
AK: Make Vector capable of holding forward-declared types
This is pretty useful for making trees.
Diffstat (limited to 'AK/Vector.h')
-rw-r--r-- | AK/Vector.h | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/AK/Vector.h b/AK/Vector.h index 7a4f578a3c..5b7ec2d966 100644 --- a/AK/Vector.h +++ b/AK/Vector.h @@ -793,7 +793,23 @@ private: size_t m_size { 0 }; size_t m_capacity { 0 }; - alignas(StorageType) unsigned char m_inline_buffer_storage[sizeof(StorageType) * inline_capacity]; + static constexpr size_t storage_size() + { + if constexpr (inline_capacity == 0) + return 0; + else + return sizeof(StorageType) * inline_capacity; + } + + static constexpr size_t storage_alignment() + { + if constexpr (inline_capacity == 0) + return 1; + else + return alignof(StorageType); + } + + alignas(storage_alignment()) unsigned char m_inline_buffer_storage[storage_size()]; StorageType* m_outline_buffer { nullptr }; }; |