More useful fixed-size array literals

bearophile via Digitalmars-d digitalmars-d at puremagic.com
Fri May 30 15:43:13 PDT 2014


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 the 
> stack like static arrays?
>
> immutable data = [1, 5, 3, 1, 5, 1, 5];
> void main() @nogc {
>     import std.algorithm: count;
>     //Assume count has a variadic template implementation
>     assert(data.count(1, 5) == 3);
> }

Currently they are allocated on the stack. But "count" doesn't 
work like that. And I think this feature of D is bug-prone, and 
in bugzilla I've asked to change it (allocating on the heap on 
default).

Bye,
bearophile


More information about the Digitalmars-d mailing list