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(comptime T: type, graph: *Graph(T), value: T) !void {
- try graph.constants.append(value);
- }
- test "create graph" {
- var arena = std.heap.ArenaAllocator.init(std.heap.page_allocator);
- defer arena.deinit();
- const allocator = &arena.allocator;
- var graph = Graph(i32).init(allocator);
- const x = try constant(i32, &graph, 5);
- const y = try constant(i32, &graph, 10);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement