http://stxxl.sourceforge.net
<dementiev@mpi-sb.mpg.de>
<beckmann@cs.uni-frankfurt.de>
http://www.boost.org/LICENSE_1_0.txt
#ifndef STXXL_NEW_ALLOC_HEADER
#define STXXL_NEW_ALLOC_HEADER
#include <memory>
#include <limits>
#include <stxxl/bits/namespace.h>
__STXXL_BEGIN_NAMESPACE
template <class T>
class new_alloc;
template <typename T, typename U>
struct new_alloc_rebind;
template <typename T>
struct new_alloc_rebind<T, T>{
typedef new_alloc<T> other;
};
template <typename T, typename U>
struct new_alloc_rebind {
typedef std::allocator<U> other;
};
template <class T>
class new_alloc {
public:
typedef T value_type;
typedef T * pointer;
typedef const T * const_pointer;
typedef T & reference;
typedef const T & const_reference;
typedef std::size_t size_type;
typedef std::ptrdiff_t difference_type;
template <class U>
struct rebind {
typedef typename new_alloc_rebind<T, U>::other other;
};
pointer address(reference value) const
{
return &value;
}
const_pointer address(const_reference value) const
{
return &value;
}
new_alloc() throw () { }
new_alloc(const new_alloc &) throw () { }
template <class U>
new_alloc(const new_alloc<U> &) throw () { }
~new_alloc() throw () { }
template <class U>
operator std::allocator<U>()
{
static std::allocator<U> helper_allocator;
return helper_allocator;
}
size_type max_size() const throw ()
{
return (std::numeric_limits<size_type>::max)() / sizeof(T);
}
pointer allocate(size_type num, const void * = 0)
{
return static_cast<T *>(T::operator new (num * sizeof(T)));
}
void construct(pointer p, const T & value)
{
::new ((void *)p)T(value);
}
#ifdef __GXX_EXPERIMENTAL_CXX0X__
template <typename ... Args>
void construct(pointer p, Args && ... args)
{
::new ((void *)p)T(std::forward<Args>(args) ...);
}
#endif
void destroy(pointer p)
{
p->~T();
}
void deallocate(pointer p, size_type )
{
T::operator delete (p);
}
};
template <class T1, class T2>
inline bool operator == (const new_alloc<T1> &,
const new_alloc<T2> &) throw ()
{
return true;
}
template <class T1, class T2>
inline bool operator != (const new_alloc<T1> &,
const new_alloc<T2> &) throw ()
{
return false;
}
__STXXL_END_NAMESPACE
#endif