1 // This file is part of the ustl library, an STL implementation.
3 // Copyright (C) 2005 by Mike Sharov <msharov@users.sourceforge.net>
4 // This file is free software, distributed under the MIT License.
8 /// \brief Same as \<new\>, but throws ustl:: exceptions.
11 #ifndef UNEW_H_11D237512B324C9C05A55DAF1BF086F1
12 #define UNEW_H_11D237512B324C9C05A55DAF1BF086F1
14 #include "uexception.h"
16 /// Just like malloc, but throws on failure.
17 void* throwing_malloc (size_t n
) throw (ustl::bad_alloc
);
18 /// Just like free, but doesn't crash when given a NULL.
19 void free_nullok (void* p
) throw();
21 #ifdef WITHOUT_LIBSTDCPP
24 // These are replaceable signatures:
25 // - normal single new and delete (no arguments, throw @c bad_alloc on error)
26 // - normal array new and delete (same)
27 // - @c nothrow single new and delete (take a @c nothrow argument, return
29 // - @c nothrow array new and delete (same)
31 // Placement new and delete signatures (take a memory address argument,
32 // does nothing) may not be replaced by a user's program.
34 inline void* operator new (size_t n
) throw (ustl::bad_alloc
) { return (throwing_malloc (n
)); }
35 inline void* operator new[] (size_t n
) throw (ustl::bad_alloc
) { return (throwing_malloc (n
)); }
36 inline void operator delete (void* p
) throw() { free_nullok (p
); }
37 inline void operator delete[] (void* p
) throw() { free_nullok (p
); }
39 // Default placement versions of operator new.
40 inline void* operator new (size_t, void* p
) throw() { return (p
); }
41 inline void* operator new[] (size_t, void* p
) throw() { return (p
); }
43 // Default placement versions of operator delete.
44 inline void operator delete (void*, void*) throw() { }
45 inline void operator delete[](void*, void*) throw() { }
49 #endif // WITHOUT_LIBSTDCPP