commit 457c0f0a7e424177e7d8d00f4429da292b7c67d5 (tree)
parent 55193cb13bbc69350474f6a66728319b41149274
Author: kristopher tate <kt@connectfree.co.jp>
Date: Thu, 21 Jun 2018 00:39:19 +0900
std.mem: remove allocator create in favor of construct; ref #733
Diffstat:
1 file changed, 8 insertions(+), 9 deletions(-)
diff --git 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));