aboutsummaryrefslogtreecommitdiff
path: root/core/dvector.h
diff options
context:
space:
mode:
authorJuan Linietsky2016-09-10 12:22:31 -0300
committerGitHub2016-09-10 12:22:31 -0300
commit6abd1437cd2d8a0448f37c6b6f2b8bf00a652b84 (patch)
treede5e82a8fa28c72dcf0c92be9d575762c5c22652 /core/dvector.h
parentfc61eb37ce004ecfa0656a46c68d111c68bb5c19 (diff)
parent82d4cb5114a9d5f341dba84cbee51fcfe1504de6 (diff)
downloadgodot-6abd1437cd2d8a0448f37c6b6f2b8bf00a652b84.tar.gz
godot-6abd1437cd2d8a0448f37c6b6f2b8bf00a652b84.tar.zst
godot-6abd1437cd2d8a0448f37c6b6f2b8bf00a652b84.zip
Merge pull request #5879 from gau-veldt/subarray_patch
Subarray patch
Diffstat (limited to '')
-rw-r--r--core/dvector.h28
1 files changed, 28 insertions, 0 deletions
diff --git a/core/dvector.h b/core/dvector.h
index a5519ed60..9a5464161 100644
--- a/core/dvector.h
+++ b/core/dvector.h
@@ -262,6 +262,34 @@ public:
w[bs+i]=r[i];
}
+ DVector<T> subarray(int p_from, int p_to) {
+
+ if (p_from<0) {
+ p_from=size()+p_from;
+ }
+ if (p_to<0) {
+ p_to=size()+p_to;
+ }
+ if (p_from<0 || p_from>=size()) {
+ DVector<T>& aux=*((DVector<T>*)0); // nullreturn
+ ERR_FAIL_COND_V(p_from<0 || p_from>=size(),aux)
+ }
+ if (p_to<0 || p_to>=size()) {
+ DVector<T>& aux=*((DVector<T>*)0); // nullreturn
+ ERR_FAIL_COND_V(p_to<0 || p_to>=size(),aux)
+ }
+
+ DVector<T> slice;
+ int span=1 + p_to - p_from;
+ slice.resize(span);
+ Read r = read();
+ Write w = slice.write();
+ for (int i=0; i<span; ++i) {
+ w[i] = r[p_from+i];
+ }
+
+ return slice;
+ }
Error insert(int p_pos,const T& p_val) {