diff options
| author | Amlal <amlal@el-mahrouss-logic.com> | 2024-09-28 19:13:46 +0200 |
|---|---|---|
| committer | Amlal <amlal@el-mahrouss-logic.com> | 2024-09-28 19:13:46 +0200 |
| commit | 421db65331663304466577b7187780d9eba18077 (patch) | |
| tree | 3c7c4dc68537935b8cf98313e6a5bfe51786b7d2 /dev/crt/base_alloc.hxx | |
| parent | b6e416c9986bb545956a642d626e6aafd54f3b76 (diff) | |
feat: Add common XPCOM controls directory, restructure project, and introduce API breaking changes
- Added a new directory for common XPCOM controls to organize reusable components.
- Restructured project layout for better modularity and maintainability.
- Introduced API breaking changes in the process, requiring adjustments for backward compatibility.
Signed-off-by: Amlal <amlal@el-mahrouss-logic.com>
Diffstat (limited to 'dev/crt/base_alloc.hxx')
| -rw-r--r-- | dev/crt/base_alloc.hxx | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/dev/crt/base_alloc.hxx b/dev/crt/base_alloc.hxx new file mode 100644 index 00000000..de157866 --- /dev/null +++ b/dev/crt/base_alloc.hxx @@ -0,0 +1,49 @@ +/* ------------------------------------------- + + Copyright ZKA Technologies. + +------------------------------------------- */ + +#pragma once + +#include <crt/defines.hxx> + +namespace std::base_alloc +{ + /// @brief allocate a new class. + /// @tparam KindClass the class type to allocate. + template <typename KindClass, typename... Args> + inline KindClass* allocate(Args&&... args) + { + return new KindClass(forward(args)...); + } + + /// @brief allocate a new class. + /// @note aborts on error. + /// @tparam KindClass the class type to allocate. + template <typename KindClass, typename... Args> + inline KindClass* allocate_nothrow(Args&&... args) noexcept + { + return allocate(forward(args)...); + } + + /// @brief free a class. + /// @tparam KindClass the class type to allocate. + template <typename KindClass> + inline void release(KindClass ptr) + { + if (!ptr) + return; + + delete ptr; + } + + /// @brief destroy and free a class. + /// @note aborts on error. + /// @tparam KindClass the class type to allocate. + template <typename KindClass> + inline void release_nothrow(KindClass ptr) noexcept + { + release(ptr); + } +} // namespace std::base_alloc |
