//
// Copyright (C) 2008, 2009 Francesco Salvestrini
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License along
// with this program; if not, write to the Free Software Foundation, Inc.,
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
//

#ifndef ELKLIB_LIBCXX_NEW
#define ELKLIB_LIBCXX_NEW

#include "elklib.h"
#include "libc++/cstddef"
#include "libc++/exception"

namespace ktl {
	class bad_alloc : public exception { };

	struct nothrow_t { };
	extern const nothrow_t nothrow;

	typedef void (* new_handler)();
	new_handler set_new_handler(new_handler h) throw();
}

// Throw operators
void * operator new(ktl::size_t s)   throw (ktl::bad_alloc);
void * operator new[](ktl::size_t s) throw (ktl::bad_alloc);
void   operator delete(void * p)     throw();
void   operator delete[](void * p)   throw();

// No-throws operators
void * operator new(ktl::size_t s,   const ktl::nothrow_t & e) throw();
void * operator new[](ktl::size_t s, const ktl::nothrow_t & e) throw();
void   operator delete(void * p,     const ktl::nothrow_t & e) throw();
void   operator delete[](void * p,   const ktl::nothrow_t & e) throw();

// Placement operators
inline void * operator new(ktl::size_t,   void * p) throw() { return p; }
inline void * operator new[](ktl::size_t, void * p) throw() { return p; }
inline void   operator delete  (void *, void *) throw() { }
inline void   operator delete[](void *, void *) throw() { }

#endif // ELKLIB_LIBCXX_NEW
