More useful fixed-size array literals

Mason McGill via Digitalmars-d digitalmars-d at puremagic.com
Fri May 30 19:35:41 PDT 2014


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: count;
>     assert(data.count([1, 5]s[]) == 3);
> }

I would use this often. It's always seemed strange to me that 
static arrays are one of the few built-in data structures that 
don't have a dedicated literal form. `[1, 2, 3]s` nicely 
parallels the syntax for string and number literals.


More information about the Digitalmars-d mailing list