From: TimePath Date: Thu, 17 Mar 2016 00:08:31 +0000 (+1100) Subject: iter: allow toggling between const/mutable `it` X-Git-Tag: xonotic-v0.8.2~1070 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=9098a2f9e9e57f47d85ae3172b13b84ef80b46f3;p=xonotic%2Fxonotic-data.pk3dir.git iter: allow toggling between const/mutable `it` --- diff --git a/qcsrc/lib/iter.qh b/qcsrc/lib/iter.qh index 89b455ab5..eaac63f5e 100644 --- a/qcsrc/lib/iter.qh +++ b/qcsrc/lib/iter.qh @@ -1,12 +1,18 @@ #pragma once +#if 1 +#define ITER_CONST const +#else +#define ITER_CONST +#endif + #define FOREACH_ARRAY(arr, start, end, cond, body) \ MACRO_BEGIN \ { \ for (int _i = start; _i < end; ++_i) \ { \ const noref int i = _i; \ - const noref entity it = arr[i]; \ + ITER_CONST noref entity it = arr[i]; \ if (cond) { LAMBDA(body) } \ } \ } MACRO_END @@ -20,7 +26,7 @@ for (entity _it = list##_first; _it; (_it = _it.next, ++_i)) \ { \ const noref int i = _i; \ - const noref entity it = _it; \ + ITER_CONST noref entity it = _it; \ if (cond) { LAMBDA(body) } \ } \ } MACRO_END @@ -88,7 +94,7 @@ for (entity _it = NULL; (_it = nextent(_it)); ++_i) \ { \ const noref int i = _i; \ - const noref entity it = _it; \ + ITER_CONST noref entity it = _it; \ if (cond) { LAMBDA(body) } \ } \ } MACRO_END diff --git a/qcsrc/lib/linkedlist.qh b/qcsrc/lib/linkedlist.qh index 07d99b4f1..6afc862ed 100644 --- a/qcsrc/lib/linkedlist.qh +++ b/qcsrc/lib/linkedlist.qh @@ -78,7 +78,7 @@ entity LL_POP(LinkedList this) noref int i = 0; \ for (entity _it = list.ll_head; _it; (_it = _it.ll_next, ++i)) \ { \ - noref entity it = _it.ll_data; \ + ITER_CONST noref entity it = _it.ll_data; \ if (cond) { body } \ } \ } MACRO_END diff --git a/qcsrc/lib/oo.qh b/qcsrc/lib/oo.qh index 8d50d2b92..49147765e 100644 --- a/qcsrc/lib/oo.qh +++ b/qcsrc/lib/oo.qh @@ -5,9 +5,9 @@ #include "static.qh" #ifdef MENUQC - #define NULL (null_entity) + #define NULL (0, null_entity) #else - #define NULL (world) + #define NULL (0, world) #endif .vector origin; diff --git a/qcsrc/server/_all.qh b/qcsrc/server/_all.qh index b52046037..c43605435 100644 --- a/qcsrc/server/_all.qh +++ b/qcsrc/server/_all.qh @@ -33,7 +33,7 @@ const string STR_OBSERVER = "observer"; for(int _i = 1; _i <= maxclients; ++_i) \ { \ const noref int i = _i; \ - const noref entity it = ftoe(i); \ + ITER_CONST noref entity it = ftoe(i); \ if(cond) { LAMBDA(body) } \ } \ } MACRO_END