Commit 457c0f0a7e

kristopher tate <kt@connectfree.co.jp>
2018-06-20 17:39:19
std.mem: remove allocator create in favor of construct; ref #733
1 parent 55193cb
Changed files (1)
std/mem.zig
@@ -32,15 +32,7 @@ pub const Allocator = struct {
     freeFn: fn (self: *Allocator, old_mem: []u8) void,
 
     /// Call destroy with the result
-    pub fn create(self: *Allocator, comptime T: type) !*T {
-        if (@sizeOf(T) == 0) return *{};
-        const slice = try self.alloc(T, 1);
-        return &slice[0];
-    }
-
-    /// Call destroy with the result
-    /// TODO once #733 is solved, this will replace create
-    pub fn construct(self: *Allocator, init: var) Error!*@typeOf(init) {
+    pub fn create(self: *Allocator, init: var) Error!*@typeOf(init) {
         const T = @typeOf(init);
         if (@sizeOf(T) == 0) return &{};
         const slice = try self.alloc(T, 1);
@@ -49,6 +41,13 @@ pub const Allocator = struct {
         return ptr;
     }
 
+    /// Alias of create
+    /// Call destroy with the result
+    pub fn construct(self: *Allocator, init: var) Error!*@typeOf(init) {
+      debug.warn("std.mem.Allocator.construct is deprecated;\n");
+      return self.create(init);
+    }
+
     /// `ptr` should be the return value of `construct` or `create`
     pub fn destroy(self: *Allocator, ptr: var) void {
         const non_const_ptr = @intToPtr([*]u8, @ptrToInt(ptr));