-//===-- 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;
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();
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