root/core/non_allocatable.hpp

/* [<][>][^][v][top][bottom][index][help] */

INCLUDED FROM


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

/* [<][>][^][v][top][bottom][index][help] */