From 6e9b5225d27d10f3d83e35928454b8cea0b64d60 Mon Sep 17 00:00:00 2001 From: W2Wizard Date: Sat, 17 Apr 2021 20:08:10 +0200 Subject: [PATCH] Add init functions --- Source/Engine/Core/Collections/Array.h | 32 ++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/Source/Engine/Core/Collections/Array.h b/Source/Engine/Core/Collections/Array.h index 6a841bac5..cc8bcf6e0 100644 --- a/Source/Engine/Core/Collections/Array.h +++ b/Source/Engine/Core/Collections/Array.h @@ -47,6 +47,20 @@ public: _allocation.Allocate(capacity); } + /// + /// Initializes a new instance of the class. + /// + /// The initial values defined in the array. + Array(std::initializer_list initList) + { + _count = _capacity = (int32)initList.size(); + if (_count > 0) + { + _allocation.Allocate(_count); + Memory::ConstructItems(Get(), initList.begin(), _count); + } + } + /// /// Initializes a new instance of the class. /// @@ -123,6 +137,24 @@ public: _allocation.Swap(other._allocation); } + /// + /// The assignment operator that deletes the current collection of items and the copies items from the initializer list. + /// + /// The other collection to copy. + /// The reference to this. + Array& operator=(std::initializer_list initList) noexcept + { + Memory::DestructItems(Get(), _count); + + _count = _capacity = (int32)initList.size(); + if (_capacity > 0) + { + _allocation.Allocate(_capacity); + Memory::ConstructItems(Get(), initList.begin(), _count); + } + return *this; + } + /// /// The assignment operator that deletes the current collection of items and the copies items from the other array. ///