Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- pub fn Graph(comptime T: type) type {
- return struct {
- constants: std.ArrayList(T),
- pub fn init(allocator: *std.mem.Allocator) Graph(T) {
- return .{ .constants = std.ArrayList(T).init(allocator) };
- }
- pub fn constant(graph: *Graph(T), value: T) !void {
- try graph.constants.append(value);
- }
- };
- }
- const GraphT = Graph(i32);
- const constant = GraphT.constant;
- test "create graph" {
- var arena = std.heap.ArenaAllocator.init(std.heap.page_allocator);
- defer arena.deinit();
- const allocator = &arena.allocator;
- var graph = &GraphT.init(allocator);
- const x = try constant(graph, 5);
- const y = try constant(graph, 10);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement