全部代码
#pragma once
#include "alloc.h"
namespace tinySTL {
template <typename T, typename Alloc>
class allocator {
public:
using value_type = T;
using pointer = T*;
using const_pointer = const T*;
using reference = T&;
using const_reference = const T&;
using size_type = size_t;
using difference_type = ptrdiff_t;
public:
static pointer allocate();
static pointer allocate(size_type n);
static void deallocate(pointer ptr);
static void deallocate(pointer ptr, size_type n);
};
template <typename T, typename Alloc>
T* allocator<T, Alloc>::allocate() {
return static_cast<T*>(Alloc::allocate(sizeof(T)));
}
template<typename T, typename Alloc>
T* allocator<T, Alloc>::allocate(size_type n) {
return static_cast<T*>(Alloc::allocate(sizeof(T) * n));
}
template<typename T, typena