Skip to content

Commit

Permalink
Add more function to make it confirm to the standard implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
dhruvbird committed Jul 25, 2012
1 parent 0463f47 commit df65b12
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 7 deletions.
24 changes: 23 additions & 1 deletion bitmap_allocator.h
Expand Up @@ -359,11 +359,23 @@ namespace __gnu_cxx {
void
destroy(pointer __p) { __p->~T(); }

bitmap_allocator() throw() { }
bitmap_allocator() throw() { }

bitmap_allocator(const bitmap_allocator&) throw() { }

template<typename T1>
bitmap_allocator(const bitmap_allocator<T1>&) throw() { }

pointer
address(reference __x) const { return std::__addressof(__x); }

const_pointer
address(const_reference __x) const { return std::__addressof(__x); }

size_type
max_size() const throw()
{ return size_t(-1) / sizeof(T); }

T* allocate(size_t nobjs, const void* = 0) {
return reinterpret_cast<T*>(this->impl.allocate(nobjs));
}
Expand All @@ -376,6 +388,16 @@ namespace __gnu_cxx {
template <typename T>
alloc_impl<sizeof(T)> bitmap_allocator<T>::impl;

template<typename T>
inline bool
operator==(const bitmap_allocator<T>&, const bitmap_allocator<T>&)
{ return true; }

template<typename T>
inline bool
operator!=(const bitmap_allocator<T>&, const bitmap_allocator<T>&)
{ return false; }

}

#endif // BITMAP_ALLOCATOR_H
12 changes: 6 additions & 6 deletions test.cpp
Expand Up @@ -16,8 +16,8 @@ std::vector<int*> vpi;
std::vector<int> numbers;

void test_list(int n) {
typedef bitmap_allocator<int> alloc_t;
// typedef std::allocator<int> alloc_t;
typedef bitmap_allocator<int> alloc_t;
// typedef std::allocator<int> alloc_t;
typedef std::list<int, alloc_t> list_t;
list_t il;

Expand All @@ -29,8 +29,8 @@ void test_list(int n) {
}

void test_alloc(int n) {
bitmap_allocator<int> ia;
// std::allocator<int> ia;
bitmap_allocator<int> ia;
// std::allocator<int> ia;

for (int i = 0; i < n-1; ++i) {
vpi.push_back(ia.allocate(1));
Expand All @@ -54,8 +54,8 @@ main() {
}

for (int i = 0; i < 24; ++i) {
// test_alloc(1<<i);
test_list(1<<i);
test_alloc(1<<i);
// test_list(1<<i);
}
// sleep(50);
}

0 comments on commit df65b12

Please sign in to comment.