Boost logo

Boost :

From: Armin (armins_post_at_[hidden])
Date: 2008-06-05 16:19:22


Hello,

excuse me, I am not sure whether this hasn't already been discussed or
noted elsewhere, but aren't the allocator classes "pool_allocator<T,..>"
and "fast_pool_allocator<T,..>" missing a template specialisation for
T=void?

In section 20.4.1 [lib.default.allocator] of the C++ standard 1998 the
following specialisation is defined for class std::allocator:

<code>
template <class T> class allocator;
// specialize for void:
template <> class allocator<void> {
public:
   typedef void* pointer;
   typedef const void* const_pointer;
   // reference-to-void members are impossible.
   typedef void value_type;
   template <class U> struct rebind { typedef allocator<U> other; };
};
</code>

The library boost::multi_index, e.g., currently uses the
std::allocator<void> notation.

In order to use the pool allocators with multi_index_container I would
suggest the following additions (or something similar) to pool_alloc.hpp:

<code>
   template<
     typename UserAllocator,
     typename Mutex,
     unsigned NextSize>
   class pool_allocator<void, UserAllocator, Mutex, NextSize> {
   public:
     typedef void* pointer;
     typedef const void* const_pointer;
     typedef void value_type;
     template <class U> struct rebind {
         typedef pool_allocator<U, UserAllocator, Mutex, NextSize> other;
     };
   };

   template<
     typename UserAllocator,
     typename Mutex,
     unsigned NextSize>
   class fast_pool_allocator<void, UserAllocator, Mutex, NextSize> {
   public:
     typedef void* pointer;
     typedef const void* const_pointer;
     typedef void value_type;
     template <class U> struct rebind {
         typedef fast_pool_allocator<
                U, UserAllocator, Mutex, NextSize> other;
     };
   };
</code>

Best regards
Armin


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk