From 6058a69182d0e62bc96e651d618b63310a55f99e Mon Sep 17 00:00:00 2001 From: apio Date: Wed, 23 Aug 2023 11:08:18 +0200 Subject: [PATCH] libluna: Document Alloc.h --- libluna/include/luna/Alloc.h | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/libluna/include/luna/Alloc.h b/libluna/include/luna/Alloc.h index a6e0dfb5..0e28a901 100644 --- a/libluna/include/luna/Alloc.h +++ b/libluna/include/luna/Alloc.h @@ -1,16 +1,30 @@ +/** + * @file Alloc.h + * @author apio (cloudapio.eu) + * @brief Fallible version of new. + * + * @copyright Copyright (c) 2022-2023, the Luna authors. + * + */ + #pragma once #include #include #include +/** + * @brief Allocate a value on the heap and initialize it. + * + * When this value is no longer used, you must call delete to destroy it. + * + * @tparam T The type of the value. + * @tparam Args The types of arguments to pass to the value's constructor. + * @param args The arguments to pass to the value's constructor. + * @return Result An error, or a pointer to the new value. + */ template [[nodiscard]] Result make(Args... args) { T* const result = (T*)TRY(malloc_impl(sizeof(T))); new (result) T(args...); return result; } - -template void destroy(T* item) -{ - delete item; -}