From 457c0f0a7e424177e7d8d00f4429da292b7c67d5 Mon Sep 17 00:00:00 2001 From: kristopher tate Date: Thu, 21 Jun 2018 00:39:19 +0900 Subject: [PATCH] std.mem: remove allocator create in favor of construct; ref #733 --- std/mem.zig | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/std/mem.zig b/std/mem.zig index 55844b88db..b3c3e59cec 100644 --- a/std/mem.zig +++ b/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));