crlib: avoid including <new>
This commit is contained in:
parent
faf654c883
commit
b70d2af4ab
1 changed files with 11 additions and 8 deletions
|
|
@ -15,12 +15,15 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <new>
|
|
||||||
|
|
||||||
#include <crlib/cr-basic.h>
|
#include <crlib/cr-basic.h>
|
||||||
#include <crlib/cr-movable.h>
|
#include <crlib/cr-movable.h>
|
||||||
#include <crlib/cr-platform.h>
|
#include <crlib/cr-platform.h>
|
||||||
|
|
||||||
|
// provide placment new to avoid stdc++ <new> header
|
||||||
|
inline void *operator new (const size_t, void *ptr) noexcept {
|
||||||
|
return ptr;
|
||||||
|
}
|
||||||
|
|
||||||
CR_NAMESPACE_BEGIN
|
CR_NAMESPACE_BEGIN
|
||||||
|
|
||||||
// default allocator for cr-objects
|
// default allocator for cr-objects
|
||||||
|
|
@ -31,12 +34,12 @@ public:
|
||||||
|
|
||||||
public:
|
public:
|
||||||
template <typename T> T *allocate (const size_t length = 1) {
|
template <typename T> T *allocate (const size_t length = 1) {
|
||||||
auto ptr = reinterpret_cast <T *> (malloc (length * sizeof (T)));
|
auto memory = reinterpret_cast <T *> (malloc (length * sizeof (T)));
|
||||||
|
|
||||||
if (!ptr) {
|
if (!memory) {
|
||||||
plat.abort ();
|
plat.abort ();
|
||||||
}
|
}
|
||||||
return ptr;
|
return memory;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T> void deallocate (T *memory) {
|
template <typename T> void deallocate (T *memory) {
|
||||||
|
|
@ -55,10 +58,10 @@ public:
|
||||||
|
|
||||||
public:
|
public:
|
||||||
template <typename T, typename ...Args> T *create (Args &&...args) {
|
template <typename T, typename ...Args> T *create (Args &&...args) {
|
||||||
auto d = allocate <T> ();
|
auto memory = allocate <T> ();
|
||||||
new (d) T (cr::forward <Args> (args)...);
|
new (memory) T (cr::forward <Args> (args)...);
|
||||||
|
|
||||||
return d;
|
return memory;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T> T *createArray (const size_t amount) {
|
template <typename T> T *createArray (const size_t amount) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue