summaryrefslogtreecommitdiffstats
path: root/core/templates/vector.h
diff options
context:
space:
mode:
authorHaoyu Qiu <timothyqiu32@gmail.com>2021-07-16 00:28:05 +0800
committerHaoyu Qiu <timothyqiu32@gmail.com>2022-01-05 20:42:09 +0800
commitc0d3bdc0cac39f9a7a1ba5327b694f7b4350faeb (patch)
tree8af7999e0c4e2e6fcc543ab56862a8f667dc302c /core/templates/vector.h
parentd2ac67d55e693e26b1927ca25b9b1037acb1a256 (diff)
downloadredot-engine-c0d3bdc0cac39f9a7a1ba5327b694f7b4350faeb.tar.gz
Add list initialization support for Vector & LocalVector
Diffstat (limited to 'core/templates/vector.h')
-rw-r--r--core/templates/vector.h11
1 files changed, 11 insertions, 0 deletions
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() {}