News Score: Score the News, Sort the News, Rewrite the Headlines

Zig's (.{}){} syntax

One of the first pieces of Zig code that you're likely to see, and write, is this beginner-unfriendly line: var gpa = std.heap.GeneralPurposeAllocator(.{}){}; While we can reason that we're creating an allocator, the (.{}){} syntax can seem a bit much. This is a combination of three separate language features: generics, anonymous struct literals and default field values. One of Zig's more compelling feature is its advance compile-time (aka comptime) capabilities. This is the ability to have a su...

Read more at openmymind.net

© News Score  score the news, sort the news, rewrite the headlines