forked from andrewprock/ustl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathunew.h
44 lines (37 loc) · 1.54 KB
/
unew.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
// This file is part of the uSTL library, an STL implementation.
//
// Copyright (c) 2005 by Mike Sharov <[email protected]>
// This file is free software, distributed under the MIT License.
#pragma once
#include "uexception.h"
/// Just like malloc, but throws on failure.
extern "C" void* tmalloc (size_t n) __attribute__((malloc));
/// Just like free, but doesn't crash when given a nullptr.
extern "C" void nfree (void* p) noexcept;
#if WITHOUT_LIBSTDCPP
//
// These are replaceable signatures:
// - normal single new and delete (no arguments, throw @c bad_alloc on error)
// - normal array new and delete (same)
// - @c nothrow single new and delete (take a @c nothrow argument, return
// @c nullptr on error)
// - @c nothrow array new and delete (same)
//
// Placement new and delete signatures (take a memory address argument,
// does nothing) may not be replaced by a user's program.
//
void* operator new (size_t n);
void* operator new[] (size_t n);
void operator delete (void* p) noexcept;
void operator delete[] (void* p) noexcept;
#if HAVE_CPP14
void operator delete (void* p, size_t) noexcept;
void operator delete[] (void* p, size_t) noexcept;
#endif
// Default placement versions of operator new.
inline void* operator new (size_t, void* p) noexcept { return p; }
inline void* operator new[] (size_t, void* p) noexcept { return p; }
// Default placement versions of operator delete.
inline void operator delete (void*, void*) noexcept { }
inline void operator delete[](void*, void*) noexcept { }
#endif // WITHOUT_LIBSTDCPP