Changes For Bug 352
[oota-llvm.git] / include / llvm / Support / MallocAllocator.h
index 98957d4c8e9cb1cd4c385b14d490cc244b7a5cb7..c17517e2a0c7e4bb7e6e08f0a9c55424c615572a 100644 (file)
@@ -1,4 +1,4 @@
-//===-- Support/MallocAllocator.h - Allocator using malloc/free -*- C++ -*-===//
+//===-- llvm/Support/MallocAllocator.h --------------------------*- C++ -*-===//
 // 
 //                     The LLVM Compiler Infrastructure
 //
 //
 //===----------------------------------------------------------------------===//
 
-#ifndef SUPPORT_MALLOCALLOCATOR_H
-#define SUPPORT_MALLOCALLOCATOR_H
+#ifndef LLVM_SUPPORT_MALLOCALLOCATOR_H
+#define LLVM_SUPPORT_MALLOCALLOCATOR_H
 
 #include <cstdlib>
 #include <memory>
 
+namespace llvm {
+
 template<typename T>
 struct MallocAllocator {
   typedef size_t size_type;
@@ -36,20 +38,24 @@ struct MallocAllocator {
     typedef MallocAllocator<U> other;
   };
 
+  template<typename R>
+  MallocAllocator(const MallocAllocator<R> &) {}
+  MallocAllocator() {}
+
   pointer address(reference x) const { return &x; }
   const_pointer address(const_reference x) const { return &x; }
   size_type max_size() const { return ~0 / sizeof(T); }
   
-  pointer allocate(size_t n, void* hint = 0) {
-    return (pointer)malloc(n*sizeof(T));
+  static pointer allocate(size_t n, void* hint = 0) {
+    return static_cast<pointer>(malloc(n*sizeof(T)));
   }
 
-  void deallocate(pointer p, size_t n) {
-    free((void*)p);
+  static void deallocate(pointer p, size_t n) {
+    free(static_cast<void*>(p));
   }
 
   void construct(pointer p, const T &val) {
-    new((void*)p) T(val);
+    new(static_cast<void*>(p)) T(val);
   }
   void destroy(pointer p) {
     p->~T();
@@ -64,5 +70,16 @@ template<typename T>
 inline bool operator!=(const MallocAllocator<T>&, const MallocAllocator<T>&) {
   return false;
 }
+} // End llvm namespace
+
+namespace std {
+  template<typename Type, typename Type2>
+  struct _Alloc_traits<Type, ::llvm::MallocAllocator<Type2> > {
+    static const bool _S_instanceless = true;
+    typedef ::llvm::MallocAllocator<Type> base_alloc_type;
+    typedef ::llvm::MallocAllocator<Type> _Alloc_type;
+    typedef ::llvm::MallocAllocator<Type> allocator_type;
+  };
+}
 
 #endif