From 2141f87c5eb61eaf0839f269b762c9e718b162ca Mon Sep 17 00:00:00 2001 From: Jordan Orelli Date: Thu, 24 Dec 2020 23:26:20 +0000 Subject: [PATCH] it's a box --- box.zig | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 box.zig diff --git a/box.zig b/box.zig new file mode 100644 index 0000000..5e42857 --- /dev/null +++ b/box.zig @@ -0,0 +1,34 @@ +const std = @import("std"); +const stdout = std.io.getStdOut().writer(); + +fn Box(comptime T: type) type { + return struct { + value: T, + }; +} + +const Point = struct { + X: i32 = 1, + Y: i32 = 2, +}; + +pub fn main() !void { + var vbox = Box(Point){ + .value = undefined, + }; + try stdout.print("var box with undefined: {}\n", vbox); + + var vbox2 = Box(Point){ + .value = Point{}, + }; + try stdout.print("var box with explicit defaults: {}\n", vbox2); + + const cbox = Box(Point){ + .value = undefined, + }; + try stdout.print("const box with undefined: {}\n", cbox); + + try stdout.print("Box literal with undefined: {}\n", Box(Point){ + .value = undefined, + }); +}