M
mar00ned
Hi,
I have a written a custom allocator for STL, on the lines of default
allocator as follows :
template <class T>
class pool_allocator
{
public:
typedef size_t size_type;
typedef ptrdiff_t difference_type;
typedef T* pointer;
typedef const T* const_pointer;
typedef T& reference;
typedef const T& const_reference;
typedef T value_type;
template <class U>
struct rebind { typedef pool_allocator<U> other; };
pointer address(reference x) const {return &x;}
const_pointer address(const_reference x) const {return &x;}
pool_allocator(){}
pool_allocator(const pool_allocator&) {}
template <class U>
pool_allocator (const pool_allocator<U>&) {}
~pool_allocator(){}
size_type max_size() const throw() {return size_t(-1) /
sizeof(value_type);}
pointer allocate(size_type size, const void* hint = 0)
return static_cast<pointer>(mem_.allocate(size*sizeof(T)));
}
void construct(pointer p, const T& val)
{
new(static_cast<void*>(p)) T(val);
}
void construct(pointer p)
{
new(static_cast<void*>(p)) T();
}
void destroy(pointer p){p->~T();}
void destroy(char* ){}
void destroy(void* ){}
void deallocate(pointer p, size_type n)
{
mem_.deallocate(p, n);
}
void deallocate(void *p, size_type n)
{
mem_.deallocate(p, n);
}
void deallocate(pointer p)
{
mem_.deallocate(p);
}
void deallocate(void *p)
{
mem_.deallocate(p);
}
static void dump(){
mem_.dump();
}
private:
static pool mem_;
};
//template <class T> pool pool_allocator<T>::mem_;
template <class T, class U>
inline bool operator==(const pool_allocator<T>&, const
pool_allocator<U>){return true;}
template <class T, class U>
inline bool operator!=(const pool_allocator<T>&, const
pool_allocator<U>){return false;}
I do a simple thing like : map<int, float, less<int>,
pool_allocator<pair<int, float> > > m;
I try to build it on HPUX using aCC (aCC: HP ANSI C++ B3910B A.03.39
). But unfortunately, I am facing following errors :
Error 874: "/opt/aCC/include/memory", line 529 # A non-void type is
required for specialization instead of 'void' since the template
creates a reference to that type.
typedef T& reference;
^^^^^^^^^
Error 874: "/opt/aCC/include/memory", line 530 # A non-void type is
required for specialization instead of 'void' since the template
creates a reference to that type.
typedef const T& const_reference;
^^^^^^^^^^^^^^^
Error 874: "/opt/aCC/include/memory", line 546 # A non-void type is
required for specialization instead of 'void' since the template
creates a reference to that type.
pointer address (T& x)
^^^^^^^
Error 874: "/opt/aCC/include/memory", line 546 # A non-void type is
required for specialization instead of 'void' since the template
creates a reference to that type.
pointer address (T& x)
^^^^^^^
Error 874: "/opt/aCC/include/memory", line 595 # A non-void type is
required for specialization instead of 'void' since the template
creates a reference to that type.
allocator_interface<Allocator,T>::construct(pointer p, const T&
val)
^^^^^^^^^
Error 874: "/opt/aCC/include/memory", line 595 # A non-void type is
required for specialization instead of 'void' since the template
creates a reference to that type.
allocator_interface<Allocator,T>::construct(pointer p, const T&
val)
I am not very good at this ... any reasons why this could be happening
?
~mar00ned
I have a written a custom allocator for STL, on the lines of default
allocator as follows :
template <class T>
class pool_allocator
{
public:
typedef size_t size_type;
typedef ptrdiff_t difference_type;
typedef T* pointer;
typedef const T* const_pointer;
typedef T& reference;
typedef const T& const_reference;
typedef T value_type;
template <class U>
struct rebind { typedef pool_allocator<U> other; };
pointer address(reference x) const {return &x;}
const_pointer address(const_reference x) const {return &x;}
pool_allocator(){}
pool_allocator(const pool_allocator&) {}
template <class U>
pool_allocator (const pool_allocator<U>&) {}
~pool_allocator(){}
size_type max_size() const throw() {return size_t(-1) /
sizeof(value_type);}
pointer allocate(size_type size, const void* hint = 0)
return static_cast<pointer>(mem_.allocate(size*sizeof(T)));
}
void construct(pointer p, const T& val)
{
new(static_cast<void*>(p)) T(val);
}
void construct(pointer p)
{
new(static_cast<void*>(p)) T();
}
void destroy(pointer p){p->~T();}
void destroy(char* ){}
void destroy(void* ){}
void deallocate(pointer p, size_type n)
{
mem_.deallocate(p, n);
}
void deallocate(void *p, size_type n)
{
mem_.deallocate(p, n);
}
void deallocate(pointer p)
{
mem_.deallocate(p);
}
void deallocate(void *p)
{
mem_.deallocate(p);
}
static void dump(){
mem_.dump();
}
private:
static pool mem_;
};
//template <class T> pool pool_allocator<T>::mem_;
template <class T, class U>
inline bool operator==(const pool_allocator<T>&, const
pool_allocator<U>){return true;}
template <class T, class U>
inline bool operator!=(const pool_allocator<T>&, const
pool_allocator<U>){return false;}
I do a simple thing like : map<int, float, less<int>,
pool_allocator<pair<int, float> > > m;
I try to build it on HPUX using aCC (aCC: HP ANSI C++ B3910B A.03.39
). But unfortunately, I am facing following errors :
Error 874: "/opt/aCC/include/memory", line 529 # A non-void type is
required for specialization instead of 'void' since the template
creates a reference to that type.
typedef T& reference;
^^^^^^^^^
Error 874: "/opt/aCC/include/memory", line 530 # A non-void type is
required for specialization instead of 'void' since the template
creates a reference to that type.
typedef const T& const_reference;
^^^^^^^^^^^^^^^
Error 874: "/opt/aCC/include/memory", line 546 # A non-void type is
required for specialization instead of 'void' since the template
creates a reference to that type.
pointer address (T& x)
^^^^^^^
Error 874: "/opt/aCC/include/memory", line 546 # A non-void type is
required for specialization instead of 'void' since the template
creates a reference to that type.
pointer address (T& x)
^^^^^^^
Error 874: "/opt/aCC/include/memory", line 595 # A non-void type is
required for specialization instead of 'void' since the template
creates a reference to that type.
allocator_interface<Allocator,T>::construct(pointer p, const T&
val)
^^^^^^^^^
Error 874: "/opt/aCC/include/memory", line 595 # A non-void type is
required for specialization instead of 'void' since the template
creates a reference to that type.
allocator_interface<Allocator,T>::construct(pointer p, const T&
val)
I am not very good at this ... any reasons why this could be happening
?
~mar00ned