But there is a difference in how they behave, and I have no way of checking
this behavior.
Consider the following little snippet:
void f(int[] a) {
a[0] = -1;
}
void main() {
int[] a = [1,2,3];
static assert(is(typeof(a) == int[]));
f(a);
assert(a[0] == -1); // a passed by
On 2011-04-04 01:16, simendsjo wrote:
But there is a difference in how they behave, and I have no way of checking
this behavior. Consider the following little snippet:
void f(int[] a) {
a[0] = -1;
}
void main() {
int[] a = [1,2,3];
static assert(is(typeof(a) == int[]));
What use case do you have for wanting to know whether a variable is an enum
or not?
The same reason I'd like to check if it's const/immutable; if an algorithm
requires a
modifiable array.
void sortInPlace(int[] array) {
array.sort;
}
void main() {
int[] a = [3,2,1];
On 2011-04-03 08:29, simendsjo wrote:
The behavior for manifest constant arrays is different from regular arrays
and const/immutable arrays. The problem is that typeof() returns T[]. How
can I see if the array is a manifest constant?
void g(int[] x) { }
const c = [1,2,3];
Jonathan M Davis:
But there should be no need to worry about whether something is a manifest
constant or not.
I'd like in DMD a way to know if something is a compile-time constant. There is
a GCC extension that sometimes is able to do it, named __builtin_constant_p: