Advertisement
adamkowalski

Untitled

Dec 4th, 2019
197
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.66 KB | None | 0 0
  1. pub fn Graph(comptime T: type) type {
  2. return struct {
  3. constants: std.ArrayList(T),
  4.  
  5. pub fn init(allocator: *std.mem.Allocator) Graph(T) {
  6. return .{ .constants = std.ArrayList(T).init(allocator) };
  7. }
  8.  
  9. pub fn constant(graph: *Graph(T), value: T) !void {
  10. try graph.constants.append(value);
  11. }
  12. };
  13. }
  14.  
  15. test "create graph" {
  16. var arena = std.heap.ArenaAllocator.init(std.heap.page_allocator);
  17. defer arena.deinit();
  18. const allocator = &arena.allocator;
  19.  
  20. var graph = Graph(i32).init(allocator);
  21. const x = try graph.constant(5);
  22. const y = try graph.constant(10);
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement