#include "min_allocator.h"
#ifndef TEST_HAS_NO_EXCEPTIONS
-template <class T>
struct alloc_imp {
bool active;
alloc_imp() : active(true) {}
+ template <class T>
T* allocate(std::size_t n)
{
if (active)
throw std::bad_alloc();
}
+ template <class T>
void deallocate(T* p, std::size_t) { std::free(p); }
void activate () { active = true; }
void deactivate() { active = false; }
typedef T value_type;
typedef std::true_type propagate_on_container_copy_assignment;
- alloc_imp<T> *imp;
+ alloc_imp *imp;
- poca_alloc(alloc_imp<T> *imp_) : imp (imp_) {}
+ poca_alloc(alloc_imp *imp_) : imp (imp_) {}
template <class U>
poca_alloc(const poca_alloc<U>& other) : imp(other.imp) {}
- T* allocate (std::size_t n) { return imp->allocate(n);}
+ T* allocate (std::size_t n) { return imp->allocate<T>(n);}
void deallocate(T* p, std::size_t n) { imp->deallocate(p, n); }
};
const char * p1 = "This is my first string";
const char * p2 = "This is my second string";
- alloc_imp<char> imp1;
- alloc_imp<char> imp2;
+ alloc_imp imp1;
+ alloc_imp imp2;
S s1(p1, A(&imp1));
S s2(p2, A(&imp2));