newer.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. // new standard header for Microsoft
  2. #include <iostream>
  3. using namespace std;
  4. #pragma once
  5. #ifndef _NEWER_
  6. #define _NEWER_
  7. #ifndef RC_INVOKED
  8. #include <exception>
  9. #pragma pack(push,_CRT_PACKING)
  10. #pragma warning(push,3)
  11. // #pragma push_macro("new")
  12. // #undef new
  13. #if !defined(__CRTDECL)
  14. #if defined(_M_CEE_PURE)
  15. #define __CRTDECL
  16. #else
  17. #define __CRTDECL __cdecl
  18. #endif
  19. #endif
  20. _STD_BEGIN
  21. // SUPPORT TYPES
  22. #if !defined(_INC_NEW) || !defined(_MSC_EXTENSIONS)
  23. // handler for operator new failures
  24. #ifdef _M_CEE_PURE
  25. typedef void (__clrcall * new_handler) ();
  26. #else
  27. typedef void (__cdecl * new_handler) ();
  28. #endif
  29. #endif /* !defined(_INC_NEW) || !defined(_MSC_EXTENSIONS) */
  30. #ifndef __NOTHROW_T_DEFINED
  31. struct nothrow_t
  32. { // placement new tag type to suppress exceptions
  33. };
  34. extern const nothrow_t nothrow; // constant for placement new tag
  35. #endif /* __NOTHROW_T_DEFINED */
  36. // FUNCTION AND OBJECT DECLARATIONS
  37. _CRTIMP2 new_handler __cdecl set_new_handler(_In_opt_ new_handler)
  38. _THROW0(); // establish alternate new handler
  39. _STD_END
  40. // new AND delete DECLARATIONS (NB: NOT IN std)
  41. void __CRTDECL operator delete(void *) _THROW0();
  42. #pragma warning (suppress: 4985)
  43. _Ret_bytecap_(_Size) void *__CRTDECL operator new(size_t _Size) _THROW1(_STD bad_alloc);
  44. #ifndef __PLACEMENT_NEW_INLINE
  45. #define __PLACEMENT_NEW_INLINE
  46. inline void *__CRTDECL operator new(size_t, void *_Where) _THROW0()
  47. { // construct array with placement at _Where
  48. cout << "New!\n";
  49. return (_Where);
  50. }
  51. inline void __CRTDECL operator delete(void *, void *) _THROW0()
  52. { // delete if placement new fails
  53. cout << "Delete!\n";
  54. }
  55. #endif /* __PLACEMENT_NEW_INLINE */
  56. #ifndef __PLACEMENT_VEC_NEW_INLINE
  57. #define __PLACEMENT_VEC_NEW_INLINE
  58. inline void *__CRTDECL operator new[](size_t, void *_Where) _THROW0()
  59. { // construct array with placement at _Where
  60. cout << "New!\n";
  61. return (_Where);
  62. }
  63. inline void __CRTDECL operator delete[](void *, void *) _THROW0()
  64. { // delete if placement array new fails
  65. cout << "Delete!\n";
  66. }
  67. #endif /* __PLACEMENT_VEC_NEW_INLINE */
  68. void __CRTDECL operator delete[](void *) _THROW0(); // delete allocated array
  69. _Ret_bytecap_(_Size) void *__CRTDECL operator new[](size_t _Size)
  70. _THROW1(_STD bad_alloc); // allocate array or throw exception
  71. #ifndef __NOTHROW_T_DEFINED
  72. #define __NOTHROW_T_DEFINED
  73. _Ret_opt_bytecap_(_Size) void *__CRTDECL operator new(size_t _Size, const _STD nothrow_t&)
  74. _THROW0();
  75. _Ret_opt_bytecap_(_Size) void *__CRTDECL operator new[](size_t _Size, const _STD nothrow_t&)
  76. _THROW0(); // allocate array or return null pointer
  77. void __CRTDECL operator delete(void *, const _STD nothrow_t&)
  78. _THROW0(); // delete if nothrow new fails -- REPLACEABLE
  79. void __CRTDECL operator delete[](void *, const _STD nothrow_t&)
  80. _THROW0(); // delete if nothrow array new fails -- REPLACEABLE
  81. #endif /* __NOTHROW_T_DEFINED */
  82. #if !defined(_INC_NEW) || !defined(_MSC_EXTENSIONS)
  83. using _STD new_handler;
  84. #endif /* !defined(_INC_NEW) || !defined(_MSC_EXTENSIONS) */
  85. #pragma pop_macro("new")
  86. #pragma warning(pop)
  87. #pragma pack(pop)
  88. #endif /* RC_INVOKED */
  89. #endif /* _NEWER_ */
  90. /*
  91. * Copyright (c) 1992-2007 by P.J. Plauger. ALL RIGHTS RESERVED.
  92. * Consult your license regarding permissions and restrictions.
  93. V5.03:0009 */