libjmmcg  release_579_6_g8cffd
A C++ library containing an eclectic mix of useful, advanced components.
non_allocatable.hpp
Go to the documentation of this file.
1 #ifndef LIBJMMCG_CORE_NON_ALLOCATABLE_HPP
2 #define LIBJMMCG_CORE_NON_ALLOCATABLE_HPP
3 /******************************************************************************
4 ** Copyright © 2008 by J.M.McGuiness, jmmcg@sourceforge.net & coder@hussar.me.uk
5 **
6 ** This library is free software; you can redistribute it and/or
7 ** modify it under the terms of the GNU Lesser General Public
8 ** License as published by the Free Software Foundation; either
9 ** version 2.1 of the License, or (at your option) any later version.
10 **
11 ** This library is distributed in the hope that it will be useful,
12 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
13 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 ** Lesser General Public License for more details.
15 **
16 ** You should have received a copy of the GNU Lesser General Public
17 ** License along with this library; if not, write to the Free Software
18 ** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
20 
21 #include "config.h"
22 #include "debug_defines.hpp"
23 
24 #include <new>
25 
26 namespace jmmcg { namespace LIBJMMCG_VER_NAMESPACE {
27 
28 /// Used to try to help ensure that an object can only be allocated on the stack.
29 class non_newable {
30  static void * operator new(std::size_t) noexcept(false)=delete;
31  static void * operator new(std::size_t, const std::nothrow_t&) noexcept(true)=delete;
32  static void * operator new[](std::size_t) noexcept(false)=delete;
33  static void * operator new[](std::size_t, const std::nothrow_t&) noexcept(true)=delete;
34  static void * operator new(std::size_t, void *) noexcept(false)=delete;
35  static void * operator new[](std::size_t, void *) noexcept(false)=delete;
36 };
37 
39  static void operator delete(void *) noexcept(true)=delete;
40  static void operator delete(void *, const std::nothrow_t&) noexcept(true)=delete;
41  static void operator delete[](void *) noexcept(true)=delete;
42  static void operator delete[](void *, const std::nothrow_t&) noexcept(true)=delete;
43  static void operator delete(void *, void *) noexcept(true)=delete;
44  static void operator delete[](void *, void *) noexcept(true)=delete;
45 };
46 
47 class non_allocatable : protected non_newable, protected non_deleteable {
48 };
49 
51  void operator&()=delete;
52 };
53 
54 } }
55 
56 #endif