}
// Derive an allocator from CacheAlloc:
template <class T>
-class Allocator : public CacheAlloc<T>
+class Alloc : public CacheAlloc<T>
{
public:
template <class U>
struct rebind
{
- typedef Allocator<U> other;
+ typedef Alloc<U> other;
};
using CacheAlloc<T>::lru;
- Allocator();
+ Alloc();
};
{
public:
typedef int ValueType;
- vector<ValueType, Allocator<ValueType>> data;
+ vector<ValueType, Alloc<ValueType>> data;
};
// Instantiate a cache, as soon as we know the Item type:
// Implement the allocator constructor AFTER we have a cache object
// to point to and the implementation of our base CacheAlloc:
template <class T>
-Allocator<T>::Allocator()
+Alloc<T>::Alloc()
{
lru = &cache;
}
};
typedef LruCacheSharedMemcap<string, Item, hash<string>> CacheType;
-CacheType cache(100);
+CacheType cache1(100);
CacheType cache2(100);
template <class T>
Allocator<T>::Allocator()
{
- lru = &cache;
+ lru = &cache1;
}
{
//declare a list with allocator cache
std::list<string, Allocator<string>> test_list;
- CHECK(test_list.get_allocator().get_lru() == &cache);
+ CHECK(test_list.get_allocator().get_lru() == &cache1);
//update cache interface of test_list to cache_2
update_allocator(test_list, &cache2);
CHECK(test_list.get_allocator().get_lru() == &cache2);