diff options
author | RĂ©mi Verschelde <remi@verschelde.fr> | 2022-01-06 16:51:57 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-01-06 16:51:57 +0100 |
commit | f57bdf13af3e99b0f0235909eecc428d913c9b01 (patch) | |
tree | c3de2d4e926715519ecf3f1980b24ae6b8ecb0fe /core | |
parent | 6ebbdb4a80a4ae6ac83485dc01622d9795c4e451 (diff) | |
parent | c0d3bdc0cac39f9a7a1ba5327b694f7b4350faeb (diff) |
Merge pull request #50493 from timothyqiu/local-vector-list-init
Diffstat (limited to 'core')
-rw-r--r-- | core/templates/local_vector.h | 8 | ||||
-rw-r--r-- | core/templates/vector.h | 11 |
2 files changed, 19 insertions, 0 deletions
diff --git a/core/templates/local_vector.h b/core/templates/local_vector.h index 1a19f29f3b..f4e0748c27 100644 --- a/core/templates/local_vector.h +++ b/core/templates/local_vector.h @@ -36,6 +36,8 @@ #include "core/templates/sort_array.h" #include "core/templates/vector.h" +#include <initializer_list> + template <class T, class U = uint32_t, bool force_trivial = false> class LocalVector { private: @@ -228,6 +230,12 @@ public: } _FORCE_INLINE_ LocalVector() {} + _FORCE_INLINE_ LocalVector(std::initializer_list<T> p_init) { + reserve(p_init.size()); + for (const T &element : p_init) { + push_back(element); + } + } _FORCE_INLINE_ LocalVector(const LocalVector &p_from) { resize(p_from.size()); for (U i = 0; i < p_from.count; i++) { diff --git a/core/templates/vector.h b/core/templates/vector.h index 18b731c458..4ada3b597a 100644 --- a/core/templates/vector.h +++ b/core/templates/vector.h @@ -43,6 +43,8 @@ #include "core/templates/search_array.h" #include "core/templates/sort_array.h" +#include <initializer_list> + template <class T> class VectorWriteProxy { public: @@ -258,6 +260,15 @@ public: } _FORCE_INLINE_ Vector() {} + _FORCE_INLINE_ Vector(std::initializer_list<T> p_init) { + Error err = _cowdata.resize(p_init.size()); + ERR_FAIL_COND(err); + + int i = 0; + for (const T &element : p_init) { + _cowdata.set(i++, element); + } + } _FORCE_INLINE_ Vector(const Vector &p_from) { _cowdata._ref(p_from._cowdata); } _FORCE_INLINE_ ~Vector() {} |