From e21fa158dd6e06d53fe7a4c3ba25fc392515ca69 Mon Sep 17 00:00:00 2001 From: Ali Mohammad Pur Date: Sat, 26 Mar 2022 21:29:33 +0430 Subject: [PATCH] AK: Make Vector capable of holding forward-declared types This is pretty useful for making trees. --- AK/Vector.h | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) 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 }; };