On Friday, 30 May 2014 at 22:19:51 UTC, bearophile wrote:
Code similar to this is not uncommon. Currently it's refused:
immutable data = [1, 5, 3, 1, 5, 1, 5];
void main() @nogc {
import std.algorithm: count;
assert(data.count([1, 5]) == 3);
}
test.d(4,23): Error: array literal in @no
Meta:
What about prepending the word static?
immutable data = [1, 5, 3, 1, 5, 1, 5];
void main() @nogc {
import std.algorithm: count;
assert(data.count(static[1, 5]) == 3);
}
This is about the same as appending the char 's'.
Or variadic template arguments. Aren't they allocated on t
On Friday, 30 May 2014 at 22:19:51 UTC, bearophile wrote:
A language solution is a literal syntax for fixed-sized arrays
(here I slice it again because unfortunately count doesn't
accept fixed-sized arrays):
immutable data = [1, 5, 3, 1, 5, 1, 5];
void main() @nogc {
import std.algorithm:
Am 31.05.2014 00:19, schrieb bearophile:
Code similar to this is not uncommon. Currently it's refused:
immutable data = [1, 5, 3, 1, 5, 1, 5];
void main() @nogc {
import std.algorithm: count;
assert(data.count([1, 5]) == 3);
}
test.d(4,23): Error: array literal in @nogc function mai
I remember Kenji is not fond of this []s syntax, for reasons I
don't remember. Do you think there are other better/different
solutions?
Bye,
bearophile
Read it on my closed Pull Request:
https://github.com/D-Programming-Language/dmd/pull/2952
Another attempt was also closed:
https://github.c
Benjamin Thaut:
give "scope" a meaning for function arguments other then
lambdas E.g:
size_t count(scope int[] heystack, scope int[] needle);
Now the compiler can allocate the literal [1, 5] on the stack
without any special syntax because it knows that the array
literal will not be escaped.
int foo(scope int[] items) @nogc {
return foo.sum;
}
That was:
return items.sum;
Bye,
bearophile
Am 31.05.2014 11:08, schrieb bearophile:
int foo(scope int[] items) @nogc {
return foo.sum;
}
That was:
return items.sum;
Bye,
bearophile
Well obviously the std.algorithm sum would also be annoted with scope.
Because it doesn't escape it either. I don't see the problem here. And
in ca
Benjamin Thaut:
Well obviously the std.algorithm sum would also be annoted with
scope. Because it doesn't escape it either. I don't see the
problem here. And in case you really want to escape it, you
need to .dup it.
A additional advantage of my solution is, that the compiler can
prove it t
Namespace:
Another attempt was also closed:
https://github.com/D-Programming-Language/dmd/pull/2958
There is a good hope:
https://github.com/D-Programming-Language/dmd/pull/3615
Bye,
bearophile
10 matches
Mail list logo