I have written a list-like template class sll (Single Linked List). Now, I am trying to plugin an allocator to it. I have the default allocator, allocator, and a pool based allocator, pool_allocator. These are designed after STL allocator interface, but I need to add the number of elements that the allocator would handle (the max_size) as a template parameter. So, I have done the following.
enum {Default_1 = 16}; // for example
template <typename T, size_t N = Default_1>
struct allocator {
};
enum {Default_2 = 32}; // for example
template <typename T, size_t N = Default_2>
struct pool_allocator {
};
I want to support two kinds if usage by the client:
1. sll<int> == implying ==> sll<int, allocator<int, Default_1> >
2. sll<int, pool_allocator<int, 4096> >
The difficulty I am having is specifying the default allocator in the sll template class. Initially I had
template<typename T, typename Allocator = allocator<T> > class sll { ...};
It works, but the problem is, user can;t specify the capacity of the allocator.
I tried
template<typename T,
typename Allocator = allocator< typename T, size_t N = Default_3> >
class sll { ... };
but I receive the error:
error: template argument 1 is invalid
I tried few other combinations, but none of them worked. At this point, I am out of ideas, and looking for help from the SO community. Any suggestions or pointers are appreciated.
You have to write: