
#ifndef TINYSTL_VECTOR_MEMORY
#define TINYSTL_VECTOR_MEMORY

#include <new>

namespace std {

  template <typename T>
  class allocator;
  
  template<>
  class allocator<void>
  {
  public:
    typedef size_t      size_type;
    //    typedef ptrdiff_t   difference_type;
    typedef void*       pointer;
    typedef const void* const_pointer;
    typedef void        value_type;
    
  };

  template<typename T>
  class new_allocator
  {
  public:
    typedef size_t     size_type;
    //    typedef ptrdiff_t  difference_type;
    typedef T*       pointer;
    typedef const T* const_pointer;
    typedef T&       reference;
    typedef const T& const_reference;
    typedef T        value_type;
    
    new_allocator () {}
    
    new_allocator (const new_allocator&) { }
    
    ~new_allocator () { }

    pointer address (reference x) const { return &x; }
    
    const_pointer address (const_reference x) const { return &x; }
    
    pointer allocate (size_type n, const void* hint = 0) {
      return static_cast<T*>(::operator new(n * sizeof(T)));
    }
    
    void  deallocate (pointer p, size_type) {
      ::operator delete (p);
    }
    
    size_type max_size() const throw() {
      return size_t(-1) / sizeof(T);
    }

    void construct (pointer p, const T &val) {
      ::new(p) T(val);
    }

    void destroy (pointer p) {
      p->~T();
    }
  };
  
  template<typename T> bool operator== (const new_allocator<T>&,
					const new_allocator<T>&) {
    return true;
  }

  template<typename T> bool operator!= (const new_allocator<T>&,
					const new_allocator<T>&) {
    return false;
  }
  
  // ...
  
  template <typename T>
  class allocator : public new_allocator<T>
  {
  };
  
}

#endif
